| 1 |
<?php |
| 2 |
/** |
| 3 |
* Copyright (C) 2009-2023 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 SVGGraph { |
| 25 |
|
| 26 |
use SVGGraphTrait; |
| 27 |
|
| 28 |
const VERSION = 'SVGGraph 3.20'; |
| 29 |
private $width = 100; |
| 30 |
private $height = 100; |
| 31 |
private $settings = []; |
| 32 |
private $values = []; |
| 33 |
private $links = null; |
| 34 |
private $colours = null; |
| 35 |
private $subgraph = false; |
| 36 |
private $subgraphs = []; |
| 37 |
protected static $last_instance = null; |
| 38 |
|
| 39 |
public function __construct($w, $h, $settings = null, $subgraph = false) |
| 40 |
{ |
| 41 |
$this->subgraph = $subgraph; |
| 42 |
$this->width = $w; |
| 43 |
$this->height = $h; |
| 44 |
|
| 45 |
if(is_array($settings)) { |
| 46 |
// structured_data, when FALSE disables structure |
| 47 |
if(isset($settings['structured_data']) && !$settings['structured_data']) |
| 48 |
unset($settings['structure']); |
| 49 |
$this->settings = $settings; |
| 50 |
} |
| 51 |
$this->colours = new Colours; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Prevent direct access to members |
| 56 |
*/ |
| 57 |
public function __set($name, $val) |
| 58 |
{ |
| 59 |
if($name == 'values' || $name == 'links' || $name == 'colours') { |
| 60 |
throw new \BadMethodCallException('Modifying $graph->' . $name . |
| 61 |
' directly is not supported - please use the $graph->' . $name . |
| 62 |
'() function.'); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Fetch the content |
| 68 |
*/ |
| 69 |
public function fetch($class, $header = true, $defer_js = true) |
| 70 |
{ |
| 71 |
SVGGraph::$last_instance = $this->setup($class); |
| 72 |
return SVGGraph::$last_instance->fetch($header, $defer_js); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Pass in the type of graph to display |
| 77 |
*/ |
| 78 |
public function render($class, $header = true, $content_type = true, |
| 79 |
$defer_js = false) |
| 80 |
{ |
| 81 |
SVGGraph::$last_instance = $this->setup($class); |
| 82 |
return SVGGraph::$last_instance->render($header, $content_type, $defer_js); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Fetch the Javascript for ALL graphs that have been Fetched |
| 87 |
*/ |
| 88 |
public static function fetchJavascript() |
| 89 |
{ |
| 90 |
if(SVGGraph::$last_instance === null) |
| 91 |
return ''; |
| 92 |
return SVGGraph::$last_instance->fetchJavascript(true, true); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
|