cvs: pear /Image_Graph Graph.php /Image_Graph/Graph Elements.php

From: Date: Wed, 18 Feb 2004 22:01:09 +0000
Subject: cvs: pear /Image_Graph Graph.php /Image_Graph/Graph Elements.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-16652@lists.php.net to get a copy of this message
neufeind Wed Feb 18 17:01:09 2004 EDT Modified files: /pear/Image_Graph Graph.php /pear/Image_Graph/Graph Elements.php Log: changes for usage of Image_Text >=0.3 mostly done; only a few mirow things need to be done tomorrow :-)

http://cvs.php.net/diff.php/pear/Image_Graph/Graph.php?r1=1.29&r2=1.30&ty=u Index: pear/Image_Graph/Graph.php diff -u pear/Image_Graph/Graph.php:1.29 pear/Image_Graph/Graph.php:1.30 --- pear/Image_Graph/Graph.php:1.29 Tue Feb 17 20:36:54 2004 +++ pear/Image_Graph/Graph.php Wed Feb 18 17:01:08 2004 @@ -16,7 +16,7 @@ // | Author: Stefan Neufeind <pear.neufeind@speedpartner.de> | // +----------------------------------------------------------------------+ // -// $Id: Graph.php,v 1.29 2004/02/18 01:36:54 neufeind Exp $ +// $Id: Graph.php,v 1.30 2004/02/18 22:01:08 neufeind Exp $ /** * Package for drawing graphs (bars, lines, ...) @@ -239,8 +239,6 @@ $this->axisX =& new Image_Graph_Axis_X(); $this->axisY0 =& new Image_Graph_Axis_Y(); $this->axisY1 =& new Image_Graph_Axis_Y(); - $this->axisY0->title->setSpacer(array("right" => 5)); - $this->axisY1->title->setSpacer(array("left" => 5)); $this->gridX =& new Image_Graph_Grid($this->axisX); $this->gridY0 =& new Image_Graph_Grid($this->axisY0); @@ -249,7 +247,7 @@ $this->_size = array($width, $height); $this->_pos = array($pos_x, $pox_y); - $this->setSpaceFromBorder(10); + $this->setSpaceFromBorder(2); $this->setAxesColor("black"); // set default color to black, all axes $this->_drawingareaSize = $this->_size; @@ -640,8 +638,7 @@ $this->diagramTitle->_fontOptions = $this->_mergeFontOptions($this->diagramTitle->_fontOptions); require_once 'Image/Text.php'; - $text = (is_array($this->diagramTitle->_text)) ? implode('\n', $this->diagramTitle->_text) : $this->diagramTitle->_text; - $tempText = new Image_Text($text, $this->diagramTitle->_fontOptions); + $tempText = new Image_Text($this->diagramTitle->_text, $this->diagramTitle->_fontOptions); $tempText->init(); $tempText->measurize(); $textSize = $tempText->_realTextSize; @@ -654,8 +651,7 @@ $this->axisX->title->_fontOptions = $this->_mergeFontOptions($this->axisX->title->_fontOptions); require_once 'Image/Text.php'; - $text = (is_array($this->axisX->title->_text)) ? implode("\n", $this->axisX->title->_text) : $this->axisX->title->_text; - $tempText = new Image_Text($text, $this->axisX->title->_fontOptions); + $tempText = new Image_Text($this->axisX->title->_text, $this->axisX->title->_fontOptions); $tempText->init(); $tempText->measurize(); $textSize = $tempText->_realTextSize; @@ -672,8 +668,7 @@ $this->axisX->title->_spacer['top'] + $this->axisX->title->_spacer['bottom']; $this->axisX->_internalTempValues['totalTitleHeight'] = $totalTitleHeight; - - + $this->axisX->_internalTempValues['titleHeight'] = $textSize['height']; } for ($axisCount=0; $axisCount<=1; $axisCount++) { @@ -684,8 +679,7 @@ $this->{$currAxis}->title->_fontOptions = $this->_mergeFontOptions($this->{$currAxis}->title->_fontOptions); require_once 'Image/Text.php'; - $text = (is_array($this->{$currAxis}->title->_text)) ? implode("\n", $this->{$currAxis}->title->_text) : $this->{$currAxis}->title->_text; - $tempText = new Image_Text($text, $this->{$currAxis}->title->_fontOptions); + $tempText = new Image_Text($this->{$currAxis}->title->_text, $this->{$currAxis}->title->_fontOptions); $tempText->set('angle', 90); $tempText->init(); $tempText->measurize(); @@ -704,8 +698,12 @@ if ($axisCount == 0) { $borderspaceSum['left'] += $totalTitleWidth; + $borderspaceSum['left'] += $this->axisX->title->_spacer['left']; + $borderspaceSum['left'] += $this->axisX->title->_spacer['right']; } else { // else axisCount == 1 $borderspaceSum['right'] += $totalTitleWidth; + $borderspaceSum['right'] += $this->axisX->title->_spacer['left']; + $borderspaceSum['right'] += $this->axisX->title->_spacer['right']; } } } @@ -757,7 +755,8 @@ require_once 'Image/Text.php'; $maxWidth = 0; foreach ($this->{$currAxis}->_ticksMajorEffective as $currTick) { - $tempText = new Image_Text(sprintf($this->{$currAxis}->_numberformat, $currTick), $this->{$currAxis}->_fontOptions); + $textStr = sprintf($this->{$currAxis}->_numberformat, $currTick); + $tempText = new Image_Text($textStr, $this->{$currAxis}->_fontOptions); $tempText->init(); $tempText->measurize(); $textSize = $tempText->_realTextSize; @@ -815,14 +814,7 @@ $textX = 0; $options = array_merge($this->diagramTitle->_fontOptions, array('x' => $textX, 'y' => $textY)); - /*********************************************************** - - //Why is diagramTitle->_text an array??? - - ***********************************************************/ - - $text = (is_array($this->diagramTitle->_text)) ? implode("\n", $this->diagramTitle->_text) : $this->diagramTitle->_text; - $tempText = new Image_Text($text, $options); + $tempText = new Image_Text($this->diagramTitle->_text, $options); $tempText->set('halign', IMAGE_TEXT_ALIGN_CENTER); $tempText->set('canvas', $img); $tempText->init(); @@ -837,19 +829,14 @@ // draw x-axis text if (!empty($this->axisX->title->_text)) { require_once 'Image/Text.php'; // already done in _prepareInternalVariables() - but remember it's an require_once - $textX = $this->_pos[0] + ($this->_size[0] / 2); - $textY = $this->_pos[1] + $this->_size[1] - $this->axisX->_internalTempValues['totalTitleHeight'] - $this->_borderspace; - $width = $this->axisX->_internalTempValues['totalTitleWidth']; - $height = $this->axisX->_internalTempValues['totalTitleHeight']; - $options = array_merge($this->axisX->_fontOptions, array('cx' => $textX, 'cy' => $textY, 'width' => $width, 'height' => $height)); + $textY = $this->_pos[1] + $this->_size[1] - $this->axisX->_internalTempValues['titleHeight'] - $this->_borderspace - $this->axisX->title->_spacer['bottom']; + $height = $this->axisX->_internalTempValues['titleHeight']; - /*********************************************************** + $width = $this->_drawingareaSize[0]; + $textX = $this->_drawingareaPos[0]; - //Why is axisX->_text an array??? - - ***********************************************************/ - $text = (is_array($this->axisX->title->_text)) ? implode("\n", $this->axisX->title->_text) : $this->axisX->_text; - $tempText = new Image_Text($text, $options); + $options = array_merge($this->axisX->_fontOptions, array('x' => $textX, 'y' => $textY, 'width' => $width, 'height' => $height)); + $tempText = new Image_Text($this->axisX->title->_text, $options); $tempText->set('halign', IMAGE_TEXT_ALIGN_CENTER); $tempText->set('canvas', $img); $tempText->init(); @@ -857,7 +844,6 @@ $tempText->setColor(array ("r" => $this->axisX->title->_color[0], "g" => $this->axisX->title->_color[1], "b" => $this->axisX->title->_color[2])); - $tempText->render(); } @@ -868,15 +854,16 @@ require_once 'Image/Text.php'; $options = array('angle' => 90, 'canvas' => $img); $options = array_merge($options, $this->{$currAxis}->title->_fontOptions); - $text = (is_array($this->{$currAxis}->title->_text)) ? implode('\n', $this->{$currAxis}->title->_text) : $this->{$currAxis}->title->_text; - $tempText = new Image_Text($text, $options); + + $tempText = new Image_Text($this->{$currAxis}->title->_text, $options); + $tempText->set('canvas', $img); $tempText->init(); $tempText->measurize(); $textSize = $tempText->_realTextSize; if ($axisCount == 0) { $textX = $this->_pos[0] + $this->_borderspace + $this->{$currAxis}->title->_spacer['left']; } else { - $textX = $this->_pos[0] + $this->_size[0] - $this->_borderspace - $this->{$currAxis}->title->_spacer['right']; + $textX = $this->_pos[0] + $this->_size[0] - 1 - $this->_borderspace - $this->{$currAxis}->title->_spacer['right'] - $textSize['height']; } $textY = $this->_drawingareaPos[1] + ($this->_drawingareaSize[1]/2) + ($textSize['width']/2); @@ -933,6 +920,7 @@ require_once 'Image/Text.php'; // already done in _prepareInternalVariables() - but remember it's an require_once $textoptions = $this->axisX->_fontOptions; $tempText = new Image_Text("", $textoptions); + $tempText->set('canvas', $img); $textY = $this->_drawingareaPos[1] + $this->_drawingareaSize[1]; if (($this->axisX->_tickStyle == IMAGE_GRAPH_TICKS_OUTSIDE) || @@ -940,6 +928,8 @@ ) { $textY += $this->axisX->_tickSize; } + $textY += round($this->axisX->_internalTempValues['maxLabelHeight'] / 2); + $tempText->set('height', $this->axisX->_internalTempValues['maxLabelHeight']); for ($labelCount=0; $labelCount<$this->axisX->_bounds['max']; $labelCount++) { @@ -955,7 +945,7 @@ $tempText->set('text', sprintf($this->axisX->_numberformat, $currLabel)); } - $tempText->set('align', IMAGE_TEXT_ALIGN_CENTER); + $tempText->set('halign', IMAGE_TEXT_ALIGN_CENTER); $tempText->init(); $tempText->measurize(); $textSize = $tempText->_realTextSize; @@ -968,7 +958,7 @@ $tempText->setColor(array ("r" => $this->axisX->_numbercolor[0], "g" => $this->axisX->_numbercolor[1], "b" => $this->axisX->_numbercolor[2])); - $opts = array('x' => $textX, 'y' => $textY, 'canvas' => $img); + $opts = array('cx' => $textX, 'cy' => $textY, 'canvas' => $img); $tempText->set($opts); $tempText->init(); $tempText->measurize(); @@ -1046,31 +1036,36 @@ $textoptions = $this->{$currAxis}->_fontOptions; $textoptions['width'] = $this->{$currAxis}->_internalTempValues['maxNumWidth']; $tempText = new Image_Text("", $textoptions); + $tempText->set('canvas', $img); if ($axisCount == 0) { // axis 0 (left axis) - $textX = $this->_drawingareaPos[0] + $textX = $this->_drawingareaPos[0]-1 - $this->{$currAxis}->_internalTempValues['maxNumWidth']; if (($this->{$currAxis}->_tickStyle == IMAGE_GRAPH_TICKS_OUTSIDE) || ($this->{$currAxis}->_tickStyle == IMAGE_GRAPH_TICKS_BOTH)) { $textX -= $this->{$currAxis}->_internalTempValues['tickSize']; } + $textX -= $this->{$currAxis}->_spacer['right']; } else { // axis 1 (right axis) - $textX = $this->_drawingareaPos[0] + $this->_drawingareaSize[0]; + $textX = $this->_drawingareaPos[0] + $this->_drawingareaSize[0]-1; if (($this->{$currAxis}->_tickStyle == IMAGE_GRAPH_TICKS_OUTSIDE) || ($this->{$currAxis}->_tickStyle == IMAGE_GRAPH_TICKS_BOTH)) { $textX += $this->{$currAxis}->_internalTempValues['tickSize']; } + $textX += $this->{$currAxis}->_spacer['left']; } foreach ($this->{$currAxis}->_ticksMajorEffective as $currTick) { $tempText->set('text', sprintf($this->{$currAxis}->_numberformat, $currTick)); - $tempText->set('align', IMAGE_TEXT_ALIGN_LEFT); + $tempText->set('halign', IMAGE_TEXT_ALIGN_RIGHT); + $tempText->set('width', $this->{$currAxis}->_internalTempValues['maxNumWidth']); $tempText->set('canvas', $img); $tempText->init(); $tempText->measurize(); $textSize = $tempText->_realTextSize; $relativeYPosition = $this->{$currAxis}->valueToPixelRelative($currTick); - $textY = $this->_drawingareaPos[1]+$relativeYPosition - ($textSize['height']/2); + + $textY = (int) round($this->_drawingareaPos[1]+$relativeYPosition - ($textSize['height']/2)); if (is_null($this->{$currAxis}->_numbercolor)) { $this->{$currAxis}->_numbercolor = $this->{$currAxis}->_color; http://cvs.php.net/diff.php/pear/Image_Graph/Graph/Elements.php?r1=1.13&r2=1.14&ty=u Index: pear/Image_Graph/Graph/Elements.php diff -u pear/Image_Graph/Graph/Elements.php:1.13 pear/Image_Graph/Graph/Elements.php:1.14 --- pear/Image_Graph/Graph/Elements.php:1.13 Sun Feb 15 16:38:44 2004 +++ pear/Image_Graph/Graph/Elements.php Wed Feb 18 17:01:09 2004 @@ -16,7 +16,7 @@ // | Author: Stefan Neufeind <pear.neufeind@speedpartner.de> | // +----------------------------------------------------------------------+ // -// $Id: Elements.php,v 1.13 2004/02/15 21:38:44 toby Exp $ +// $Id: Elements.php,v 1.14 2004/02/18 22:01:09 neufeind Exp $ /** * Contains various classes for elements of a graph @@ -144,6 +144,14 @@ class Image_Graph_Axis extends Image_Graph_Base { /** + * Spacer + * + * @var array (array of 4 ints) array with keys "top, bottom, left, right"; describes extra-space to add + * @access private + */ + var $_spacer = array("top" => 2, "bottom" => 2, "left" => 2, "right" => 2); + + /** * Title for axis * * @var object Image_Graph_Title @@ -741,7 +749,7 @@ * @var array (array of 4 ints) array with keys "top, bottom, left, right"; describes extra-space to add beside this title * @access private */ - var $_spacer = array("top" => 0, "bottom" => 0, "left" => 0, "right" => 0); + var $_spacer = array("top" => 2, "bottom" => 2, "left" => 2, "right" => 2); /** * Constructor for the class
« previous php.pear.cvs (#16652) next »