Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CSvgGraphGrid.php « svg « html « classes « include « php « frontends - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c6b7d022f8b23b382266f1f170e8bee0cf8c7c23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/*
** Zabbix
** Copyright (C) 2001-2019 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/


class CSvgGraphGrid extends CSvgTag {

	protected $points_value = [];
	protected $points_time = [];

	protected $position_x = 0;
	protected $position_y = 0;

	protected $color;

	public function __construct(array $points_value, array $points_time) {
		parent::__construct('g', true);

		$this
			->setAttribute('shape-rendering', 'crispEdges')
			->addClass(CSvgTag::ZBX_STYLE_GRAPH_GRID);

		$this->points_value = $points_value;
		$this->points_time = $points_time;
	}

	public function makeStyles() {
		return [
			'.'.CSvgTag::ZBX_STYLE_GRAPH_GRID.' path' => [
				'stroke-dasharray' => '2,2',
				'stroke' => $this->color
			]
		];
	}

	public function setPosition($x, $y) {
		$this->position_x = $x;
		$this->position_y = $y;

		return $this;
	}

	/**
	 * Set color.
	 *
	 * @param string $color  Color value.
	 *
	 * @return CSvgGraphGrid
	 */
	public function setColor($color) {
		$this->color = $color;

		return $this;
	}

	public function toString($destroy = true) {
		parent::addItem($this->draw());

		return parent::toString($destroy);
	}

	protected function draw() {
		$path = (new CSvgPath());

		foreach ($this->points_time as $pos => $time) {
			if (($this->position_x + $pos) <= ($this->position_x + $this->width)) {
				$path
					->moveTo($this->position_x + $pos, $this->position_y)
					->lineTo($this->position_x + $pos, $this->position_y + $this->height);
			}
		}

		foreach ($this->points_value as $pos => $value) {
			if (($this->position_y + $this->height - $pos) <= ($this->position_y + $this->height)) {
				$path
					->moveTo($this->position_x, $this->position_y + $this->height - $pos)
					->lineTo($this->position_x + $this->width, $this->position_y + $this->height - $pos);
			}
		}

		return $path;
	}
}