| 1 |
<?php |
| 2 |
/** |
| 3 |
* Copyright (C) 2017-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 SemiDonutGraph extends DonutGraph { |
| 25 |
|
| 26 |
/** |
| 27 |
* Override to set the options for semi-ness |
| 28 |
*/ |
| 29 |
public function __construct($w, $h, array $settings, array $fixed_settings = []) |
| 30 |
{ |
| 31 |
$reverse = isset($settings['reverse']) && $settings['reverse']; |
| 32 |
$flipped = isset($settings['flipped']) && $settings['flipped']; |
| 33 |
|
| 34 |
$start = 180; |
| 35 |
if($flipped) { |
| 36 |
$start = 0; |
| 37 |
$reverse = !$reverse; |
| 38 |
} |
| 39 |
if($reverse) { |
| 40 |
$start += 180; |
| 41 |
} |
| 42 |
|
| 43 |
$fixed = [ |
| 44 |
'reverse' => $reverse, |
| 45 |
'start_angle' => $start, |
| 46 |
'end_angle' => $start + 180, |
| 47 |
'slice_fit' => true |
| 48 |
]; |
| 49 |
$fixed_settings = array_merge($fixed, $fixed_settings); |
| 50 |
parent::__construct($w, $h, $settings, $fixed_settings); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Overridden to keep inner text in the middle |
| 55 |
*/ |
| 56 |
public function dataLabelPosition($dataset, $index, &$item, $x, $y, $w, $h, |
| 57 |
$label_w, $label_h) |
| 58 |
{ |
| 59 |
if($dataset === 'innertext') { |
| 60 |
if($this->getOption('flipped')) |
| 61 |
$y_offset = new Number($label_h / 2); |
| 62 |
else |
| 63 |
$y_offset = new Number($label_h / -2); |
| 64 |
return ['centre middle 0 ' . $y_offset, [$x, $y] ]; |
| 65 |
} |
| 66 |
|
| 67 |
return parent::dataLabelPosition($dataset, $index, $item, $x, $y, $w, $h, |
| 68 |
$label_w, $label_h); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
|