| 1 |
<?php |
| 2 |
/** |
| 3 |
* Copyright (C) 2011-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 |
/** |
| 25 |
* MultiRadarGraph - multiple radar graphs on one plot |
| 26 |
*/ |
| 27 |
class MultiRadarGraph extends RadarGraph { |
| 28 |
|
| 29 |
use MultiGraphTrait; |
| 30 |
|
| 31 |
protected function draw() |
| 32 |
{ |
| 33 |
$body = $this->grid() . $this->underShapes(); |
| 34 |
$plots = ''; |
| 35 |
|
| 36 |
$datasets = $this->multi_graph->getEnabledDatasets(); |
| 37 |
foreach($datasets as $i) { |
| 38 |
$bnum = 0; |
| 39 |
$points = []; |
| 40 |
$plot = ''; |
| 41 |
$line_breaks = $this->getOption(['line_breaks', $i]); |
| 42 |
$y_axis = $this->y_axes[$this->main_y_axis]; |
| 43 |
$first_point = null; |
| 44 |
foreach($this->multi_graph[$i] as $item) { |
| 45 |
if($line_breaks && $item->value === null && count($points) > 0) { |
| 46 |
$plot .= $this->drawLine($i, $points, 0); |
| 47 |
$points = []; |
| 48 |
} else { |
| 49 |
$point_pos = $this->gridPosition($item, $bnum); |
| 50 |
if($item->value !== null && $point_pos !== null) { |
| 51 |
$val = $y_axis->position($item->value); |
| 52 |
$angle = $this->arad + $point_pos / $this->g_height; |
| 53 |
$x = $this->xc + ($val * sin($angle)); |
| 54 |
$y = $this->yc + ($val * cos($angle)); |
| 55 |
$points[] = [$x, $y, $item, $i, $bnum]; |
| 56 |
if($first_point === null) |
| 57 |
$first_point = $points[0]; |
| 58 |
} |
| 59 |
} |
| 60 |
++$bnum; |
| 61 |
} |
| 62 |
|
| 63 |
// close graph or segment? |
| 64 |
if($first_point && (!$line_breaks || $first_point[4] == 0)) { |
| 65 |
$first_point[2] = null; |
| 66 |
$points[] = $first_point; |
| 67 |
} |
| 68 |
|
| 69 |
$plot .= $this->drawLine($i, $points, 0); |
| 70 |
if($this->getOption('semantic_classes')) |
| 71 |
$plots .= $this->element('g', ['class' => 'series'], null, $plot); |
| 72 |
else |
| 73 |
$plots .= $plot; |
| 74 |
} |
| 75 |
|
| 76 |
$group = []; |
| 77 |
if($this->getOption('semantic_classes')) |
| 78 |
$group['class'] = 'series'; |
| 79 |
$plots = $this->element('g', $group, null, $plots); |
| 80 |
|
| 81 |
$group = []; |
| 82 |
$shadow_id = $this->defs->getShadow(); |
| 83 |
if($shadow_id !== null) |
| 84 |
$group['filter'] = 'url(#' . $shadow_id . ')'; |
| 85 |
if(!empty($group)) |
| 86 |
$plots = $this->element('g', $group, null, $plots); |
| 87 |
|
| 88 |
$body .= $plots; |
| 89 |
$body .= $this->overShapes(); |
| 90 |
$body .= $this->axes(); |
| 91 |
$body .= $this->drawMarkers(); |
| 92 |
return $body; |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
|