GridLines.php 13 KB

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