| 1 |
<?php |
| 2 |
/** |
| 3 |
* Copyright (C) 2021-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 Donut3DGraph extends Pie3DGraph { |
| 25 |
|
| 26 |
use DonutGraphTrait; |
| 27 |
protected $edge_class = 'Goat1000\\SVGGraph\\DonutSliceEdge'; |
| 28 |
|
| 29 |
public function __construct($w, $h, array $settings, array $fixed_settings = []) |
| 30 |
{ |
| 31 |
$fs = []; |
| 32 |
// enable flat sides when drawing a gap |
| 33 |
if(isset($settings['donut_slice_gap']) && $settings['donut_slice_gap'] > 0) |
| 34 |
$fs['draw_flat_sides'] = true; |
| 35 |
|
| 36 |
$fs = array_merge($fs, $fixed_settings); |
| 37 |
parent::__construct($w, $h, $settings, $fs); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Returns the gradient overlay |
| 42 |
*/ |
| 43 |
protected function getEdgeOverlay($x_centre, $y_centre, $depth, $clip_path, $edge) |
| 44 |
{ |
| 45 |
if(!$edge->inner()) |
| 46 |
return parent::getEdgeOverlay($x_centre, $y_centre, $depth, $clip_path, $edge); |
| 47 |
|
| 48 |
// use radius of whole pie unless slice values are set |
| 49 |
$radius_x = $this->radius_x; |
| 50 |
$radius_y = $this->radius_y; |
| 51 |
if($edge->slice['radius_x'] && $edge->slice['radius_y']) { |
| 52 |
$radius_x = $edge->slice['radius_x']; |
| 53 |
$radius_y = $edge->slice['radius_y']; |
| 54 |
} |
| 55 |
|
| 56 |
$ratio = $edge->getInnerRatio(); |
| 57 |
$radius_x *= $ratio; |
| 58 |
$radius_y *= $ratio; |
| 59 |
|
| 60 |
// clip a gradient-filled rect to the edge shape |
| 61 |
$cx = new Number($x_centre); |
| 62 |
$cy = new Number($y_centre); |
| 63 |
$gradient_id = $this->defs->addGradient($this->getOption('depth_shade_gradient')); |
| 64 |
$rect = [ |
| 65 |
'x' => $x_centre - $radius_x, |
| 66 |
'y' => $y_centre - $radius_y, |
| 67 |
'width' => $radius_x * 2.0, |
| 68 |
'height' => $radius_y * 2.0 + $this->depth + 2.0, |
| 69 |
'fill' => 'url(#' . $gradient_id . ')', |
| 70 |
|
| 71 |
// rotate the rect to reverse the gradient |
| 72 |
'transform' => "rotate(180,{$cx},{$cy})", |
| 73 |
]; |
| 74 |
|
| 75 |
// clip a group containing the rotated rect |
| 76 |
$g = [ 'clip-path' => 'url(#' . $clip_path . ')' ]; |
| 77 |
return $this->element('g', $g, null, $this->element('rect', $rect)); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
|