. **/ class CSvgGraphLine extends CSvgPath { public const ZBX_STYLE_CLASS = 'svg-graph-line'; public const ZBX_STYLE_LINE_AUXILIARY = 'svg-graph-line-auxiliary'; protected $path; protected $itemid; protected $item_name; protected $units; protected $host; protected $add_labels; protected $options; public function __construct(array $path, array $metric, bool $add_labels = true) { parent::__construct(); $this->add_labels = $add_labels; $this->path = $path; $this->itemid = $metric['itemid']; $this->item_name = $metric['name']; $this->units = $metric['units']; $this->host = $metric['host']; $this->options = $metric['options'] + [ 'transparency' => CSvgGraph::SVG_GRAPH_DEFAULT_TRANSPARENCY, 'width' => CSvgGraph::SVG_GRAPH_DEFAULT_LINE_WIDTH, 'color' => CSvgGraph::SVG_GRAPH_DEFAULT_COLOR, 'type' => SVG_GRAPH_TYPE_LINE, 'order' => 1 ]; } protected function draw(): void { if (count($this->path) > 1) { $last_point = [0, 0]; foreach ($this->path as $index => $point) { if ($index == 0) { $this->moveTo($point[0], $point[1]); } else { if ($this->options['type'] == SVG_GRAPH_TYPE_STAIRCASE) { $this->lineTo($point[0], $last_point[1]); } $this->lineTo($point[0], $point[1]); } $last_point = $point; } } } public function toString($destroy = true): string { if ($this->path) { if ($this->add_labels) { // Create a label for each point, including stacked graph blank "points". $line_values = implode(',', array_map(static function ($point): string { return $point[2]; }, $this->path)); $this->setAttribute('label', $line_values); } $this->draw(); } return parent::toString($destroy); } }