PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/library/ezc/Graph/src/options/renderer.php

https://github.com/fusenigk/mantisbt-1
PHP | 248 lines | 104 code | 14 blank | 130 comment | 7 complexity | cb92bc7168a56b532d2c0b879cb68f80 MD5 | raw file
  1. <?php
  2. /**
  3. * File containing the ezcGraphRenderer2dOptions class
  4. *
  5. * @package Graph
  6. * @version 1.5
  7. * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
  8. * @license http://ez.no/licenses/new_bsd New BSD License
  9. */
  10. /**
  11. * Class containing the basic options for renderers.
  12. *
  13. * Renderer options are used to define the general appearance of charts beside
  14. * the palettes. The renderer transforms chart primitives (like the legend, or
  15. * one pie slice) into image primitives, which are then rendered by the
  16. * drivers. The way this transformation is done, and which effects are also
  17. * rendered is specified by the values in this option class.
  18. *
  19. * The example below shows some basic bar rendering options, which are
  20. * available in all renderers. You mya want to check the tutorial sections
  21. * about the renderer, which show example output for more renderer options.
  22. *
  23. * <code>
  24. * $wikidata = include 'tutorial_wikipedia_data.php';
  25. *
  26. * $graph = new ezcGraphBarChart();
  27. * $graph->title = 'Wikipedia articles';
  28. *
  29. * // Add data
  30. * foreach ( $wikidata as $language => $data )
  31. * {
  32. * $graph->data[$language] = new ezcGraphArrayDataSet( $data );
  33. * }
  34. *
  35. * // $graph->renderer = new ezcGraphRenderer2d();
  36. *
  37. * $graph->renderer->options->barMargin = .2;
  38. * $graph->renderer->options->barPadding = .2;
  39. *
  40. * $graph->renderer->options->dataBorder = 0;
  41. *
  42. * $graph->render( 400, 150, 'tutorial_bar_chart_options.svg' );
  43. * </code>
  44. *
  45. * For additional options, which are special to some chart type you may
  46. * also want to check the option classes for the repective chart type you
  47. * are using and the elements of the chart. The chart type dependant option
  48. * classes are:
  49. *
  50. * - ezcGraphLineChartOptions
  51. * - ezcGraphPieChartOptions
  52. * - ezcGraphRadarChartOptions
  53. *
  54. * There may be additional options dependant on the renderer you are using.
  55. * You may want to check the extensions of this class:
  56. *
  57. * - ezcGraphRenderer2dOptions
  58. * - ezcGraphRenderer3dOptions
  59. *
  60. * @property float $maxLabelHeight
  61. * Percent of chart height used as maximum height for pie chart
  62. * labels.
  63. * @property bool $showSymbol
  64. * Indicates wheather to show the line between pie elements and
  65. * labels.
  66. * @property float $symbolSize
  67. * Size of symbols used to connect a label with a pie.
  68. * @property float $moveOut
  69. * Percent to move pie chart elements out of the middle on highlight.
  70. * @property int $titlePosition
  71. * Position of title in a box.
  72. * @property int $titleAlignement
  73. * Alignement of box titles.
  74. * @property float $dataBorder
  75. * Factor to darken border of data elements, like lines, bars and
  76. * pie segments.
  77. * @property float $barMargin
  78. * Percentual distance between bar blocks.
  79. * @property float $barPadding
  80. * Percentual distance between bars.
  81. * @property float $pieChartOffset
  82. * Offset for starting with first pie chart segment in degrees.
  83. * @property float $legendSymbolGleam
  84. * Opacity of gleam in legend symbols
  85. * @property float $legendSymbolGleamSize
  86. * Size of gleam in legend symbols
  87. * @property float $legendSymbolGleamColor
  88. * Color of gleam in legend symbols
  89. * @property float $pieVerticalSize
  90. * Percent of vertical space used for maximum pie chart size.
  91. * @property float $pieHorizontalSize
  92. * Percent of horizontal space used for maximum pie chart size.
  93. * @property float $pieChartSymbolColor
  94. * Color of pie chart symbols
  95. * @property float $pieChartGleam
  96. * Enhance pie chart with gleam on top.
  97. * @property float $pieChartGleamColor
  98. * Color used for gleam on pie charts.
  99. * @property float $pieChartGleamBorder
  100. * Do not draw gleam on an outer border of this size.
  101. * @property bool $syncAxisFonts
  102. * Synchronize fonts of axis. With the defaut true value, the only
  103. * the fonts of the yAxis will be used.
  104. * @property bool $axisEndStyle
  105. * Style of axis end markers. Defauls to arrow heads, but you may
  106. * also use all symbol constants defined ein the ezcGraph class,
  107. * especially ezcGraph::NO_SYMBOL.
  108. * @property bool $shortAxis
  109. * Defines wheather to render the axis extending the chart boundings
  110. * or stop them at the chart boundings. Deafults to false.
  111. *
  112. * @version 1.5
  113. * @package Graph
  114. */
  115. class ezcGraphRendererOptions extends ezcGraphChartOptions
  116. {
  117. /**
  118. * Constructor
  119. *
  120. * @param array $options Default option array
  121. * @return void
  122. * @ignore
  123. */
  124. public function __construct( array $options = array() )
  125. {
  126. $this->properties['maxLabelHeight'] = .10;
  127. $this->properties['showSymbol'] = true;
  128. $this->properties['symbolSize'] = 6;
  129. $this->properties['moveOut'] = .1;
  130. $this->properties['titlePosition'] = ezcGraph::TOP;
  131. $this->properties['titleAlignement'] = ezcGraph::MIDDLE | ezcGraph::CENTER;
  132. $this->properties['dataBorder'] = .5;
  133. $this->properties['barMargin'] = .1;
  134. $this->properties['barPadding'] = .05;
  135. $this->properties['pieChartOffset'] = 0;
  136. $this->properties['pieChartSymbolColor'] = ezcGraphColor::fromHex( '#000000' );
  137. $this->properties['pieChartGleam'] = false;
  138. $this->properties['pieChartGleamColor'] = ezcGraphColor::fromHex( '#FFFFFF' );
  139. $this->properties['pieChartGleamBorder'] = 0;
  140. $this->properties['legendSymbolGleam'] = false;
  141. $this->properties['legendSymbolGleamSize'] = .9;
  142. $this->properties['legendSymbolGleamColor'] = ezcGraphColor::fromHex( '#FFFFFF' );
  143. $this->properties['pieVerticalSize'] = .5;
  144. $this->properties['pieHorizontalSize'] = .25;
  145. $this->properties['syncAxisFonts'] = true;
  146. $this->properties['axisEndStyle'] = ezcGraph::ARROW;
  147. $this->properties['shortAxis'] = false;
  148. parent::__construct( $options );
  149. }
  150. /**
  151. * Set an option value
  152. *
  153. * @param string $propertyName
  154. * @param mixed $propertyValue
  155. * @throws ezcBasePropertyNotFoundException
  156. * If a property is not defined in this class
  157. * @return void
  158. * @ignore
  159. */
  160. public function __set( $propertyName, $propertyValue )
  161. {
  162. switch ( $propertyName )
  163. {
  164. case 'dataBorder':
  165. case 'pieChartGleam':
  166. case 'legendSymbolGleam':
  167. if ( $propertyValue !== false &&
  168. !is_numeric( $propertyValue ) ||
  169. ( $propertyValue < 0 ) ||
  170. ( $propertyValue > 1 ) )
  171. {
  172. throw new ezcBaseValueException( $propertyName, $propertyValue, 'false OR 0 <= float <= 1' );
  173. }
  174. $this->properties[$propertyName] = (
  175. $propertyValue === false
  176. ? false
  177. : (float) $propertyValue );
  178. break;
  179. case 'maxLabelHeight':
  180. case 'moveOut':
  181. case 'barMargin':
  182. case 'barPadding':
  183. case 'legendSymbolGleamSize':
  184. case 'pieVerticalSize':
  185. case 'pieHorizontalSize':
  186. if ( !is_numeric( $propertyValue ) ||
  187. ( $propertyValue < 0 ) ||
  188. ( $propertyValue > 1 ) )
  189. {
  190. throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= float <= 1' );
  191. }
  192. $this->properties[$propertyName] = (float) $propertyValue;
  193. break;
  194. case 'symbolSize':
  195. case 'titlePosition':
  196. case 'titleAlignement':
  197. case 'pieChartGleamBorder':
  198. case 'axisEndStyle':
  199. if ( !is_numeric( $propertyValue ) ||
  200. ( $propertyValue < 0 ) )
  201. {
  202. throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 0' );
  203. }
  204. $this->properties[$propertyName] = (int) $propertyValue;
  205. break;
  206. case 'showSymbol':
  207. case 'syncAxisFonts':
  208. case 'shortAxis':
  209. if ( !is_bool( $propertyValue ) )
  210. {
  211. throw new ezcBaseValueException( $propertyName, $propertyValue, 'bool' );
  212. }
  213. $this->properties[$propertyName] = (bool) $propertyValue;
  214. break;
  215. case 'pieChartOffset':
  216. if ( !is_numeric( $propertyValue ) ||
  217. ( $propertyValue < 0 ) ||
  218. ( $propertyValue > 360 ) )
  219. {
  220. throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= float <= 360' );
  221. }
  222. $this->properties[$propertyName] = (float) $propertyValue;
  223. break;
  224. case 'pieChartSymbolColor':
  225. case 'pieChartGleamColor':
  226. case 'legendSymbolGleamColor':
  227. $this->properties[$propertyName] = ezcGraphColor::create( $propertyValue );
  228. break;
  229. default:
  230. return parent::__set( $propertyName, $propertyValue );
  231. }
  232. }
  233. }
  234. ?>