Skip to content

Commit f300908

Browse files
Custom series format values for pie chart #36
1 parent 497fa25 commit f300908

File tree

14 files changed

+413
-317
lines changed

14 files changed

+413
-317
lines changed

classes/Visualizer/Module/Admin.php

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,20 @@ public function enqueueLibraryScripts( $suffix ) {
246246
wp_enqueue_style( 'visualizer-library', VISUALIZER_ABSURL . 'css/library.css', array(), Visualizer_Plugin::VERSION );
247247
$this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' );
248248
wp_enqueue_media();
249-
wp_enqueue_script( 'visualizer-library', VISUALIZER_ABSURL . 'js/library.js', array(
250-
'jquery',
251-
'media-views',
252-
), Visualizer_Plugin::VERSION, true );
249+
wp_enqueue_script(
250+
'visualizer-library', VISUALIZER_ABSURL . 'js/library.js', array(
251+
'jquery',
252+
'media-views',
253+
), Visualizer_Plugin::VERSION, true
254+
);
253255
wp_enqueue_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true );
254256
wp_enqueue_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true );
255-
wp_enqueue_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array(
256-
'google-jsapi-old',
257-
'visualizer-library',
258-
), Visualizer_Plugin::VERSION, true );
257+
wp_enqueue_script(
258+
'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array(
259+
'google-jsapi-old',
260+
'visualizer-library',
261+
), Visualizer_Plugin::VERSION, true
262+
);
259263
}
260264
}
261265

@@ -298,12 +302,14 @@ public function registerAdminMenu() {
298302
*/
299303
public function renderLibraryPage() {
300304
// get current page
301-
$page = filter_input( INPUT_GET, 'vpage', FILTER_VALIDATE_INT, array(
302-
'options' => array(
303-
'min_range' => 1,
304-
'default' => 1,
305-
),
306-
) );
305+
$page = filter_input(
306+
INPUT_GET, 'vpage', FILTER_VALIDATE_INT, array(
307+
'options' => array(
308+
'min_range' => 1,
309+
'default' => 1,
310+
),
311+
)
312+
);
307313
// the initial query arguments to fetch charts
308314
$query_args = array(
309315
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
@@ -358,32 +364,40 @@ public function renderLibraryPage() {
358364
}
359365
// enqueue charts array
360366
$ajaxurl = admin_url( 'admin-ajax.php' );
361-
wp_localize_script( 'visualizer-library', 'visualizer', array(
362-
'charts' => $charts,
363-
'urls' => array(
364-
'base' => add_query_arg( 'vpage', false ),
365-
'create' => add_query_arg( array(
366-
'action' => Visualizer_Plugin::ACTION_CREATE_CHART,
367-
'library' => 'yes',
368-
), $ajaxurl ),
369-
'edit' => add_query_arg( array(
370-
'action' => Visualizer_Plugin::ACTION_EDIT_CHART,
371-
'library' => 'yes',
372-
), $ajaxurl ),
373-
),
374-
) );
367+
wp_localize_script(
368+
'visualizer-library', 'visualizer', array(
369+
'charts' => $charts,
370+
'urls' => array(
371+
'base' => add_query_arg( 'vpage', false ),
372+
'create' => add_query_arg(
373+
array(
374+
'action' => Visualizer_Plugin::ACTION_CREATE_CHART,
375+
'library' => 'yes',
376+
), $ajaxurl
377+
),
378+
'edit' => add_query_arg(
379+
array(
380+
'action' => Visualizer_Plugin::ACTION_EDIT_CHART,
381+
'library' => 'yes',
382+
), $ajaxurl
383+
),
384+
),
385+
)
386+
);
375387
// render library page
376388
$render = new Visualizer_Render_Library();
377389
$render->charts = $charts;
378390
$render->type = $filter;
379391
$render->types = self::_getChartTypesLocalized();
380-
$render->pagination = paginate_links( array(
381-
'base' => add_query_arg( 'vpage', '%#%' ),
382-
'format' => '',
383-
'current' => $page,
384-
'total' => $query->max_num_pages,
385-
'type' => 'array',
386-
) );
392+
$render->pagination = paginate_links(
393+
array(
394+
'base' => add_query_arg( 'vpage', '%#%' ),
395+
'format' => '',
396+
'current' => $page,
397+
'total' => $query->max_num_pages,
398+
'type' => 'array',
399+
)
400+
);
387401
$render->render();
388402
}
389403

classes/Visualizer/Module/Chart.php

Lines changed: 110 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ public function getCharts() {
7373
$query_args = array(
7474
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
7575
'posts_per_page' => 9,
76-
'paged' => filter_input( INPUT_GET, 'page', FILTER_VALIDATE_INT, array(
77-
'options' => array(
78-
'min_range' => 1,
79-
'default' => 1,
80-
),
81-
) ),
76+
'paged' => filter_input(
77+
INPUT_GET, 'page', FILTER_VALIDATE_INT, array(
78+
'options' => array(
79+
'min_range' => 1,
80+
'default' => 1,
81+
),
82+
)
83+
),
8284
);
8385
$filter = filter_input( INPUT_GET, 's', FILTER_SANITIZE_STRING );
8486
if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) {
@@ -98,11 +100,13 @@ public function getCharts() {
98100
$chart_data['id'] = $chart->ID;
99101
$charts[] = $chart_data;
100102
}
101-
self::_sendResponse( array(
102-
'success' => true,
103-
'data' => $charts,
104-
'total' => $query->max_num_pages,
105-
) );
103+
self::_sendResponse(
104+
array(
105+
'success' => true,
106+
'data' => $charts,
107+
'total' => $query->max_num_pages,
108+
)
109+
);
106110
}
107111

108112
/**
@@ -163,11 +167,13 @@ public function deleteChart() {
163167
$nonce = wp_verify_nonce( filter_input( $input_method, 'nonce' ) );
164168
$capable = current_user_can( 'delete_posts' );
165169
if ( $nonce && $capable ) {
166-
$chart_id = filter_input( $input_method, 'chart', FILTER_VALIDATE_INT, array(
167-
'options' => array(
168-
'min_range' => 1,
169-
),
170-
) );
170+
$chart_id = filter_input(
171+
$input_method, 'chart', FILTER_VALIDATE_INT, array(
172+
'options' => array(
173+
'min_range' => 1,
174+
),
175+
)
176+
);
171177
if ( $chart_id ) {
172178
$chart = get_post( $chart_id );
173179
$success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
@@ -177,9 +183,11 @@ public function deleteChart() {
177183
wp_delete_post( $chart_id, true );
178184
}
179185
if ( $is_post ) {
180-
self::_sendResponse( array(
181-
'success' => $success,
182-
) );
186+
self::_sendResponse(
187+
array(
188+
'success' => $success,
189+
)
190+
);
183191
}
184192
wp_redirect( wp_get_referer() );
185193
exit;
@@ -201,21 +209,25 @@ public function renderChartPages() {
201209
$default_type = 'line';
202210
$source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $default_type . '.csv' );
203211
$source->fetch();
204-
$chart_id = wp_insert_post( array(
205-
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
206-
'post_title' => 'Visualization',
207-
'post_author' => get_current_user_id(),
208-
'post_status' => 'auto-draft',
209-
'post_content' => $source->getData(),
210-
) );
212+
$chart_id = wp_insert_post(
213+
array(
214+
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
215+
'post_title' => 'Visualization',
216+
'post_author' => get_current_user_id(),
217+
'post_status' => 'auto-draft',
218+
'post_content' => $source->getData(),
219+
)
220+
);
211221
if ( $chart_id && ! is_wp_error( $chart_id ) ) {
212222
add_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, $default_type );
213223
add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 );
214224
add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
215225
add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
216-
add_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, array(
217-
'focusTarget' => 'datum',
218-
) );
226+
add_post_meta(
227+
$chart_id, Visualizer_Plugin::CF_SETTINGS, array(
228+
'focusTarget' => 'datum',
229+
)
230+
);
219231
}
220232
wp_redirect( add_query_arg( 'chart', (int) $chart_id ) );
221233
defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
@@ -225,15 +237,19 @@ public function renderChartPages() {
225237
wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true );
226238
wp_register_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true );
227239
wp_register_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true );
228-
wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array(
229-
'google-jsapi-old',
230-
'google-jsapi-new',
231-
'visualizer-frame',
232-
), Visualizer_Plugin::VERSION, true );
233-
wp_register_script( 'visualizer-preview', VISUALIZER_ABSURL . 'js/preview.js', array(
234-
'wp-color-picker',
235-
'visualizer-render',
236-
), Visualizer_Plugin::VERSION, true );
240+
wp_register_script(
241+
'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array(
242+
'google-jsapi-old',
243+
'google-jsapi-new',
244+
'visualizer-frame',
245+
), Visualizer_Plugin::VERSION, true
246+
);
247+
wp_register_script(
248+
'visualizer-preview', VISUALIZER_ABSURL . 'js/preview.js', array(
249+
'wp-color-picker',
250+
'visualizer-render',
251+
), Visualizer_Plugin::VERSION, true
252+
);
237253
// added by Ash/Upwork
238254
if ( VISUALIZER_PRO ) {
239255
global $Visualizer_Pro;
@@ -293,15 +309,17 @@ private function _handleDataAndSettingsPage() {
293309
wp_enqueue_style( 'visualizer-frame' );
294310
wp_enqueue_script( 'visualizer-preview' );
295311
wp_enqueue_script( 'visualizer-render' );
296-
wp_localize_script( 'visualizer-render', 'visualizer', array(
297-
'l10n' => array(
298-
'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
299-
),
300-
'charts' => array(
301-
'canvas' => $data,
302-
),
303-
'map_api_key' => get_option( 'visualizer-map-api-key' ),
304-
) );
312+
wp_localize_script(
313+
'visualizer-render', 'visualizer', array(
314+
'l10n' => array(
315+
'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
316+
),
317+
'charts' => array(
318+
'canvas' => $data,
319+
),
320+
'map_api_key' => get_option( 'visualizer-map-api-key' ),
321+
)
322+
);
305323
$render = new Visualizer_Render_Page_Data();
306324
$render->chart = $this->_chart;
307325
$render->type = $data['type'];
@@ -441,35 +459,41 @@ public function cloneChart() {
441459
$nonce = wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), Visualizer_Plugin::ACTION_CLONE_CHART );
442460
$capable = current_user_can( 'edit_posts' );
443461
if ( $nonce && $capable ) {
444-
$chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT, array(
445-
'options' => array(
446-
'min_range' => 1,
447-
),
448-
) );
462+
$chart_id = filter_input(
463+
INPUT_GET, 'chart', FILTER_VALIDATE_INT, array(
464+
'options' => array(
465+
'min_range' => 1,
466+
),
467+
)
468+
);
449469
if ( $chart_id ) {
450470
$chart = get_post( $chart_id );
451471
$success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
452472
}
453473
}
454474
$redirect = wp_get_referer();
455475
if ( $success ) {
456-
$new_chart_id = wp_insert_post( array(
457-
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
458-
'post_title' => 'Visualization',
459-
'post_author' => get_current_user_id(),
460-
'post_status' => $chart->post_status,
461-
'post_content' => $chart->post_content,
462-
) );
476+
$new_chart_id = wp_insert_post(
477+
array(
478+
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
479+
'post_title' => 'Visualization',
480+
'post_author' => get_current_user_id(),
481+
'post_status' => $chart->post_status,
482+
'post_content' => $chart->post_content,
483+
)
484+
);
463485
if ( $new_chart_id && ! is_wp_error( $new_chart_id ) ) {
464486
add_post_meta( $new_chart_id, Visualizer_Plugin::CF_CHART_TYPE, get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ) );
465487
add_post_meta( $new_chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, get_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, true ) );
466488
add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SOURCE, get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) );
467489
add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SERIES, get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true ) );
468490
add_post_meta( $new_chart_id, Visualizer_Plugin::CF_SETTINGS, get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ) );
469-
$redirect = add_query_arg( array(
470-
'page' => 'visualizer',
471-
'type' => filter_input( INPUT_GET, 'type' ),
472-
), admin_url( 'upload.php' ) );
491+
$redirect = add_query_arg(
492+
array(
493+
'page' => 'visualizer',
494+
'type' => filter_input( INPUT_GET, 'type' ),
495+
), admin_url( 'upload.php' )
496+
);
473497
}
474498
}
475499
wp_redirect( $redirect );
@@ -488,11 +512,13 @@ public function exportData() {
488512
$chart_id = $success = false;
489513
$capable = current_user_can( 'edit_posts' );
490514
if ( $capable ) {
491-
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT, array(
492-
'options' => array(
493-
'min_range' => 1,
494-
),
495-
) ) : '';
515+
$chart_id = isset( $_GET['chart'] ) ? filter_var(
516+
$_GET['chart'], FILTER_VALIDATE_INT, array(
517+
'options' => array(
518+
'min_range' => 1,
519+
),
520+
)
521+
) : '';
496522
if ( $chart_id ) {
497523
$chart = get_post( $chart_id );
498524
$success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
@@ -553,10 +579,12 @@ public function exportData() {
553579
$csv .= implode( ',', $array );
554580
}
555581
fclose( $fp );
556-
echo wp_send_json_success( array(
557-
'csv' => $csv,
558-
'name' => $filename,
559-
) );
582+
echo wp_send_json_success(
583+
array(
584+
'csv' => $csv,
585+
'name' => $filename,
586+
)
587+
);
560588
}// End if().
561589
defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
562590
}
@@ -576,14 +604,16 @@ private function _handleDataPage() {
576604
unset( $data['settings']['width'], $data['settings']['height'] );
577605
wp_enqueue_style( 'visualizer-frame' );
578606
wp_enqueue_script( 'visualizer-render' );
579-
wp_localize_script( 'visualizer-render', 'visualizer', array(
580-
'l10n' => array(
581-
'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
582-
),
583-
'charts' => array(
584-
'canvas' => $data,
585-
),
586-
) );
607+
wp_localize_script(
608+
'visualizer-render', 'visualizer', array(
609+
'l10n' => array(
610+
'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
611+
),
612+
'charts' => array(
613+
'canvas' => $data,
614+
),
615+
)
616+
);
587617
// Added by Ash/Upwork
588618
if ( VISUALIZER_PRO ) {
589619
global $Visualizer_Pro;

0 commit comments

Comments
 (0)