| 1 |
<?php |
| 2 |
|
| 3 |
// +----------------------------------------------------------------------+ |
| 4 |
// | Copyright 2013 Madpixels (email : visualizer@madpixels.net) | |
| 5 |
// +----------------------------------------------------------------------+ |
| 6 |
// | This program is free software; you can redistribute it and/or modify | |
| 7 |
// | it under the terms of the GNU General Public License, version 2, as | |
| 8 |
// | published by the Free Software Foundation. | |
| 9 |
// | | |
| 10 |
// | This program is distributed in the hope that it will be useful, | |
| 11 |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 |
// | GNU General Public License for more details. | |
| 14 |
// | | |
| 15 |
// | You should have received a copy of the GNU General Public License | |
| 16 |
// | along with this program; if not, write to the Free Software | |
| 17 |
// | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, | |
| 18 |
// | MA 02110-1301 USA | |
| 19 |
// +----------------------------------------------------------------------+ |
| 20 |
// | Author: Eugene Manuilov <eugene@manuilov.org> | |
| 21 |
// +----------------------------------------------------------------------+ |
| 22 |
|
| 23 |
|
| 24 |
/** |
| 25 |
* Base class for sidebar settigns of graph based charts. |
| 26 |
* |
| 27 |
* @category Visualizer |
| 28 |
* @package Render |
| 29 |
* @subpackage Sidebar |
| 30 |
* |
| 31 |
* @since 1.0.0 |
| 32 |
* @abstract |
| 33 |
*/ |
| 34 |
abstract class Visualizer_Render_Sidebar_Graph extends Visualizer_Render_Sidebar { |
| 35 |
|
| 36 |
/** |
| 37 |
* Determines whether we need to render vertical gridlines options or not. |
| 38 |
* |
| 39 |
* @since 1.0.0 |
| 40 |
* |
| 41 |
* @access protected |
| 42 |
* @var boolean |
| 43 |
*/ |
| 44 |
protected $_verticalGridLines; |
| 45 |
|
| 46 |
/** |
| 47 |
* Determines whether we need to render horizontal gridlines options or not. |
| 48 |
* |
| 49 |
* @since 1.0.0 |
| 50 |
* |
| 51 |
* @access protected |
| 52 |
* @var boolean |
| 53 |
*/ |
| 54 |
protected $_horizontalGridLines; |
| 55 |
|
| 56 |
/** |
| 57 |
* The array of available axis positions. |
| 58 |
* |
| 59 |
* @since 1.0.0 |
| 60 |
* |
| 61 |
* @access protected |
| 62 |
* @var array |
| 63 |
*/ |
| 64 |
protected $_positions; |
| 65 |
|
| 66 |
/** |
| 67 |
* Constructor. |
| 68 |
* |
| 69 |
* @since 1.0.0 |
| 70 |
* |
| 71 |
* @access public |
| 72 |
* @param array $data The data what has to be associated with this render. |
| 73 |
*/ |
| 74 |
public function __construct( $data = array() ) { |
| 75 |
parent::__construct( $data ); |
| 76 |
|
| 77 |
$this->_verticalGridLines = true; |
| 78 |
$this->_horizontalGridLines = true; |
| 79 |
|
| 80 |
$this->_positions = array( |
| 81 |
'' => '', |
| 82 |
'in' => esc_html__( 'Inside the chart', Visualizer_Plugin::NAME ), |
| 83 |
'out' => esc_html__( 'Outside the chart', Visualizer_Plugin::NAME ), |
| 84 |
'none' => esc_html__( 'None', Visualizer_Plugin::NAME ), |
| 85 |
); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Renders chart title settings. |
| 90 |
* |
| 91 |
* @since 1.0.0 |
| 92 |
* |
| 93 |
* @access protected |
| 94 |
*/ |
| 95 |
protected function _renderChartTitleSettings() { |
| 96 |
parent::_renderChartTitleSettings(); |
| 97 |
|
| 98 |
self::_renderSelectItem( |
| 99 |
esc_html__( 'Chart Title Position', Visualizer_Plugin::NAME ), |
| 100 |
'titlePosition', |
| 101 |
$this->titlePosition, |
| 102 |
$this->_positions, |
| 103 |
esc_html__( 'Where to place the chart title, compared to the chart area.', Visualizer_Plugin::NAME ) |
| 104 |
); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Renders chart axes settings. |
| 109 |
* |
| 110 |
* @since 1.0.0 |
| 111 |
* |
| 112 |
* @access protected |
| 113 |
*/ |
| 114 |
protected function _renderAxesSettings() { |
| 115 |
$directions = array( |
| 116 |
'' => '', |
| 117 |
'1' => esc_html__( 'Identical Direction', Visualizer_Plugin::NAME ), |
| 118 |
'-1' => esc_html__( 'Reverse Direction', Visualizer_Plugin::NAME ), |
| 119 |
); |
| 120 |
|
| 121 |
self::_renderGroupStart( esc_html__( 'Horizontal & Vertical Axes', Visualizer_Plugin::NAME ) ); |
| 122 |
self::_renderSectionStart(); |
| 123 |
self::_renderSelectItem( |
| 124 |
esc_html__( 'Axes Titles Position', Visualizer_Plugin::NAME ), |
| 125 |
'axisTitlesPosition', |
| 126 |
$this->axisTitlesPosition, |
| 127 |
$this->_positions, |
| 128 |
esc_html__( 'Determines where to place the axis titles, compared to the chart area.', Visualizer_Plugin::NAME ) |
| 129 |
); |
| 130 |
self::_renderSectionEnd(); |
| 131 |
|
| 132 |
self::_renderSectionStart( esc_html__( 'Horizontal Axis', Visualizer_Plugin::NAME ), false ); |
| 133 |
self::_renderTextItem( |
| 134 |
esc_html__( 'Axis Title', Visualizer_Plugin::NAME ), |
| 135 |
'hAxis[title]', |
| 136 |
isset( $this->hAxis['title'] ) ? $this->hAxis['title'] : '', |
| 137 |
esc_html__( 'The title of the horizontal axis.', Visualizer_Plugin::NAME ) |
| 138 |
); |
| 139 |
|
| 140 |
self::_renderSelectItem( |
| 141 |
esc_html__( 'Text Position', Visualizer_Plugin::NAME ), |
| 142 |
'vAxis[textPosition]', |
| 143 |
isset( $this->vAxis['textPosition'] ) ? $this->vAxis['textPosition'] : '', |
| 144 |
$this->_positions, |
| 145 |
esc_html__( 'Position of the horizontal axis text, relative to the chart area.', Visualizer_Plugin::NAME ) |
| 146 |
); |
| 147 |
|
| 148 |
self::_renderSelectItem( |
| 149 |
esc_html__( 'Direction', Visualizer_Plugin::NAME ), |
| 150 |
'hAxis[direction]', |
| 151 |
isset( $this->hAxis['direction'] ) ? $this->hAxis['direction'] : '', |
| 152 |
$directions, |
| 153 |
esc_html__( 'The direction in which the values along the horizontal axis grow.', Visualizer_Plugin::NAME ) |
| 154 |
); |
| 155 |
|
| 156 |
if ( $this->_horizontalGridLines ) { |
| 157 |
self::_renderTextItem( |
| 158 |
esc_html__( 'Grid Lines Count', Visualizer_Plugin::NAME ), |
| 159 |
'vAxis[gridlines][count]', |
| 160 |
isset( $this->vAxis['gridlines']['count'] ) ? $this->vAxis['gridlines']['count'] : '', |
| 161 |
esc_html__( 'The number of horizontal gridlines inside the chart area. Minimum value is 2. Specify -1 to automatically compute the number of gridlines.', Visualizer_Plugin::NAME ), |
| 162 |
5 |
| 163 |
); |
| 164 |
|
| 165 |
self::_renderColorPickerItem( |
| 166 |
esc_html__( 'Grid Lines Color', Visualizer_Plugin::NAME ), |
| 167 |
'vAxis[gridlines][color]', |
| 168 |
isset( $this->vAxis['gridlines']['color'] ) ? $this->vAxis['gridlines']['color'] : null, |
| 169 |
'#ccc' |
| 170 |
); |
| 171 |
} |
| 172 |
|
| 173 |
self::_renderColorPickerItem( |
| 174 |
esc_html__( 'Base Line Color', Visualizer_Plugin::NAME ), |
| 175 |
'vAxis[baselineColor]', |
| 176 |
isset( $this->vAxis['baselineColor'] ) ? $this->vAxis['baselineColor'] : null, |
| 177 |
'#000' |
| 178 |
); |
| 179 |
self::_renderSectionEnd(); |
| 180 |
|
| 181 |
self::_renderSectionStart( esc_html__( 'Vertical Axis', Visualizer_Plugin::NAME ), false ); |
| 182 |
self::_renderTextItem( |
| 183 |
esc_html__( 'Axis Title', Visualizer_Plugin::NAME ), |
| 184 |
'vAxis[title]', |
| 185 |
isset( $this->vAxis['title'] ) ? $this->vAxis['title'] : '', |
| 186 |
esc_html__( 'The title of the vertical axis.', Visualizer_Plugin::NAME ) |
| 187 |
); |
| 188 |
|
| 189 |
self::_renderSelectItem( |
| 190 |
esc_html__( 'Text Position', Visualizer_Plugin::NAME ), |
| 191 |
'hAxis[textPosition]', |
| 192 |
isset( $this->hAxis['textPosition'] ) ? $this->hAxis['textPosition'] : '', |
| 193 |
$this->_positions, |
| 194 |
esc_html__( 'Position of the vertical axis text, relative to the chart area.', Visualizer_Plugin::NAME ) |
| 195 |
); |
| 196 |
|
| 197 |
self::_renderSelectItem( |
| 198 |
esc_html__( 'Direction', Visualizer_Plugin::NAME ), |
| 199 |
'vAxis[direction]', |
| 200 |
isset( $this->vAxis['direction'] ) ? $this->vAxis['direction'] : '', |
| 201 |
$directions, |
| 202 |
esc_html__( 'The direction in which the values along the vertical axis grow.', Visualizer_Plugin::NAME ) |
| 203 |
); |
| 204 |
|
| 205 |
if ( $this->_verticalGridLines ) { |
| 206 |
self::_renderTextItem( |
| 207 |
esc_html__( 'Grid Lines Count', Visualizer_Plugin::NAME ), |
| 208 |
'hAxis[gridlines][count]', |
| 209 |
isset( $this->hAxis['gridlines']['count'] ) ? $this->hAxis['gridlines']['count'] : '', |
| 210 |
esc_html__( 'The number of vertical gridlines inside the chart area. Minimum value is 2. Specify -1 to automatically compute the number of gridlines.', Visualizer_Plugin::NAME ), |
| 211 |
5 |
| 212 |
); |
| 213 |
|
| 214 |
self::_renderColorPickerItem( |
| 215 |
esc_html__( 'Grid Lines Color', Visualizer_Plugin::NAME ), |
| 216 |
'hAxis[gridlines][color]', |
| 217 |
isset( $this->hAxis['gridlines']['color'] ) ? $this->hAxis['gridlines']['color'] : null, |
| 218 |
'#ccc' |
| 219 |
); |
| 220 |
} |
| 221 |
|
| 222 |
self::_renderColorPickerItem( |
| 223 |
esc_html__( 'Base Line Color', Visualizer_Plugin::NAME ), |
| 224 |
'hAxis[baselineColor]', |
| 225 |
isset( $this->hAxis['baselineColor'] ) ? $this->hAxis['baselineColor'] : null, |
| 226 |
'#000' |
| 227 |
); |
| 228 |
self::_renderSectionEnd(); |
| 229 |
self::_renderGroupEnd(); |
| 230 |
} |
| 231 |
|
| 232 |
/** |
| 233 |
* Renders series settings group. |
| 234 |
* |
| 235 |
* @since 1.0.0 |
| 236 |
* |
| 237 |
* @access protected |
| 238 |
*/ |
| 239 |
protected function _renderSeriesSettings() { |
| 240 |
self::_renderGroupStart( esc_html__( 'Series Settings', Visualizer_Plugin::NAME ) ); |
| 241 |
for ( $i = 1, $cnt = count( $this->__series ); $i < $cnt; $i++ ) { |
| 242 |
if ( !empty( $this->__series[$i]['label'] ) ) { |
| 243 |
self::_renderSectionStart( esc_html( $this->__series[$i]['label'] ), false ); |
| 244 |
$this->_renderSeries( $i - 1 ); |
| 245 |
self::_renderSectionEnd(); |
| 246 |
} |
| 247 |
} |
| 248 |
self::_renderGroupEnd(); |
| 249 |
} |
| 250 |
|
| 251 |
/** |
| 252 |
* Renders concreate series settings. |
| 253 |
* |
| 254 |
* @since 1.0.0 |
| 255 |
* |
| 256 |
* @access protected |
| 257 |
* @param int $index The series index. |
| 258 |
*/ |
| 259 |
protected function _renderSeries( $index ) { |
| 260 |
self::_renderSelectItem( |
| 261 |
esc_html__( 'Visible In Legend', Visualizer_Plugin::NAME ), |
| 262 |
'series[' . $index . '][visibleInLegend]', |
| 263 |
isset( $this->series[$index]['visibleInLegend'] ) ? $this->series[$index]['visibleInLegend'] : '', |
| 264 |
array( |
| 265 |
'' => '', |
| 266 |
'0' => esc_html__( 'No', Visualizer_Plugin::NAME ), |
| 267 |
'1' => esc_html__( 'Yes', Visualizer_Plugin::NAME ), |
| 268 |
), |
| 269 |
esc_html__( 'Determines whether the series has to be presented in the legend or not.', Visualizer_Plugin::NAME ) |
| 270 |
); |
| 271 |
|
| 272 |
self::_renderColorPickerItem( |
| 273 |
esc_html__( 'Color', Visualizer_Plugin::NAME ), |
| 274 |
'series[' . $index . '][color]', |
| 275 |
isset( $this->series[$index]['color'] ) ? $this->series[$index]['color'] : null, |
| 276 |
null |
| 277 |
); |
| 278 |
} |
| 279 |
|
| 280 |
} |