Improve SVG layout

This commit is contained in:
Matthias Jentsch 2015-01-13 18:21:11 +01:00
parent 807666bf88
commit d1c7d9d2f9
3 changed files with 23 additions and 10 deletions

View File

@ -182,9 +182,11 @@ class Axis implements Drawable
$steps = $ticks * 5; $steps = $ticks * 5;
} }
/*
$line = new Line(0, 100, 100, 100); $line = new Line(0, 100, 100, 100);
$line->setStrokeWidth(2); $line->setStrokeWidth(2);
$group->appendChild($line->toSvg($ctx)); $group->appendChild($line->toSvg($ctx));
*/
// contains the approximate end position of the last label // contains the approximate end position of the last label
$lastLabelEnd = -1; $lastLabelEnd = -1;
@ -194,8 +196,10 @@ class Axis implements Drawable
foreach ($this->xUnit as $label => $pos) { foreach ($this->xUnit as $label => $pos) {
if ($i % $ticks === 0) { if ($i % $ticks === 0) {
/*
$tick = new Line($pos, 100, $pos, 101); $tick = new Line($pos, 100, $pos, 101);
$group->appendChild($tick->toSvg($ctx)); $group->appendChild($tick->toSvg($ctx));
*/
} }
if ($i % $steps === 0) { if ($i % $steps === 0) {
@ -211,7 +215,7 @@ class Axis implements Drawable
$labelField = new Text($pos + 0.5, ($this->xLabel ? 107 : 105) + $shift, $label); $labelField = new Text($pos + 0.5, ($this->xLabel ? 107 : 105) + $shift, $label);
if ($this->labelRotationStyle === self::LABEL_ROTATE_HORIZONTAL) { if ($this->labelRotationStyle === self::LABEL_ROTATE_HORIZONTAL) {
$labelField->setAlignment(Text::ALIGN_MIDDLE) $labelField->setAlignment(Text::ALIGN_MIDDLE)
->setFontSize('1.8em'); ->setFontSize('2.5em');
} else { } else {
$labelField->setFontSize('2.5em'); $labelField->setFontSize('2.5em');
} }
@ -226,7 +230,7 @@ class Axis implements Drawable
if ($this->drawYGrid) { if ($this->drawYGrid) {
$bgLine = new Line($pos, 0, $pos, 100); $bgLine = new Line($pos, 0, $pos, 100);
$bgLine->setStrokeWidth(0.5) $bgLine->setStrokeWidth(0.5)
->setStrokeColor('#232'); ->setStrokeColor('#BFBFBF');
$group->appendChild($bgLine->toSvg($ctx)); $group->appendChild($bgLine->toSvg($ctx));
} }
$lastLabelEnd = $pos + strlen($label) * 1.2; $lastLabelEnd = $pos + strlen($label) * 1.2;
@ -259,9 +263,11 @@ class Axis implements Drawable
if ($ticks !== $steps) { if ($ticks !== $steps) {
$steps = $ticks * 5; $steps = $ticks * 5;
} }
/*
$line = new Line(0, 0, 0, 100); $line = new Line(0, 0, 0, 100);
$line->setStrokeWidth(2); $line->setStrokeWidth(2);
$group->appendChild($line->toSvg($ctx)); $group->appendChild($line->toSvg($ctx));
*/
$i = 0; $i = 0;
foreach ($this->yUnit as $label => $pos) { foreach ($this->yUnit as $label => $pos) {
@ -269,21 +275,21 @@ class Axis implements Drawable
if ($i % $ticks === 0) { if ($i % $ticks === 0) {
// draw a tick // draw a tick
$tick = new Line(0, $pos, -1, $pos); //$tick = new Line(0, $pos, -1, $pos);
$group->appendChild($tick->toSvg($ctx)); //$group->appendChild($tick->toSvg($ctx));
} }
if ($i % $steps === 0) { if ($i % $steps === 0) {
// draw a step // draw a step
$labelField = new Text(-0.5, $pos + 0.5, $label); $labelField = new Text(-0.5, $pos + 0.5, $label);
$labelField->setFontSize('1.8em') $labelField->setFontSize('2.5em')
->setAlignment(Text::ALIGN_END); ->setAlignment(Text::ALIGN_END);
$group->appendChild($labelField->toSvg($ctx)); $group->appendChild($labelField->toSvg($ctx));
if ($this->drawXGrid) { if ($this->drawXGrid) {
$bgLine = new Line(0, $pos, 100, $pos); $bgLine = new Line(0, $pos, 100, $pos);
$bgLine->setStrokeWidth(0.5) $bgLine->setStrokeWidth(0.5)
->setStrokeColor('#343'); ->setStrokeColor('#BFBFBF');
$group->appendChild($bgLine->toSvg($ctx)); $group->appendChild($bgLine->toSvg($ctx));
} }
} }

View File

@ -45,6 +45,13 @@ class LineGraph extends Styleable implements Drawable
*/ */
public $strokeWidth = 5; public $strokeWidth = 5;
/**
* The size of the displayed dots
*
* @var int
*/
public $dotWith = 0;
/** /**
* Create a new LineGraph displaying the given dataset * Create a new LineGraph displaying the given dataset
* *
@ -138,8 +145,8 @@ class LineGraph extends Styleable implements Drawable
$group = $path->toSvg($ctx); $group = $path->toSvg($ctx);
if ($this->showDataPoints === true) { if ($this->showDataPoints === true) {
foreach ($this->dataset as $point) { foreach ($this->dataset as $point) {
$dot = new Circle($point[0], $point[1], $this->strokeWidth*5); $dot = new Circle($point[0], $point[1], $this->dotWith);
$dot->setFill('black'); $dot->setFill($this->strokeColor);
$group->appendChild($dot->toSvg($ctx)); $group->appendChild($dot->toSvg($ctx));
} }

View File

@ -61,7 +61,7 @@ class Circle extends Styleable implements Drawable
$circle = $ctx->getDocument()->createElement('circle'); $circle = $ctx->getDocument()->createElement('circle');
$circle->setAttribute('cx', Format::formatSVGNumber($coords[0])); $circle->setAttribute('cx', Format::formatSVGNumber($coords[0]));
$circle->setAttribute('cy', Format::formatSVGNumber($coords[1])); $circle->setAttribute('cy', Format::formatSVGNumber($coords[1]));
$circle->setAttribute('r', 5); $circle->setAttribute('r', $this->radius);
$circle->setAttribute('style', $this->getStyle()); $circle->setAttribute('style', $this->getStyle());
$this->applyAttributes($circle); $this->applyAttributes($circle);
return $circle; return $circle;