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

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

438 lines 13.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Base class for sidebar settigns of ChartJS based charts.
5 *
6 * @category Visualizer
7 * @package Render
8 * @subpackage Sidebar
9 *
10 * @since 3.2.0
11 * @abstract
12 */
13 abstract class Visualizer_Render_Sidebar_ChartJS extends Visualizer_Render_Sidebar {
14
15 /**
16 * The array of available legend positions.
17 *
18 * @since 1.0.0
19 *
20 * @access protected
21 * @var array
22 */
23 protected $_legendPositions;
24
25
26 /**
27 * The constructor.
28 */
29 public function __construct( $data = array() ) {
30 $this->_library = 'chartjs';
31 parent::__construct( $data );
32
33 $this->_legendPositions = array(
34 'left' => esc_html__( 'Left of the chart', 'visualizer' ),
35 'right' => esc_html__( 'Right of the chart', 'visualizer' ),
36 'top' => esc_html__( 'Above the chart', 'visualizer' ),
37 'bottom' => esc_html__( 'Below the chart', 'visualizer' ),
38 'bottom' => esc_html__( 'Below the chart', 'visualizer' ),
39 'none' => esc_html__( 'Omit the legend', 'visualizer' ),
40 );
41
42 }
43
44 /**
45 * Renders concrete series settings for the Bar chart.
46 *
47 * @since 3.3.0
48 *
49 * @access protected
50 * @param int $index The series index.
51 */
52 protected function _renderChartTypeSeries( $index ) {
53 // empty.
54 }
55
56 /**
57 * Renders settings specific to the Bar chart.
58 *
59 * @since 3.3.0
60 *
61 * @access protected
62 */
63 protected function _renderChartTypeSettings() {
64 // empty
65 }
66
67 /**
68 * Registers additional hooks.
69 *
70 * @access protected
71 */
72 protected function hooks() {
73 if ( $this->_library === 'chartjs' ) {
74 add_filter( 'visualizer_assets_render', array( $this, 'load_chartjs_assets' ), 10, 2 );
75 }
76 }
77
78 /**
79 * Loads the assets.
80 */
81 function load_chartjs_assets( $deps, $is_frontend ) {
82 $this->load_dependent_assets( array( 'moment', 'numeral' ) );
83
84 wp_register_script( 'chartjs', VISUALIZER_ABSURL . 'js/lib/chartjs.min.js', array( 'numeral', 'moment' ), null, true );
85 wp_register_script(
86 'visualizer-render-chartjs-lib',
87 VISUALIZER_ABSURL . 'js/render-chartjs.js',
88 array(
89 'chartjs',
90 ),
91 Visualizer_Plugin::VERSION,
92 true
93 );
94
95 return array_merge(
96 $deps,
97 array( 'visualizer-render-chartjs-lib' )
98 );
99
100 }
101
102 /**
103 * Renders series settings group.
104 *
105 * @since 3.3.0
106 *
107 * @access protected
108 */
109 protected function _renderSeriesSettings() {
110 self::_renderGroupStart( esc_html__( 'Series Settings', 'visualizer' ) );
111 self::_renderSectionStart();
112 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' );
113 self::_renderSectionEnd();
114
115 for ( $i = 1, $cnt = count( $this->__series ); $i < $cnt; $i++ ) {
116 if ( ! empty( $this->__series[ $i ]['label'] ) ) {
117 self::_renderSectionStart( esc_html( $this->__series[ $i ]['label'] ), false );
118 $this->_renderSeries( $i - 1 );
119 self::_renderSectionEnd();
120 }
121 }
122 self::_renderGroupEnd();
123 }
124
125 /**
126 * Renders concrete series settings.
127 *
128 * @since 3.3.0
129 *
130 * @access protected
131 * @param int $index The series index.
132 */
133 protected function _renderSeries( $index ) {
134 $this->_renderFormatField( $index );
135 $this->_renderChartTypeSeries( $index );
136
137 }
138
139 /**
140 * Renders template.
141 *
142 * @since 3.3.0
143 *
144 * @access protected
145 */
146 protected function _toHTML() {
147 $this->_renderGeneralSettings();
148 $this->_renderAxesSettings();
149 $this->_renderChartTypeSettings();
150 $this->_renderSeriesSettings();
151 $this->_renderViewSettings();
152 $this->_renderAdvancedSettings();
153 }
154
155 /**
156 * Renders chart title settings.
157 *
158 * @since 3.3.0
159 *
160 * @access protected
161 */
162 protected function _renderChartTitleSettings() {
163 self::_renderTextItem(
164 esc_html__( 'Chart Title', 'visualizer' ),
165 'title[text]',
166 isset( $this->title['text'] ) ? $this->title['text'] : '',
167 esc_html__( 'Text to display above the chart.', 'visualizer' )
168 );
169
170 self::_renderColorPickerItem(
171 esc_html__( 'Chart Title Color', 'visualizer' ),
172 'title[fontColor]',
173 isset( $this->title['fontColor'] ) ? $this->title['fontColor'] : '',
174 '#000'
175 );
176
177 echo '<div class="viz-section-delimiter"></div>';
178
179 self::_renderTextAreaItem(
180 esc_html__( 'Chart Description', 'visualizer' ),
181 'description',
182 $this->description,
183 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>' )
184 );
185
186 }
187
188 /**
189 * Renders chart general settings group.
190 *
191 * @since 3.3.0
192 *
193 * @access protected
194 */
195 protected function _renderGeneralSettings() {
196 self::_renderGroupStart( esc_html__( 'General Settings', 'visualizer' ) );
197 self::_renderSectionStart();
198 self::_renderSectionDescription( esc_html__( 'Configure title, font styles, tooltip, legend and else settings for the chart.', 'visualizer' ) );
199 self::_renderSectionEnd();
200
201 self::_renderSectionStart( esc_html__( 'Title', 'visualizer' ), false );
202 $this->_renderChartTitleSettings();
203 self::_renderSectionEnd();
204
205 self::_renderSectionStart( esc_html__( 'Font Styles', 'visualizer' ), false );
206 echo '<div class="viz-section-item">';
207 echo '<a class="more-info" href="javascript:;">[?]</a>';
208 echo '<b>', esc_html__( 'Family And Size', 'visualizer' ), '</b>';
209
210 echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">';
211 echo '<tr>';
212 echo '<td class="viz-section-table-column">';
213 echo '<select name="fontName" class="control-select">';
214 echo '<option></option>';
215 foreach ( self::$_fontFamilies as $font => $label ) {
216 echo '<option value="', $font, '"', selected( $font, $this->fontName, false ), '>';
217 echo $label;
218 echo '</option>';
219 }
220 echo '</select>';
221 echo '</td>';
222 echo '<td class="viz-section-table-column">';
223 echo '<select name="fontSize" class="control-select">';
224 echo '<option></option>';
225 for ( $i = 7; $i <= 20; $i++ ) {
226 echo '<option value="', $i, '"', selected( $i, $this->fontSize, false ), '>', $i, '</option>';
227 }
228 echo '</select>';
229 echo '</td>';
230 echo '</tr>';
231 echo '</table>';
232
233 echo '<p class="viz-section-description">';
234 esc_html_e( 'The default font family and size for all text in the chart.', 'visualizer' );
235 echo '</p>';
236 echo '</div>';
237 self::_renderSectionEnd();
238
239 self::_renderSectionStart( esc_html__( 'Legend', 'visualizer' ), false );
240 self::_renderSelectItem(
241 esc_html__( 'Position', 'visualizer' ),
242 'legend[position]',
243 // let's have a default otherwise the chart behaves weird when hovering in edit mode
244 isset( $this->legend['position'] ) ? $this->legend['position'] : 'top',
245 $this->_legendPositions,
246 esc_html__( 'Determines where to place the legend, compared to the chart area.', 'visualizer' )
247 );
248
249 self::_renderCheckboxItem(
250 esc_html__( 'Show datasets in reverse order', 'visualizer' ),
251 'legend[reverse]',
252 isset( $this->legend['reverse'] ) ? $this->legend['reverse'] : false,
253 'true',
254 esc_html__( 'Legend will show datasets in reverse order.', 'visualizer' )
255 );
256
257 echo '<div class="viz-section-item">';
258 echo '<a class="more-info" href="javascript:;">[?]</a>';
259 echo '<b>', esc_html__( 'Family And Size', 'visualizer' ), '</b>';
260
261 echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">';
262 echo '<tr>';
263 echo '<td class="viz-section-table-column">';
264 echo '<select name="legend[labels][fontName]" class="control-select">';
265 echo '<option></option>';
266 foreach ( self::$_fontFamilies as $font => $label ) {
267 echo '<option value="', $font, '"', selected( $font, $this->legend['labels']['fontName'], false ), '>';
268 echo $label;
269 echo '</option>';
270 }
271 echo '</select>';
272 echo '</td>';
273 echo '<td class="viz-section-table-column">';
274 echo '<select name="legend[labels][fontSize]" class="control-select">';
275 echo '<option></option>';
276 for ( $i = 7; $i <= 20; $i++ ) {
277 echo '<option value="', $i, '"', selected( $i, $this->legend['labels']['fontSize'], false ), '>', $i, '</option>';
278 }
279 echo '</select>';
280 echo '</td>';
281 echo '</tr>';
282 echo '</table>';
283
284 self::_renderColorPickerItem(
285 esc_html__( 'Font Color', 'visualizer' ),
286 'legend[labels][fontColor]',
287 isset( $this->legend['labels']['fontColor'] ) ? $this->legend['labels']['fontColor'] : null,
288 '#000'
289 );
290
291 echo '</div>';
292
293 self::_renderSectionEnd();
294
295 self::_renderSectionStart( esc_html__( 'Tooltip', 'visualizer' ), false );
296 $this->_renderTooltipSettigns();
297 self::_renderSectionEnd();
298
299 $this->_renderAnimationSettings();
300
301 self::_renderSectionStart( esc_html__( 'License & Creator', 'visualizer' ), false );
302 self::_renderTextItem(
303 esc_html__( 'License', 'visualizer' ),
304 'license',
305 $this->license,
306 ''
307 );
308 self::_renderTextItem(
309 esc_html__( 'Creator', 'visualizer' ),
310 'creator',
311 $this->creator,
312 ''
313 );
314 self::_renderSectionEnd();
315
316 self::_renderChartImageSettings();
317
318 self::_renderGroupEnd();
319 }
320
321 /**
322 * Renders animation settings section.
323 *
324 * @access protected
325 */
326 protected function _renderAnimationSettings() {
327 if ( ! $this->_supportsAnimation ) {
328 return;
329 }
330
331 self::_renderSectionStart( esc_html__( 'Animation', 'visualizer' ), false );
332
333 self::_renderTextItem(
334 esc_html__( 'Duration', 'visualizer' ),
335 'animation[duration]',
336 isset( $this->animation['duration'] ) ? $this->animation['duration'] : 1000,
337 esc_html__( 'The duration of the animation, in milliseconds', 'visualizer' ),
338 1000,
339 'number',
340 array( 'min' => 1000 )
341 );
342
343 self::_renderSelectItem(
344 esc_html__( 'Easing', 'visualizer' ),
345 'animation[easing]',
346 isset( $this->animation['easing'] ) ? $this->animation['easing'] : null,
347 array(
348 'linear' => esc_html__( 'Constant speed', 'visualizer' ),
349 'easeInQuad' => esc_html__( 'easeInQuad', 'visualizer' ),
350 'easeOutQuad' => esc_html__( 'easeOutQuad', 'visualizer' ),
351 'easeInOutQuad' => esc_html__( 'easeInOutQuad', 'visualizer' ),
352 'easeInCubic' => esc_html__( 'easeInCubic', 'visualizer' ),
353 'easeOutCubic' => esc_html__( 'easeOutCubic', 'visualizer' ),
354 'easeInOutCubic' => esc_html__( 'easeInOutCubic', 'visualizer' ),
355 'easeInQuart' => esc_html__( 'easeInQuart', 'visualizer' ),
356 'easeOutQuart' => esc_html__( 'easeOutQuart', 'visualizer' ),
357 'easeInOutQuart' => esc_html__( 'easeInOutQuart', 'visualizer' ),
358 'easeInQuint' => esc_html__( 'easeInQuint', 'visualizer' ),
359 'easeOutQuint' => esc_html__( 'easeOutQuint', 'visualizer' ),
360 ),
361 esc_html__( 'The easing function applied to the animation.', 'visualizer' )
362 );
363
364 self::_renderSectionEnd();
365
366 }
367
368 /**
369 * Renders tooltip settings section.
370 *
371 * @since 1.4.0
372 *
373 * @access protected
374 */
375 protected function _renderTooltipSettigns() {
376 self::_renderCheckboxItem(
377 esc_html__( 'Trigger', 'visualizer' ),
378 'tooltip[intersect]',
379 $this->tooltip['intersect'],
380 1,
381 esc_html__( 'Determines if the tooltip should only display when the mouse intersects with an element.', 'visualizer' )
382 );
383 }
384
385 /**
386 * Add the correct description for the manual configuration box.
387 */
388 protected function _renderManualConfigDescription() {
389 self::_renderSectionStart();
390 self::_renderSectionDescription( '<span class="viz-gvlink">' . sprintf( __( 'Configure the graph by providing configuration variables right from the %1$sChartJS API%2$s. You can refer to to some examples %3$shere%4$s.', 'visualizer' ), '<a href="https://www.chartjs.org/docs/latest/configuration/" target="_blank">', '</a>', '<a href="https://docs.themeisle.com/article/728-manual-configuration" target="_blank">', '</a>' ) . '</span>' );
391 }
392
393 /**
394 * Add the correct example for the manual configuration box.
395 */
396 protected function _renderManualConfigExample() {
397 return '{
398 "cutoutPercentage": 5,
399 "rotation": 60
400 }';
401 }
402
403 /**
404 * Renders chart view settings group.
405 *
406 * @since 3.3.0
407 *
408 * @access protected
409 */
410 protected function _renderViewSettings() {
411 self::_renderGroupStart( esc_html__( 'Chart Size', 'visualizer' ) );
412 self::_renderSectionStart();
413 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' ) );
414
415 echo '<div class="viz-section-item">';
416 echo '<a class="more-info" href="javascript:;">[?]</a>';
417 echo '<b>', esc_html__( 'Width And Height Of Chart', 'visualizer' ), '</b>';
418
419 echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">';
420 echo '<tr>';
421 echo '<td class="viz-section-table-column">';
422 echo '<input type="text" name="width" class="control-text" value="', esc_attr( $this->width ), '" placeholder="100%">';
423 echo '</td>';
424 echo '<td class="viz-section-table-column">';
425 echo '<input type="text" name="height" class="control-text" value="', esc_attr( $this->height ), '" placeholder="400">';
426 echo '</td>';
427 echo '</tr>';
428 echo '</table>';
429
430 echo '<p class="viz-section-description">';
431 esc_html_e( 'Determines the total width and height of the chart. This will only show in the front-end.', 'visualizer' );
432 echo '</p>';
433 echo '</div>';
434 self::_renderSectionEnd();
435 self::_renderGroupEnd();
436 }
437 }
438