| 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 |
echo '<div class="section-delimiter"></div>'; |
| 107 |
|
| 108 |
self::_renderSelectItem( |
| 109 |
esc_html__( 'Axes Titles Position', Visualizer_Plugin::NAME ), |
| 110 |
'axisTitlesPosition', |
| 111 |
$this->axisTitlesPosition, |
| 112 |
$this->_positions, |
| 113 |
esc_html__( 'Determines where to place the axis titles, compared to the chart area.', Visualizer_Plugin::NAME ) |
| 114 |
); |
| 115 |
|
| 116 |
echo '<div class="section-delimiter"></div>'; |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Renders horizontal axis settings. |
| 121 |
* |
| 122 |
* @since 1.2.0 |
| 123 |
* |
| 124 |
* @access protected |
| 125 |
*/ |
| 126 |
protected function _renderHorizontalAxisSettings() { |
| 127 |
self::_renderGroupStart( esc_html__( 'Horizontal Axis Settings', Visualizer_Plugin::NAME ) ); |
| 128 |
self::_renderSectionStart( esc_html__( 'General Settings', Visualizer_Plugin::NAME ), false ); |
| 129 |
self::_renderTextItem( |
| 130 |
esc_html__( 'Axis Title', Visualizer_Plugin::NAME ), |
| 131 |
'hAxis[title]', |
| 132 |
isset( $this->hAxis['title'] ) ? $this->hAxis['title'] : '', |
| 133 |
esc_html__( 'The title of the horizontal axis.', Visualizer_Plugin::NAME ) |
| 134 |
); |
| 135 |
|
| 136 |
self::_renderSelectItem( |
| 137 |
esc_html__( 'Text Position', Visualizer_Plugin::NAME ), |
| 138 |
'vAxis[textPosition]', |
| 139 |
isset( $this->vAxis['textPosition'] ) ? $this->vAxis['textPosition'] : '', |
| 140 |
$this->_positions, |
| 141 |
esc_html__( 'Position of the horizontal axis text, relative to the chart area.', Visualizer_Plugin::NAME ) |
| 142 |
); |
| 143 |
|
| 144 |
self::_renderSelectItem( |
| 145 |
esc_html__( 'Direction', Visualizer_Plugin::NAME ), |
| 146 |
'hAxis[direction]', |
| 147 |
isset( $this->hAxis['direction'] ) ? $this->hAxis['direction'] : '', |
| 148 |
array( |
| 149 |
'' => '', |
| 150 |
'1' => esc_html__( 'Identical Direction', Visualizer_Plugin::NAME ), |
| 151 |
'-1' => esc_html__( 'Reverse Direction', Visualizer_Plugin::NAME ), |
| 152 |
), |
| 153 |
esc_html__( 'The direction in which the values along the horizontal axis grow.', Visualizer_Plugin::NAME ) |
| 154 |
); |
| 155 |
|
| 156 |
self::_renderColorPickerItem( |
| 157 |
esc_html__( 'Base Line Color', Visualizer_Plugin::NAME ), |
| 158 |
'vAxis[baselineColor]', |
| 159 |
isset( $this->vAxis['baselineColor'] ) ? $this->vAxis['baselineColor'] : null, |
| 160 |
'#000' |
| 161 |
); |
| 162 |
self::_renderSectionEnd(); |
| 163 |
|
| 164 |
if ( $this->_horizontalGridLines ) { |
| 165 |
self::_renderSectionStart( esc_html__( 'Grid Lines', Visualizer_Plugin::NAME ), false ); |
| 166 |
self::_renderTextItem( |
| 167 |
esc_html__( 'Count', Visualizer_Plugin::NAME ), |
| 168 |
'vAxis[gridlines][count]', |
| 169 |
isset( $this->vAxis['gridlines']['count'] ) ? $this->vAxis['gridlines']['count'] : '', |
| 170 |
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 ), |
| 171 |
5 |
| 172 |
); |
| 173 |
|
| 174 |
self::_renderColorPickerItem( |
| 175 |
esc_html__( 'Color', Visualizer_Plugin::NAME ), |
| 176 |
'vAxis[gridlines][color]', |
| 177 |
isset( $this->vAxis['gridlines']['color'] ) ? $this->vAxis['gridlines']['color'] : null, |
| 178 |
'#ccc' |
| 179 |
); |
| 180 |
self::_renderSectionEnd(); |
| 181 |
|
| 182 |
self::_renderSectionStart( esc_html__( 'Minor Grid Lines', Visualizer_Plugin::NAME ), false ); |
| 183 |
self::_renderTextItem( |
| 184 |
esc_html__( 'Count', Visualizer_Plugin::NAME ), |
| 185 |
'vAxis[minorGridlines][count]', |
| 186 |
isset( $this->vAxis['minorGridlines']['count'] ) ? $this->vAxis['minorGridlines']['count'] : '', |
| 187 |
esc_html__( 'The number of horizontal minor gridlines between two regular gridlines.', Visualizer_Plugin::NAME ), |
| 188 |
0 |
| 189 |
); |
| 190 |
|
| 191 |
self::_renderColorPickerItem( |
| 192 |
esc_html__( 'Color', Visualizer_Plugin::NAME ), |
| 193 |
'vAxis[minorGridlines][color]', |
| 194 |
isset( $this->vAxis['minorGridlines']['color'] ) ? $this->vAxis['minorGridlines']['color'] : null, |
| 195 |
null |
| 196 |
); |
| 197 |
self::_renderSectionEnd(); |
| 198 |
} |
| 199 |
|
| 200 |
if ( $this->_verticalGridLines ) { |
| 201 |
self::_renderSectionStart( esc_html__( 'View Window', Visualizer_Plugin::NAME ), false ); |
| 202 |
self::_renderTextItem( |
| 203 |
esc_html__( 'Maximum Value', Visualizer_Plugin::NAME ), |
| 204 |
'hAxis[viewWindow][max]', |
| 205 |
isset( $this->hAxis['viewWindow']['max'] ) ? $this->hAxis['viewWindow']['max'] : '', |
| 206 |
'The maximum vertical data value to render.' |
| 207 |
); |
| 208 |
|
| 209 |
self::_renderTextItem( |
| 210 |
esc_html__( 'Minimum Value', Visualizer_Plugin::NAME ), |
| 211 |
'hAxis[viewWindow][min]', |
| 212 |
isset( $this->hAxis['viewWindow']['min'] ) ? $this->hAxis['viewWindow']['min'] : '', |
| 213 |
'The minimum vertical data value to render.' |
| 214 |
); |
| 215 |
self::_renderSectionEnd(); |
| 216 |
} |
| 217 |
self::_renderGroupEnd(); |
| 218 |
} |
| 219 |
|
| 220 |
/** |
| 221 |
* Renders vertical axis settings. |
| 222 |
* |
| 223 |
* @since 1.2.0 |
| 224 |
* |
| 225 |
* @access protected |
| 226 |
*/ |
| 227 |
protected function _renderVerticalAxisSettings() { |
| 228 |
self::_renderGroupStart( esc_html__( 'Vertical Axis Settings', Visualizer_Plugin::NAME ) ); |
| 229 |
self::_renderSectionStart( esc_html__( 'General Settings', Visualizer_Plugin::NAME ), false ); |
| 230 |
self::_renderTextItem( |
| 231 |
esc_html__( 'Axis Title', Visualizer_Plugin::NAME ), |
| 232 |
'vAxis[title]', |
| 233 |
isset( $this->vAxis['title'] ) ? $this->vAxis['title'] : '', |
| 234 |
esc_html__( 'The title of the vertical axis.', Visualizer_Plugin::NAME ) |
| 235 |
); |
| 236 |
|
| 237 |
self::_renderSelectItem( |
| 238 |
esc_html__( 'Text Position', Visualizer_Plugin::NAME ), |
| 239 |
'hAxis[textPosition]', |
| 240 |
isset( $this->hAxis['textPosition'] ) ? $this->hAxis['textPosition'] : '', |
| 241 |
$this->_positions, |
| 242 |
esc_html__( 'Position of the vertical axis text, relative to the chart area.', Visualizer_Plugin::NAME ) |
| 243 |
); |
| 244 |
|
| 245 |
self::_renderSelectItem( |
| 246 |
esc_html__( 'Direction', Visualizer_Plugin::NAME ), |
| 247 |
'vAxis[direction]', |
| 248 |
isset( $this->vAxis['direction'] ) ? $this->vAxis['direction'] : '', |
| 249 |
array( |
| 250 |
'' => '', |
| 251 |
'1' => esc_html__( 'Identical Direction', Visualizer_Plugin::NAME ), |
| 252 |
'-1' => esc_html__( 'Reverse Direction', Visualizer_Plugin::NAME ), |
| 253 |
), |
| 254 |
esc_html__( 'The direction in which the values along the vertical axis grow.', Visualizer_Plugin::NAME ) |
| 255 |
); |
| 256 |
|
| 257 |
self::_renderColorPickerItem( |
| 258 |
esc_html__( 'Base Line Color', Visualizer_Plugin::NAME ), |
| 259 |
'hAxis[baselineColor]', |
| 260 |
isset( $this->hAxis['baselineColor'] ) ? $this->hAxis['baselineColor'] : null, |
| 261 |
'#000' |
| 262 |
); |
| 263 |
self::_renderSectionEnd(); |
| 264 |
|
| 265 |
if ( $this->_verticalGridLines ) { |
| 266 |
self::_renderSectionStart( esc_html__( 'Grid Lines', Visualizer_Plugin::NAME ), false ); |
| 267 |
self::_renderTextItem( |
| 268 |
esc_html__( 'Count', Visualizer_Plugin::NAME ), |
| 269 |
'hAxis[gridlines][count]', |
| 270 |
isset( $this->hAxis['gridlines']['count'] ) ? $this->hAxis['gridlines']['count'] : '', |
| 271 |
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 ), |
| 272 |
5 |
| 273 |
); |
| 274 |
|
| 275 |
self::_renderColorPickerItem( |
| 276 |
esc_html__( 'Color', Visualizer_Plugin::NAME ), |
| 277 |
'hAxis[gridlines][color]', |
| 278 |
isset( $this->hAxis['gridlines']['color'] ) ? $this->hAxis['gridlines']['color'] : null, |
| 279 |
'#ccc' |
| 280 |
); |
| 281 |
self::_renderSectionEnd(); |
| 282 |
|
| 283 |
self::_renderSectionStart( esc_html__( 'Minor Grid Lines', Visualizer_Plugin::NAME ), false ); |
| 284 |
self::_renderTextItem( |
| 285 |
esc_html__( 'Count', Visualizer_Plugin::NAME ), |
| 286 |
'hAxis[minorGridlines][count]', |
| 287 |
isset( $this->hAxis['minorGridlines']['count'] ) ? $this->hAxis['minorGridlines']['count'] : '', |
| 288 |
esc_html__( 'The number of vertical minor gridlines between two regular gridlines.', Visualizer_Plugin::NAME ), |
| 289 |
0 |
| 290 |
); |
| 291 |
|
| 292 |
self::_renderColorPickerItem( |
| 293 |
esc_html__( 'Color', Visualizer_Plugin::NAME ), |
| 294 |
'hAxis[minorGridlines][color]', |
| 295 |
isset( $this->hAxis['minorGridlines']['color'] ) ? $this->hAxis['minorGridlines']['color'] : null, |
| 296 |
null |
| 297 |
); |
| 298 |
self::_renderSectionEnd(); |
| 299 |
} |
| 300 |
|
| 301 |
if ( $this->_horizontalGridLines ) { |
| 302 |
self::_renderSectionStart( esc_html__( 'View Window', Visualizer_Plugin::NAME ), false ); |
| 303 |
self::_renderTextItem( |
| 304 |
esc_html__( 'Maximum Value', Visualizer_Plugin::NAME ), |
| 305 |
'vAxis[viewWindow][max]', |
| 306 |
isset( $this->vAxis['viewWindow']['max'] ) ? $this->vAxis['viewWindow']['max'] : '', |
| 307 |
'The maximum vertical data value to render.' |
| 308 |
); |
| 309 |
|
| 310 |
self::_renderTextItem( |
| 311 |
esc_html__( 'Minimum Value', Visualizer_Plugin::NAME ), |
| 312 |
'vAxis[viewWindow][min]', |
| 313 |
isset( $this->vAxis['viewWindow']['min'] ) ? $this->vAxis['viewWindow']['min'] : '', |
| 314 |
'The minimum vertical data value to render.' |
| 315 |
); |
| 316 |
self::_renderSectionEnd(); |
| 317 |
} |
| 318 |
self::_renderGroupEnd(); |
| 319 |
} |
| 320 |
|
| 321 |
/** |
| 322 |
* Renders chart axes settings. |
| 323 |
* |
| 324 |
* @since 1.0.0 |
| 325 |
* |
| 326 |
* @access protected |
| 327 |
*/ |
| 328 |
protected function _renderAxesSettings() { |
| 329 |
$this->_renderHorizontalAxisSettings(); |
| 330 |
$this->_renderVerticalAxisSettings(); |
| 331 |
} |
| 332 |
|
| 333 |
/** |
| 334 |
* Renders series settings group. |
| 335 |
* |
| 336 |
* @since 1.0.0 |
| 337 |
* |
| 338 |
* @access protected |
| 339 |
*/ |
| 340 |
protected function _renderSeriesSettings() { |
| 341 |
self::_renderGroupStart( esc_html__( 'Series Settings', Visualizer_Plugin::NAME ) ); |
| 342 |
for ( $i = 1, $cnt = count( $this->__series ); $i < $cnt; $i++ ) { |
| 343 |
if ( !empty( $this->__series[$i]['label'] ) ) { |
| 344 |
self::_renderSectionStart( esc_html( $this->__series[$i]['label'] ), false ); |
| 345 |
$this->_renderSeries( $i - 1 ); |
| 346 |
self::_renderSectionEnd(); |
| 347 |
} |
| 348 |
} |
| 349 |
self::_renderGroupEnd(); |
| 350 |
} |
| 351 |
|
| 352 |
/** |
| 353 |
* Renders concreate series settings. |
| 354 |
* |
| 355 |
* @since 1.0.0 |
| 356 |
* |
| 357 |
* @access protected |
| 358 |
* @param int $index The series index. |
| 359 |
*/ |
| 360 |
protected function _renderSeries( $index ) { |
| 361 |
self::_renderSelectItem( |
| 362 |
esc_html__( 'Visible In Legend', Visualizer_Plugin::NAME ), |
| 363 |
'series[' . $index . '][visibleInLegend]', |
| 364 |
isset( $this->series[$index]['visibleInLegend'] ) ? $this->series[$index]['visibleInLegend'] : '', |
| 365 |
array( |
| 366 |
'' => '', |
| 367 |
'0' => esc_html__( 'No', Visualizer_Plugin::NAME ), |
| 368 |
'1' => esc_html__( 'Yes', Visualizer_Plugin::NAME ), |
| 369 |
), |
| 370 |
esc_html__( 'Determines whether the series has to be presented in the legend or not.', Visualizer_Plugin::NAME ) |
| 371 |
); |
| 372 |
|
| 373 |
$this->_renderFormatField( $index ); |
| 374 |
|
| 375 |
self::_renderColorPickerItem( |
| 376 |
esc_html__( 'Color', Visualizer_Plugin::NAME ), |
| 377 |
'series[' . $index . '][color]', |
| 378 |
isset( $this->series[$index]['color'] ) ? $this->series[$index]['color'] : null, |
| 379 |
null |
| 380 |
); |
| 381 |
} |
| 382 |
|
| 383 |
} |