From d1c7d9d2f9cd8481b7d2a15830da8635189c6eaa Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 13 Jan 2015 18:21:11 +0100 Subject: [PATCH] Improve SVG layout --- library/Icinga/Chart/Axis.php | 20 +++++++++++++------- library/Icinga/Chart/Graph/LineGraph.php | 11 +++++++++-- library/Icinga/Chart/Primitive/Circle.php | 2 +- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/library/Icinga/Chart/Axis.php b/library/Icinga/Chart/Axis.php index 74c40b495..e6046705a 100644 --- a/library/Icinga/Chart/Axis.php +++ b/library/Icinga/Chart/Axis.php @@ -182,9 +182,11 @@ class Axis implements Drawable $steps = $ticks * 5; } + /* $line = new Line(0, 100, 100, 100); $line->setStrokeWidth(2); $group->appendChild($line->toSvg($ctx)); + */ // contains the approximate end position of the last label $lastLabelEnd = -1; @@ -194,8 +196,10 @@ class Axis implements Drawable foreach ($this->xUnit as $label => $pos) { if ($i % $ticks === 0) { + /* $tick = new Line($pos, 100, $pos, 101); $group->appendChild($tick->toSvg($ctx)); + */ } if ($i % $steps === 0) { @@ -211,7 +215,7 @@ class Axis implements Drawable $labelField = new Text($pos + 0.5, ($this->xLabel ? 107 : 105) + $shift, $label); if ($this->labelRotationStyle === self::LABEL_ROTATE_HORIZONTAL) { $labelField->setAlignment(Text::ALIGN_MIDDLE) - ->setFontSize('1.8em'); + ->setFontSize('2.5em'); } else { $labelField->setFontSize('2.5em'); } @@ -226,7 +230,7 @@ class Axis implements Drawable if ($this->drawYGrid) { $bgLine = new Line($pos, 0, $pos, 100); $bgLine->setStrokeWidth(0.5) - ->setStrokeColor('#232'); + ->setStrokeColor('#BFBFBF'); $group->appendChild($bgLine->toSvg($ctx)); } $lastLabelEnd = $pos + strlen($label) * 1.2; @@ -259,9 +263,11 @@ class Axis implements Drawable if ($ticks !== $steps) { $steps = $ticks * 5; } + /* $line = new Line(0, 0, 0, 100); $line->setStrokeWidth(2); $group->appendChild($line->toSvg($ctx)); + */ $i = 0; foreach ($this->yUnit as $label => $pos) { @@ -269,21 +275,21 @@ class Axis implements Drawable if ($i % $ticks === 0) { // draw a tick - $tick = new Line(0, $pos, -1, $pos); - $group->appendChild($tick->toSvg($ctx)); + //$tick = new Line(0, $pos, -1, $pos); + //$group->appendChild($tick->toSvg($ctx)); } if ($i % $steps === 0) { // draw a step - $labelField = new Text(-0.5, $pos+0.5, $label); - $labelField->setFontSize('1.8em') + $labelField = new Text(-0.5, $pos + 0.5, $label); + $labelField->setFontSize('2.5em') ->setAlignment(Text::ALIGN_END); $group->appendChild($labelField->toSvg($ctx)); if ($this->drawXGrid) { $bgLine = new Line(0, $pos, 100, $pos); $bgLine->setStrokeWidth(0.5) - ->setStrokeColor('#343'); + ->setStrokeColor('#BFBFBF'); $group->appendChild($bgLine->toSvg($ctx)); } } diff --git a/library/Icinga/Chart/Graph/LineGraph.php b/library/Icinga/Chart/Graph/LineGraph.php index d12d4eed9..3644f1492 100644 --- a/library/Icinga/Chart/Graph/LineGraph.php +++ b/library/Icinga/Chart/Graph/LineGraph.php @@ -45,6 +45,13 @@ class LineGraph extends Styleable implements Drawable */ public $strokeWidth = 5; + /** + * The size of the displayed dots + * + * @var int + */ + public $dotWith = 0; + /** * Create a new LineGraph displaying the given dataset * @@ -138,8 +145,8 @@ class LineGraph extends Styleable implements Drawable $group = $path->toSvg($ctx); if ($this->showDataPoints === true) { foreach ($this->dataset as $point) { - $dot = new Circle($point[0], $point[1], $this->strokeWidth*5); - $dot->setFill('black'); + $dot = new Circle($point[0], $point[1], $this->dotWith); + $dot->setFill($this->strokeColor); $group->appendChild($dot->toSvg($ctx)); } diff --git a/library/Icinga/Chart/Primitive/Circle.php b/library/Icinga/Chart/Primitive/Circle.php index 058211bf7..da5f1785e 100644 --- a/library/Icinga/Chart/Primitive/Circle.php +++ b/library/Icinga/Chart/Primitive/Circle.php @@ -61,7 +61,7 @@ class Circle extends Styleable implements Drawable $circle = $ctx->getDocument()->createElement('circle'); $circle->setAttribute('cx', Format::formatSVGNumber($coords[0])); $circle->setAttribute('cy', Format::formatSVGNumber($coords[1])); - $circle->setAttribute('r', 5); + $circle->setAttribute('r', $this->radius); $circle->setAttribute('style', $this->getStyle()); $this->applyAttributes($circle); return $circle;