Source for file SvgDocumentRenderer.php
Documentation is available at SvgDocumentRenderer.php
* $Source: /cvsroot/svggrapher/svggrapher/mains/SvgDocumentRenderer.php,v $
* @version CVS: $Id: SvgDocumentRenderer.php,v 1.10 2007/10/23 09:22:53 geelweb Exp $
* @author Guillaume Luchet. <guillaume@geelweb.org>
* @copyright Copyright (c) 2007, Guillaume Luchet.
* @license http://opensource.org/licenses/bsd-license.php BSD License
require_once SVGGRAPHER_ELEMENTS_PATH .
'/GElement.php';
require_once SVGGRAPHER_ELEMENTS_PATH .
'/TextElement.php';
require_once SVGGRAPHER_ELEMENTS_PATH .
'/LineElement.php';
require_once SVGGRAPHER_ELEMENTS_PATH .
'/RectElement.php';
require_once SVGGRAPHER_ELEMENTS_PATH .
'/AElement.php';
require_once SVGGRAPHER_ELEMENTS_PATH .
'/ImageElement.php';
* @version $Id: SvgDocumentRenderer.php,v 1.10 2007/10/23 09:22:53 geelweb Exp $
* @copyright Copyright (c) 2007, Guillaume Luchet
* @author guillaume luchet <guillaume@geelweb.org>
* @license http://opensource.org/licenses/bsd-license.php BSD License
// SvgDocumentRenderer::render() {{{
* Render the svg document.
* @param mixed $forceBackground if true, the elements will be added on the
* back of the existing elements.
public static function render($forceBackground=
true)
/*$forceBackground = $forceBackground && $svgGrapher->svgGraphPane->haveChild();
$tmp = $svgGrapher->svgGraphPane->removeChildren();
$svgGrapher->svgGraphPane->appendChildren($tmp);
// SvgDocumentRenderer::renderTitle() {{{
* Render the graph title.
$display =
$svgGrapher->display;
if(empty($display['title']) ||
!$display['title']) {
'x' =>
$svgGrapher->boxTitle->padding['left'],
'y' =>
$svgGrapher->boxTitle->padding['top'],
if($svgGrapher->boxTitle->x >
0 ||
$svgGrapher->boxTitle->y >
0) {
$translate =
sprintf('translate(%s,%s)', $svgGrapher->boxTitle->x, $svgGrapher->boxTitle->y);
$text->setAttribute('transform',$translate);
$svgGrapher->svgTitles->appendChild($text);
// SvgDocumentRenderer::renderGridX() {{{
* Render the abscisses lines of the grid
$display =
$svgGrapher->display;
if(empty($display['gridX']) ||
!$display['gridX']) {
$bottom =
$svgGrapher->boxGraphPane->height -
1;
foreach ($svgGrapher->tagsX as $i =>
$u) {
$x =
$svgGrapher->gridLineXDelta *
($i +
$svgGrapher->plotOffsetX);
'x1' =>
$x, 'y1' =>
$top, 'x2' =>
$x, 'y2' =>
$bottom)));
$svgGrapher->svgGraphPane->appendChild($group);
// SvgDocumentRenderer::renderGridY() {{{
* Render the ordinates lines of the grid
$display =
$svgGrapher->display;
if(empty($display['gridX']) ||
!$display['gridX']) {
$right =
$svgGrapher->boxGraphPane->width -
1;
for($i =
0; $i <
$svgGrapher->gridLineY; $i++
) {
$v =
$svgGrapher->gridLineYDelta *
($i +
$svgGrapher->plotOffsetY);
'x1' =>
$left, 'y1' =>
$v, 'x2' =>
$right, 'y2' =>
$v)));
$range =
$svgGrapher->range;
if(($range['min'] <
0 &&
$range['max'] >
0) ||
($range['min'] >
0 &&
$range['max'] <
0)) {
$v =
$svgGrapher->boxGraphPane->height -
($svgGrapher->factorY *
(0 -
$range['min']));
'x1' =>
$left, 'y1' =>
$v, 'x2' =>
$right, 'y2' =>
$v)));
$svgGrapher->svgGraphPane->appendChild($group);
// SvgDocumentRenderer::renderStepX() {{{
$display =
$svgGrapher->display;
if(empty($display['stepX']) ||
!$display['stepX']) {
$top =
$svgGrapher->boxGraphPane->height -
3;
$bottom =
$svgGrapher->boxGraphPane->height +
3;
foreach ($svgGrapher->tagsX as $i =>
$u) {
$x =
$svgGrapher->gridLineXDelta *
($i +
$svgGrapher->plotOffsetX);
'x1' =>
$x, 'y1' =>
$top, 'x2' =>
$x, 'y2' =>
$bottom)));
$svgGrapher->svgGraphPane->appendChild($group);
// SvgDocumentRenderer::renderStepY() {{{
$display =
$svgGrapher->display;
if(empty($display['stepY']) ||
!$display['stepY']) {
for($i =
0; $i <
$svgGrapher->gridLineY; $i++
) {
$v =
$svgGrapher->gridLineYDelta *
($i +
$svgGrapher->plotOffsetY);
array('x1' =>
$left, 'y1' =>
$v, 'x2' =>
$right, 'y2' =>
$v)));
if(isset
($display['minorStepY']) &&
$display['minorStepY']) {
if($i <
$svgGrapher->gridLineY -
1 ) {
for($mstep =
0; $mstep <
$svgGrapher->minorStepY; $mstep++
) {
$m =
$v +
$mstep *
$svgGrapher->minorStepYDelta;
'x1' =>
$left, 'y1' =>
$m, 'x2' =>
0, 'y2' =>
$m));
$group->appendChild($minorStep);
$svgGrapher->svgGraphPane->appendChild($group);
// SvgDocumentRenderer::renderTagsX() {{{
* Render the abscisses tags
$display =
$svgGrapher->display;
if(empty($display['tagsX']) ||
!$display['tagsX']) {
$y =
$svgGrapher->boxTagsX->y;
foreach ($svgGrapher->tagsX as $i =>
$text) {
if(isset
($svgGrapher->rendererCallBacks['tagsX'])) {
$text =
call_user_func($svgGrapher->rendererCallBacks['tagsX'], $text);
$x =
$svgGrapher->gridLineXDelta *
($i +
$svgGrapher->plotOffsetX) +
$svgGrapher->boxGraphPane->x;
if($freqCnt ==
$svgGrapher->tagXGapFrequency) {
if ($svgGrapher->tagXRotation ==
0) {
array('x' =>
$x, 'y' =>
$y, 'dy' =>
'1em',
'style' =>
'text-anchor: middle;'));
$group->appendChild($text);
} else if($svgGrapher->tagXRotation >
0) {
'x' =>
$x, 'y' =>
$y, 'dy' =>
'1em',
'style' =>
'text-anchor: start;'));
$text->setAttribute('transform',"rotate({$svgGrapher->tagXRotation} $x $y)
");
$group->appendChild($text);
'x'=>
$x, 'y'=>
$y, 'dy'=>
'1em',
'style'=>
'text-anchor: end;'));
$text->setAttribute('transform',"rotate({$svgGrapher->tagXRotation} $x $y)
");
$group->appendChild($text);
$svgGrapher->svgTitles->appendChild($group);
// SvgDocumentRenderer::renderTagsY() {{{
* Render the ordinates tags
$display =
$svgGrapher->display;
if(empty($display['tagsY']) ||
!$display['tagsY']) {
foreach ($svgGrapher->tagsY as $i =>
$text) {
if(isset
($svgGrapher->rendererCallBacks['tagsY'])) {
$text =
call_user_func($svgGrapher->rendererCallBacks['tagsY'], $text);
$y =
$svgGrapher->gridLineYDelta *
($i +
$svgGrapher->plotOffsetY) +
$svgGrapher->boxGraphPane->y;
'x'=>
$svgGrapher->boxTagsY->x, 'y'=>
$y));
$group->appendChild($text);
$range =
$svgGrapher->range;
if(($range['min'] <
0 &&
$range['max'] >
0) ||
($range['min'] >
0 &&
$range['max'] <
0)) {
if(isset
($svgGrapher->rendererCallBacks['tagsY'])) {
$text =
call_user_func($svgGrapher->rendererCallBacks['tagsY'], $text);
$y =
$svgGrapher->boxGraphPane->height -
($svgGrapher->factorY *
(0 -
$range['min'])) +
$svgGrapher->boxGraphPane->y;
'x'=>
$svgGrapher->boxTagsY->x, 'y'=>
$y));
$group->appendChild($text);
$svgGrapher->svgTitles->appendChild($group);
// SvgDocumentRenderer::renderLabelX() {{{
* Render the abscisses label
$display =
$svgGrapher->display;
if(empty($display['labelX']) ||
!$display['labelX']) {
'x' =>
$svgGrapher->boxLabelX->x,
'y' =>
$svgGrapher->boxLabelX->y,
$svgGrapher->svgTitles->appendChild($text);
// SvgDocumentRenderer::renderLabelY() {{{
* Render the ordinates label
$display =
$svgGrapher->display;
if(empty($display['labelY']) ||
!$display['labelY']) {
'x' =>
$svgGrapher->boxLabelY->x,
'y' =>
$svgGrapher->boxLabelY->y,
$text->setAttribute('transform',sprintf('rotate(%s %s %s)',
$svgGrapher->labelYRotation, $svgGrapher->boxLabelY->x, $svgGrapher->boxLabelY->y));
$svgGrapher->svgTitles->appendChild($text);
// SvgDocumentRenderer::renderLimits() {{{
* Render the limits lines (limits are only horizontals lines).
$display =
$svgGrapher->display;
if(empty($display['limits']) ||
!$display['limits']) {
$right =
$svgGrapher->boxGraphPane->width -
2;
foreach($svgGrapher->limitsLines as $name=>
$params) {
if($params['value'] !==
false) {
$svgGrapher->drawHLine($params['value'], $params['color'], $name .
'limit');
// SvgDocumentRenderer::renderLegend() {{{
$display =
$svgGrapher->display;
if(empty($display['legend']) ||
!$display['legend']) {
$width =
$svgGrapher->boxLegend->width -
1;
$height =
$svgGrapher->boxGraphPane->height -
1;
$separator =
$svgGrapher->legendTextHeight >>
2;
$lineRectHeight =
$svgGrapher->legendTextHeight;
$lineTextX =
$lineX +
$lineRectWidth +
2;
$lineTextY =
$lineY +
$lineRectHeight;
$rect =
new RectElement(array('x'=>
0, 'y'=>
0, 'width'=>
$width,
$svgGrapher->svgLegend->appendChild($rect);
foreach($svgGrapher->curves as $curve) {
$legends[$curve->legend] =
$curve->color;
foreach($curve->legend as $key=>
$text) {
$legends[$text] =
$curve->color[$key];
foreach($legends as $text=>
$color) {
'stroke-width:1; stroke: #000000; fill: %s; shape-rendering:crispEdges;',
$legendRect =
new RectElement(array('x'=>
$lineX, 'y'=>
$lineY,
'width'=>
$lineRectWidth, 'height'=>
$lineRectHeight,
'style'=>
$legendRectStyle));
$svgGrapher->svgLegend->appendChild($legendRect);
$svgGrapher->svgLegend->appendChild($legendText);
$lineY +=
$svgGrapher->legendTextHeight +
$separator;
$lineTextY =
$lineY +
$lineRectHeight;
$translate =
sprintf('translate(%s,%s)', $svgGrapher->boxLegend->x, $svgGrapher->boxLegend->y);
$svgGrapher->svgLegend->setAttribute('transform',$translate);
// SvgDocumentRenderer::renderGraphPane() {{{
$svgGrapher->svgGraphPane->setAttribute('transform',sprintf(
'translate(%s,%s)', $svgGrapher->boxGraphPane->x,
$svgGrapher->boxGraphPane->y));
// SvgDocumentRenderer::renderGraphPaneBox() {{{
* Render the graph pane box
$display =
$svgGrapher->display;
if(empty($display['box']) ||
!$display['box']) {
$width =
$svgGrapher->boxGraphPane->width -
1;
$height =
$svgGrapher->boxGraphPane->height -
1;
$rect =
new RectElement(array('x'=>
0, 'y'=>
0, 'width'=>
$width,
$svgGrapher->svgGraphPane->appendChild($rect);
// SvgDocumentRenderer::renderCurves() {{{
foreach($svgGrapher->curves as $id=>
$curve) {
// SvgDocumentRenderer::renderW3cValidatorLink() {{{
if(!$svgGrapher->display['w3link']) {
$g =
new GElement(array('id'=>
'w3validatorlink'));
array('xlink:href'=>
'http://validator.w3.org/check?uri=referer')
'xlink:href'=>
'http://www.w3.org/Icons/valid-svg11.png',
'x' =>
$svgGrapher->boxLegend->x,
'y' =>
($svgGrapher->boxLegend->y +
$svgGrapher->boxLegend->height),
$svgGrapher->svgDocument->appendChild($g);
Documentation generated on Tue, 23 Oct 2007 11:32:08 +0200 by phpDocumentor 1.4.0