diff --git a/CHANGES.txt b/CHANGES.txt index 605bef8..70bc740 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,10 @@ +Version 3.18 (02/12/2022) +------------ +- Added shading of flat 3D pie graph sides. +- Added support for colouring data labels using "fill" and "fillColour". +- Fixed axis_text structure option on multi-dataset graphs. +- Fixed explode "all" doing nothing on pie graphs with all values equal. + Version 3.17 (16/09/2022) ------------ - Added axis_tightness_x option for removing space at ends of X-axis. diff --git a/ColourGroup.php b/ColourGroup.php index e9309e7..4ed7b45 100644 --- a/ColourGroup.php +++ b/ColourGroup.php @@ -28,9 +28,11 @@ class ColourGroup { private $stroke; public function __construct(&$graph, $item, $key, $dataset, - $stroke_opt = 'stroke_colour', $fill = null, $item_opt = null) + $stroke_opt = 'stroke_colour', $fill = null, $item_opt = null, + $stroke_opt_is_colour = false) { - $stroke = $graph->getItemOption($stroke_opt, $dataset, $item, $item_opt); + $stroke = $stroke_opt_is_colour ? $stroke_opt : + $graph->getItemOption($stroke_opt, $dataset, $item, $item_opt); if(is_array($stroke)) { $this->stroke = new Colour($graph, $stroke); return; diff --git a/Colours.php b/Colours.php index 1f05a27..76d9406 100644 --- a/Colours.php +++ b/Colours.php @@ -84,7 +84,8 @@ public function getColour($index, $dataset = null) return $this->colours[$dataset][$index]; // try mod - $dataset = $dataset % $this->dataset_count; + if(is_numeric($dataset)) + $dataset = $dataset % $this->dataset_count; if(array_key_exists($dataset, $this->colours)) return $this->colours[$dataset][$index]; diff --git a/DataLabels.php b/DataLabels.php index 870d50c..a778daa 100644 --- a/DataLabels.php +++ b/DataLabels.php @@ -92,6 +92,13 @@ class DataLabels { 'align' => 'data_label_align', ]; + /** + * Options that are colours, so need translation + */ + protected $colour_options = [ + 'colour', 'altcolour', 'back_colour', 'back_altcolour', 'stroke', 'fill', + ]; + function __construct(&$graph) { $this->graph =& $graph; @@ -378,9 +385,19 @@ protected function getStyle($dataset, $index, &$gobject) // structured styles and user defined label styles if($gobject['item'] !== null) - $this->itemStyles($style, $gobject['item']); + $this->itemStyles($style, $gobject['item'], $index, $dataset); elseif($dataset === '_user') $this->userStyles($style, $gobject); + + // deal with fill/fillColour + foreach($this->colour_options as $s) { + if(isset($style[$s]) && is_string($style[$s]) && + strpos($style[$s], 'fill') !== false) { + $cg = new ColourGroup($this->graph, $gobject['item'], $index, $dataset, + $style[$s], null, null, true); + $style[$s] = $cg->stroke(); + } + } return $style; } @@ -435,13 +452,15 @@ protected function getTypeInfo($type, $field = null) protected function getColours($hpos, $vpos, $style) { // if the position is outside, use the alternative colours - $colour = $style['colour']; - $back_colour = $style['back_colour']; + $colour = new Colour($this->graph, $style['colour']); + $back_colour = new Colour($this->graph, $style['back_colour']); if(strpos($hpos . $vpos, 'o') !== false) { - if(!empty($style['altcolour'])) - $colour = $style['altcolour']; - if(!empty($style['back_altcolour'])) - $back_colour = $style['back_altcolour']; + $alt = new Colour($this->graph, $style['altcolour']); + $back_alt = new Colour($this->graph, $style['back_altcolour']); + if(!$alt->isNone()) + $colour = $alt; + if(!$back_alt->isNone()) + $back_colour = $back_alt; } return [$colour, $back_colour]; } @@ -493,7 +512,7 @@ protected function drawLabel($content, $label_w, $label_h, $dataset, $index, $text = [ 'font-family' => $style['font'], 'font-size' => $font_size, - 'fill' => new Colour($this->graph, $colour), + 'fill' => $colour, ]; $label_markup = ''; @@ -603,10 +622,11 @@ protected function drawLabel($content, $label_w, $label_h, $dataset, $index, } } - if(!empty($back_colour)) { + //$back_colour = new Colour($this, $back_colour); + if(!$back_colour->isNone()) { $outline = [ 'stroke-width' => '3px', - 'stroke' => new Colour($this->graph, $back_colour), + 'stroke' => $back_colour, 'stroke-linejoin' => 'round', ]; $t1 = array_merge($outline, $text); @@ -640,7 +660,7 @@ public function getStyleMap() /** * Individual label styles from the structured data item */ - protected function itemStyles(&$style, &$item) + protected function itemStyles(&$style, &$item, $index, $dataset) { // overwrite any style options that the item has set $v = $item->data_label_padding; diff --git a/README.txt b/README.txt index d7315c4..8d852d9 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,4 @@ -SVGGraph Library version 3.17 +SVGGraph Library version 3.18 ============================= This library provides PHP classes and functions for easily creating SVG diff --git a/SVGGraph.php b/SVGGraph.php index c4084f5..7297be3 100644 --- a/SVGGraph.php +++ b/SVGGraph.php @@ -25,7 +25,7 @@ class SVGGraph { use SVGGraphTrait; - const VERSION = 'SVGGraph 3.17'; + const VERSION = 'SVGGraph 3.18'; private $width = 100; private $height = 100; private $settings = [];