@@ -445,4 +445,98 @@ protected function get_user_customization_js() {
445
445
return $ specific ;
446
446
}
447
447
448
+ /**
449
+ * Load the class for the given chart's chart type so that its assets can be loaded.
450
+ */
451
+ protected function load_chart_type ( $ chart_id ) {
452
+ $ type = get_post_meta ( $ chart_id , Visualizer_Plugin::CF_CHART_TYPE , true );
453
+ $ name = 'Visualizer_Render_Sidebar_Type_ ' . ucwords ( $ type );
454
+ $ class = null ;
455
+ if ( class_exists ( $ name ) ) {
456
+ $ class = new $ name ;
457
+ } elseif ( true === apply_filters ( 'visualizer_load_chart ' , false , $ name ) ) {
458
+ $ class = new $ name ;
459
+ }
460
+ return is_null ( $ class ) ? null : $ class ->getLibrary ();
461
+ }
462
+
463
+ /**
464
+ * Generates the inline CSS to apply to the chart and adds these classes to the settings.
465
+ *
466
+ * @access public
467
+ * @param int $id The id of the chart.
468
+ * @param array $settings The settings of the chart.
469
+ */
470
+ protected function get_inline_custom_css ( $ id , $ settings ) {
471
+ $ css = '' ;
472
+
473
+ $ arguments = array ( '' , $ settings );
474
+ if ( ! isset ( $ settings ['customcss ' ] ) ) {
475
+ return $ arguments ;
476
+ }
477
+
478
+ $ classes = array ();
479
+ $ css = '<style type="text/css" name="visualizer-custom-css" id="customcss- ' . $ id . '"> ' ;
480
+ foreach ( $ settings ['customcss ' ] as $ name => $ element ) {
481
+ $ attributes = array ();
482
+ foreach ( $ element as $ property => $ value ) {
483
+ $ attributes [] = $ this ->handle_css_property ( $ property , $ value );
484
+ }
485
+ $ class_name = $ id . $ name ;
486
+ $ properties = implode ( '; ' , array_filter ( $ attributes ) );
487
+ if ( ! empty ( $ properties ) ) {
488
+ $ css .= '. ' . $ class_name . ' { ' . $ properties . ' !important;} ' ;
489
+ $ classes [ $ name ] = $ class_name ;
490
+ }
491
+ }
492
+ $ css .= '</style> ' ;
493
+
494
+ $ settings ['cssClassNames ' ] = $ classes ;
495
+
496
+ $ arguments = array ( $ css , $ settings );
497
+ apply_filters_ref_array ( 'visualizer_inline_css ' , array ( &$ arguments ) );
498
+
499
+ return $ arguments ;
500
+ }
501
+
502
+ /**
503
+ * Handles CSS properties that might need special syntax.
504
+ *
505
+ * @access private
506
+ * @param string $property The name of the css property.
507
+ * @param string $value The value of the css property.
508
+ */
509
+ private function handle_css_property ( $ property , $ value ) {
510
+ if ( empty ( $ property ) || empty ( $ value ) ) {
511
+ return '' ;
512
+ }
513
+
514
+ switch ( $ property ) {
515
+ case 'transform ' :
516
+ $ value = 'rotate( ' . $ value . 'deg) ' ;
517
+ break ;
518
+ }
519
+ return $ property . ': ' . $ value ;
520
+ }
521
+
522
+ /**
523
+ * Determines if charts have been created of the particular chart type.
524
+ */
525
+ protected static function hasChartType ( $ type ) {
526
+ $ args = array (
527
+ 'post_type ' => Visualizer_Plugin::CPT_VISUALIZER ,
528
+ 'fields ' => 'ids ' ,
529
+ 'post_status ' => 'publish ' ,
530
+ 'meta_query ' => array (
531
+ array (
532
+ 'key ' => Visualizer_Plugin::CF_CHART_TYPE ,
533
+ 'value ' => $ type ,
534
+ ),
535
+ ),
536
+ );
537
+
538
+ $ q = new WP_Query ( $ args );
539
+ return $ q ->found_posts > 0 ;
540
+ }
541
+
448
542
}
0 commit comments