Adapt bar width to amount of data points

This commit is contained in:
Matthias Jentsch 2015-01-19 15:12:00 +01:00
parent ab4cbc855f
commit ba1007465a
1 changed files with 9 additions and 1 deletions

View File

@ -28,7 +28,7 @@ class BarGraph extends Styleable implements Drawable
* *
* @var int * @var int
*/ */
private $barWidth = 1; private $barWidth = 3;
/** /**
* The dataset to use for this bar graph * The dataset to use for this bar graph
@ -122,6 +122,14 @@ class BarGraph extends Styleable implements Drawable
$doc = $ctx->getDocument(); $doc = $ctx->getDocument();
$group = $doc->createElement('g'); $group = $doc->createElement('g');
$idx = 0; $idx = 0;
if (count($this->dataSet) > 15) {
$this->barWidth = 2;
}
if (count($this->dataSet) > 25) {
$this->barWidth = 1;
}
foreach ($this->dataSet as $x => $point) { foreach ($this->dataSet as $x => $point) {
// add white background bar, to prevent other bars from altering transparency effects // add white background bar, to prevent other bars from altering transparency effects
$bar = $this->drawSingleBar($point, $idx++, 'white', $this->strokeWidth, $idx)->toSvg($ctx); $bar = $this->drawSingleBar($point, $idx++, 'white', $this->strokeWidth, $idx)->toSvg($ctx);