b3f8b8c31716dd093bd31ab077754f41108025af.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <?php
  2. require_once 'Properties.php';
  3. /**
  4. * Created by PhpStorm.
  5. * User: Wiktor Trzonkowski
  6. * Date: 7/2/14
  7. * Time: 2:36 PM
  8. */
  9. class PHPExcel_Chart_GridLines extends
  10. PHPExcel_Properties {
  11. /**
  12. * Properties of Class:
  13. * Object State (State for Minor Tick Mark) @var bool
  14. * Line Properties @var array of mixed
  15. * Shadow Properties @var array of mixed
  16. * Glow Properties @var array of mixed
  17. * Soft Properties @var array of mixed
  18. *
  19. */
  20. private
  21. $_object_state = FALSE,
  22. $_line_properties = array(
  23. 'color' => array(
  24. 'type' => self::EXCEL_COLOR_TYPE_STANDARD,
  25. 'value' => NULL,
  26. 'alpha' => 0
  27. ),
  28. 'style' => array(
  29. 'width' => '9525',
  30. 'compound' => self::LINE_STYLE_COMPOUND_SIMPLE,
  31. 'dash' => self::LINE_STYLE_DASH_SOLID,
  32. 'cap' => self::LINE_STYLE_CAP_FLAT,
  33. 'join' => self::LINE_STYLE_JOIN_BEVEL,
  34. 'arrow' => array(
  35. 'head' => array(
  36. 'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW,
  37. 'size' => self::LINE_STYLE_ARROW_SIZE_5
  38. ),
  39. 'end' => array(
  40. 'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW,
  41. 'size' => self::LINE_STYLE_ARROW_SIZE_8
  42. ),
  43. )
  44. )
  45. ),
  46. $_shadow_properties = array(
  47. 'presets' => self::SHADOW_PRESETS_NOSHADOW,
  48. 'effect' => NULL,
  49. 'color' => array(
  50. 'type' => self::EXCEL_COLOR_TYPE_STANDARD,
  51. 'value' => 'black',
  52. 'alpha' => 85,
  53. ),
  54. 'size' => array(
  55. 'sx' => NULL,
  56. 'sy' => NULL,
  57. 'kx' => NULL
  58. ),
  59. 'blur' => NULL,
  60. 'direction' => NULL,
  61. 'distance' => NULL,
  62. 'algn' => NULL,
  63. 'rotWithShape' => NULL
  64. ),
  65. $_glow_properties = array(
  66. 'size' => NULL,
  67. 'color' => array(
  68. 'type' => self::EXCEL_COLOR_TYPE_STANDARD,
  69. 'value' => 'black',
  70. 'alpha' => 40
  71. )
  72. ),
  73. $_soft_edges = array(
  74. 'size' => NULL
  75. );
  76. /**
  77. * Get Object State
  78. *
  79. * @return bool
  80. */
  81. public function getObjectState() {
  82. return $this->_object_state;
  83. }
  84. /**
  85. * Change Object State to True
  86. *
  87. * @return PHPExcel_Chart_GridLines
  88. */
  89. private function _activateObject() {
  90. $this->_object_state = TRUE;
  91. return $this;
  92. }
  93. /**
  94. * Set Line Color Properties
  95. *
  96. * @param string $value
  97. * @param int $alpha
  98. * @param string $type
  99. */
  100. public function setLineColorProperties($value, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_STANDARD) {
  101. $this
  102. ->_activateObject()
  103. ->_line_properties['color'] = $this->setColorProperties(
  104. $value,
  105. $alpha,
  106. $type);
  107. }
  108. /**
  109. * Set Line Color Properties
  110. *
  111. * @param float $line_width
  112. * @param string $compound_type
  113. * @param string $dash_type
  114. * @param string $cap_type
  115. * @param string $join_type
  116. * @param string $head_arrow_type
  117. * @param string $head_arrow_size
  118. * @param string $end_arrow_type
  119. * @param string $end_arrow_size
  120. */
  121. public function setLineStyleProperties($line_width = NULL, $compound_type = NULL, $dash_type = NULL, $cap_type = NULL, $join_type = NULL, $head_arrow_type = NULL, $head_arrow_size = NULL, $end_arrow_type = NULL, $end_arrow_size = NULL) {
  122. $this->_activateObject();
  123. (!is_null($line_width))
  124. ? $this->_line_properties['style']['width'] = $this->getExcelPointsWidth((float) $line_width)
  125. : NULL;
  126. (!is_null($compound_type))
  127. ? $this->_line_properties['style']['compound'] = (string) $compound_type
  128. : NULL;
  129. (!is_null($dash_type))
  130. ? $this->_line_properties['style']['dash'] = (string) $dash_type
  131. : NULL;
  132. (!is_null($cap_type))
  133. ? $this->_line_properties['style']['cap'] = (string) $cap_type
  134. : NULL;
  135. (!is_null($join_type))
  136. ? $this->_line_properties['style']['join'] = (string) $join_type
  137. : NULL;
  138. (!is_null($head_arrow_type))
  139. ? $this->_line_properties['style']['arrow']['head']['type'] = (string) $head_arrow_type
  140. : NULL;
  141. (!is_null($head_arrow_size))
  142. ? $this->_line_properties['style']['arrow']['head']['size'] = (string) $head_arrow_size
  143. : NULL;
  144. (!is_null($end_arrow_type))
  145. ? $this->_line_properties['style']['arrow']['end']['type'] = (string) $end_arrow_type
  146. : NULL;
  147. (!is_null($end_arrow_size))
  148. ? $this->_line_properties['style']['arrow']['end']['size'] = (string) $end_arrow_size
  149. : NULL;
  150. }
  151. /**
  152. * Get Line Color Property
  153. *
  154. * @param string $parameter
  155. *
  156. * @return string
  157. */
  158. public function getLineColorProperty($parameter) {
  159. return $this->_line_properties['color'][$parameter];
  160. }
  161. /**
  162. * Get Line Style Property
  163. *
  164. * @param array|string $elements
  165. *
  166. * @return string
  167. */
  168. public function getLineStyleProperty($elements) {
  169. return $this->getArrayElementsValue($this->_line_properties['style'], $elements);
  170. }
  171. /**
  172. * Set Glow Properties
  173. *
  174. * @param float $size
  175. * @param string $color_value
  176. * @param int $color_alpha
  177. * @param string $color_type
  178. *
  179. */
  180. public function setGlowProperties($size, $color_value = NULL, $color_alpha = NULL, $color_type = NULL) {
  181. $this
  182. ->_activateObject()
  183. ->_setGlowSize($size)
  184. ->_setGlowColor($color_value, $color_alpha, $color_type);
  185. }
  186. /**
  187. * Get Glow Color Property
  188. *
  189. * @param string $property
  190. *
  191. * @return string
  192. */
  193. public function getGlowColor($property) {
  194. return $this->_glow_properties['color'][$property];
  195. }
  196. /**
  197. * Get Glow Size
  198. *
  199. * @return string
  200. */
  201. public function getGlowSize() {
  202. return $this->_glow_properties['size'];
  203. }
  204. /**
  205. * Set Glow Size
  206. *
  207. * @param float $size
  208. *
  209. * @return PHPExcel_Chart_GridLines
  210. */
  211. private function _setGlowSize($size) {
  212. $this->_glow_properties['size'] = $this->getExcelPointsWidth((float) $size);
  213. return $this;
  214. }
  215. /**
  216. * Set Glow Color
  217. *
  218. * @param string $color
  219. * @param int $alpha
  220. * @param string $type
  221. *
  222. * @return PHPExcel_Chart_GridLines
  223. */
  224. private function _setGlowColor($color, $alpha, $type) {
  225. if (!is_null($color)) {
  226. $this->_glow_properties['color']['value'] = (string) $color;
  227. }
  228. if (!is_null($alpha)) {
  229. $this->_glow_properties['color']['alpha'] = $this->getTrueAlpha((int) $alpha);
  230. }
  231. if (!is_null($type)) {
  232. $this->_glow_properties['color']['type'] = (string) $type;
  233. }
  234. return $this;
  235. }
  236. /**
  237. * Get Line Style Arrow Parameters
  238. *
  239. * @param string $arrow_selector
  240. * @param string $property_selector
  241. *
  242. * @return string
  243. */
  244. public function getLineStyleArrowParameters($arrow_selector, $property_selector) {
  245. return $this->getLineStyleArrowSize($this->_line_properties['style']['arrow'][$arrow_selector]['size'], $property_selector);
  246. }
  247. /**
  248. * Set Shadow Properties
  249. *
  250. * @param int $sh_presets
  251. * @param string $sh_color_value
  252. * @param string $sh_color_type
  253. * @param int $sh_color_alpha
  254. * @param string $sh_blur
  255. * @param int $sh_angle
  256. * @param float $sh_distance
  257. *
  258. */
  259. public function setShadowProperties($sh_presets, $sh_color_value = NULL, $sh_color_type = NULL, $sh_color_alpha = NULL, $sh_blur = NULL, $sh_angle = NULL, $sh_distance = NULL) {
  260. $this
  261. ->_activateObject()
  262. ->_setShadowPresetsProperties((int) $sh_presets)
  263. ->_setShadowColor(
  264. is_null($sh_color_value) ? $this->_shadow_properties['color']['value'] : $sh_color_value
  265. , is_null($sh_color_alpha) ? (int) $this->_shadow_properties['color']['alpha']
  266. : $this->getTrueAlpha($sh_color_alpha)
  267. , is_null($sh_color_type) ? $this->_shadow_properties['color']['type'] : $sh_color_type)
  268. ->_setShadowBlur($sh_blur)
  269. ->_setShadowAngle($sh_angle)
  270. ->_setShadowDistance($sh_distance);
  271. }
  272. /**
  273. * Set Shadow Presets Properties
  274. *
  275. * @param int $shadow_presets
  276. *
  277. * @return PHPExcel_Chart_GridLines
  278. */
  279. private function _setShadowPresetsProperties($shadow_presets) {
  280. $this->_shadow_properties['presets'] = $shadow_presets;
  281. $this->_setShadowProperiesMapValues($this->getShadowPresetsMap($shadow_presets));
  282. return $this;
  283. }
  284. /**
  285. * Set Shadow Properties Values
  286. *
  287. * @param array $properties_map
  288. * @param * $reference
  289. *
  290. * @return PHPExcel_Chart_GridLines
  291. */
  292. private function _setShadowProperiesMapValues(array $properties_map, &$reference = NULL) {
  293. $base_reference = $reference;
  294. foreach ($properties_map as $property_key => $property_val) {
  295. if (is_array($property_val)) {
  296. if ($reference === NULL) {
  297. $reference = & $this->_shadow_properties[$property_key];
  298. } else {
  299. $reference = & $reference[$property_key];
  300. }
  301. $this->_setShadowProperiesMapValues($property_val, $reference);
  302. } else {
  303. if ($base_reference === NULL) {
  304. $this->_shadow_properties[$property_key] = $property_val;
  305. } else {
  306. $reference[$property_key] = $property_val;
  307. }
  308. }
  309. }
  310. return $this;
  311. }
  312. /**
  313. * Set Shadow Color
  314. *
  315. * @param string $color
  316. * @param int $alpha
  317. * @param string $type
  318. *
  319. * @return PHPExcel_Chart_GridLines
  320. */
  321. private function _setShadowColor($color, $alpha, $type) {
  322. if (!is_null($color)) {
  323. $this->_shadow_properties['color']['value'] = (string) $color;
  324. }
  325. if (!is_null($alpha)) {
  326. $this->_shadow_properties['color']['alpha'] = $this->getTrueAlpha((int) $alpha);
  327. }
  328. if (!is_null($type)) {
  329. $this->_shadow_properties['color']['type'] = (string) $type;
  330. }
  331. return $this;
  332. }
  333. /**
  334. * Set Shadow Blur
  335. *
  336. * @param float $blur
  337. *
  338. * @return PHPExcel_Chart_GridLines
  339. */
  340. private function _setShadowBlur($blur) {
  341. if ($blur !== NULL) {
  342. $this->_shadow_properties['blur'] = (string) $this->getExcelPointsWidth($blur);
  343. }
  344. return $this;
  345. }
  346. /**
  347. * Set Shadow Angle
  348. *
  349. * @param int $angle
  350. *
  351. * @return PHPExcel_Chart_GridLines
  352. */
  353. private function _setShadowAngle($angle) {
  354. if ($angle !== NULL) {
  355. $this->_shadow_properties['direction'] = (string) $this->getExcelPointsAngle($angle);
  356. }
  357. return $this;
  358. }
  359. /**
  360. * Set Shadow Distance
  361. *
  362. * @param float $distance
  363. *
  364. * @return PHPExcel_Chart_GridLines
  365. */
  366. private function _setShadowDistance($distance) {
  367. if ($distance !== NULL) {
  368. $this->_shadow_properties['distance'] = (string) $this->getExcelPointsWidth($distance);
  369. }
  370. return $this;
  371. }
  372. /**
  373. * Get Shadow Property
  374. *
  375. * @param string $elements
  376. * @param array $elements
  377. *
  378. * @return string
  379. */
  380. public function getShadowProperty($elements) {
  381. return $this->getArrayElementsValue($this->_shadow_properties, $elements);
  382. }
  383. /**
  384. * Set Soft Edges Size
  385. *
  386. * @param float $size
  387. */
  388. public function setSoftEdgesSize($size) {
  389. if (!is_null($size)) {
  390. $this->_activateObject();
  391. $_soft_edges['size'] = (string) $this->getExcelPointsWidth($size);
  392. }
  393. }
  394. /**
  395. * Get Soft Edges Size
  396. *
  397. * @return string
  398. */
  399. public function getSoftEdgesSize() {
  400. return $this->_soft_edges['size'];
  401. }
  402. }