[ class tree: phpchartPlus ] [ index: phpchartPlus ] [ all elements ]

Source for file Line.php

Documentation is available at Line.php

  1. <?php
  2.  
  3. /*
  4. **************************************************
  5. Class: Line.php
  6. **************************************************
  7. Author: Tsiavos Chris <jaames@freemail.gr>
  8. Date: October 2004
  9. **************************************************/
  10.  
  11. /**
  12. *Includes the shape abstract class
  13. */
  14. require_once("Shape.php");
  15.  
  16. /**
  17. *Wrapper around gd's ImageLine function
  18. *@author Tsiavos Chris <jaames@freemail.gr>
  19. *@license http://opensource.org/licenses/gpl-license.php GNU Public License
  20. */
  21. class Line extends Shape {
  22. /**
  23. *@access private
  24. *@var string[]
  25. */
  26. private $Points=array();
  27. /**
  28. *The line breadth
  29. *@access private
  30. *@return integer
  31. */
  32. private $Breadth;
  33. /**
  34. *Constructor
  35. *@param mixed &$Canvas reference to the image handler the line will be drawn in
  36. *@param ColorAllocator &$ColorAllocator reference to the ColorAllocator the class will use for allocating the line color
  37. *@param string ("Yes","No") $UseAntialias specifies if antialias functions should be used or not when drawing the line
  38. *@param integer $Breadth
  39. */
  40. public function __construct(&$Canvas,ColorAllocator &$ColorAllocator,$UseAntialias,$Breadth=NULL) {
  41. Shape::__construct($Canvas,$ColorAllocator,$UseAntialias);
  42. $this->Breadth=$Breadth;
  43. }
  44. /**
  45. *Adds a point to the line
  46. *@access public
  47. *@return void
  48. */
  49. public function add_Point($point) {
  50. array_push($this->Points,$point);
  51. }
  52. /**
  53. *Returns the line's points
  54. *@access public
  55. *@return string[]
  56. */
  57. public function get_Points() {
  58. return $this->Points;
  59. }
  60. /**
  61. *Draws a dashed line
  62. *@access public
  63. *@return void
  64. *@param string $BorderColor
  65. *@param integer 0-127 $Alpha
  66. */
  67. public function draw_Dashed($BorderColor,$Alpha) {
  68. $ColorHandler=$this->ColorAllocator->Allocate($this->Canvas,$BorderColor,$BorderColor,$Alpha,1);
  69. for ($i=0;$i<count($this->Points);$i++) {
  70. $current=$i;
  71. if ($current==count($this->Points)-1)
  72. $next=$current;
  73. else
  74. $next=$i+1;
  75. $StartPoint=explode(",",$this->Points[$current]);
  76. $FinishPoint=explode(",",$this->Points[$next]);
  77. ImageDashedLine($this->Canvas,$StartPoint[0],$StartPoint[1],$FinishPoint[0],$FinishPoint[1],$ColorHandler);
  78. }
  79. }
  80. /**
  81. *Draws the border of a line
  82. *@access public
  83. *@return void
  84. *@param string $BorderColor
  85. *@param integer 0-127 $Alpha
  86. */
  87. public function draw($BorderColor,$Alpha) {
  88. if ($this->UseAntialias=="Yes")
  89. ImageAntialias($this->Canvas,1);
  90. $ColorHandler=$this->ColorAllocator->Allocate($this->Canvas,$BorderColor,$BorderColor,$Alpha,1);
  91. for ($i=0;$i<count($this->Points);$i++) {
  92. $current=$i;
  93. if ($current==count($this->Points)-1)
  94. $next=$current;
  95. else
  96. $next=$i+1;
  97. $StartPoint=explode(",",$this->Points[$current]);
  98. $FinishPoint=explode(",",$this->Points[$next]);
  99. ImageLine($this->Canvas,$StartPoint[0],$StartPoint[1],$FinishPoint[0],$FinishPoint[1],$ColorHandler);
  100. if ($this->Breadth!=NULL)
  101. ImageLine($this->Canvas,$StartPoint[0],$StartPoint[1]+$this->Breadth,$FinishPoint[0],$FinishPoint[1]+$this->Breadth,$ColorHandler);
  102. }
  103. if ($this->UseAntialias=="Yes")
  104. ImageAntialias($this->Canvas,0);
  105. }
  106. /**
  107. *Draws a filled with color line
  108. *@access public
  109. *@return void
  110. *@param string $StartColor
  111. *@param string $FinishColor
  112. *@param integer 0-127 $Alpha
  113. */
  114. public function draw_Filled($StartColor,$FinishColor,$Alpha) {
  115. $ColorHandler=$this->ColorAllocator->Allocate($this->Canvas,$StartColor,$FinishColor,$Alpha,$this->Breadth);
  116. if (is_array($ColorHandler))
  117. $this->draw_GradientLine($ColorHandler);
  118. else
  119. $this->draw_NormalLine($ColorHandler);
  120. }
  121. /**
  122. *Draws a gradient color line with breadth=$this->Breadth
  123. *@access private
  124. *@return void
  125. *@param mixed $ColorHandler
  126. */
  127. private function draw_GradientLine($ColorHandler) {
  128. for ($i=0;$i<count($this->Points);$i++) {
  129. $current=$i;
  130. if ($current==count($this->Points)-1)
  131. $next=$current;
  132. else
  133. $next=$i+1;
  134. $StartPoint=explode(",",$this->Points[$current]);
  135. $FinishPoint=explode(",",$this->Points[$next]);
  136. for ($breadth=0;$breadth<$this->Breadth;$breadth++)
  137. ImageLine($this->Canvas,$StartPoint[0],$StartPoint[1]+$breadth,$FinishPoint[0],$FinishPoint[1]+$breadth,$ColorHandler[$breadth]);
  138. }
  139. }
  140. /**
  141. *Draws a uniform color line with breadth=$this->Breadth
  142. *@access private
  143. *@return void
  144. *@param mixed $ColorHandler
  145. */
  146. private function draw_NormalLine($ColorHandler) {
  147. for ($i=0;$i<count($this->Points);$i++) {
  148. $current=$i;
  149. if ($current==count($this->Points)-1)
  150. $next=$current;
  151. else
  152. $next=$i+1;
  153. $StartPoint=explode(",",$this->Points[$current]);
  154. $FinishPoint=explode(",",$this->Points[$next]);
  155. for ($breadth=0;$breadth<$this->Breadth;$breadth++)
  156. ImageLine($this->Canvas,$StartPoint[0],$StartPoint[1]+$breadth,$FinishPoint[0],$FinishPoint[1]+$breadth,$ColorHandler);
  157. }
  158. }
  159. }
  160.  
  161. ?>

Documentation generated on Sun, 3 Oct 2004 14:59:18 +0300 by phpDocumentor 1.3.0RC3