/** * Render the vertical axis * * @param RenderContext $ctx The context to use for rendering * @param DOMElement $group The DOMElement this axis will be added to */ private function renderVerticalAxis(RenderContext $ctx, DOMElement $group) { $line = new Line(0, 0, 0, 100); $line->setStrokeWidth(2); $group->appendChild($line->toSvg($ctx)); foreach ($this->yUnit as $label => $pos) { $pos = 100 - $pos; $tick = new Line(0, $pos, -1, $pos); $group->appendChild($tick->toSvg($ctx)); $labelField = new Text(-0.5, $pos + 0.5, $label); $labelField->setFontSize('1.8em')->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'); $group->appendChild($bgLine->toSvg($ctx)); } } if ($this->yLabel) { $axisLabel = new Text(-8, 50, $this->yLabel); $axisLabel->setFontSize('2em')->setAdditionalStyle(Text::ORIENTATION_VERTICAL)->setFontWeight('bold')->setAlignment(Text::ALIGN_MIDDLE); $group->appendChild($axisLabel->toSvg($ctx)); } }
/** * Render the vertical axis * * @param RenderContext $ctx The context to use for rendering * @param DOMElement $group The DOMElement this axis will be added to */ private function renderVerticalAxis(RenderContext $ctx, DOMElement $group) { $steps = $this->ticksPerX($this->yUnit->getTicks(), $ctx->getNrOfUnitsY(), $this->minUnitsPerStep); $ticks = $this->ticksPerX($this->yUnit->getTicks(), $ctx->getNrOfUnitsY(), $this->minUnitsPerTick); // Steps should always be ticks 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) { $pos = 100 - $pos; if ($i % $ticks === 0) { // draw a tick //$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('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('#BFBFBF'); $group->appendChild($bgLine->toSvg($ctx)); } } $i++; } if ($this->yLabel || $this->xLabel) { if ($this->yLabel && $this->xLabel) { $txt = $this->yLabel . ' / ' . $this->xLabel; } else { if ($this->xLabel) { $txt = $this->xLabel; } else { $txt = $this->yLabel; } } $axisLabel = new Text(50, -3, $txt); $axisLabel->setFontSize('2em')->setFontWeight('bold')->setAlignment(Text::ALIGN_MIDDLE); $group->appendChild($axisLabel->toSvg($ctx)); } }