1<?php
2/*
3** Zabbix
4** Copyright (C) 2001-2021 Zabbix SIA
5**
6** This program is free software; you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation; either version 2 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19**/
20
21
22class CSvgTag extends CTag {
23
24	const ZBX_STYLE_GRAPH_DASHED = 'svg-graph-dashed';
25
26	const ZBX_STYLE_GRAPH_PROBLEMS = 'svg-graph-problems';
27	const ZBX_STYLE_GRAPH_PROBLEM_BOX = 'svg-graph-problem-box';
28	const ZBX_STYLE_GRAPH_PROBLEM_HANDLE = 'svg-graph-problem-handle';
29	const ZBX_STYLE_GRAPH_PROBLEM_ARROW = 'svg-graph-problem-arrow';
30
31	const ZBX_STYLE_GRAPH_AXIS = 'svg-graph-axis';
32	const ZBX_STYLE_GRAPH_AXIS_LEFT = 'svg-graph-axis-left';
33	const ZBX_STYLE_GRAPH_AXIS_RIGHT = 'svg-graph-axis-right';
34	const ZBX_STYLE_GRAPH_AXIS_BOTTOM = 'svg-graph-axis-bottom';
35
36	const ZBX_STYLE_GRAPH_AREA = 'svg-graph-area';
37	const ZBX_STYLE_GRAPH_GRID = 'svg-graph-grid';
38	const ZBX_STYLE_GRAPH_LINE = 'svg-graph-line';
39	const ZBX_STYLE_GRAPH_POINTS = 'svg-graph-points';
40	const ZBX_STYLE_GRAPH_BAR = 'svg-graph-bar';
41
42	const ZBX_STYLE_GRAPH_LEGEND = 'svg-graph-legend';
43	const ZBX_STYLE_GRAPH_LEGEND_SINGLE_ITEM = 'svg-single-item-graph-legend';
44	const ZBX_STYLE_GRAPH_LEGEND_TWO_ITEMS = 'svg-single-two-items-graph-legend';
45
46	const ZBX_STYLE_GRAPH_HIGHLIGHTED_VALUE = 'svg-point-highlight';
47	const ZBX_STYLE_GRAPH_HELPER = 'svg-helper';
48
49	/**
50	 * SVG styles array.
51	 */
52	protected $styles = [];
53
54	protected $width = 0;
55	protected $height = 0;
56	protected $x = 0;
57	protected $y = 0;
58
59	public function __construct($tag) {
60		parent::__construct($tag, true);
61	}
62
63	public function makeStyles() {
64		return $this->styles;
65	}
66
67	/**
68	 * Add child item with styles.
69	 *
70	 * @param string|array|CSvgTag    Child item.
71	 *
72	 * @return CSvgTag
73	 */
74	public function addItem($value) {
75		if ($value instanceof CSvgTag) {
76			$this->styles = $value->makeStyles() + $this->styles;
77		}
78
79		return parent::addItem($value);
80	}
81
82	/**
83	 * Set axis container size.
84	 *
85	 * @param int $width    Axis container width.
86	 * @param int $height   Axis container height.
87	 *
88	 * @return CSvgTag
89	 */
90	public function setSize($width, $height) {
91		$this->width = $width;
92		$this->height = $height;
93
94		return $this;
95	}
96
97	/**
98	 * Set axis container position.
99	 *
100	 * @param int $x        Horizontal position of container element.
101	 * @param int $y        Vertical position of container element.
102	 *
103	 * @return CSvgTag
104	 */
105	public function setPosition($x, $y) {
106		$this->x = (int) $x;
107		$this->y = (int) $y;
108
109		return $this;
110	}
111
112	public function setFillColor($color) {
113		$this->setAttribute('fill', $color);
114
115		return $this;
116	}
117
118	public function setStrokeColor($color) {
119		$this->setAttribute('stroke', $color);
120
121		return $this;
122	}
123
124	public function setStrokeWidth($width) {
125		$this->setAttribute('stroke-width', $width);
126
127		return $this;
128	}
129
130	public function setFillOpacity($opacity) {
131		$this->setAttribute('fill-opacity', $opacity);
132
133		return $this;
134	}
135
136	public function setStrokeOpacity($opacity) {
137		$this->setAttribute('stroke-opacity', $opacity);
138
139		return $this;
140	}
141}
142