| 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 all chart sidebar groups. |
| 26 |
* |
| 27 |
* @category Visualizer |
| 28 |
* @package Render |
| 29 |
* |
| 30 |
* @since 1.0.0 |
| 31 |
* @abstract |
| 32 |
*/ |
| 33 |
abstract class Visualizer_Render_Sidebar extends Visualizer_Render { |
| 34 |
|
| 35 |
/** |
| 36 |
* The array of font families accepted by visualization API. |
| 37 |
* |
| 38 |
* @since 1.0.0 |
| 39 |
* |
| 40 |
* @static |
| 41 |
* @access protected |
| 42 |
* @var array |
| 43 |
*/ |
| 44 |
protected static $_fontFamilies = array( |
| 45 |
'Arial' => 'Arial', |
| 46 |
'Sans Serif' => 'Sans Serif', |
| 47 |
'serif' => 'Serif', |
| 48 |
'Arial black' => 'Wide', |
| 49 |
'Arial Narrow' => 'Narrow', |
| 50 |
'Comic Sans MS' => 'Comic Sans MS', |
| 51 |
'Courier New' => 'Courier New', |
| 52 |
'Garamond' => 'Garamond', |
| 53 |
'Georgia' => 'Georgia', |
| 54 |
'Tahoma' => 'Tahoma', |
| 55 |
'Verdana' => 'Verdana', |
| 56 |
); |
| 57 |
|
| 58 |
/** |
| 59 |
* The Yes/No array. |
| 60 |
* |
| 61 |
* @since 1.0.0 |
| 62 |
* |
| 63 |
* @access protected |
| 64 |
* @var array |
| 65 |
*/ |
| 66 |
protected $_yesno; |
| 67 |
|
| 68 |
/** |
| 69 |
* The array of available legend positions. |
| 70 |
* |
| 71 |
* @since 1.0.0 |
| 72 |
* |
| 73 |
* @access protected |
| 74 |
* @var array |
| 75 |
*/ |
| 76 |
protected $_legendPositions; |
| 77 |
|
| 78 |
/** |
| 79 |
* The array of available alignments. |
| 80 |
* |
| 81 |
* @since 1.0.0 |
| 82 |
* |
| 83 |
* @access protected |
| 84 |
* @var array |
| 85 |
*/ |
| 86 |
protected $_alignments; |
| 87 |
|
| 88 |
/** |
| 89 |
* Constructor. |
| 90 |
* |
| 91 |
* @since 1.0.0 |
| 92 |
* |
| 93 |
* @access public |
| 94 |
* @param array $data The data what has to be associated with this render. |
| 95 |
*/ |
| 96 |
public function __construct( $data = array() ) { |
| 97 |
parent::__construct( $data ); |
| 98 |
|
| 99 |
$this->_legendPositions = array( |
| 100 |
'' => '', |
| 101 |
'right' => esc_html__( 'Right of the chart', Visualizer_Plugin::NAME ), |
| 102 |
'top' => esc_html__( 'Above the chart', Visualizer_Plugin::NAME ), |
| 103 |
'bottom' => esc_html__( 'Below the chart', Visualizer_Plugin::NAME ), |
| 104 |
'in' => esc_html__( 'Inside the chart', Visualizer_Plugin::NAME ), |
| 105 |
'none' => esc_html__( 'Omit the legend', Visualizer_Plugin::NAME ), |
| 106 |
); |
| 107 |
|
| 108 |
$this->_alignments = array( |
| 109 |
'' => '', |
| 110 |
'start' => esc_html__( 'Aligned to the start of the allocated area', Visualizer_Plugin::NAME ), |
| 111 |
'center' => esc_html__( 'Centered in the allocated area', Visualizer_Plugin::NAME ), |
| 112 |
'end' => esc_html__( 'Aligned to the end of the allocated area', Visualizer_Plugin::NAME ), |
| 113 |
); |
| 114 |
|
| 115 |
$this->_yesno = array( |
| 116 |
'' => '', |
| 117 |
'1' => esc_html__( 'Yes', Visualizer_Plugin::NAME ), |
| 118 |
'0' => esc_html__( 'No', Visualizer_Plugin::NAME ), |
| 119 |
); |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* Renders chart title settings. |
| 124 |
* |
| 125 |
* @since 1.0.0 |
| 126 |
* |
| 127 |
* @access protected |
| 128 |
*/ |
| 129 |
protected function _renderChartTitleSettings() { |
| 130 |
self::_renderTextItem( |
| 131 |
esc_html__( 'Chart Title', Visualizer_Plugin::NAME ), |
| 132 |
'title', |
| 133 |
$this->title, |
| 134 |
esc_html__( 'Text to display above the chart.', Visualizer_Plugin::NAME ) |
| 135 |
); |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Renders chart general settings group. |
| 140 |
* |
| 141 |
* @since 1.0.0 |
| 142 |
* |
| 143 |
* @access protected |
| 144 |
*/ |
| 145 |
protected function _renderGeneralSettings() { |
| 146 |
self::_renderGroupStart( esc_html__( 'General Settings', Visualizer_Plugin::NAME ) ); |
| 147 |
self::_renderSectionStart(); |
| 148 |
self::_renderSectionDescription( esc_html__( 'Configure title, font styles and legend positioning settings for the chart.', Visualizer_Plugin::NAME ) ); |
| 149 |
|
| 150 |
$this->_renderChartTitleSettings(); |
| 151 |
|
| 152 |
echo '<div class="section-item">'; |
| 153 |
echo '<a class="more-info" href="javascript:;">[?]</a>'; |
| 154 |
echo '<b>', esc_html__( 'Font Family And Size', Visualizer_Plugin::NAME ), '</b>'; |
| 155 |
|
| 156 |
echo '<table class="section-table" cellspacing="0" cellpadding="0" border="0">'; |
| 157 |
echo '<tr>'; |
| 158 |
echo '<td class="section-table-column">'; |
| 159 |
echo '<select name="fontName" class="control-select">'; |
| 160 |
echo '<option></option>'; |
| 161 |
foreach ( self::$_fontFamilies as $font => $label ) { |
| 162 |
echo '<option value="', $font, '"', selected( $font, $this->fontName, false ), '>'; |
| 163 |
echo $label; |
| 164 |
echo '</option>'; |
| 165 |
} |
| 166 |
echo '</select>'; |
| 167 |
echo '</td>'; |
| 168 |
echo '<td class="section-table-column">'; |
| 169 |
echo '<select name="fontSize" class="control-select">'; |
| 170 |
echo '<option></option>'; |
| 171 |
for ( $i = 7; $i <= 20; $i++ ) { |
| 172 |
echo '<option value="', $i, '"', selected( $i, $this->fontSize, false ), '>', $i, '</option>'; |
| 173 |
} |
| 174 |
echo '</select>'; |
| 175 |
echo '</td>'; |
| 176 |
echo '</tr>'; |
| 177 |
echo '</table>'; |
| 178 |
|
| 179 |
echo '<p class="section-description">'; |
| 180 |
esc_html_e( 'The default font family and size for all text in the chart.', Visualizer_Plugin::NAME ); |
| 181 |
echo '</p>'; |
| 182 |
echo '</div>'; |
| 183 |
self::_renderSectionEnd(); |
| 184 |
|
| 185 |
self::_renderSectionStart( esc_html__( 'Legend', Visualizer_Plugin::NAME ), false ); |
| 186 |
self::_renderSelectItem( |
| 187 |
esc_html__( 'Position', Visualizer_Plugin::NAME ), |
| 188 |
'legend[position]', |
| 189 |
$this->legend['position'], |
| 190 |
$this->_legendPositions, |
| 191 |
esc_html__( 'Determines where to place the legend, compared to the chart area.', Visualizer_Plugin::NAME ) |
| 192 |
); |
| 193 |
|
| 194 |
self::_renderSelectItem( |
| 195 |
esc_html__( 'Alignment', Visualizer_Plugin::NAME ), |
| 196 |
'legend[alignment]', |
| 197 |
$this->legend['alignment'], |
| 198 |
$this->_alignments, |
| 199 |
esc_html__( 'Determines the alignment of the legend.', Visualizer_Plugin::NAME ) |
| 200 |
); |
| 201 |
self::_renderSectionEnd(); |
| 202 |
self::_renderGroupEnd(); |
| 203 |
} |
| 204 |
|
| 205 |
/** |
| 206 |
* Renders chart view settings group. |
| 207 |
* |
| 208 |
* @since 1.0.0 |
| 209 |
* |
| 210 |
* @access protected |
| 211 |
*/ |
| 212 |
protected function _renderViewSettings() { |
| 213 |
self::_renderGroupStart( esc_html__( 'Layout & Chart Area', Visualizer_Plugin::NAME ) ); |
| 214 |
self::_renderSectionStart( esc_html__( 'Layout', Visualizer_Plugin::NAME ), false ); |
| 215 |
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_Plugin::NAME ) ); |
| 216 |
|
| 217 |
echo '<div class="section-item">'; |
| 218 |
echo '<a class="more-info" href="javascript:;">[?]</a>'; |
| 219 |
echo '<b>', esc_html__( 'Width And Height Of Chart', Visualizer_Plugin::NAME ), '</b>'; |
| 220 |
|
| 221 |
echo '<table class="section-table" cellspacing="0" cellpadding="0" border="0">'; |
| 222 |
echo '<tr>'; |
| 223 |
echo '<td class="section-table-column">'; |
| 224 |
echo '<input type="text" name="width" class="control-text" value="', esc_attr( $this->width ), '" placeholder="100%">'; |
| 225 |
echo '</td>'; |
| 226 |
echo '<td class="section-table-column">'; |
| 227 |
echo '<input type="text" name="height" class="control-text" value="', esc_attr( $this->height ), '" placeholder="400">'; |
| 228 |
echo '</td>'; |
| 229 |
echo '</tr>'; |
| 230 |
echo '</table>'; |
| 231 |
|
| 232 |
echo '<p class="section-description">'; |
| 233 |
esc_html_e( 'Determines the total width and height of the chart.', Visualizer_Plugin::NAME ); |
| 234 |
echo '</p>'; |
| 235 |
echo '</div>'; |
| 236 |
|
| 237 |
echo '<div class="section-delimiter"></div>'; |
| 238 |
|
| 239 |
self::_renderSectionDescription( esc_html__( 'Configure the background color for the main area of the chart and the chart border width and color.', Visualizer_Plugin::NAME ) ); |
| 240 |
|
| 241 |
self::_renderTextItem( |
| 242 |
esc_html__( 'Stroke Width', Visualizer_Plugin::NAME ), |
| 243 |
'backgroundColor[strokeWidth]', |
| 244 |
isset( $this->backgroundColor['strokeWidth'] ) ? $this->backgroundColor['strokeWidth'] : null, |
| 245 |
esc_html__( 'The chart border width in pixels.', Visualizer_Plugin::NAME ), |
| 246 |
'0' |
| 247 |
); |
| 248 |
|
| 249 |
self::_renderColorPickerItem( |
| 250 |
esc_html__( 'Stroke Color', Visualizer_Plugin::NAME ), |
| 251 |
'backgroundColor[stroke]', |
| 252 |
!empty( $this->backgroundColor['stroke'] ) ? $this->backgroundColor['stroke'] : null, |
| 253 |
'#666' |
| 254 |
); |
| 255 |
|
| 256 |
self::_renderColorPickerItem( |
| 257 |
esc_html__( 'Background Color', Visualizer_Plugin::NAME ), |
| 258 |
'backgroundColor[fill]', |
| 259 |
!empty( $this->backgroundColor['fill'] ) ? $this->backgroundColor['fill'] : null, |
| 260 |
'#fff' |
| 261 |
); |
| 262 |
self::_renderSectionEnd(); |
| 263 |
|
| 264 |
self::_renderSectionStart( esc_html__( 'Chart Area', Visualizer_Plugin::NAME ), false ); |
| 265 |
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_Plugin::NAME ) ); |
| 266 |
|
| 267 |
echo '<div class="section-item">'; |
| 268 |
echo '<a class="more-info" href="javascript:;">[?]</a>'; |
| 269 |
echo '<b>', esc_html__( 'Left And Top Margins', Visualizer_Plugin::NAME ), '</b>'; |
| 270 |
|
| 271 |
echo '<table class="section-table" cellspacing="0" cellpadding="0" border="0">'; |
| 272 |
echo '<tr>'; |
| 273 |
echo '<td class="section-table-column">'; |
| 274 |
echo '<input type="text" name="chartArea[left]" class="control-text" value="', !empty( $this->chartArea['left'] ) ? esc_attr( $this->chartArea['left'] ) : '', '" placeholder="20%">'; |
| 275 |
echo '</td>'; |
| 276 |
echo '<td class="section-table-column">'; |
| 277 |
echo '<input type="text" name="chartArea[top]" class="control-text" value="', !empty( $this->chartArea['top'] ) ? esc_attr( $this->chartArea['top'] ) : '', '" placeholder="20%">'; |
| 278 |
echo '</td>'; |
| 279 |
echo '</tr>'; |
| 280 |
echo '</table>'; |
| 281 |
|
| 282 |
echo '<p class="section-description">'; |
| 283 |
esc_html_e( 'Determines how far to draw the chart from the left and top borders.', Visualizer_Plugin::NAME ); |
| 284 |
echo '</p>'; |
| 285 |
echo '</div>'; |
| 286 |
|
| 287 |
echo '<div class="section-item">'; |
| 288 |
echo '<a class="more-info" href="javascript:;">[?]</a>'; |
| 289 |
echo '<b>', esc_html__( 'Width And Height Of Chart Area', Visualizer_Plugin::NAME ), '</b>'; |
| 290 |
|
| 291 |
echo '<table class="section-table" cellspacing="0" cellpadding="0" border="0">'; |
| 292 |
echo '<tr>'; |
| 293 |
echo '<td class="section-table-column">'; |
| 294 |
echo '<input type="text" name="chartArea[width]" class="control-text" value="', !empty( $this->chartArea['width'] ) ? esc_attr( $this->chartArea['width'] ) : '', '" placeholder="60%">'; |
| 295 |
echo '</td>'; |
| 296 |
echo '<td class="section-table-column">'; |
| 297 |
echo '<input type="text" name="chartArea[height]" class="control-text" value="', !empty( $this->chartArea['height'] ) ? esc_attr( $this->chartArea['height'] ) : '', '" placeholder="60%">'; |
| 298 |
echo '</td>'; |
| 299 |
echo '</tr>'; |
| 300 |
echo '</table>'; |
| 301 |
|
| 302 |
echo '<p class="section-description">'; |
| 303 |
esc_html_e( 'Determines the width and hight of the chart area.', Visualizer_Plugin::NAME ); |
| 304 |
echo '</p>'; |
| 305 |
echo '</div>'; |
| 306 |
self::_renderSectionEnd(); |
| 307 |
self::_renderGroupEnd(); |
| 308 |
} |
| 309 |
|
| 310 |
/** |
| 311 |
* Renders select item. |
| 312 |
* |
| 313 |
* @since 1.0.0 |
| 314 |
* |
| 315 |
* @static |
| 316 |
* @access protected |
| 317 |
* @param string $title The title of the select item. |
| 318 |
* @param string $name The name of the select item. |
| 319 |
* @param string $value The actual value of the select item. |
| 320 |
* @param array $options The array of select options. |
| 321 |
* @param string $desc The description of the select item. |
| 322 |
*/ |
| 323 |
protected static function _renderSelectItem( $title, $name, $value, array $options, $desc ) { |
| 324 |
echo '<div class="section-item">'; |
| 325 |
echo '<a class="more-info" href="javascript:;">[?]</a>'; |
| 326 |
echo '<b>', $title, '</b>'; |
| 327 |
echo '<select class="control-select" name="', $name, '">'; |
| 328 |
foreach ( $options as $key => $label ) { |
| 329 |
echo '<option value="', $key, '"', selected( $key, $value, false ), '>'; |
| 330 |
echo $label; |
| 331 |
echo '</option>'; |
| 332 |
} |
| 333 |
echo '</select>'; |
| 334 |
echo '<p class="section-description">', $desc, '</p>'; |
| 335 |
echo '</div>'; |
| 336 |
} |
| 337 |
|
| 338 |
/** |
| 339 |
* Renders color picker item. |
| 340 |
* |
| 341 |
* @since 1.0.0 |
| 342 |
* |
| 343 |
* @static |
| 344 |
* @access protected |
| 345 |
* @param string $title The title of the select item. |
| 346 |
* @param string $name The name of the select item. |
| 347 |
* @param string $value The actual value of the select item. |
| 348 |
* @param string $default The default value of the color picker. |
| 349 |
*/ |
| 350 |
protected static function _renderColorPickerItem( $title, $name, $value, $default ) { |
| 351 |
echo '<div class="section-item">'; |
| 352 |
echo '<b>', $title, '</b>'; |
| 353 |
echo '<div>'; |
| 354 |
echo '<input type="text" class="color-picker-hex" name="', $name, '" maxlength="7" placeholder="', esc_attr__( 'Hex Value', Visualizer_Plugin::NAME ), '" value="', is_null( $value ) ? $default : esc_attr( $value ), '" data-default-color="', $default, '">'; |
| 355 |
echo '</div>'; |
| 356 |
echo '</div>'; |
| 357 |
} |
| 358 |
|
| 359 |
/** |
| 360 |
* Renders text item. |
| 361 |
* |
| 362 |
* @since 1.0.0 |
| 363 |
* |
| 364 |
* @static |
| 365 |
* @access protected |
| 366 |
* @param string $title The title of the select item. |
| 367 |
* @param string $name The name of the select item. |
| 368 |
* @param string $value The actual value of the select item. |
| 369 |
* @param string $desc The description of the select item. |
| 370 |
* @param string $placeholder The placeholder for the input. |
| 371 |
*/ |
| 372 |
protected static function _renderTextItem( $title, $name, $value, $desc, $placeholder = '' ) { |
| 373 |
echo '<div class="section-item">'; |
| 374 |
echo '<a class="more-info" href="javascript:;">[?]</a>'; |
| 375 |
echo '<b>', $title, '</b>'; |
| 376 |
echo '<input type="text" class="control-text" name="', $name, '" value="', esc_attr( $value ), '" placeholder="', $placeholder, '">'; |
| 377 |
echo '<p class="section-description">', $desc, '</p>'; |
| 378 |
echo '</div>'; |
| 379 |
} |
| 380 |
|
| 381 |
/** |
| 382 |
* Renders the beginning of a group. |
| 383 |
* |
| 384 |
* @since 1.0.0 |
| 385 |
* |
| 386 |
* @static |
| 387 |
* @access protected |
| 388 |
* @param string $title The title of this group. |
| 389 |
*/ |
| 390 |
protected static function _renderGroupStart( $title ) { |
| 391 |
echo '<li class="group">'; |
| 392 |
echo '<h3 class="group-title">', $title, '</h3>'; |
| 393 |
echo '<ul class="group-content">'; |
| 394 |
} |
| 395 |
|
| 396 |
/** |
| 397 |
* Renders the ending of a group. |
| 398 |
* |
| 399 |
* @since 1.0.0 |
| 400 |
* |
| 401 |
* @static |
| 402 |
* @access protected |
| 403 |
*/ |
| 404 |
protected static function _renderGroupEnd() { |
| 405 |
echo '</ul>'; |
| 406 |
echo '</li>'; |
| 407 |
} |
| 408 |
|
| 409 |
/** |
| 410 |
* Renders the beginning of a section. |
| 411 |
* |
| 412 |
* @since 1.0.0 |
| 413 |
* |
| 414 |
* @static |
| 415 |
* @access protected |
| 416 |
* @param string $title The title of this section. If the title is empty, no title will be displayed. |
| 417 |
* @param boolean $open Determines whether the section items block has to be expanded or collapsed. |
| 418 |
*/ |
| 419 |
protected static function _renderSectionStart( $title = false, $open = true ) { |
| 420 |
echo '<li>'; |
| 421 |
if ( !empty( $title ) ) { |
| 422 |
echo '<span class="section-title">', $title, '</span>'; |
| 423 |
} |
| 424 |
echo '<div class="section-items', $open ? ' open' : '', '">'; |
| 425 |
} |
| 426 |
|
| 427 |
/** |
| 428 |
* Renders the ending of a section. |
| 429 |
* |
| 430 |
* @since 1.0.0 |
| 431 |
* |
| 432 |
* @static |
| 433 |
* @access protected |
| 434 |
*/ |
| 435 |
protected static function _renderSectionEnd() { |
| 436 |
echo '</div>'; |
| 437 |
echo '</li>'; |
| 438 |
} |
| 439 |
|
| 440 |
/** |
| 441 |
* Renders section description block. |
| 442 |
* |
| 443 |
* @since 1.0.0 |
| 444 |
* |
| 445 |
* @static |
| 446 |
* @access protected |
| 447 |
* @param string $description The description text. |
| 448 |
*/ |
| 449 |
protected static function _renderSectionDescription( $description ) { |
| 450 |
echo '<div class="section-item">'; |
| 451 |
echo '<div class="section-description">', $description, '</div>'; |
| 452 |
echo '</div>'; |
| 453 |
} |
| 454 |
|
| 455 |
} |