PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.48
E2Pdf – Export Pdf Tool for WordPress v1.32.48
1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 1.08.06 All 72 releases
e2pdf / vendors / svggraph / SVGGraphTrait.php

SVGGraphTrait.php in E2Pdf – Export Pdf Tool for WordPress 1.32.48, at vendors/svggraph/SVGGraphTrait.php

161 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Copyright (C) 2009-2019 Graham Breach
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 /**
19 * For more information, please contact <graham@goat1000.com>
20 */
21
22 namespace Goat1000\SVGGraph;
23
24 trait SVGGraphTrait {
25
26 /**
27 * Assign values, either from an array or from numeric arguments
28 */
29 public function values($values)
30 {
31 $this->values = is_array($values) ? $values : func_get_args();
32 }
33
34 /**
35 * Assign links to data items
36 */
37 public function links($links)
38 {
39 $this->links = is_array($links) ? $links : func_get_args();
40 }
41
42 /**
43 * Assign a single colour set for use across datasets
44 */
45 public function colours($colours)
46 {
47 $this->colours = new Colours($colours);
48 }
49
50 /**
51 * Sets colours for a single dataset
52 */
53 public function colourSet($dataset, $colours)
54 {
55 $this->colours->set($dataset, $colours);
56 }
57
58 /**
59 * Sets up RGB colour range
60 */
61 public function colourRangeRGB($dataset, $r1, $g1, $b1, $r2, $g2, $b2)
62 {
63 $this->colours->rangeRGB($dataset, $r1, $g1, $b1, $r2, $g2, $b2);
64 }
65
66 /**
67 * RGB colour range from hex codes
68 */
69 public function colourRangeHexRGB($dataset, $c1, $c2)
70 {
71 $this->colours->rangeHexRGB($dataset, $c1, $c2);
72 }
73
74 /**
75 * Sets up HSL colour range
76 */
77 public function colourRangeHSL($dataset, $h1, $s1, $l1, $h2, $s2, $l2,
78 $reverse = false)
79 {
80 $this->colours->rangeHSL($dataset, $h1, $s1, $l1, $h2, $s2, $l2, $reverse);
81 }
82
83 /**
84 * HSL colour range from hex codes
85 */
86 public function colourRangeHexHSL($dataset, $c1, $c2, $reverse = false)
87 {
88 $this->colours->rangeHexHSL($dataset, $c1, $c2, $reverse);
89 }
90
91 /**
92 * Sets up HSL colour range from RGB values
93 */
94 public function colourRangeRGBtoHSL($dataset, $r1, $g1, $b1, $r2, $g2, $b2,
95 $reverse = false)
96 {
97 $this->colours->rangeRGBtoHSL($dataset, $r1, $g1, $b1, $r2, $g2, $b2,
98 $reverse);
99 }
100
101 /**
102 * Instantiate the correct class
103 */
104 private function setup($class)
105 {
106 if(!strstr($class, '\\')) {
107 $class = __NAMESPACE__ . '\\' . $class;
108 }
109
110 if(!class_exists($class)) {
111 throw new \InvalidArgumentException('Unknown graph type: ' . $class);
112 }
113
114 if(!is_subclass_of($class, '\\Goat1000\\SVGGraph\\Graph')) {
115 throw new \InvalidArgumentException('Not a graph class: ' . $class);
116 }
117
118 $g = new $class($this->width, $this->height, $this->settings);
119 $g->subgraph = $this->subgraph;
120 $g->values($this->values);
121 $g->links($this->links);
122 $g->colours($this->colours);
123 $g->subgraphs($this->subgraphs);
124 return $g;
125 }
126
127 /**
128 * Returns a sub-graph
129 */
130 public function subgraph($type, $x, $y, $w, $h, $settings = null,
131 $extra = null)
132 {
133 if(!is_string($x) && $x < 0)
134 $x = $this->width + $x;
135 if(!is_string($y) && $y < 0)
136 $y = $this->height + $y;
137 if(!is_string($w) && $w <= 0)
138 $w = $this->width - $x + $w;
139 if(!is_string($h) && $h <= 0)
140 $h = $this->height - $y + $h;
141
142 if($settings === null)
143 $settings = $this->settings;
144 if(is_array($extra))
145 $settings = array_merge($settings, $extra);
146 $sg = new Subgraph($type, $x, $y, $w, $h, $settings);
147 $sg->setColours(clone $this->colours);
148 $this->subgraphs[] = $sg;
149 return $sg;
150 }
151
152 /**
153 * Replaces the list of subgraphs
154 */
155 public function setSubgraphs($list)
156 {
157 $this->subgraphs = $list;
158 }
159 }
160
161