| 1 |
<?php |
| 2 |
/** |
| 3 |
* Copyright (C) 2019 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 Subgraph { |
| 25 |
|
| 26 |
use SVGGraphTrait; |
| 27 |
|
| 28 |
private $type; |
| 29 |
private $x; |
| 30 |
private $y; |
| 31 |
private $width; |
| 32 |
private $height; |
| 33 |
private $settings; |
| 34 |
private $values = []; |
| 35 |
private $links = null; |
| 36 |
private $colours = null; |
| 37 |
private $subgraph = true; |
| 38 |
private $subgraphs = []; |
| 39 |
|
| 40 |
public function __construct($type, $x, $y, $w, $h, $settings) |
| 41 |
{ |
| 42 |
$this->type = $type; |
| 43 |
$this->x = $x; |
| 44 |
$this->y = $y; |
| 45 |
$this->width = $w; |
| 46 |
$this->height = $h; |
| 47 |
if($settings === null) |
| 48 |
$settings = []; |
| 49 |
|
| 50 |
$this->settings = $settings; |
| 51 |
$this->colours = new Colours; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Used to duplicate parent graph's colours |
| 56 |
*/ |
| 57 |
public function setColours($colours) |
| 58 |
{ |
| 59 |
$this->colours = $colours; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Fetches the graph content |
| 64 |
*/ |
| 65 |
public function fetch($parent) |
| 66 |
{ |
| 67 |
// transform any non-numeric dimensions |
| 68 |
if(is_string($this->x) || is_string($this->y) || |
| 69 |
is_string($this->width) || is_string($this->height)) { |
| 70 |
$coords = new Coords($parent); |
| 71 |
|
| 72 |
list($this->x, $this->y) = $coords->transformCoords($this->x, $this->y); |
| 73 |
$this->width = $coords->transform($this->width, 'x'); |
| 74 |
$this->height = $coords->transform($this->height, 'y'); |
| 75 |
} |
| 76 |
|
| 77 |
// pass position as settings |
| 78 |
$this->settings['graph_x'] = $this->x; |
| 79 |
$this->settings['graph_y'] = $this->y; |
| 80 |
|
| 81 |
// no header, defer javascript |
| 82 |
$graph = $this->setup($this->type); |
| 83 |
return $graph->fetch(false, true); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
|