/** * Render the horizontal axis * * @param RenderContext $ctx The context to use for rendering * @param DOMElement $group The DOMElement this axis will be added to */ private function renderHorizontalAxis(RenderContext $ctx, DOMElement $group) { $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; $shift = 0; foreach ($this->xUnit as $label => $pos) { if ($this->labelRotationStyle === self::LABEL_ROTATE_HORIZONTAL) { // If the last label would overlap this label we shift the y axis a bit if ($lastLabelEnd > $pos) { $shift = ($shift + 5) % 10; } else { $shift = 0; } } $tick = new Line($pos, 100, $pos, 102); $group->appendChild($tick->toSvg($ctx)); $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'); } else { $labelField->setFontSize('2.5em'); } $labelField = $labelField->toSvg($ctx); if ($this->labelRotationStyle === self::LABEL_ROTATE_DIAGONAL) { $labelField = $this->rotate($ctx, $labelField, 45); } $group->appendChild($labelField); if ($this->drawYGrid) { $bgLine = new Line($pos, 0, $pos, 100); $bgLine->setStrokeWidth(0.5)->setStrokeColor('#232'); $group->appendChild($bgLine->toSvg($ctx)); } $lastLabelEnd = $pos + strlen($label) * 1.2; } // render the label for this axis if ($this->xLabel) { $axisLabel = new Text(50, 104, $this->xLabel); $axisLabel->setFontSize('2em')->setFontWeight('bold')->setAlignment(Text::ALIGN_MIDDLE); $group->appendChild($axisLabel->toSvg($ctx)); } }
/** * Draw the label handler and the text for this pie slice * * @param RenderContext $ctx The rendering context to use for coordinate translation * @param int $r The radius of the pie in absolute coordinates * * @return DOMElement The group DOMElement containing the handle and label */ private function drawDescriptionLabel(RenderContext $ctx, $r) { $group = $ctx->getDocument()->createElement('g'); $rOuter = ($ctx->xToAbsolute($this->outerCaptionBound) + $ctx->yToAbsolute($this->outerCaptionBound)) / 2; $addOffset = $rOuter - $r; if ($addOffset < 0) { $addOffset = 0; } list($x, $y) = $ctx->toAbsolute($this->x, $this->y); $midRadius = $this->startRadian + ($this->endRadian - $this->startRadian) / 2; list($offsetX, $offsetY) = $ctx->toAbsolute($this->captionOffset, $this->captionOffset); $midX = $x + intval(($offsetX + $r) / 2 * sin($midRadius)); $midY = $y - intval(($offsetY + $r) / 2 * cos($midRadius)); // Draw the handle $path = new Path(array($midX, $midY)); $midX += ($addOffset + $r / 1.8) * ($midRadius > M_PI ? -1 : 1); $path->append(array($midX, $midY))->toAbsolute(); $midX += intval($r / 2 * sin(M_PI / 9)) * ($midRadius > M_PI ? -1 : 1); $midY -= intval($r / 2 * cos(M_PI / 3)) * ($midRadius < M_PI * 1.4 && $midRadius > M_PI / 3 ? -1 : 1); if ($ctx->ytoRelative($midY) > 100) { $midY = $ctx->yToAbsolute(100); } elseif ($ctx->ytoRelative($midY) < 0) { $midY = $ctx->yToAbsolute($ctx->ytoRelative(100 + $midY)); } $path->append(array($midX, $midY)); $rel = $ctx->toRelative($midX, $midY); // Draw the text box $text = new Text($rel[0] + 1.5, $rel[1], $this->caption); $text->setFontSize('2.5em'); $text->setAlignment($midRadius > M_PI ? Text::ALIGN_END : Text::ALIGN_START); $group->appendChild($path->toSvg($ctx)); $group->appendChild($text->toSvg($ctx)); return $group; }
/** * Render the horizontal axis * * @param RenderContext $ctx The context to use for rendering * @param DOMElement $group The DOMElement this axis will be added to */ private function renderHorizontalAxis(RenderContext $ctx, DOMElement $group) { $steps = $this->ticksPerX($this->xUnit->getTicks(), $ctx->getNrOfUnitsX(), $this->minUnitsPerStep); $ticks = $this->ticksPerX($this->xUnit->getTicks(), $ctx->getNrOfUnitsX(), $this->minUnitsPerTick); // Steps should always be ticks if ($ticks !== $steps) { $steps = $ticks * 5; } // Check whether there is enough room for regular labels $labelRotationStyle = $this->labelRotationStyle; if ($this->labelsOversized($this->xUnit, 6)) { $labelRotationStyle = self::LABEL_ROTATE_DIAGONAL; } /* $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; $shift = 0; $i = 0; 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) { if ($labelRotationStyle === self::LABEL_ROTATE_HORIZONTAL) { // If the last label would overlap this label we shift the y axis a bit if ($lastLabelEnd > $pos) { $shift = ($shift + 5) % 10; } else { $shift = 0; } } $labelField = new Text($pos + 0.5, ($this->xLabel ? 107 : 105) + $shift, $label); if ($labelRotationStyle === self::LABEL_ROTATE_HORIZONTAL) { $labelField->setAlignment(Text::ALIGN_MIDDLE)->setFontSize('2.5em'); } else { $labelField->setFontSize('2.5em'); } if ($labelRotationStyle === self::LABEL_ROTATE_DIAGONAL) { $labelField = new Rotator($labelField, 45); } $labelField = $labelField->toSvg($ctx); $group->appendChild($labelField); if ($this->drawYGrid) { $bgLine = new Line($pos, 0, $pos, 100); $bgLine->setStrokeWidth(0.5)->setStrokeColor('#BFBFBF'); $group->appendChild($bgLine->toSvg($ctx)); } $lastLabelEnd = $pos + strlen($label) * 1.2; } $i++; } }