| 1 |
<?php |
| 2 |
/** |
| 3 |
* Copyright (C) 2009-2022 Graham Breach |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU Lesser General Public License as published by |
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 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 Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Lesser General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
/** |
| 19 |
* For more information, please contact <graham@goat1000.com> |
| 20 |
*/ |
| 21 |
|
| 22 |
namespace Goat1000\SVGGraph; |
| 23 |
|
| 24 |
class Bar3DGraph extends ThreeDGraph { |
| 25 |
|
| 26 |
use BarGraphTrait { |
| 27 |
barGroup as traitBarGroup; |
| 28 |
setBarWidth as traitSetBarWidth; |
| 29 |
} |
| 30 |
|
| 31 |
protected $tx; |
| 32 |
protected $ty; |
| 33 |
protected $bar_class = 'Goat1000\\SVGGraph\\Bar3D'; |
| 34 |
protected $bar_drawer; |
| 35 |
|
| 36 |
public function __construct($w, $h, array $settings, array $fixed_settings = []) |
| 37 |
{ |
| 38 |
$fs = ['label_centre' => !isset($settings['datetime_keys'])]; |
| 39 |
$fs = array_merge($fs, $fixed_settings); |
| 40 |
parent::__construct($w, $h, $settings, $fs); |
| 41 |
|
| 42 |
$this->bar_drawer = new $this->bar_class($this); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Returns the SVG code for a 3D bar |
| 47 |
*/ |
| 48 |
protected function bar3D($item, &$bar, $top, $index, $dataset = null, |
| 49 |
$start = null, $axis = null) |
| 50 |
{ |
| 51 |
$pos = $this->barY($item->value, $tmp_bar, $start, $axis); |
| 52 |
if($pos === null || $pos > $this->height - $this->pad_bottom) |
| 53 |
return ''; |
| 54 |
|
| 55 |
return $this->bar_drawer->draw($bar['x'], $bar['y'], |
| 56 |
$bar['width'], $bar['height'], $top, true, |
| 57 |
$this->getColour($item, $index, $dataset, false, false)); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Set the bar width and space, create the top |
| 62 |
*/ |
| 63 |
protected function setBarWidth($width, $space) |
| 64 |
{ |
| 65 |
$this->traitSetBarWidth($width, $space); |
| 66 |
$this->bar_drawer->setDepth($width); |
| 67 |
list($this->tx, $this->ty) = $this->project(0, 0, $space); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Add the translation to the bar group |
| 72 |
*/ |
| 73 |
protected function barGroup() |
| 74 |
{ |
| 75 |
$group = $this->traitBarGroup(); |
| 76 |
if($this->tx || $this->ty) { |
| 77 |
$xform = new Transform; |
| 78 |
$xform->translate($this->tx, $this->ty); |
| 79 |
$group['transform'] = $xform; |
| 80 |
} |
| 81 |
return $group; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Returns the SVG code for a bar |
| 86 |
*/ |
| 87 |
protected function drawBar(DataItem $item, $index, $start = 0, $axis = null, |
| 88 |
$dataset = 0, $options = []) |
| 89 |
{ |
| 90 |
return $this->drawBar3D($item, $index, $start, $axis, $dataset, $options); |
| 91 |
} |
| 92 |
} |
| 93 |
|