Improve SVG layout
This commit is contained in:
parent
807666bf88
commit
d1c7d9d2f9
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue