/**
  * Callback function to show chart data meta box
  *
  * @since  1.0.0
  *
  * @param  object $post post obkect
  */
 function _data_box($post)
 {
     $current_type = cherry_charts_get_meta($post->ID, 'type', 'progress_bar');
     foreach ($this->chart_types as $type) {
         $active_class = $type == $current_type ? 'active' : '';
         $atts_array = array('type' => $type);
         switch ($type) {
             case 'progress_bar':
                 $spare_rows = 0;
                 $spare_cols = 0;
                 break;
             case 'pie':
                 $spare_rows = 1;
                 $spare_cols = 0;
                 break;
             case 'multi_progress':
                 $spare_rows = 1;
                 $spare_cols = 0;
                 break;
             case 'doughnut':
                 $spare_rows = 1;
                 $spare_cols = 0;
                 break;
             case 'bar':
                 $spare_rows = 1;
                 $spare_cols = 1;
                 break;
             default:
                 $spare_rows = 0;
                 $spare_cols = 0;
                 break;
         }
         $atts_array['spare_rows'] = $spare_rows;
         $atts_array['spare_cols'] = $spare_cols;
         $atts = cherry_charts_parse_atts($atts_array);
         $data = cherry_charts_get_meta($post->ID, 'data_' . $type, array());
         echo '<div id="cherry-chart-data-' . $type . '" class="cherry-chart-data_ ' . $active_class . '" ' . $atts . '></div>';
         echo '<input type="hidden" class="data-input-' . $type . '" name="' . $this->meta_key . '[data_' . $type . ']" value="' . json_encode($data) . '">';
     }
 }
 /**
  * Get charts pie and doughnut content
  *
  * @since  1.0.0
  *
  * @param  int    $id  Chart post ID
  * @param  string $id  Chart type
  * @return string      Chart output
  */
 function chart_pie($id, $type)
 {
     $width = cherry_charts_get_meta($id, 'width', 200);
     $height = cherry_charts_get_meta($id, 'height', 200);
     $icon = cherry_charts_get_meta($id, 'chart_icon', '');
     $data = cherry_charts_get_meta($id, 'data_' . $type, array());
     $opacity = cherry_charts_get_meta($id, 'items_opacity', 100);
     $bg_color = cherry_charts_get_meta($id, 'bg_color', false);
     $bg_opacity = cherry_charts_get_meta($id, 'bg_opacity', 100);
     $border = cherry_charts_get_meta($id, 'canvas_stroke', 0);
     $show_title = cherry_charts_get_meta($id, 'show_title', 'yes');
     $show_labels = cherry_charts_get_meta($id, 'show_labels', 'yes');
     $show_legend = cherry_charts_get_meta($id, 'show_legend', 'yes');
     // fix labels triggers
     if ('true' == $show_title) {
         $show_title = 'yes';
     }
     if ('true' == $show_labels) {
         $show_labels = 'yes';
     }
     if ('true' == $show_legend) {
         $show_legend = 'yes';
     }
     $bg_color = cherry_charts_maybe_to_rgba($bg_color, $bg_opacity);
     if (empty($data)) {
         return __('No data to show', 'cherry-charts');
     }
     $prepared_data = array();
     foreach ($data as $index => $value) {
         $color = cherry_charts_get_meta($id, 'item_color_' . ($index + 1), '');
         $color = cherry_charts_maybe_to_rgba($color, $opacity);
         $prepared_data[$index] = array('value' => !empty($value[1]) ? intval($value[1]) : 0, 'label' => !empty($value[0]) ? $value[0] : '', 'color' => $color);
     }
     $prepared_data = json_encode($prepared_data);
     /**
      * Filter custom scrip parameters. Pass to init via data attribue 'user-settings'
      * and merged with default chart init
      *
      * @since  1.0.0
      *
      * @var    array
      * @param  int  $id  chart ID
      */
     $user_chart_settings = apply_filters('cherry_charts_pie_user_settings', array(), $id);
     $data_atts = array($type => $prepared_data, 'show-labels' => $show_labels, 'show-legend' => $show_legend, 'user-settings' => json_encode($user_chart_settings));
     if ('doughnut' == $type) {
         $data_atts['cutout'] = cherry_charts_get_meta($id, 'inner_cut', 50);
     }
     $data_atts = cherry_charts_parse_atts($data_atts);
     $title = 'yes' === $show_title ? '<h3>' . get_the_title($id) . '</h3>' : '';
     $pie_format = sprintf('%5$s<div class="cherry-charts-%4$s" %1$s><canvas width="%2$d" height="%3$d"></canvas></div>', $data_atts, $width, $height, $type, $title);
     return apply_filters('cherry_charts_pie_format', $pie_format, $id);
 }