/**
  * Callback function to show chart style box
  *
  * @since  1.0.0
  *
  * @param  object $post post obkect
  */
 function _style_box($post)
 {
     $color_fields = array('item_color_1' => array('id' => 'item_color_1', 'type' => 'colorpicker', 'label' => __('Item #1 color', 'cherry-charts'), 'description' => '', 'value' => '#F7464A'), 'item_color_2' => array('id' => 'item_color_2', 'type' => 'colorpicker', 'label' => __('Item #2 color', 'cherry-charts'), 'description' => '', 'value' => '#46BFBD'), 'item_color_3' => array('id' => 'item_color_3', 'type' => 'colorpicker', 'label' => __('Item #3 color', 'cherry-charts'), 'description' => '', 'value' => '#FDB45C'), 'item_color_4' => array('id' => 'item_color_4', 'type' => 'colorpicker', 'label' => __('Item #4 color', 'cherry-charts'), 'description' => '', 'value' => '#f39c12'), 'item_color_5' => array('id' => 'item_color_5', 'type' => 'colorpicker', 'label' => __('Item #5 color', 'cherry-charts'), 'description' => '', 'value' => '#27ae60'), 'item_color_6' => array('id' => 'item_color_6', 'type' => 'colorpicker', 'label' => __('Item #6 color', 'cherry-charts'), 'description' => '', 'value' => '#16a085'), 'item_color_7' => array('id' => 'item_color_7', 'type' => 'colorpicker', 'label' => __('Item #7 color', 'cherry-charts'), 'description' => '', 'value' => '#2980b9'), 'item_color_8' => array('id' => 'item_color_8', 'type' => 'colorpicker', 'label' => __('Item #8 color', 'cherry-charts'), 'description' => '', 'value' => '#8e44ad'), 'item_color_9' => array('id' => 'item_color_9', 'type' => 'colorpicker', 'label' => __('Item #9 color', 'cherry-charts'), 'description' => '', 'value' => '#34495e'), 'item_color_10' => array('id' => 'item_color_10', 'type' => 'colorpicker', 'label' => __('Item #10 color', 'cherry-charts'), 'description' => '', 'value' => '#d35400'));
     $color_fields = apply_filters('cherry_charts_colors_meta_fields', $color_fields);
     $this->meta_fields = array_merge($this->meta_fields, $color_fields);
     $colors = '';
     foreach ($color_fields as $field) {
         $field['value'] = cherry_charts_get_meta($post->ID, $field['id'], $field['value']);
         $colors .= $this->builder->add_form_item($field);
     }
     $style_fields = array('bg_color' => array('id' => 'bg_color', 'type' => 'colorpicker', 'label' => __('Background color', 'cherry-charts'), 'description' => '', 'value' => '#ecf0f1'), 'items_opacity' => array('id' => 'items_opacity', 'type' => 'stepper', 'label' => __('Items opacity', 'cherry-charts'), 'description' => __('Set items opacity (0 - transparent, 100 - opaque)', 'cherry-charts'), 'value' => 100, 'min_value' => 0, 'max_value' => 100, 'step' => 1), 'bg_opacity' => array('id' => 'bg_opacity', 'type' => 'stepper', 'label' => __('Background opacity', 'cherry-charts'), 'description' => __('Set Background opacity (0 - transparent, 100 - opaque)', 'cherry-charts'), 'value' => 100, 'min_value' => 0, 'max_value' => 100, 'step' => 1), 'canvas_stroke' => array('id' => 'canvas_stroke', 'type' => 'stepper', 'label' => __('Chart stroke thickness', 'cherry-charts'), 'description' => __('Set chart stroke thickness (0 - without stroke)', 'cherry-charts'), 'value' => 5, 'min_value' => 0, 'max_value' => 30, 'step' => 1), 'canvas_stroke_color' => array('id' => 'canvas_stroke_color', 'type' => 'colorpicker', 'label' => __('Chart stroke color', 'cherry-charts'), 'description' => '', 'value' => '#bdc3c7'), 'canvas_stroke_opacity' => array('id' => 'canvas_stroke_opacity', 'type' => 'stepper', 'label' => __('Chart stroke opacity', 'cherry-charts'), 'description' => __('Set Chart stroke opacity (0 - transparent, 100 - opaque)', 'cherry-charts'), 'value' => 100, 'min_value' => 0, 'max_value' => 100, 'step' => 1));
     $style_fields = apply_filters('cherry_charts_style_meta_fields', $style_fields);
     $this->meta_fields = array_merge($this->meta_fields, $style_fields);
     $style = '';
     foreach ($style_fields as $field) {
         $field['value'] = cherry_charts_get_meta($post->ID, $field['id'], $field['value']);
         $style .= $this->builder->add_form_item($field);
     }
     printf('<div class="cherry-ui-core"><div class="item-colors_">%1$s</div><div class="item-styles_">%2$s</div></div>', $colors, $style);
 }
 /**
  * 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);
 }