| 1 |
<?php |
| 2 |
/** |
| 3 |
* Copyright (C) 2019-2021 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 MarkerShape extends Shape { |
| 25 |
protected $element = 'use'; |
| 26 |
protected $required = ['type', 'x', 'y']; |
| 27 |
protected $transform = ['size' => 'y']; |
| 28 |
protected $transform_from = ['size' => 'y']; |
| 29 |
protected $transform_pairs = [ ['x', 'y'] ]; |
| 30 |
|
| 31 |
/** |
| 32 |
* Override to draw a marker |
| 33 |
*/ |
| 34 |
protected function drawElement(&$graph, &$attributes) |
| 35 |
{ |
| 36 |
$markers = new Markers($graph); |
| 37 |
$size = isset($attributes['size']) ? $attributes['size'] : 10; |
| 38 |
$stroke_width = isset($attributes['stroke-width']) ? |
| 39 |
$attributes['stroke-width'] : 1; |
| 40 |
$opacity = isset($attributes['opacity']) ? |
| 41 |
$attributes['opacity'] : 1; |
| 42 |
$angle = isset($attributes['angle']) ? |
| 43 |
$attributes['angle'] : 0; |
| 44 |
$id = $markers->create($attributes['type'], $size, |
| 45 |
$attributes['fill'], $stroke_width, $attributes['stroke'], |
| 46 |
$opacity, $angle); |
| 47 |
|
| 48 |
$remove = ['type', 'size', 'fill', 'stroke', 'stroke-width', |
| 49 |
'opacity', 'angle']; |
| 50 |
$use = $attributes; |
| 51 |
foreach($remove as $key) { |
| 52 |
unset($use[$key]); |
| 53 |
} |
| 54 |
|
| 55 |
// clip-path must be applied to <g> to prevent being offset with <use> |
| 56 |
if(isset($use['clip-path'])) { |
| 57 |
$group = ['clip-path' => $use['clip-path']]; |
| 58 |
unset($use['clip-path']); |
| 59 |
$e = $graph->element('g', $group, null, |
| 60 |
$graph->defs->useSymbol($id, $use)); |
| 61 |
} else { |
| 62 |
$e = $graph->defs->useSymbol($id, $use); |
| 63 |
} |
| 64 |
return $e; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
|