PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.3.1
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.3.1
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.3.1, at classes/Visualizer/Render/Sidebar/ChartJS.php

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