PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.9.7
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.9.7
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
visualizer / classes / Visualizer / Render / Sidebar / Graph.php

Graph.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.9.7, at classes/Visualizer/Render/Sidebar/Graph.php

521 lines 16.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // +----------------------------------------------------------------------+
4 // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) |
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, version 2, as |
8 // | published by the Free Software Foundation. |
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 General Public License for more details. |
14 // | |
15 // | You should have received a copy of the GNU General Public License |
16 // | along with this program; if not, write to the Free Software |
17 // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
18 // | MA 02110-1301 USA |
19 // +----------------------------------------------------------------------+
20 // | Author: Eugene Manuilov <eugene@manuilov.org> |
21 // +----------------------------------------------------------------------+
22 /**
23 * Base class for sidebar settigns of graph based charts.
24 *
25 * @category Visualizer
26 * @package Render
27 * @subpackage Sidebar
28 *
29 * @since 1.0.0
30 * @abstract
31 */
32 abstract class Visualizer_Render_Sidebar_Graph extends Visualizer_Render_Sidebar_Google {
33
34 /**
35 * Determines whether we need to render vertical gridlines options or not.
36 *
37 * @since 1.0.0
38 *
39 * @access protected
40 * @var boolean
41 */
42 protected $_verticalGridLines;
43
44 /**
45 * Determines whether we need to render horizontal gridlines options or not.
46 *
47 * @since 1.0.0
48 *
49 * @access protected
50 * @var boolean
51 */
52 protected $_horizontalGridLines;
53
54 /**
55 * The array of available axis positions.
56 *
57 * @since 1.0.0
58 *
59 * @access protected
60 * @var array
61 */
62 protected $_positions;
63
64 /**
65 * Constructor.
66 *
67 * @since 1.0.0
68 *
69 * @access public
70 * @param array $data The data what has to be associated with this render.
71 */
72 public function __construct( $data = array() ) {
73 parent::__construct( $data );
74
75 $this->_verticalGridLines = true;
76 $this->_horizontalGridLines = true;
77
78 $this->_positions = array(
79 '' => '',
80 'in' => esc_html__( 'Inside the chart', 'visualizer' ),
81 'out' => esc_html__( 'Outside the chart', 'visualizer' ),
82 'none' => esc_html__( 'None', 'visualizer' ),
83 );
84 }
85
86 /**
87 * Renders chart title settings.
88 *
89 * @since 1.0.0
90 *
91 * @access protected
92 */
93 protected function _renderChartTitleSettings() {
94 self::_renderTextItem(
95 esc_html__( 'Chart Title', 'visualizer' ),
96 'title',
97 $this->title,
98 esc_html__( 'Text to display above the chart.', 'visualizer' )
99 );
100
101 self::_renderSelectItem(
102 esc_html__( 'Chart Title Position', 'visualizer' ),
103 'titlePosition',
104 $this->titlePosition,
105 $this->_positions,
106 esc_html__( 'Where to place the chart title, compared to the chart area.', 'visualizer' )
107 );
108
109 self::_renderColorPickerItem(
110 esc_html__( 'Chart Title Color', 'visualizer' ),
111 'titleTextStyle[color]',
112 isset( $this->titleTextStyle['color'] ) ? $this->titleTextStyle['color'] : null,
113 '#000'
114 );
115
116 echo '<div class="viz-section-delimiter"></div>';
117
118 self::_renderSelectItem(
119 esc_html__( 'Axes Titles Position', 'visualizer' ),
120 'axisTitlesPosition',
121 $this->axisTitlesPosition,
122 $this->_positions,
123 esc_html__( 'Determines where to place the axis titles, compared to the chart area.', 'visualizer' )
124 );
125
126 echo '<div class="viz-section-delimiter"></div>';
127
128 self::_renderTextAreaItem(
129 esc_html__( 'Chart Description', 'visualizer' ),
130 'description',
131 $this->description,
132 sprintf( esc_html__( 'Description to display in the structured data schema as explained %1$shere%2$s', 'visualizer' ), '<a href="https://developers.google.com/search/docs/data-types/dataset#dataset" target="_blank">', '</a>' )
133 );
134
135 }
136
137 /**
138 * Renders general settings block for horizontal axis settings.
139 *
140 * @since 1.4.0
141 *
142 * @access protected
143 */
144 protected function _renderHorizontalAxisGeneralSettings() {
145 self::_renderTextItem(
146 esc_html__( 'Axis Title', 'visualizer' ),
147 'hAxis[title]',
148 isset( $this->hAxis['title'] ) ? $this->hAxis['title'] : '',
149 esc_html__( 'The title of the horizontal axis.', 'visualizer' )
150 );
151
152 self::_renderSelectItem(
153 esc_html__( 'Slanted Text', 'visualizer' ),
154 'hAxis[slantedText]',
155 isset( $this->hAxis['slantedText'] ) ? $this->hAxis['slantedText'] : false,
156 array(
157 false => 'False',
158 true => 'True',
159 ),
160 '',
161 false
162 );
163
164 self::_renderTextItem(
165 esc_html__( 'Slanted Text Angle', 'visualizer' ),
166 'hAxis[slantedTextAngle]',
167 isset( $this->hAxis['slantedTextAngle'] ) ? $this->hAxis['slantedTextAngle'] : 45,
168 '',
169 45,
170 'number',
171 array(
172 'min' => 1,
173 'step' => 15,
174 )
175 );
176
177 self::_renderSelectItem(
178 esc_html__( 'Text Position', 'visualizer' ),
179 'hAxis[textPosition]',
180 isset( $this->hAxis['textPosition'] ) ? $this->hAxis['textPosition'] : '',
181 $this->_positions,
182 esc_html__( 'Position of the horizontal axis text, relative to the chart area.', 'visualizer' )
183 );
184
185 self::_renderSelectItem(
186 esc_html__( 'Direction', 'visualizer' ),
187 'hAxis[direction]',
188 isset( $this->hAxis['direction'] ) ? $this->hAxis['direction'] : '',
189 array(
190 '' => '',
191 '1' => esc_html__( 'Identical Direction', 'visualizer' ),
192 '-1' => esc_html__( 'Reverse Direction', 'visualizer' ),
193 ),
194 esc_html__( 'The direction in which the values along the horizontal axis grow.', 'visualizer' )
195 );
196
197 self::_renderColorPickerItem(
198 esc_html__( 'Base Line Color', 'visualizer' ),
199 'vAxis[baselineColor]',
200 isset( $this->vAxis['baselineColor'] ) ? $this->vAxis['baselineColor'] : null,
201 '#000'
202 );
203 }
204
205 /**
206 * Renders horizontal axis settings.
207 *
208 * @since 1.2.0
209 *
210 * @access protected
211 */
212 protected function _renderHorizontalAxisSettings() {
213 self::_renderGroupStart( esc_html__( 'Horizontal Axis Settings', 'visualizer' ) );
214 self::_renderSectionStart( esc_html__( 'General Settings', 'visualizer' ), false );
215 $this->_renderHorizontalAxisGeneralSettings();
216 self::_renderSectionEnd();
217 if ( $this->_horizontalGridLines ) {
218 self::_renderSectionStart( esc_html__( 'Grid Lines', 'visualizer' ), false );
219 self::_renderTextItem(
220 esc_html__( 'Count', 'visualizer' ),
221 'hAxis[gridlines][count]',
222 isset( $this->hAxis['gridlines']['count'] ) ? $this->hAxis['gridlines']['count'] : '',
223 esc_html__( 'The approximate number of horizontal gridlines inside the chart area. You can specify a value of -1 to automatically compute the number of gridlines, 0 or 1 to draw no gridlines, or 2 or more to only draw gridline. Any number greater than 2 will be used to compute the minSpacing between gridlines.', 'visualizer' ),
224 5,
225 'number',
226 array( 'min' => -1, 'max' => 1000, 'step' => 1 )
227 );
228
229 self::_renderColorPickerItem(
230 esc_html__( 'Color', 'visualizer' ),
231 'hAxis[gridlines][color]',
232 isset( $this->hAxis['gridlines']['color'] ) ? $this->hAxis['gridlines']['color'] : null,
233 '#ccc'
234 );
235 self::_renderSectionEnd();
236
237 self::_renderSectionStart( esc_html__( 'Minor Grid Lines', 'visualizer' ), false );
238 self::_renderTextItem(
239 esc_html__( 'Count', 'visualizer' ),
240 'hAxis[minorGridlines][count]',
241 isset( $this->hAxis['minorGridlines']['count'] ) ? $this->hAxis['minorGridlines']['count'] : '',
242 esc_html__( 'Specify 0 to disable the minor gridlines.', 'visualizer' ),
243 0,
244 'number',
245 array( 'min' => 0, 'step' => 1 )
246 );
247
248 self::_renderColorPickerItem(
249 esc_html__( 'Color', 'visualizer' ),
250 'hAxis[minorGridlines][color]',
251 isset( $this->hAxis['minorGridlines']['color'] ) ? $this->hAxis['minorGridlines']['color'] : null,
252 null
253 );
254 self::_renderSectionEnd();
255 }
256
257 if ( $this->_horizontalGridLines ) {
258 self::_renderSectionStart( esc_html__( 'View Window', 'visualizer' ), false );
259 self::_renderTextItem(
260 esc_html__( 'Maximum Value', 'visualizer' ),
261 'hAxis[viewWindow][max]',
262 isset( $this->hAxis['viewWindow']['max'] ) ? $this->hAxis['viewWindow']['max'] : '',
263 'The maximum vertical data value to render.'
264 );
265
266 self::_renderTextItem(
267 esc_html__( 'Minimum Value', 'visualizer' ),
268 'hAxis[viewWindow][min]',
269 isset( $this->hAxis['viewWindow']['min'] ) ? $this->hAxis['viewWindow']['min'] : '',
270 'The minimum vertical data value to render.'
271 );
272 self::_renderSectionEnd();
273 }
274 self::_renderGroupEnd();
275 }
276
277 /**
278 * Renders general settings block for vertical axis settings.
279 *
280 * @since 1.4.0
281 *
282 * @access protected
283 */
284 protected function _renderVerticalAxisGeneralSettings() {
285 self::_renderTextItem(
286 esc_html__( 'Axis Title', 'visualizer' ),
287 'vAxis[title]',
288 isset( $this->vAxis['title'] ) ? $this->vAxis['title'] : '',
289 esc_html__( 'The title of the vertical axis.', 'visualizer' )
290 );
291
292 self::_renderSelectItem(
293 esc_html__( 'Text Position', 'visualizer' ),
294 'vAxis[textPosition]',
295 isset( $this->vAxis['textPosition'] ) ? $this->vAxis['textPosition'] : '',
296 $this->_positions,
297 esc_html__( 'Position of the vertical axis text, relative to the chart area.', 'visualizer' )
298 );
299
300 self::_renderSelectItem(
301 esc_html__( 'Direction', 'visualizer' ),
302 'vAxis[direction]',
303 isset( $this->vAxis['direction'] ) ? $this->vAxis['direction'] : '',
304 array(
305 '' => '',
306 '1' => esc_html__( 'Identical Direction', 'visualizer' ),
307 '-1' => esc_html__( 'Reverse Direction', 'visualizer' ),
308 ),
309 esc_html__( 'The direction in which the values along the vertical axis grow.', 'visualizer' )
310 );
311
312 self::_renderColorPickerItem(
313 esc_html__( 'Base Line Color', 'visualizer' ),
314 'hAxis[baselineColor]',
315 isset( $this->hAxis['baselineColor'] ) ? $this->hAxis['baselineColor'] : null,
316 '#000'
317 );
318 }
319
320 /**
321 * Renders vertical axis settings.
322 *
323 * @since 1.2.0
324 *
325 * @access protected
326 */
327 protected function _renderVerticalAxisSettings() {
328 self::_renderGroupStart( esc_html__( 'Vertical Axis Settings', 'visualizer' ) );
329 self::_renderSectionStart( esc_html__( 'General Settings', 'visualizer' ), false );
330 $this->_renderVerticalAxisGeneralSettings();
331 self::_renderSectionEnd();
332
333 if ( $this->_verticalGridLines ) {
334 self::_renderSectionStart( esc_html__( 'Grid Lines', 'visualizer' ), false );
335 self::_renderTextItem(
336 esc_html__( 'Count', 'visualizer' ),
337 'vAxis[gridlines][count]',
338 isset( $this->vAxis['gridlines']['count'] ) ? $this->vAxis['gridlines']['count'] : '',
339 esc_html__( 'The approximate number of vertical gridlines inside the chart area. You can specify a value of -1 to automatically compute the number of gridlines, 0 or 1 to draw no gridlines, or 2 or more to only draw gridline. Any number greater than 2 will be used to compute the minSpacing between gridlines.', 'visualizer' ),
340 5,
341 'number',
342 array( 'min' => -1, 'max' => 1000, 'step' => 1 )
343 );
344
345 self::_renderColorPickerItem(
346 esc_html__( 'Color', 'visualizer' ),
347 'vAxis[gridlines][color]',
348 isset( $this->vAxis['gridlines']['color'] ) ? $this->vAxis['gridlines']['color'] : null,
349 '#ccc'
350 );
351 self::_renderSectionEnd();
352
353 self::_renderSectionStart( esc_html__( 'Minor Grid Lines', 'visualizer' ), false );
354 self::_renderTextItem(
355 esc_html__( 'Count', 'visualizer' ),
356 'vAxis[minorGridlines][count]',
357 isset( $this->vAxis['minorGridlines']['count'] ) ? $this->vAxis['minorGridlines']['count'] : '',
358 esc_html__( 'Specify 0 to disable the minor gridlines.', 'visualizer' ),
359 0,
360 'number',
361 array( 'min' => 0, 'step' => 1 )
362 );
363
364 self::_renderColorPickerItem(
365 esc_html__( 'Color', 'visualizer' ),
366 'vAxis[minorGridlines][color]',
367 isset( $this->vAxis['minorGridlines']['color'] ) ? $this->vAxis['minorGridlines']['color'] : null,
368 null
369 );
370 self::_renderSectionEnd();
371 }
372
373 if ( $this->_verticalGridLines ) {
374 self::_renderSectionStart( esc_html__( 'View Window', 'visualizer' ), false );
375 self::_renderTextItem(
376 esc_html__( 'Maximum Value', 'visualizer' ),
377 'vAxis[viewWindow][max]',
378 isset( $this->vAxis['viewWindow']['max'] ) ? $this->vAxis['viewWindow']['max'] : '',
379 'The maximum vertical data value to render.'
380 );
381
382 self::_renderTextItem(
383 esc_html__( 'Minimum Value', 'visualizer' ),
384 'vAxis[viewWindow][min]',
385 isset( $this->vAxis['viewWindow']['min'] ) ? $this->vAxis['viewWindow']['min'] : '',
386 'The minimum vertical data value to render.'
387 );
388 self::_renderSectionEnd();
389 }
390 self::_renderGroupEnd();
391 }
392
393 /**
394 * Renders chart axes settings.
395 *
396 * @since 1.0.0
397 *
398 * @access protected
399 */
400 protected function _renderAxesSettings() {
401 $this->_renderHorizontalAxisSettings();
402 $this->_renderVerticalAxisSettings();
403 }
404
405 /**
406 * Renders series settings group.
407 *
408 * @since 1.0.0
409 *
410 * @access protected
411 */
412 protected function _renderSeriesSettings() {
413 self::_renderGroupStart( esc_html__( 'Series Settings', 'visualizer' ) );
414 self::_renderSectionStart();
415 self::_renderSectionDescription( esc_html__( 'If you have just updated/modified the chart data, you may need to save it before the new data reflects in the settings.', 'visualizer' ), 'viz-info-msg' );
416 self::_renderSectionEnd();
417
418 for ( $i = 1, $cnt = count( $this->__series ); $i < $cnt; $i++ ) {
419 if ( ! empty( $this->__series[ $i ]['label'] ) ) {
420 self::_renderSectionStart( esc_html( $this->__series[ $i ]['label'] ), false );
421 $this->_renderSeries( $i - 1 );
422 self::_renderSectionEnd();
423 }
424 }
425 self::_renderGroupEnd();
426 }
427
428 /**
429 * Renders concreate series settings.
430 *
431 * @since 1.0.0
432 *
433 * @access protected
434 * @param int $index The series index.
435 */
436 protected function _renderSeries( $index ) {
437 self::_renderSelectItem(
438 esc_html__( 'Visible In Legend', 'visualizer' ),
439 'series[' . $index . '][visibleInLegend]',
440 isset( $this->series[ $index ]['visibleInLegend'] ) ? $this->series[ $index ]['visibleInLegend'] : '',
441 array(
442 '' => '',
443 '0' => esc_html__( 'No', 'visualizer' ),
444 '1' => esc_html__( 'Yes', 'visualizer' ),
445 ),
446 esc_html__( 'Determines whether the series has to be presented in the legend or not.', 'visualizer' )
447 );
448
449 $this->_renderFormatField( $index );
450
451 self::_renderColorPickerItem(
452 esc_html__( 'Color', 'visualizer' ),
453 'series[' . $index . '][color]',
454 isset( $this->series[ $index ]['color'] ) ? $this->series[ $index ]['color'] : null,
455 null
456 );
457
458 $this->_renderRoleField( $index );
459
460 }
461
462 /**
463 * Renders format field for horizontal axis.
464 *
465 * @since 1.4.3
466 *
467 * @access protected
468 */
469 protected function _renderHorizontalAxisFormatField() {
470 self::_renderTextItem(
471 esc_html__( 'Number Format', 'visualizer' ),
472 'hAxis[format]',
473 isset( $this->hAxis['format'] ) ? $this->hAxis['format'] : '',
474 sprintf(
475 '%s<br><br>%s<br><br>%s',
476 esc_html__( 'Enter custom format pattern to apply to horizontal axis labels.', 'visualizer' ),
477 sprintf(
478 esc_html__( 'For number axis labels, this is a subset of the decimal formatting %1$sICU pattern set%2$s. For instance, $#,###.## will display values $1,234.56 for value 1234.56. Pay attention that if you use #&#37;&#37; percentage format then your values will be multiplied by 100.', 'visualizer' ),
479 '<a href="http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details" target="_blank">',
480 '</a>'
481 ),
482 sprintf(
483 esc_html__( 'For date axis labels, this is a subset of the date formatting %1$sICU date and time format%2$s.', 'visualizer' ),
484 '<a href="https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax" target="_blank">',
485 '</a>'
486 )
487 )
488 );
489 }
490
491 /**
492 * Renders format field for vertical axis settings.
493 *
494 * @since 1.4.3
495 *
496 * @access protected
497 */
498 protected function _renderVerticalAxisFormatField() {
499 self::_renderTextItem(
500 esc_html__( 'Number Format', 'visualizer' ),
501 'vAxis[format]',
502 isset( $this->vAxis['format'] ) ? $this->vAxis['format'] : '',
503 sprintf(
504 '%s<br><br>%s<br><br>%s',
505 esc_html__( 'Enter custom format pattern to apply to vertical axis labels.', 'visualizer' ),
506 sprintf(
507 esc_html__( 'For number axis labels, this is a subset of the decimal formatting %1$sICU pattern set%2$s. For instance, $#,###.## will display values $1,234.56 for value 1234.56. Pay attention that if you use #&#37;&#37; percentage format then your values will be multiplied by 100.', 'visualizer' ),
508 '<a href="http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details" target="_blank">',
509 '</a>'
510 ),
511 sprintf(
512 esc_html__( 'For date axis labels, this is a subset of the date formatting %1$sICU date and time format%2$s.', 'visualizer' ),
513 '<a href="https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax" target="_blank">',
514 '</a>'
515 )
516 )
517 );
518 }
519
520 }
521