PageRenderTime 25ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/zeta/Graph/src/options/svg_driver.php

https://gitlab.com/OnBlox/OnBlox-Template
PHP | 288 lines | 168 code | 10 blank | 110 comment | 12 complexity | 8c3b656d685504481232338488647281 MD5 | raw file
  1. <?php
  2. /**
  3. * File containing the ezcGraphSvgDriverOption class
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one
  6. * or more contributor license agreements. See the NOTICE file
  7. * distributed with this work for additional information
  8. * regarding copyright ownership. The ASF licenses this file
  9. * to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance
  11. * with the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing,
  16. * software distributed under the License is distributed on an
  17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. * KIND, either express or implied. See the License for the
  19. * specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. * @package Graph
  23. * @version //autogentag//
  24. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  25. */
  26. /**
  27. * Class containing the extended options for the SVG driver.
  28. *
  29. * <code>
  30. * $graph = new ezcGraphPieChart();
  31. * $graph->background->color = '#FFFFFFFF';
  32. * $graph->title = 'Access statistics';
  33. * $graph->legend = false;
  34. *
  35. * $graph->data['Access statistics'] = new ezcGraphArrayDataSet( array(
  36. * 'Mozilla' => 19113,
  37. * 'Explorer' => 10917,
  38. * 'Opera' => 1464,
  39. * 'Safari' => 652,
  40. * 'Konqueror' => 474,
  41. * ) );
  42. *
  43. * $graph->driver->options->templateDocument = dirname( __FILE__ ) . '/template.svg';
  44. * $graph->driver->options->graphOffset = new ezcGraphCoordinate( 25, 40 );
  45. * $graph->driver->options->insertIntoGroup = 'ezcGraph';
  46. *
  47. * $graph->render( 400, 200, 'tutorial_driver_svg.svg' );
  48. * </code>
  49. *
  50. * @property string $encoding
  51. * Encoding of the SVG XML document
  52. * @property float $assumedNumericCharacterWidth
  53. * Assumed percentual average width of chars in numeric strings with
  54. * the used font.
  55. * @property float $assumedTextCharacterWidth
  56. * Assumed percentual average width of chars in non numeric strings
  57. * with the used font.
  58. * @property string $strokeLineCap
  59. * This specifies the shape to be used at the end of open subpaths
  60. * when they are stroked.
  61. * @property string $strokeLineJoin
  62. * This specifies the shape to be used at the edges of paths.
  63. * @property string $shapeRendering
  64. * "The creator of SVG content might want to provide a hint to the
  65. * implementation about what tradeoffs to make as it renders vector
  66. * graphics elements such as 'path' elements and basic shapes such as
  67. * circles and rectangles."
  68. * @property string $colorRendering
  69. * "The creator of SVG content might want to provide a hint to the
  70. * implementation about how to make speed vs. quality tradeoffs as it
  71. * performs color interpolation and compositing. The
  72. * 'color-rendering' property provides a hint to the SVG user agent
  73. * about how to optimize its color interpolation and compositing
  74. * operations."
  75. * @property string $textRendering
  76. * "The creator of SVG content might want to provide a hint to the
  77. * implementation about what tradeoffs to make as it renders text."
  78. * @property mixed $templateDocument
  79. * Use existing SVG document as template to insert graph into. If
  80. * insertIntoGroup is not set, a new group will be inserted in the
  81. * svg root node.
  82. * @property mixed $insertIntoGroup
  83. * ID of a SVG group node to insert the graph. Only works with a
  84. * custom template document.
  85. * @property ezcGraphCoordinate $graphOffset
  86. * Offset of the graph in the svg.
  87. * @property string $idPrefix
  88. * Prefix used for the ids in SVG documents.
  89. * @property string $linkCursor
  90. * CSS value for cursor property used for linked SVG elements
  91. *
  92. * @version //autogentag//
  93. * @package Graph
  94. */
  95. class ezcGraphSvgDriverOptions extends ezcGraphDriverOptions
  96. {
  97. /**
  98. * Constructor
  99. *
  100. * @param array $options Default option array
  101. * @return void
  102. * @ignore
  103. */
  104. public function __construct( array $options = array() )
  105. {
  106. $this->properties['encoding'] = null;
  107. $this->properties['assumedNumericCharacterWidth'] = .62;
  108. $this->properties['assumedTextCharacterWidth'] = .53;
  109. $this->properties['strokeLineJoin'] = 'round';
  110. $this->properties['strokeLineCap'] = 'round';
  111. $this->properties['shapeRendering'] = 'geometricPrecision';
  112. $this->properties['colorRendering'] = 'optimizeQuality';
  113. $this->properties['textRendering'] = 'optimizeLegibility';
  114. $this->properties['templateDocument'] = false;
  115. $this->properties['insertIntoGroup'] = false;
  116. $this->properties['graphOffset'] = new ezcGraphCoordinate( 0, 0 );
  117. $this->properties['idPrefix'] = 'ezcGraph';
  118. $this->properties['linkCursor'] = 'pointer';
  119. parent::__construct( $options );
  120. }
  121. /**
  122. * Set an option value
  123. *
  124. * @param string $propertyName
  125. * @param mixed $propertyValue
  126. * @throws ezcBasePropertyNotFoundException
  127. * If a property is not defined in this class
  128. * @return void
  129. * @ignore
  130. */
  131. public function __set( $propertyName, $propertyValue )
  132. {
  133. switch ( $propertyName )
  134. {
  135. case 'assumedNumericCharacterWidth':
  136. if ( !is_numeric( $propertyValue ) ||
  137. ( $propertyValue < 0 ) )
  138. {
  139. throw new ezcBaseValueException( $propertyName, $propertyValue, 'float > 0' );
  140. }
  141. $this->properties['assumedNumericCharacterWidth'] = (float) $propertyValue;
  142. break;
  143. case 'assumedTextCharacterWidth':
  144. if ( !is_numeric( $propertyValue ) ||
  145. ( $propertyValue < 0 ) )
  146. {
  147. throw new ezcBaseValueException( $propertyName, $propertyValue, 'float > 0' );
  148. }
  149. $this->properties['assumedTextCharacterWidth'] = (float) $propertyValue;
  150. break;
  151. case 'strokeLineJoin':
  152. $values = array(
  153. 'round',
  154. 'miter',
  155. 'bevel',
  156. 'inherit',
  157. );
  158. if ( in_array( $propertyValue, $values, true ) )
  159. {
  160. $this->properties['strokeLineJoin'] = $propertyValue;
  161. }
  162. else
  163. {
  164. throw new ezcBaseValueException( $propertyName, $propertyValue, implode( $values, ', ' ) );
  165. }
  166. break;
  167. case 'strokeLineCap':
  168. $values = array(
  169. 'round',
  170. 'butt',
  171. 'square',
  172. 'inherit',
  173. );
  174. if ( in_array( $propertyValue, $values, true ) )
  175. {
  176. $this->properties['strokeLineCap'] = $propertyValue;
  177. }
  178. else
  179. {
  180. throw new ezcBaseValueException( $propertyName, $propertyValue, implode( $values, ', ' ) );
  181. }
  182. break;
  183. case 'shapeRendering':
  184. $values = array(
  185. 'auto',
  186. 'optimizeSpeed',
  187. 'crispEdges',
  188. 'geometricPrecision',
  189. 'inherit',
  190. );
  191. if ( in_array( $propertyValue, $values, true ) )
  192. {
  193. $this->properties['shapeRendering'] = $propertyValue;
  194. }
  195. else
  196. {
  197. throw new ezcBaseValueException( $propertyName, $propertyValue, implode( $values, ', ' ) );
  198. }
  199. break;
  200. case 'colorRendering':
  201. $values = array(
  202. 'auto',
  203. 'optimizeSpeed',
  204. 'optimizeQuality',
  205. 'inherit',
  206. );
  207. if ( in_array( $propertyValue, $values, true ) )
  208. {
  209. $this->properties['colorRendering'] = $propertyValue;
  210. }
  211. else
  212. {
  213. throw new ezcBaseValueException( $propertyName, $propertyValue, implode( $values, ', ' ) );
  214. }
  215. break;
  216. case 'textRendering':
  217. $values = array(
  218. 'auto',
  219. 'optimizeSpeed',
  220. 'optimizeLegibility',
  221. 'geometricPrecision',
  222. 'inherit',
  223. );
  224. if ( in_array( $propertyValue, $values, true ) )
  225. {
  226. $this->properties['textRendering'] = $propertyValue;
  227. }
  228. else
  229. {
  230. throw new ezcBaseValueException( $propertyName, $propertyValue, implode( $values, ', ' ) );
  231. }
  232. break;
  233. case 'templateDocument':
  234. if ( !is_file( $propertyValue ) || !is_readable( $propertyValue ) )
  235. {
  236. throw new ezcBaseFileNotFoundException( $propertyValue );
  237. }
  238. else
  239. {
  240. $this->properties['templateDocument'] = realpath( $propertyValue );
  241. }
  242. break;
  243. case 'insertIntoGroup':
  244. if ( !is_string( $propertyValue ) )
  245. {
  246. throw new ezcBaseValueException( $propertyName, $propertyValue, 'string' );
  247. }
  248. else
  249. {
  250. $this->properties['insertIntoGroup'] = $propertyValue;
  251. }
  252. break;
  253. case 'graphOffset':
  254. if ( $propertyValue instanceof ezcGraphCoordinate )
  255. {
  256. $this->properties['graphOffset'] = $propertyValue;
  257. }
  258. else
  259. {
  260. throw new ezcBaseValueException( $propertyName, $propertyValue, 'ezcGraphCoordinate' );
  261. }
  262. break;
  263. case 'idPrefix':
  264. $this->properties['idPrefix'] = (string) $propertyValue;
  265. break;
  266. case 'encoding':
  267. $this->properties['encoding'] = (string) $propertyValue;
  268. break;
  269. case 'linkCursor':
  270. $this->properties['linkCursor'] = (string) $propertyValue;
  271. break;
  272. default:
  273. parent::__set( $propertyName, $propertyValue );
  274. break;
  275. }
  276. }
  277. }
  278. ?>