PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.2.0
GiveWP – Donation Plugin and Fundraising Platform v2.2.0
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / libraries / googlechartlib / markers / GoogleChartTextMarker.php
give / includes / libraries / googlechartlib / markers Last commit date
GoogleChartCandlestickMarker.php 8 years ago GoogleChartLineMarker.php 8 years ago GoogleChartRangeMarker.php 8 years ago GoogleChartShapeMarker.php 8 years ago GoogleChartTextMarker.php 8 years ago
GoogleChartTextMarker.php
291 lines
1 <?php
2
3 /** @file
4 * This file is part of Google Chart PHP library.
5 *
6 * Copyright (c) 2010 Rémi Lanvin <remi@cloudconnected.fr>
7 *
8 * Licensed under the MIT license.
9 *
10 * For the full copyright and license information, please view the LICENSE file.
11 */
12
13 require_once dirname(__FILE__).'/../GoogleChartMarker.php';
14
15 /**
16 * A Text marker.
17 *
18 * This class implement Text and Data Value Markers feature (@c chm).
19 *
20 * @par Example with value marker
21 * @include marker_text_value.php
22 *
23 * @par Example with text marker
24 * @include marker_text_text.php
25 *
26 * @see GoogleChartMarker
27 * @see http://code.google.com/apis/chart/docs/chart_params.html#gcharts_data_point_labels
28 */
29 class GoogleChartTextMarker extends GoogleChartMarker
30 {
31 const FLAG = 'f';
32 const TEXT = 't';
33 const ANNOTATION = 'A';
34 const VALUE = 'N';
35
36 const LEFT = 'r';
37 const CENTER = 'h';
38 const RIGHT = 'l';
39
40 const TOP = 'b';
41 const MIDDLE = 'v';
42 const BOTTOM = 't';
43
44 const BAR_BASE = 's';
45 const BAR_CENTER = 'c';
46 const BAR_TOP = 'e';
47
48 protected $marker_type = null;
49
50 protected $points = null;
51 protected $position = null;
52 protected $size = 10;
53 protected $placement = null;
54 protected $text = null;
55
56 protected $bar_sum = false;
57
58 /**
59 * Create a new text marker.
60 *
61 * @param $marker_type (enum)
62 * One of the text marker type. The library provides a set of constant for
63 * currently implemented text marker. However, this parameter is not checked
64 * so it is open for other values the API may add in the future.
65 * - GoogleChartTextMarker::FLAG
66 * - GoogleChartTextMarker::TEXT
67 * - GoogleChartTextMarker::ANNOTATION
68 * - GoogleChartTextMarker::VALUE
69 *
70 * @param $text (string)
71 * For FLAG, TEXT and ANNOTATION markers, specify the text to be displayed.
72 * Ignored for VALUE marker.
73 */
74 public function __construct($marker_type = self::VALUE, $text = null)
75 {
76 $this->marker_type = $marker_type;
77 $this->text = $text;
78 }
79
80 /**
81 * Set the text for FLAG, TEXT and ANNOTATION markers.
82 *
83 * @param $text (string)
84 * @return $this
85 */
86 public function setText($text)
87 {
88 $this->text = $text;
89 return $this;
90 }
91
92 /**
93 * @name Position
94 * Thoses functions are mutually exclusive (if you call more than one of them,
95 * only the last one will be remembered).
96 */
97 //@{
98 /**
99 * Displays the marker at a fixed position (@c x:y format).
100 *
101 * When a marker has a fixed position, you MUST NOT associate it to a data
102 * serie (with setData()). Otherwise, the fixed position will be ignored.
103 *
104 * @note Fixed position is not supported for VALUE markers.
105 */
106 public function setFixedPosition($x, $y)
107 {
108 if ( $x < 0 || $x > 1 || ! is_numeric($x) )
109 throw new InvalidArgumentException('Invalid x position (must be between 0 and 1)');
110 if ( $y < 0 || $y > 1 || ! is_numeric($y) )
111 throw new InvalidArgumentException('Invalid y position (must be between 0 and 1)');
112
113 if ( $this->marker_type === self::VALUE )
114 throw new LogicException('Fixed position is not supported for VALUE marker.');
115
116 $this->position = array(
117 'x' => $x,
118 'y' => $y
119 );
120 return $this;
121 }
122
123 /**
124 * Displays only the selected point (@c n.d format).
125 *
126 * @param $point (int) The index of the point to display (0 based) in the data serie
127 * @return $this
128 */
129 public function setPoint($point)
130 {
131 $this->points = $point;
132 return $this;
133 }
134
135 /**
136 * Displays a range of points (@c start:end:n or @c -n format).
137 *
138 * @return $this
139 */
140 public function setPoints($start = null, $end = null, $step = null)
141 {
142 if ( $this->points['start'] === null && $this->points['end'] === null && $this->points['step'] === null ) {
143 $this->points = null;
144 }
145
146 $this->points = array(
147 'start' => $start,
148 'end' => $end,
149 'step' => $step
150 );
151 return $this;
152 }
153
154 /**
155 * Displays every nth points (@c -n format).
156 *
157 * @return $this
158 */
159 public function setStep($step)
160 {
161 $this->points = array(
162 'start' => null,
163 'end' => null,
164 'step' => $step
165 );
166 return $this;
167 }
168 //@}
169
170 /**
171 * Set the size.
172 *
173 * @param $size (int)
174 * @return $this
175 */
176 public function setSize($size)
177 {
178 $this->size = $size;
179 return $this;
180 }
181
182 public function setPlacement($horizontal_placement = null, $vertical_placement = null,
183 $horizontal_offset = null, $vertical_offset = null, $bar_relative_placement = null)
184 {
185 $this->placement = array(
186 'horizontal_placement' => $horizontal_placement,
187 'vertical_placement' => $vertical_placement,
188 'horizontal_offset' => $horizontal_offset,
189 'vertical_offset' => $vertical_offset,
190 'bar_relative_placement' => $bar_relative_placement
191 );
192 return $this;
193 }
194
195 public function getPlacement($bar_chart = false)
196 {
197 $str = '';
198
199 $str .= $this->placement['horizontal_placement'].$this->placement['vertical_placement'];
200
201 if ( $bar_chart ) {
202 $str .= $this->placement['bar_relative_placement'];
203 }
204
205 $str .= ':'.$this->placement['horizontal_offset'].':'.$this->placement['vertical_offset'];
206 $str = trim($str,':');
207 return $str;
208 }
209
210 public function setBarSum($sum)
211 {
212 $this->bar_sum = (bool) $sum;
213 return $this;
214 }
215
216 /**
217 * Compute the parameter value.
218 *
219 * @note For internal use only.
220 * @param $index (int) index of the data serie.
221 * @return string
222 */
223 public function compute($index, $chart_type = null)
224 {
225 if ( $chart_type[0] == 'b' && $this->bar_sum ) {
226 $index = -1;
227 }
228
229 if ( $index === null ) {
230 if ( $this->position === null ) {
231 throw new LogicException('Text marker requires one data serie or requires to have a fixed position.');
232 }
233
234 // Fixed position marker (x:y format)
235 $str = '@';
236 $points = $this->position['x'].':'.$this->position['y'];
237 }
238 else {
239 $str = '';
240 // Default = all (-1 format)
241 if ( $this->points === null ) {
242 $points = '-1';
243 }
244 // Only one point (n.d format)
245 elseif ( ! is_array($this->points) ) {
246 $points = number_format($this->points,1);
247 }
248 // Step only (-n format)
249 elseif ( $this->points['start'] === null && $this->points['end'] === null ) {
250 $points = '-'.$this->points['step'];
251 }
252 // Serie (start:end:n)
253 else {
254 $points = $this->points['start'].':'.$this->points['end'].':'.$this->points['step'];
255 }
256 }
257
258 $str .= $this->marker_type;
259 if ( $this->marker_type === self::VALUE ) {
260
261 }
262 else {
263 $str .= str_replace(',','\,',$this->text);
264 }
265
266 $str .= sprintf(
267 ',%s,%d,%s,%s',
268 $this->color,
269 $index,
270 $points,
271 $this->size
272 );
273
274 if ( $this->z_order !== null ) {
275 $str .= ','.$this->z_order;
276 }
277
278 if ( $this->placement !== null ) {
279 $tmp = $this->getPlacement($chart_type !== null && $chart_type[0] === 'b');
280 if ( $tmp ) {
281 if ( $this->z_order === null ) {
282 $str .= ','; // Add an empty z-order
283 }
284
285 $str .= ','.$tmp;
286 }
287 }
288 return $str;
289 }
290 }
291