dot_base.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. /**
  3. * A private class. All the other line-dots inherit from this.
  4. * Gives them all some common methods.
  5. */
  6. class dot_base
  7. {
  8. /**
  9. * @param $type string
  10. * @param $value integer
  11. */
  12. function dot_base($type, $value=null)
  13. {
  14. $this->type = $type;
  15. if( isset( $value ) )
  16. $this->value( $value );
  17. }
  18. /**
  19. * For line charts that only require a Y position
  20. * for each point.
  21. * @param $value as integer, the Y position
  22. */
  23. function value( $value )
  24. {
  25. $this->value = $value;
  26. }
  27. /**
  28. * For scatter charts that require an X and Y position for
  29. * each point.
  30. *
  31. * @param $x as integer
  32. * @param $y as integer
  33. */
  34. function position( $x, $y )
  35. {
  36. $this->x = $x;
  37. $this->y = $y;
  38. }
  39. /**
  40. * @param $colour is a string, HEX colour, e.g. '#FF0000' red
  41. */
  42. function colour($colour)
  43. {
  44. $this->colour = $colour;
  45. return $this;
  46. }
  47. /**
  48. * The tooltip for this dot.
  49. */
  50. function tooltip( $tip )
  51. {
  52. $this->tip = $tip;
  53. return $this;
  54. }
  55. /**
  56. * @param $size is an integer. Size of the dot.
  57. */
  58. function size($size)
  59. {
  60. $tmp = 'dot-size';
  61. $this->$tmp = $size;
  62. return $this;
  63. }
  64. /**
  65. * a private method
  66. */
  67. function type( $type )
  68. {
  69. $this->type = $type;
  70. return $this;
  71. }
  72. /**
  73. * @param $size is an integer. The size of the hollow 'halo' around the dot that masks the line.
  74. */
  75. function halo_size( $size )
  76. {
  77. $tmp = 'halo-size';
  78. $this->$tmp = $size;
  79. return $this;
  80. }
  81. /**
  82. * @param $do as string. One of three options (examples):
  83. * - "http://example.com" - browse to this URL
  84. * - "https://example.com" - browse to this URL
  85. * - "trace:message" - print this message in the FlashDevelop debug pane
  86. * - all other strings will be called as Javascript functions, so a string "hello_world"
  87. * will call the JS function "hello_world(index)". It passes in the index of the
  88. * point.
  89. */
  90. function on_click( $do )
  91. {
  92. $tmp = 'on-click';
  93. $this->$tmp = $do;
  94. }
  95. }
  96. /**
  97. * Draw a hollow dot
  98. */
  99. class hollow_dot extends dot_base
  100. {
  101. function hollow_dot($value=null)
  102. {
  103. parent::dot_base( 'hollow-dot', $value );
  104. }
  105. }
  106. /**
  107. * Draw a star
  108. */
  109. class star extends dot_base
  110. {
  111. /**
  112. * The constructor, takes an optional $value
  113. */
  114. function star($value=null)
  115. {
  116. parent::dot_base( 'star', $value );
  117. }
  118. /**
  119. * @param $angle is an integer.
  120. */
  121. function rotation($angle)
  122. {
  123. $this->rotation = $angle;
  124. return $this;
  125. }
  126. /**
  127. * @param $is_hollow is a boolean.
  128. */
  129. function hollow($is_hollow)
  130. {
  131. $this->hollow = $is_hollow;
  132. }
  133. }
  134. /**
  135. * Draw a 'bow tie' shape.
  136. */
  137. class bow extends dot_base
  138. {
  139. /**
  140. * The constructor, takes an optional $value
  141. */
  142. function bow($value=null)
  143. {
  144. parent::dot_base( 'bow', $value );
  145. }
  146. /**
  147. * Rotate the anchor object.
  148. * @param $angle is an integer.
  149. */
  150. function rotation($angle)
  151. {
  152. $this->rotation = $angle;
  153. return $this;
  154. }
  155. }
  156. /**
  157. * An <i><b>n</b></i> sided shape.
  158. */
  159. class anchor extends dot_base
  160. {
  161. /**
  162. * The constructor, takes an optional $value
  163. */
  164. function anchor($value=null)
  165. {
  166. parent::dot_base( 'anchor', $value );
  167. }
  168. /**
  169. * Rotate the anchor object.
  170. * @param $angle is an integer.
  171. */
  172. function rotation($angle)
  173. {
  174. $this->rotation = $angle;
  175. return $this;
  176. }
  177. /**
  178. * @param $sides is an integer. Number of sides this shape has.
  179. */
  180. function sides($sides)
  181. {
  182. $this->sides = $sides;
  183. return $this;
  184. }
  185. }
  186. /**
  187. * A simple dot
  188. */
  189. class dot extends dot_base
  190. {
  191. /**
  192. * The constructor, takes an optional $value
  193. */
  194. function dot($value=null)
  195. {
  196. parent::dot_base( 'dot', $value );
  197. }
  198. }
  199. /**
  200. * A simple dot
  201. */
  202. class solid_dot extends dot_base
  203. {
  204. /**
  205. * The constructor, takes an optional $value
  206. */
  207. function solid_dot($value=null)
  208. {
  209. parent::dot_base( 'solid-dot', $value );
  210. }
  211. }