PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.6
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.6
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 / Google.php

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

427 lines 16.1 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_Google extends Visualizer_Render_Sidebar {
33
34 /**
35 * The array of available legend positions.
36 *
37 * @since 1.0.0
38 *
39 * @access protected
40 * @var array
41 */
42 protected $_legendPositions;
43
44 /**
45 * The array of available alignments.
46 *
47 * @since 1.0.0
48 *
49 * @access protected
50 * @var array
51 */
52 protected $_alignments;
53
54 /**
55 * The constructor.
56 */
57 public function __construct( $data = array() ) {
58 $this->_library = 'google';
59 parent::__construct( $data );
60
61 $this->_legendPositions = array(
62 '' => '',
63 'left' => esc_html__( 'Left of the chart', 'visualizer' ),
64 'right' => esc_html__( 'Right of the chart', 'visualizer' ),
65 'top' => esc_html__( 'Above the chart', 'visualizer' ),
66 'bottom' => esc_html__( 'Below the chart', 'visualizer' ),
67 'none' => esc_html__( 'Omit the legend', 'visualizer' ),
68 );
69
70 if ( ! in_array( $this->get_chart_type( false ), array( 'Pie' ), true ) ) {
71 $this->_legendPositions['in'] = esc_html__( 'Inside the chart', 'visualizer' );
72 }
73
74 $this->_alignments = array(
75 '' => '',
76 'start' => esc_html__( 'Aligned to the start of the allocated area', 'visualizer' ),
77 'center' => esc_html__( 'Centered in the allocated area', 'visualizer' ),
78 'end' => esc_html__( 'Aligned to the end of the allocated area', 'visualizer' ),
79 );
80
81 }
82
83 /**
84 * Registers additional hooks.
85 *
86 * @access protected
87 */
88 protected function hooks() {
89 if ( $this->_library === 'google' ) {
90 add_filter( 'visualizer_assets_render', array( $this, 'load_google_assets' ), 10, 2 );
91 }
92 }
93
94 /**
95 * Loads the assets.
96 */
97 function load_google_assets( $deps, $is_frontend ) {
98 wp_register_script( 'google-jsapi', '//www.gstatic.com/charts/loader.js', array(), null, true );
99 wp_register_script(
100 'visualizer-render-google-lib',
101 VISUALIZER_ABSURL . 'js/render-google.js',
102 array(
103 'google-jsapi',
104 ),
105 Visualizer_Plugin::VERSION,
106 true
107 );
108
109 return array_merge(
110 $deps,
111 array( 'visualizer-render-google-lib' )
112 );
113
114 }
115
116 /**
117 * Enqueue assets.
118 */
119 public static function enqueue_assets( $deps = array() ) {
120 wp_enqueue_script( 'visualizer-google-jsapi', '//www.gstatic.com/charts/loader.js', array(), null, true );
121 wp_enqueue_script( 'visualizer-render-google-lib', VISUALIZER_ABSURL . 'js/render-google.js', array_merge( $deps, array( 'visualizer-google-jsapi' ) ), Visualizer_Plugin::VERSION, true );
122 return 'visualizer-render-google-lib';
123 }
124
125 /**
126 * Renders the role field.
127 *
128 * @since 3.4.0
129 *
130 * @access protected
131 */
132 protected function _renderRoleField( $index ) {
133 self::_renderSelectItem(
134 esc_html__( 'Special Role', 'visualizer' ),
135 'series[' . $index . '][role]',
136 isset( $this->series[ $index ]['role'] ) ? $this->series[ $index ]['role'] : '',
137 array(
138 '' => esc_html__( 'Default (Data)', 'visualizer' ),
139 'annotation' => esc_html__( 'Annotation', 'visualizer' ),
140 'annotationText' => esc_html__( 'Annotation Text', 'visualizer' ),
141 'certainty' => esc_html__( 'Certainty', 'visualizer' ),
142 'emphasis' => esc_html__( 'Emphasis', 'visualizer' ),
143 'scope' => esc_html__( 'Scope', 'visualizer' ),
144 'style' => esc_html__( 'Style', 'visualizer' ),
145 'tooltip' => esc_html__( 'Tooltip', 'visualizer' ),
146 ),
147 sprintf( esc_html__( 'Determines whether the series has to be used for a special role as mentioned in %1$shere%2$s. You can view a few examples %3$shere%4$s.', 'visualizer' ), '<a href="https://developers.google.com/chart/interactive/docs/roles#what-roles-are-available" target="_blank">', '</a>', '<a href="https://docs.themeisle.com/article/1160-roles-for-series-visualizer" target="_blank">', '</a>' )
148 );
149 }
150
151 /**
152 * Renders chart general settings group.
153 *
154 * @since 1.0.0
155 *
156 * @access protected
157 */
158 protected function _renderGeneralSettings() {
159 self::_renderGroupStart( esc_html__( 'General Settings', 'visualizer' ) );
160 self::_renderSectionStart();
161 self::_renderSectionDescription( esc_html__( 'Configure title, font styles, tooltip, legend and else settings for the chart.', 'visualizer' ) );
162 self::_renderSectionEnd();
163
164 self::_renderSectionStart( esc_html__( 'Title', 'visualizer' ), false );
165 $this->_renderChartTitleSettings();
166 self::_renderSectionEnd();
167
168 self::_renderSectionStart( esc_html__( 'Font Styles', 'visualizer' ), false );
169 echo '<div class="viz-section-item">';
170 echo '<a class="more-info" href="javascript:;">[?]</a>';
171 echo '<b>', esc_html__( 'Family And Size', 'visualizer' ), '</b>';
172
173 echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">';
174 echo '<tr>';
175 echo '<td class="viz-section-table-column">';
176 echo '<select name="fontName" class="control-select">';
177 echo '<option></option>';
178 foreach ( self::$_fontFamilies as $font => $label ) {
179 echo '<option value="', $font, '"', selected( $font, $this->fontName, false ), '>';
180 echo $label;
181 echo '</option>';
182 }
183 echo '</select>';
184 echo '</td>';
185 echo '<td class="viz-section-table-column">';
186 echo '<select name="fontSize" class="control-select">';
187 echo '<option></option>';
188 for ( $i = 7; $i <= 20; $i++ ) {
189 echo '<option value="', $i, '"', selected( $i, $this->fontSize, false ), '>', $i, '</option>';
190 }
191 echo '</select>';
192 echo '</td>';
193 echo '</tr>';
194 echo '</table>';
195
196 echo '<p class="viz-section-description">';
197 esc_html_e( 'The default font family and size for all text in the chart.', 'visualizer' );
198 echo '</p>';
199 echo '</div>';
200 self::_renderSectionEnd();
201
202 self::_renderSectionStart( esc_html__( 'Legend', 'visualizer' ), false );
203 self::_renderSelectItem(
204 esc_html__( 'Position', 'visualizer' ),
205 'legend[position]',
206 $this->legend['position'],
207 $this->_legendPositions,
208 esc_html__( 'Determines where to place the legend, compared to the chart area.', 'visualizer' )
209 );
210
211 self::_renderSelectItem(
212 esc_html__( 'Alignment', 'visualizer' ),
213 'legend[alignment]',
214 $this->legend['alignment'],
215 $this->_alignments,
216 esc_html__( 'Determines the alignment of the legend.', 'visualizer' )
217 );
218
219 self::_renderColorPickerItem(
220 esc_html__( 'Font Color', 'visualizer' ),
221 'legend[textStyle][color]',
222 isset( $this->legend['textStyle']['color'] ) ? $this->legend['textStyle']['color'] : null,
223 '#000'
224 );
225 self::_renderSectionEnd();
226
227 self::_renderSectionStart( esc_html__( 'Tooltip', 'visualizer' ), false );
228 $this->_renderTooltipSettigns();
229 self::_renderSectionEnd();
230
231 $this->_renderAnimationSettings();
232
233 do_action( 'visualizer_chart_settings', get_class( $this ), $this->_data, 'general', array( 'generic' => true ) );
234
235 self::_renderGroupEnd();
236 }
237
238 /**
239 * Renders animation settings section.
240 *
241 * @access protected
242 */
243 protected function _renderAnimationSettings() {
244 if ( ! $this->_supportsAnimation ) {
245 return;
246 }
247
248 self::_renderSectionStart( esc_html__( 'Animation', 'visualizer' ), false );
249
250 self::_renderCheckboxItem(
251 esc_html__( 'Animate on startup', 'visualizer' ),
252 'animation[startup]',
253 isset( $this->animation['startup'] ) ? $this->animation['startup'] : 0,
254 true,
255 esc_html__( 'Determines if the chart will animate on the initial draw.', 'visualizer' )
256 );
257
258 self::_renderTextItem(
259 esc_html__( 'Duration', 'visualizer' ),
260 'animation[duration]',
261 isset( $this->animation['duration'] ) ? $this->animation['duration'] : 0,
262 esc_html__( 'The duration of the animation, in milliseconds', 'visualizer' ),
263 0,
264 'number'
265 );
266
267 self::_renderSelectItem(
268 esc_html__( 'Easing', 'visualizer' ),
269 'animation[easing]',
270 isset( $this->animation['easing'] ) ? $this->animation['easing'] : null,
271 array(
272 'linear' => esc_html__( 'Constant speed', 'visualizer' ),
273 'in' => esc_html__( 'Start slow and speed up', 'visualizer' ),
274 'out' => esc_html__( 'Start fast and slow down', 'visualizer' ),
275 'inAndOut' => esc_html__( 'Start slow, speed up, then slow down', 'visualizer' ),
276 ),
277 esc_html__( 'The easing function applied to the animation.', 'visualizer' )
278 );
279
280 self::_renderSectionEnd();
281
282 }
283
284 /**
285 * Renders tooltip settings section.
286 *
287 * @since 1.4.0
288 *
289 * @access protected
290 */
291 protected function _renderTooltipSettigns() {
292 self::_renderSelectItem(
293 esc_html__( 'Trigger', 'visualizer' ),
294 'tooltip[trigger]',
295 isset( $this->tooltip['trigger'] ) ? $this->tooltip['trigger'] : null,
296 array(
297 '' => '',
298 'focus' => esc_html__( 'The tooltip will be displayed when the user hovers over an element', 'visualizer' ),
299 'selection' => esc_html__( 'The tooltip will be displayed when the user selects an element', 'visualizer' ),
300 'none' => esc_html__( 'The tooltip will not be displayed', 'visualizer' ),
301 ),
302 esc_html__( 'Determines the user interaction that causes the tooltip to be displayed.', 'visualizer' )
303 );
304
305 self::_renderSelectItem(
306 esc_html__( 'Show Color Code', 'visualizer' ),
307 'tooltip[showColorCode]',
308 isset( $this->tooltip['showColorCode'] ) ? $this->tooltip['showColorCode'] : null,
309 $this->_yesno,
310 esc_html__( 'If set to yes, will show colored squares next to the slice information in the tooltip.', 'visualizer' )
311 );
312 }
313
314 /**
315 * Renders chart view settings group.
316 *
317 * @since 1.0.0
318 *
319 * @access protected
320 */
321 protected function _renderViewSettings() {
322 self::_renderGroupStart( esc_html__( 'Chart Size & Placement', 'visualizer' ) );
323 self::_renderSectionStart( esc_html__( 'Chart Size/Layout', 'visualizer' ), false );
324 self::_renderSectionDescription( esc_html__( 'Configure the total size of the chart. Two formats are supported: a number, or a number followed by %. A simple number is a value in pixels; a number followed by % is a percentage.', 'visualizer' ) );
325
326 echo '<div class="viz-section-item">';
327 echo '<a class="more-info" href="javascript:;">[?]</a>';
328 echo '<b>', esc_html__( 'Width And Height Of Chart', 'visualizer' ), '</b>';
329
330 echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">';
331 echo '<tr>';
332 echo '<td class="viz-section-table-column">';
333 echo '<input type="text" name="width" class="control-text" value="', esc_attr( $this->width ), '" placeholder="100%">';
334 echo '</td>';
335 echo '<td class="viz-section-table-column">';
336 echo '<input type="text" name="height" class="control-text" value="', esc_attr( $this->height ), '" placeholder="400">';
337 echo '</td>';
338 echo '</tr>';
339 echo '</table>';
340
341 echo '<p class="viz-section-description">';
342 esc_html_e( 'Determines the total width and height of the chart. This will only show in the front-end.', 'visualizer' );
343 echo '</p>';
344 echo '</div>';
345
346 echo '<div class="viz-section-delimiter"></div>';
347
348 self::_renderSectionDescription( esc_html__( 'Configure the background color for the main area of the chart and the chart border width and color.', 'visualizer' ) );
349
350 self::_renderTextItem(
351 esc_html__( 'Stroke Width', 'visualizer' ),
352 'backgroundColor[strokeWidth]',
353 isset( $this->backgroundColor['strokeWidth'] ) ? $this->backgroundColor['strokeWidth'] : null,
354 esc_html__( 'The chart border width in pixels.', 'visualizer' ),
355 '0'
356 );
357
358 self::_renderColorPickerItem(
359 esc_html__( 'Stroke Color', 'visualizer' ),
360 'backgroundColor[stroke]',
361 ! empty( $this->backgroundColor['stroke'] ) ? $this->backgroundColor['stroke'] : null,
362 '#666'
363 );
364
365 $background_color = ! empty( $this->backgroundColor['fill'] ) ? $this->backgroundColor['fill'] : null;
366 self::_renderColorPickerItem(
367 esc_html__( 'Background Color', 'visualizer' ),
368 'backgroundColor[fill]',
369 $background_color,
370 '#fff'
371 );
372
373 echo '<div class="viz-section-item">';
374 echo '<label>';
375 echo '<input type="checkbox" class="control-checkbox" name="backgroundColor[fill]" value="transparent"', checked( $background_color, 'transparent', false ), '> ';
376 esc_html_e( 'Transparent background', 'visualizer' );
377 echo '</label>';
378 echo '</div>';
379 self::_renderSectionEnd();
380
381 self::_renderSectionStart( esc_html__( 'Placement', 'visualizer' ), false );
382 self::_renderSectionDescription( esc_html__( 'Configure the placement and size of the chart area (where the chart itself is drawn, excluding axis and legends). Two formats are supported: a number, or a number followed by %. A simple number is a value in pixels; a number followed by % is a percentage.', 'visualizer' ) );
383
384 echo '<div class="viz-section-item">';
385 echo '<a class="more-info" href="javascript:;">[?]</a>';
386 echo '<b>', esc_html__( 'Left And Top Margins', 'visualizer' ), '</b>';
387
388 echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">';
389 echo '<tr>';
390 echo '<td class="viz-section-table-column">';
391 echo '<input type="text" name="chartArea[left]" class="control-text" value="', $this->chartArea['left'] || $this->chartArea['left'] === '0' ? esc_attr( $this->chartArea['left'] ) : '', '" placeholder="20%">';
392 echo '</td>';
393 echo '<td class="viz-section-table-column">';
394 echo '<input type="text" name="chartArea[top]" class="control-text" value="', $this->chartArea['top'] || $this->chartArea['top'] === '0' ? esc_attr( $this->chartArea['top'] ) : '', '" placeholder="20%">';
395 echo '</td>';
396 echo '</tr>';
397 echo '</table>';
398
399 echo '<p class="viz-section-description">';
400 esc_html_e( 'Determines how far to draw the chart from the left and top borders.', 'visualizer' );
401 echo '</p>';
402 echo '</div>';
403
404 echo '<div class="viz-section-item">';
405 echo '<a class="more-info" href="javascript:;">[?]</a>';
406 echo '<b>', esc_html__( 'Width And Height Of Chart Area', 'visualizer' ), '</b>';
407
408 echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">';
409 echo '<tr>';
410 echo '<td class="viz-section-table-column">';
411 echo '<input type="text" name="chartArea[width]" class="control-text" value="', ! empty( $this->chartArea['width'] ) ? esc_attr( $this->chartArea['width'] ) : '', '" placeholder="60%">';
412 echo '</td>';
413 echo '<td class="viz-section-table-column">';
414 echo '<input type="text" name="chartArea[height]" class="control-text" value="', ! empty( $this->chartArea['height'] ) ? esc_attr( $this->chartArea['height'] ) : '', '" placeholder="60%">';
415 echo '</td>';
416 echo '</tr>';
417 echo '</table>';
418
419 echo '<p class="viz-section-description">';
420 esc_html_e( 'Determines the width and hight of the chart area.', 'visualizer' );
421 echo '</p>';
422 echo '</div>';
423 self::_renderSectionEnd();
424 self::_renderGroupEnd();
425 }
426 }
427