| // +----------------------------------------------------------------------+ /** * Base class for all chart sidebar groups. * * @category Visualizer * @package Render * * @since 1.0.0 * @abstract */ abstract class Visualizer_Render_Sidebar extends Visualizer_Render { /** * The array of font families accepted by visualization API. * * @since 1.0.0 * * @static * @access protected * @var array */ protected static $_fontFamilies = array( 'Arial' => 'Arial', 'Sans Serif' => 'Sans Serif', 'serif' => 'Serif', 'Arial black' => 'Wide', 'Arial Narrow' => 'Narrow', 'Comic Sans MS' => 'Comic Sans MS', 'Courier New' => 'Courier New', 'Garamond' => 'Garamond', 'Georgia' => 'Georgia', 'Tahoma' => 'Tahoma', 'Verdana' => 'Verdana', ); /** * The Yes/No array. * * @since 1.0.0 * * @access protected * @var array */ protected $_yesno; /** * The array of available legend positions. * * @since 1.0.0 * * @access protected * @var array */ protected $_legendPositions; /** * The array of available alignments. * * @since 1.0.0 * * @access protected * @var array */ protected $_alignments; /** * Whether this chart supports animation or not. * * @access protected * @var bool */ protected $_supportsAnimation = true; /** * Which library does this this chart implement? * * @access protected * @var string */ protected $_library = null; /** * Constructor. * * @since 1.0.0 * * @access public * @param array $data The data what has to be associated with this render. */ public function __construct( $data = array() ) { parent::__construct( $data ); $this->_legendPositions = array( '' => '', 'left' => esc_html__( 'Left of the chart', 'visualizer' ), 'right' => esc_html__( 'Right of the chart', 'visualizer' ), 'top' => esc_html__( 'Above the chart', 'visualizer' ), 'bottom' => esc_html__( 'Below the chart', 'visualizer' ), 'in' => esc_html__( 'Inside the chart', 'visualizer' ), 'none' => esc_html__( 'Omit the legend', 'visualizer' ), ); $this->_alignments = array( '' => '', 'start' => esc_html__( 'Aligned to the start of the allocated area', 'visualizer' ), 'center' => esc_html__( 'Centered in the allocated area', 'visualizer' ), 'end' => esc_html__( 'Aligned to the end of the allocated area', 'visualizer' ), ); $this->_yesno = array( '' => '', '1' => esc_html__( 'Yes', 'visualizer' ), '0' => esc_html__( 'No', 'visualizer' ), ); $this->hooks(); } /** * Renders chart title settings. * * @since 1.0.0 * * @access protected */ protected function _renderChartTitleSettings() { self::_renderTextItem( esc_html__( 'Chart Title', 'visualizer' ), 'title', $this->title, esc_html__( 'Text to display above the chart.', 'visualizer' ) ); self::_renderColorPickerItem( esc_html__( 'Chart Title Color', 'visualizer' ), 'titleTextStyle[color]', isset( $this->titleTextStyle['color'] ) ? $this->titleTextStyle['color'] : null, '#000' ); } /** * Add the correct description for the manual configuration box. */ protected function _renderManualConfigDescription() { self::_renderSectionStart(); self::_renderSectionDescription( '' . sprintf( __( 'Configure the graph by providing configuration variables right from the %1$sGoogle Visualization API%2$s. You can refer to to some examples %3$shere%4$s.', 'visualizer' ), '', '', '', '' ) . '' ); } /** * Add the correct example for the manual configuration box. */ protected function _renderManualConfigExample() { return '{ "vAxis": { "ticks": [5, 10, 15, 20], "titleTextStyle": { "color": "red" }, "textPosition": "in" } }'; } /** * Renders chart advanced settings group. * * @access protected */ protected function _renderAdvancedSettings() { self::_renderGroupStart( esc_html__( 'Frontend Actions', 'visualizer' ) ); self::_renderSectionStart(); self::_renderSectionDescription( esc_html__( 'Configure frontend actions that need to be shown.', 'visualizer' ) ); self::_renderSectionEnd(); $this->_renderActionSettings(); self::_renderGroupEnd(); self::_renderGroupStart( esc_html__( 'Manual Configuration', 'visualizer' ) ); $this->_renderManualConfigDescription(); self::_renderTextAreaItem( esc_html__( 'Configuration', 'visualizer' ), 'manual', $this->manual, sprintf( esc_html__( 'One per line in valid JSON (key:value) format e.g. %s', 'visualizer' ), '
' . $this->_renderManualConfigExample() . '' ), '', array( 'rows' => 5 ) ); self::_renderSectionEnd(); self::_renderGroupEnd(); } /** * Renders chart action buttons group. * * @access protected */ protected function _renderActionSettings() { global $wp_version; $disable_actions = version_compare( $wp_version, '4.7.0', '<' ); self::_renderSectionStart( esc_html__( 'Actions', 'visualizer' ), false ); self::_renderCheckboxItem( esc_html__( 'Print', 'visualizer' ), 'actions[]', isset( $this->actions ) && in_array( 'print', $this->actions, true ) ? true : false, 'print', $disable_actions ? '' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '' : esc_html__( 'To enable printing the chart/data.', 'visualizer' ), $disable_actions ); self::_renderCheckboxItem( esc_html__( 'CSV', 'visualizer' ), 'actions[]', isset( $this->actions ) && in_array( 'csv;application/csv', $this->actions, true ) ? true : false, 'csv;application/csv', $disable_actions ? '' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '' : esc_html__( 'To enable downloading the data as a CSV.', 'visualizer' ), $disable_actions ); $disabled = ! self::is_excel_enabled(); self::_renderCheckboxItem( esc_html__( 'Excel', 'visualizer' ), 'actions[]', isset( $this->actions ) && in_array( 'xls;application/vnd.ms-excel', $this->actions, true ) ? true : false, 'xls;application/vnd.ms-excel', $disable_actions ? '' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '' : ( $disabled ? '' . esc_html__( 'Enable the ZIP and XML extensions to use this setting.', 'visualizer' ) . '' : esc_html__( 'To enable downloading the data as an Excel spreadsheet.', 'visualizer' ) ), $disable_actions || $disabled ); self::_renderCheckboxItem( esc_html__( 'Copy', 'visualizer' ), 'actions[]', isset( $this->actions ) && in_array( 'copy', $this->actions, true ) ? true : false, 'copy', $disable_actions ? '' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '' : esc_html__( 'To enable copying the data to the clipboard.', 'visualizer' ), $disable_actions ); self::_renderSectionEnd(); } /** * Checks if the Excel module can be enabled. */ private static function is_excel_enabled() { $vendor_file = VISUALIZER_ABSPATH . '/vendor/autoload.php'; if ( is_readable( $vendor_file ) ) { include_once( $vendor_file ); } if ( version_compare( phpversion(), '5.6.0', '<' ) ) { do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'PHP version %s not supported', phpversion() ), 'error', __FILE__, __LINE__ ); return false; } return class_exists( 'PhpOffice\PhpSpreadsheet\Spreadsheet' ) && extension_loaded( 'zip' ) && extension_loaded( 'xml' ) && extension_loaded( 'fileinfo' ); } /** * Renders chart general settings group. * * @since 1.0.0 * * @access protected */ protected function _renderGeneralSettings() { self::_renderGroupStart( esc_html__( 'General Settings', 'visualizer' ) ); self::_renderSectionStart(); self::_renderSectionDescription( esc_html__( 'Configure title, font styles, tooltip, legend and else settings for the chart.', 'visualizer' ) ); self::_renderSectionEnd(); self::_renderSectionStart( esc_html__( 'Title', 'visualizer' ), false ); $this->_renderChartTitleSettings(); self::_renderSectionEnd(); self::_renderSectionStart( esc_html__( 'Font Styles', 'visualizer' ), false ); echo '
'; echo '[?]'; echo '', esc_html__( 'Family And Size', 'visualizer' ), ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'; echo ''; echo ''; echo ''; echo '
'; echo '

'; esc_html_e( 'The default font family and size for all text in the chart.', 'visualizer' ); echo '

'; echo '
'; self::_renderSectionEnd(); self::_renderSectionStart( esc_html__( 'Legend', 'visualizer' ), false ); self::_renderSelectItem( esc_html__( 'Position', 'visualizer' ), 'legend[position]', $this->legend['position'], $this->_legendPositions, esc_html__( 'Determines where to place the legend, compared to the chart area.', 'visualizer' ) ); self::_renderSelectItem( esc_html__( 'Alignment', 'visualizer' ), 'legend[alignment]', $this->legend['alignment'], $this->_alignments, esc_html__( 'Determines the alignment of the legend.', 'visualizer' ) ); self::_renderColorPickerItem( esc_html__( 'Font Color', 'visualizer' ), 'legend[textStyle][color]', isset( $this->legend['textStyle']['color'] ) ? $this->legend['textStyle']['color'] : null, '#000' ); self::_renderSectionEnd(); self::_renderSectionStart( esc_html__( 'Tooltip', 'visualizer' ), false ); $this->_renderTooltipSettigns(); self::_renderSectionEnd(); $this->_renderAnimationSettings(); self::_renderGroupEnd(); } /** * Renders animation settings section. * * @access protected */ protected function _renderAnimationSettings() { if ( ! $this->_supportsAnimation ) { return; } self::_renderSectionStart( esc_html__( 'Animation', 'visualizer' ), false ); self::_renderCheckboxItem( esc_html__( 'Animate on startup', 'visualizer' ), 'animation[startup]', isset( $this->animation['startup'] ) ? $this->animation['startup'] : 0, true, esc_html__( 'Determines if the chart will animate on the initial draw.', 'visualizer' ) ); self::_renderTextItem( esc_html__( 'Duration', 'visualizer' ), 'animation[duration]', isset( $this->animation['duration'] ) ? $this->animation['duration'] : 0, esc_html__( 'The duration of the animation, in milliseconds', 'visualizer' ), 0, 'number' ); self::_renderSelectItem( esc_html__( 'Easing', 'visualizer' ), 'animation[easing]', isset( $this->animation['easing'] ) ? $this->animation['easing'] : null, array( 'linear' => esc_html__( 'Constant speed', 'visualizer' ), 'in' => esc_html__( 'Start slow and speed up', 'visualizer' ), 'out' => esc_html__( 'Start fast and slow down', 'visualizer' ), 'inAndOut' => esc_html__( 'Start slow, speed up, then slow down', 'visualizer' ), ), esc_html__( 'The easing function applied to the animation.', 'visualizer' ) ); self::_renderSectionEnd(); } /** * Renders tooltip settings section. * * @since 1.4.0 * * @access protected */ protected function _renderTooltipSettigns() { self::_renderSelectItem( esc_html__( 'Trigger', 'visualizer' ), 'tooltip[trigger]', isset( $this->tooltip['trigger'] ) ? $this->tooltip['trigger'] : null, array( '' => '', 'focus' => esc_html__( 'The tooltip will be displayed when the user hovers over an element', 'visualizer' ), 'selection' => esc_html__( 'The tooltip will be displayed when the user selects an element', 'visualizer' ), 'none' => esc_html__( 'The tooltip will not be displayed', 'visualizer' ), ), esc_html__( 'Determines the user interaction that causes the tooltip to be displayed.', 'visualizer' ) ); self::_renderSelectItem( esc_html__( 'Show Color Code', 'visualizer' ), 'tooltip[showColorCode]', isset( $this->tooltip['showColorCode'] ) ? $this->tooltip['showColorCode'] : null, $this->_yesno, esc_html__( 'If set to yes, will show colored squares next to the slice information in the tooltip.', 'visualizer' ) ); } /** * Renders chart view settings group. * * @since 1.0.0 * * @access protected */ protected function _renderViewSettings() { self::_renderGroupStart( esc_html__( 'Chart Size & Placement', 'visualizer' ) ); self::_renderSectionStart( esc_html__( 'Chart Size/Layout', 'visualizer' ), false ); self::_renderSectionDescription( esc_html__( 'Configure the total size of the chart. Two formats are supported: a number, or a number followed by %. A simple number is a value in pixels; a number followed by % is a percentage.', 'visualizer' ) ); echo '
'; echo '[?]'; echo '', esc_html__( 'Width And Height Of Chart', 'visualizer' ), ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'; echo ''; echo ''; echo ''; echo '
'; echo '

'; esc_html_e( 'Determines the total width and height of the chart. This will only show in the front-end.', 'visualizer' ); echo '

'; echo '
'; echo '
'; self::_renderSectionDescription( esc_html__( 'Configure the background color for the main area of the chart and the chart border width and color.', 'visualizer' ) ); self::_renderTextItem( esc_html__( 'Stroke Width', 'visualizer' ), 'backgroundColor[strokeWidth]', isset( $this->backgroundColor['strokeWidth'] ) ? $this->backgroundColor['strokeWidth'] : null, esc_html__( 'The chart border width in pixels.', 'visualizer' ), '0' ); self::_renderColorPickerItem( esc_html__( 'Stroke Color', 'visualizer' ), 'backgroundColor[stroke]', ! empty( $this->backgroundColor['stroke'] ) ? $this->backgroundColor['stroke'] : null, '#666' ); $background_color = ! empty( $this->backgroundColor['fill'] ) ? $this->backgroundColor['fill'] : null; self::_renderColorPickerItem( esc_html__( 'Background Color', 'visualizer' ), 'backgroundColor[fill]', $background_color, '#fff' ); echo '
'; echo ''; echo '
'; self::_renderSectionEnd(); self::_renderSectionStart( esc_html__( 'Placement', 'visualizer' ), false ); self::_renderSectionDescription( esc_html__( 'Configure the placement and size of the chart area (where the chart itself is drawn, excluding axis and legends). Two formats are supported: a number, or a number followed by %. A simple number is a value in pixels; a number followed by % is a percentage.', 'visualizer' ) ); echo '
'; echo '[?]'; echo '', esc_html__( 'Left And Top Margins', 'visualizer' ), ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'; echo ''; echo ''; echo ''; echo '
'; echo '

'; esc_html_e( 'Determines how far to draw the chart from the left and top borders.', 'visualizer' ); echo '

'; echo '
'; echo '
'; echo '[?]'; echo '', esc_html__( 'Width And Height Of Chart Area', 'visualizer' ), ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'; echo ''; echo ''; echo ''; echo '
'; echo '

'; esc_html_e( 'Determines the width and hight of the chart area.', 'visualizer' ); echo '

'; echo '
'; self::_renderSectionEnd(); self::_renderGroupEnd(); } /** * Renders select item. * * @since 1.0.0 * * @static * @access public * @param string $title The title of the select item. * @param string $name The name of the select item. * @param string $value The actual value of the select item. * @param array $options The array of select options. * @param string $desc The description of the select item. * @param bool $multiple Is this a multiple select box. * @param array $classes Any additional classes. * @param array $attributes Custom attributes. */ public static function _renderSelectItem( $title, $name, $value, array $options, $desc, $multiple = false, $classes = array(), $attributes = array() ) { $atts = ''; if ( $attributes ) { foreach ( $attributes as $k => $v ) { $atts .= ' data-visualizer-' . $k . '=' . esc_attr( $v ); } } echo '
'; echo '[?]'; echo '', $title, ''; echo ''; echo '

', $desc, '

'; echo '
'; } /** * Renders color picker item. * * @since 1.0.0 * * @static * @access protected * @param string $title The title of the select item. * @param string $name The name of the select item. * @param string $value The actual value of the select item. * @param string $default The default value of the color picker. */ protected static function _renderColorPickerItem( $title, $name, $value, $default ) { echo '
'; echo '', $title, ''; echo '
'; echo ''; echo '
'; echo '
'; } /** * Renders text item. * * @since 1.0.0 * * @static * @access protected * @param string $title The title of the select item. * @param string $name The name of the select item. * @param string $value The actual value of the select item. * @param string $desc The description of the select item. * @param string $placeholder The placeholder for the input. * @param string $type The type for the input (out of number, email, tel etc., default is text). * @param array $custom_attributes The custom attributes. */ protected static function _renderTextItem( $title, $name, $value, $desc, $placeholder = '', $type = 'text', $custom_attributes = array() ) { $attributes = ''; if ( $custom_attributes ) { foreach ( $custom_attributes as $k => $v ) { $attributes .= ' ' . $k . '="' . esc_attr( $v ) . '"'; } } echo '
'; echo '[?]'; echo '', $title, ''; echo ''; echo '

', $desc, '

'; echo '
'; } /** * Renders the beginning of a group. * * @since 1.0.0 * * @static * @access public * @param string $title The title of this group. * @param string $html Any additional HTML. * @param string $class Any additional classes. */ public static function _renderGroupStart( $title, $html = '', $class = '' ) { echo '
  • '; echo '

    ', $title, '

    '; echo $html; echo ''; echo '
  • '; } /** * Renders the beginning of a section. * * @since 1.0.0 * * @static * @access public * @param string $title The title of this section. If the title is empty, no title will be displayed. * @param boolean $open Determines whether the section items block has to be expanded or collapsed. */ public static function _renderSectionStart( $title = false, $open = true ) { if ( ! empty( $title ) ) { echo '
  • '; echo '', $title, ''; } else { echo '
  • '; } echo '
    '; } /** * Renders the ending of a section. * * @since 1.0.0 * * @public * @access protected * @param string $html Any addition HTML to add. */ public static function _renderSectionEnd( $html = '' ) { echo '
    '; echo $html; echo '
  • '; } /** * Renders section description block. * * @since 1.0.0 * * @static * @access public * @param string $description The description text. */ public static function _renderSectionDescription( $description, $classes = '' ) { echo '
    '; echo '
    ', $description, '
    '; echo '
    '; } /** * Renders format field according to series type. * * @since 1.3.0 * * @access protected * @param int $index The index of the series. */ protected function _renderFormatField( $index = 0 ) { switch ( $this->__series[ $index + 1 ]['type'] ) { case 'number': self::_renderTextItem( esc_html__( 'Number Format', 'visualizer' ), 'series[' . $index . '][format]', isset( $this->series[ $index ]['format'] ) ? $this->series[ $index ]['format'] : '', sprintf( esc_html__( 'Enter custom format pattern to apply to this series value, similar to the %1$sICU pattern set%2$s. Use something like #,### to get 1,234 as output, or $# to add dollar sign before digits. Pay attention that if you use % percentage format then your values will be multiplied by 100.', 'visualizer' ), '', '' ), '#,###.##' ); break; case 'date': case 'datetime': case 'timeofday': self::_renderTextItem( esc_html__( 'Date Format', 'visualizer' ), 'series[' . $index . '][format]', isset( $this->series[ $index ]['format'] ) ? $this->series[ $index ]['format'] : '', sprintf( esc_html__( 'Enter custom format pattern to apply to this series value, similar to the %1$sICU date and time format%2$s.', 'visualizer' ), '', '' ), 'eeee, dd LLLL yyyy' ); break; } } /** * Render a checkbox item */ protected static function _renderCheckboxItem( $title, $name, $value, $default, $desc, $disabled = false ) { echo '
    '; echo '[?]'; echo '', $title, ''; // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison echo ''; echo '

    ', $desc, '

    '; echo '
    '; } /** * Render a textarea item. */ protected static function _renderTextAreaItem( $title, $name, $value, $desc, $placeholder = '', $custom_attributes = array() ) { $attributes = ''; if ( $custom_attributes ) { foreach ( $custom_attributes as $k => $v ) { $attributes .= ' ' . $k . '="' . esc_attr( $v ) . '"'; } } echo '
    '; echo '[?]'; echo '', $title, ''; echo ''; echo '

    ', $desc, '

    '; echo '
    '; } /** * Returns the library this chart implements. */ public function getLibrary() { return $this->_library; } /** * Loads generic libraries conditionally. */ protected function load_dependent_assets( $libs ) { if ( in_array( 'moment', $libs, true ) && ! wp_script_is( 'moment', 'registered' ) ) { wp_register_script( 'moment', VISUALIZER_ABSURL . 'js/lib/moment.min.js', array(), Visualizer_Plugin::VERSION ); } if ( in_array( 'numeral', $libs, true ) && ! wp_script_is( 'numeral', 'registered' ) ) { wp_register_script( 'numeral', VISUALIZER_ABSURL . 'js/lib/numeral.min.js', array(), Visualizer_Plugin::VERSION ); } } }