| 1 |
<?php |
| 2 |
/** |
| 3 |
* Copyright (C) 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 HorizontalGroupedBar3DGraph extends HorizontalBar3DGraph { |
| 25 |
|
| 26 |
use Grouped3DGraphTrait; |
| 27 |
|
| 28 |
public function __construct($w, $h, $settings, $fixed_settings = []) |
| 29 |
{ |
| 30 |
$fixed = [ 'single_axis' => true ]; |
| 31 |
$fixed_settings = array_merge($fixed, $fixed_settings); |
| 32 |
parent::__construct($w, $h, $settings, $fixed_settings); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Sets up bar details |
| 37 |
*/ |
| 38 |
protected function barSetup() |
| 39 |
{ |
| 40 |
parent::barSetup(); |
| 41 |
$datasets = $this->multi_graph->getEnabledDatasets(); |
| 42 |
$dataset_count = count($datasets); |
| 43 |
|
| 44 |
list($chunk_width, $bspace, $chunk_unit_width) = |
| 45 |
$this->barPosition($this->getOption('bar_width'), $this->getOption('bar_width_min'), |
| 46 |
$this->y_axes[$this->main_y_axis]->unit(), $dataset_count, |
| 47 |
$this->getOption('bar_space'), $this->getOption('group_space')); |
| 48 |
$this->group_bar_spacing = $chunk_unit_width; |
| 49 |
$this->setBarWidth($chunk_width, $bspace); |
| 50 |
|
| 51 |
$offset = 0; |
| 52 |
foreach($datasets as $d) { |
| 53 |
$this->dataset_offsets[$d] = $offset; |
| 54 |
++$offset; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Returns an array with x, y, width and height set |
| 60 |
*/ |
| 61 |
protected function barDimensions($item, $index, $start, $axis, $dataset) |
| 62 |
{ |
| 63 |
$bar_y = $this->gridPosition($item, $index); |
| 64 |
if($bar_y === null) |
| 65 |
return []; |
| 66 |
|
| 67 |
$d_offset = $this->dataset_offsets[$dataset]; |
| 68 |
$bar = [ |
| 69 |
'y' => $bar_y - $this->calculated_bar_space - |
| 70 |
($d_offset * $this->group_bar_spacing) - $this->calculated_bar_width, |
| 71 |
'height' => $this->calculated_bar_width, |
| 72 |
]; |
| 73 |
|
| 74 |
$this->barY($item->value, $bar, $start, $axis); |
| 75 |
return $bar; |
| 76 |
} |
| 77 |
} |
| 78 |
|