legend_items = $legend_items; } public function setColumnsCount(int $columns_count): self { $this->columns_count = $columns_count; return $this; } public function getLinesCount(): int { return $this->lines_count + ($this->show_statistic ? 1 : 0); } public function setLinesCount(int $lines_count): self { $this->lines_count = $lines_count; return $this; } public function showStatistic(int $show_statistic): self { $this->show_statistic = ($show_statistic == SVG_GRAPH_LEGEND_STATISTIC_ON); return $this; } private function draw(): void { if ($this->show_statistic) { $this->addItem([ (new CDiv(_('min')))->addClass(self::ZBX_STYLE_GRAPH_LEGEND_HEADER), (new CDiv(_('avg')))->addClass(self::ZBX_STYLE_GRAPH_LEGEND_HEADER), (new CDiv(_('max')))->addClass(self::ZBX_STYLE_GRAPH_LEGEND_HEADER) ]); } foreach ($this->legend_items as $item) { // border-color is for legend element ::before pseudo element. $this->addItem( (new CDiv(new CSpan($item['name']))) ->addClass(self::ZBX_STYLE_GRAPH_LEGEND_ITEM) ->setAttribute('style', '--color: '.$item['color']) ); if ($this->show_statistic) { if (array_key_exists('units', $item)) { $this->addItem([ new CDiv(convertUnits([ 'value' => $item['min'], 'units' => $item['units'], 'convert' => ITEM_CONVERT_NO_UNITS ])), new CDiv(convertUnits([ 'value' => $item['avg'], 'units' => $item['units'], 'convert' => ITEM_CONVERT_NO_UNITS ])), new CDiv(convertUnits([ 'value' => $item['max'], 'units' => $item['units'], 'convert' => ITEM_CONVERT_NO_UNITS ])) ]); } else { $this->addItem( (new CDiv('['._('no data').']'))->addClass(self::ZBX_STYLE_GRAPH_LEGEND_NO_DATA) ); } } } } public function toString($destroy = true): string { $this ->addClass(self::ZBX_STYLE_CLASS) ->addClass($this->show_statistic ? self::ZBX_STYLE_GRAPH_LEGEND_STATISTIC : null) ->addStyle('--lines: '.$this->getLinesCount().';'); if (!$this->show_statistic) { $this->addStyle('--columns: '. min($this->columns_count, count($this->legend_items)).';'); } $this->draw(); return parent::toString($destroy); } }