| 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 HorizontalStackedBar3DGraph extends HorizontalBar3DGraph { |
| 25 |
|
| 26 |
use StackedBarTrait; |
| 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 |
* Trait version draws totals above or below bars, we want left and right |
| 37 |
*/ |
| 38 |
public function dataLabelPosition($dataset, $index, &$item, $x, $y, $w, $h, |
| 39 |
$label_w, $label_h) |
| 40 |
{ |
| 41 |
list($pos, $target) = parent::dataLabelPosition($dataset, $index, $item, |
| 42 |
$x, $y, $w, $h, $label_w, $label_h); |
| 43 |
if(!is_numeric($dataset)) { |
| 44 |
list($d) = explode('-', $dataset); |
| 45 |
if($d === 'totalpos') { |
| 46 |
if(isset($this->last_position_pos[$index])) { |
| 47 |
list($lpos, $l_w) = $this->last_position_pos[$index]; |
| 48 |
list($hpos, $vpos) = Graph::translatePosition($lpos); |
| 49 |
if($hpos == 'or') { |
| 50 |
$num_offset = new Number($l_w); |
| 51 |
return ['middle outside right ' . $num_offset . ' 0', $target]; |
| 52 |
} |
| 53 |
} |
| 54 |
return ['outside right', $target]; |
| 55 |
} |
| 56 |
if($d === 'totalneg') { |
| 57 |
if(isset($this->last_position_neg[$index])) { |
| 58 |
list($lpos, $l_w) = $this->last_position_neg[$index]; |
| 59 |
list($hpos, $vpos) = Graph::translatePosition($lpos); |
| 60 |
if($hpos == 'ol') { |
| 61 |
$num_offset = new Number(-$l_w); |
| 62 |
return ['middle outside left ' . $num_offset . ' 0', $target]; |
| 63 |
} |
| 64 |
} |
| 65 |
return ['outside left', $target]; |
| 66 |
} |
| 67 |
} |
| 68 |
if($label_w > $w && Graph::isPositionInside($pos)) |
| 69 |
$pos = str_replace(['outside left','outside right'], 'centre', $pos); |
| 70 |
|
| 71 |
if($item->value > 0) |
| 72 |
$this->last_position_pos[$index] = [$pos, $label_w]; |
| 73 |
else |
| 74 |
$this->last_position_neg[$index] = [$pos, $label_w]; |
| 75 |
return [$pos, $target]; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Returns the ordering for legend entries |
| 80 |
*/ |
| 81 |
public function getLegendOrder() |
| 82 |
{ |
| 83 |
// bars are stacked from left to right |
| 84 |
return null; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
|