| 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 |
* MultiLineGraph - joined line, with axes and grid |
| 26 |
*/ |
| 27 |
class MultiLineGraph extends LineGraph { |
| 28 |
|
| 29 |
use MultiGraphTrait; |
| 30 |
|
| 31 |
protected function draw() |
| 32 |
{ |
| 33 |
$body = $this->grid() . $this->underShapes(); |
| 34 |
|
| 35 |
$plots = ''; |
| 36 |
$y_axis_pos = $this->height - $this->pad_bottom - |
| 37 |
$this->y_axes[$this->main_y_axis]->zero(); |
| 38 |
$y_bottom = min($y_axis_pos, $this->height - $this->pad_bottom); |
| 39 |
$datasets = $this->multi_graph->getEnabledDatasets(); |
| 40 |
|
| 41 |
foreach($datasets as $i) { |
| 42 |
$bnum = 0; |
| 43 |
$points = []; |
| 44 |
$plot = ''; |
| 45 |
$line_breaks = $this->getOption(['line_breaks', $i]); |
| 46 |
$axis = $this->datasetYAxis($i); |
| 47 |
foreach($this->multi_graph[$i] as $item) { |
| 48 |
if($line_breaks && $item->value === null && count($points) > 0) { |
| 49 |
$plot .= $this->drawLine($i, $points, $y_bottom); |
| 50 |
$points = []; |
| 51 |
} else { |
| 52 |
$x = $this->gridPosition($item, $bnum); |
| 53 |
if($x !== null && $item->value !== null) { |
| 54 |
$y = $this->gridY($item->value, $axis); |
| 55 |
$points[] = [$x, $y, $item, $i, $bnum]; |
| 56 |
} |
| 57 |
} |
| 58 |
++$bnum; |
| 59 |
} |
| 60 |
|
| 61 |
$plot .= $this->drawLine($i, $points, $y_bottom); |
| 62 |
$plots .= $plot; |
| 63 |
} |
| 64 |
|
| 65 |
$group = []; |
| 66 |
$this->clipGrid($group); |
| 67 |
if($this->getOption('semantic_classes')) |
| 68 |
$group['class'] = 'series'; |
| 69 |
if(!empty($group)) |
| 70 |
$plots = $this->element('g', $group, null, $plots); |
| 71 |
|
| 72 |
$group = []; |
| 73 |
$shadow_id = $this->defs->getShadow(); |
| 74 |
if($shadow_id !== null) |
| 75 |
$group['filter'] = 'url(#' . $shadow_id . ')'; |
| 76 |
if(!empty($group)) |
| 77 |
$plots = $this->element('g', $group, null, $plots); |
| 78 |
|
| 79 |
list($best_fit_above, $best_fit_below) = $this->bestFitLines(); |
| 80 |
$body .= $best_fit_below; |
| 81 |
$body .= $plots; |
| 82 |
$body .= $this->overShapes(); |
| 83 |
$body .= $this->axes(); |
| 84 |
$body .= $this->drawMarkers(); |
| 85 |
$body .= $best_fit_above; |
| 86 |
return $body; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
|