<?php
/**
* Class: Jet_Elements_Pie_Chart
* Name: Pie Chart
* Slug: jet-pie-chart
*/
namespace Elementor;
use Elementor\Controls_Manager;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Box_Shadow;
use Elementor\Group_Control_Typography;
use Elementor\Repeater;
use Elementor\Scheme_Color;
use Elementor\Scheme_Typography;
use Elementor\Widget_Base;
use Elementor\Modules\DynamicTags\Module as TagsModule;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Jet Pie Chart Widget.
*/
class Jet_Elements_Pie_Chart extends Jet_Elements_Base {
/**
* Get widget name.
*
* @return string
*/
public function get_name() {
return 'jet-pie-chart';
}
/**
* Get widget title.
*
* @return string
*/
public function get_title() {
return esc_html__( 'Pie Chart', 'jet-elements' );
}
/**
* Get widget icon.
*
* @return string
*/
public function get_icon() {
return 'jet-elements-icon-pie-chart';
}
public function get_jet_help_url() {
return 'https://crocoblock.com/knowledge-base/articles/jetelements-pie-chart-widget-how-to-display-your-statistical-data-with-a-chart/';
}
/**
* Retrieve the list of scripts the widget depended on.
*
* @return array
*/
public function get_script_depends() {
return array( 'chart-js' );
}
/**
* Get widget categories.
*
* @return array
*/
public function get_categories() {
return array( 'cherry' );
}
/**
* Register widget controls.
*/
protected function _register_controls() {
$css_scheme = apply_filters(
'jet-elements/pie-chart/css-scheme',
array(
'container' => '.jet-pie-chart-container',
'title' => '.jet-pie-chart-title',
)
);
/**
* `Chart Data` Section
*/
$this->start_controls_section(
'section_chart_data',
array(
'label' => esc_html__( 'Chart Data', 'jet-elements' ),
)
);
$repeater = new Repeater();
$repeater->add_control(
'label',
array(
'label' => esc_html__( 'Label', 'jet-elements' ),
'type' => Controls_Manager::TEXT,
'dynamic' => array( 'active' => true ),
)
);
$repeater->add_control(
'value',
array(
'label' => esc_html__( 'Value', 'jet-elements' ),
'type' => Controls_Manager::NUMBER,
'min' => 0,
'dynamic' => version_compare( ELEMENTOR_VERSION, '2.7.0', '>=' ) ?
array(
'active' => true,
'categories' => array(
TagsModule::POST_META_CATEGORY,
TagsModule::NUMBER_CATEGORY,
),
) : array(),
)
);
$repeater->add_control(
'color',
array(
'label' => esc_html__( 'Color', 'jet-elements' ),
'type' => Controls_Manager::COLOR,
)
);
$this->add_control(
'chart_data',
array(
'type' => Controls_Manager::REPEATER,
'fields' => $repeater->get_controls(),
'default' => array(
array(
'label' => esc_html__( 'Google', 'jet-elements' ),
'value' => 50,
'color' => '#dd4b39',
),
array(
'label' => esc_html__( 'Facebook', 'jet-elements' ),
'value' => 50,
'color' => '#3b5998',
),
array(
'label' => esc_html__( 'Twitter', 'jet-elements' ),
'value' => 50,
'color' => '#55acee',
),
),
'title_field' => '{{{ label }}}',
)
);
$this->add_control(
'chart_title',
array(
'label' => esc_html__( 'Chart Title', 'jet-elements' ),
'type' => Controls_Manager::TEXT,
'default' => esc_html__( 'Pie Chart', 'jet-elements' ),
'dynamic' => array( 'active' => true ),
'separator' => 'before',
)
);
$this->add_control(
'chart_title_size',
array(
'label' => esc_html__( 'Title HTML Tag', 'jet-elements' ),
'type' => Controls_Manager::SELECT,
'options' => jet_elements_tools()->get_available_title_html_tags(),
'default' => 'h5',
)
);
$this->add_control(
'chart_title_position',
array(
'label' => esc_html__( 'Title Position', 'jet-elements' ),
'type' => Controls_Manager::SELECT,
'options' => array(
'before' => esc_html__( 'Before Chart', 'jet-elements' ),
'after' => esc_html__( 'After Chart', 'jet-elements' ),
),
'default' => 'after',
)
);
$this->end_controls_section();
/**
* `Settings` Section
*/
$this->start_controls_section(
'section_settings',
array(
'label' => esc_html__( 'Settings', 'jet-elements' ),
)
);
$this->add_responsive_control(
'chart_height',
array(
'label' => esc_html__( 'Chart Height', 'jet-elements' ),
'type' => Controls_Manager::SLIDER,
'range' => array(
'px' => array(
'min' => 100,
'max' => 1200,
),
),
'selectors' => array(
'{{WRAPPER}} ' . $css_scheme['container'] => 'height: {{SIZE}}{{UNIT}};',
),
'render_type' => 'template',
)
);
$this->add_control(
'chart_cutout_percentage',
array(
'label' => esc_html__( 'Cutout Percentage', 'jet-elements' ),
'description' => esc_html__( 'The percentage of the chart that is cut out of the middle.', 'jet-elements' ),
'type' => Controls_Manager::SLIDER,
'size_units' => array( '%' ),
'range' => array(
'%' => array(
'min' => 0,
'max' => 99,
),
),
'default' => array(
'unit' => '%',
),
)
);
$this->add_control(
'chart_animation_heading',
array(
'label' => esc_html__( 'Animations', 'jet-elements' ),
'type' => Controls_Manager::HEADING,
'separator' => 'before',
)
);
$this->add_control(
'chart_animation_duration',
array(
'label' => esc_html__( 'Duration', 'jet-elements' ),
'type' => Controls_Manager::SLIDER,
'size_units' => array( 'ms' ),
'range' => array(
'ms' => array(
'min' => 100,
'max' => 3000,
),
),
'default' => array(
'unit' => 'ms',
),
)
);
$animation_easing = array(
'linear',
'easeInQuad',
'easeOutQuad',
'easeInOutQuad',
'easeInCubic',
'easeOutCubic',
'easeInOutCubic',
'easeInQuart',
'easeOutQuart',
'easeInOutQuart',
'easeInQuint',
'easeOutQuint',
'easeInOutQuint',
'easeInSine',
'easeOutSine',
'easeInOutSine',
'easeInExpo',
'easeOutExpo',
'easeInOutExpo',
'easeInCirc',
'easeOutCirc',
'easeInOutCirc',
'easeInElastic',
'easeOutElastic',
'easeInOutElastic',
'easeInBack',
'easeOutBack',
'easeInOutBack',
'easeInBounce',
'easeOutBounce',
'easeInOutBounce',
);
$this->add_control(
'chart_animation_easing',
array(
'label' => esc_html__( 'Easing', 'jet-elements' ),
'type' => Controls_Manager::SELECT,
'default' => 'easeOutQuart',
'options' => array_combine( $animation_easing, $animation_easing )
)
);
$this->add_control(
'chart_animate_scale',
array(
'label' => esc_html__( 'Animate Scale', 'jet-elements' ),
'description' => esc_html__( 'If yes, will animate scaling the chart from the center outwards.', 'jet-elements' ),
'type' => Controls_Manager::SWITCHER,
'default' => '',
'return_value' => 'true',
)
);
$this->add_control(
'chart_legend_heading',
array(
'label' => esc_html__( 'Legend', 'jet-elements' ),
'type' => Controls_Manager::HEADING,
'separator' => 'before',
)
);
$this->add_control(
'chart_legend_display',
array(
'label' => esc_html__( 'Display', 'jet-elements' ),
'type' => Controls_Manager::SWITCHER,
'default' => 'true',
'return_value' => 'true',
)
);
$this->add_control(
'chart_legend_position',
Loading ...