function drawValues($image, Boundary $b) { $out = $this->getValuesArea($b); if ($out->width() < $this->depth || $out->height() < $this->depth || $out->left() > $out->right() || $out->top() > $out->bottom()) { throw new ChartException("Недостаточно места для вывода значений."); } $line = new Line(new Boundary(0, 0, 0, 0), $this->values['bgcolors'][0], $this->values['thickness']); $w = ($out->width() - $this->depth) / count($this->data); $l = new Label(new Boundary(0, 0, 0, 0), '', $this->values['font'], Color::getDefault(), Label::ALIGN_CENTER_MIDDLE); $e = new Ellipse(new Boundary(0, 0, $this->values['thickness'] * 3, $this->values['thickness'] * 3)); for ($i = 0; $i < count($this->data); $i++) { $c = $out->left() + $w * $i + $w / 2.0; $line->bounds()->right($c); $line->bounds()->bottom($out->bottom() - ($this->data[$i] - $this->min) * $out->height() / ($this->max - $this->min)); $line->background($this->values['bgcolors'][$i % count($this->values['bgcolors'])]); if ($i != 0) { $line->draw($image); $e->bounds()->move(new Size($line->bounds()->left() - $this->values['thickness'] * 3 / 2, $line->bounds()->top() - $this->values['thickness'] * 3 / 2)); $e->background($this->values['bgcolors'][($i - 1) % count($this->values['bgcolors'])]); $e->draw($image); } $line->bounds()->left($line->bounds()->right()); $line->bounds()->top($line->bounds()->bottom()); if ($this->values['labels']) { $l->text($this->data[$i]); $l->bounds()->bottom($line->bounds()->top() - 5); $l->bounds()->top($l->bounds()->bottom() - $this->values['font']->getTextExtent()->height); $l->bounds()->left($line->bounds()->left()); $l->bounds()->right($line->bounds()->left()); $l->background($this->values['fgcolors'][$i % count($this->values['fgcolors'])]); $l->draw($image); } } $e->bounds()->move(new Size($line->bounds()->left() - $this->values['thickness'] * 3 / 2, $line->bounds()->top() - $this->values['thickness'] * 3 / 2)); $e->background($line->background()); $e->draw($image); }
function drawLegend($image, Boundary $b) { $out = $this->getValuesArea($b); if ($out->width() < $this->depth || $out->height() < $this->depth || $out->left() > $out->right() || $out->top() > $out->bottom()) { throw new ChartException("Недостаточно места для вывода легенды."); } $dy = $this->getD()->width; $dx = $this->getD()->height; $linedy = new Line(new Boundary(0, 0, 0, 0)); $l = new Label(new Boundary($b->left(), 0, $out->left() - $dx - 3, 0), '', $this->axis['font_y'], $this->axis['fgcolor'], Label::ALIGN_RIGHT_TOP); $surface = new Rectangle3D(new Boundary($out->left(), $out->bottom(), 0, $out->top()), $this->axis['bgcolor'], $this->axis['fgcolor'], Rectangle3D::SURFACE_LEFT | ($this->axis['y_lines'] ? Rectangle3D::SURFACE_BACK : 0), $this->depth); for ($i = 0; $i <= $this->count_y; $i++) { $y = $i * ($this->max - $this->min) / $this->count_y; $ypx = $out->height() * $y / ($this->max - $this->min); $linedy->bounds()->left($out->left() - $dy); $linedy->bounds()->right($out->left()); $linedy->bounds()->top($out->bottom() - $ypx); $linedy->bounds()->bottom($linedy->bounds()->top()); $surface->bounds()->bottom($surface->bounds()->top()); $surface->bounds()->top($linedy->bounds()->top()); $surface->bounds()->right($out->right() - $this->depth); if ($i == 0) { $surface->surfaces($surface->surfaces() | Rectangle3D::SURFACE_BOTTOM); } else { $surface->surfaces($surface->surfaces() & ~Rectangle3D::SURFACE_BOTTOM); } $surface->draw($image); $linedy->draw($image); $text = round($y + $this->min, 2); $l->bounds()->move(new Size($b->left(), $linedy->bounds()->top() - $this->axis['font_y']->getTextExtent($text)->height / 2)); $l->text($text); $l->draw($image); } $linex = new Line(new Boundary(0, 0, 0, 0), $this->axis['fgcolor']); $w = ($out->width() - $this->depth) / count($this->data); $l->font($this->axis['font_x']); $l->align(Label::ALIGN_LEFT_TOP); for ($i = 0; $i < count($this->data); $i++) { $linex->bounds()->left($out->left() + $w * $i + $w / 2.0); $linex->bounds()->top($out->bottom()); $linex->bounds()->right($linex->bounds()->left()); $linex->bounds()->bottom($linex->bounds()->top() + $dx); $linex->draw($image); if (isset($this->leg[$i])) { $l->bounds()->move(new Size($linex->bounds()->right() - $this->axis['font_x']->getTextExtent($this->leg[$i])->width / 2, $linex->bounds()->bottom())); $l->text($this->leg[$i]); $l->draw($image); } } }