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) { $line_values = ''; foreach ($this->path as $point) { $line_values .= ($line_values === '') ? $point[2] : ','.$point[2]; } $this->setAttribute('label', $line_values); } $this->draw(); } return parent::toString($destroy); } }