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

/lib/phpexcel/PHPExcel/Chart/Axis.php

https://bitbucket.org/moodle/moodle
PHP | 561 lines | 256 code | 45 blank | 260 comment | 11 complexity | ff305dfd65347db78d8cbac1f9ef0167 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Wiktor Trzonkowski
  5. * Date: 6/17/14
  6. * Time: 12:11 PM
  7. */
  8. class PHPExcel_Chart_Axis extends PHPExcel_Chart_Properties
  9. {
  10. /**
  11. * Axis Number
  12. *
  13. * @var array of mixed
  14. */
  15. private $axisNumber = array(
  16. 'format' => self::FORMAT_CODE_GENERAL,
  17. 'source_linked' => 1
  18. );
  19. /**
  20. * Axis Options
  21. *
  22. * @var array of mixed
  23. */
  24. private $axisOptions = array(
  25. 'minimum' => null,
  26. 'maximum' => null,
  27. 'major_unit' => null,
  28. 'minor_unit' => null,
  29. 'orientation' => self::ORIENTATION_NORMAL,
  30. 'minor_tick_mark' => self::TICK_MARK_NONE,
  31. 'major_tick_mark' => self::TICK_MARK_NONE,
  32. 'axis_labels' => self::AXIS_LABELS_NEXT_TO,
  33. 'horizontal_crosses' => self::HORIZONTAL_CROSSES_AUTOZERO,
  34. 'horizontal_crosses_value' => null
  35. );
  36. /**
  37. * Fill Properties
  38. *
  39. * @var array of mixed
  40. */
  41. private $fillProperties = array(
  42. 'type' => self::EXCEL_COLOR_TYPE_ARGB,
  43. 'value' => null,
  44. 'alpha' => 0
  45. );
  46. /**
  47. * Line Properties
  48. *
  49. * @var array of mixed
  50. */
  51. private $lineProperties = array(
  52. 'type' => self::EXCEL_COLOR_TYPE_ARGB,
  53. 'value' => null,
  54. 'alpha' => 0
  55. );
  56. /**
  57. * Line Style Properties
  58. *
  59. * @var array of mixed
  60. */
  61. private $lineStyleProperties = array(
  62. 'width' => '9525',
  63. 'compound' => self::LINE_STYLE_COMPOUND_SIMPLE,
  64. 'dash' => self::LINE_STYLE_DASH_SOLID,
  65. 'cap' => self::LINE_STYLE_CAP_FLAT,
  66. 'join' => self::LINE_STYLE_JOIN_BEVEL,
  67. 'arrow' => array(
  68. 'head' => array(
  69. 'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW,
  70. 'size' => self::LINE_STYLE_ARROW_SIZE_5
  71. ),
  72. 'end' => array(
  73. 'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW,
  74. 'size' => self::LINE_STYLE_ARROW_SIZE_8
  75. ),
  76. )
  77. );
  78. /**
  79. * Shadow Properties
  80. *
  81. * @var array of mixed
  82. */
  83. private $shadowProperties = array(
  84. 'presets' => self::SHADOW_PRESETS_NOSHADOW,
  85. 'effect' => null,
  86. 'color' => array(
  87. 'type' => self::EXCEL_COLOR_TYPE_STANDARD,
  88. 'value' => 'black',
  89. 'alpha' => 40,
  90. ),
  91. 'size' => array(
  92. 'sx' => null,
  93. 'sy' => null,
  94. 'kx' => null
  95. ),
  96. 'blur' => null,
  97. 'direction' => null,
  98. 'distance' => null,
  99. 'algn' => null,
  100. 'rotWithShape' => null
  101. );
  102. /**
  103. * Glow Properties
  104. *
  105. * @var array of mixed
  106. */
  107. private $glowProperties = array(
  108. 'size' => null,
  109. 'color' => array(
  110. 'type' => self::EXCEL_COLOR_TYPE_STANDARD,
  111. 'value' => 'black',
  112. 'alpha' => 40
  113. )
  114. );
  115. /**
  116. * Soft Edge Properties
  117. *
  118. * @var array of mixed
  119. */
  120. private $softEdges = array(
  121. 'size' => null
  122. );
  123. /**
  124. * Get Series Data Type
  125. *
  126. * @return string
  127. */
  128. public function setAxisNumberProperties($format_code)
  129. {
  130. $this->axisNumber['format'] = (string) $format_code;
  131. $this->axisNumber['source_linked'] = 0;
  132. }
  133. /**
  134. * Get Axis Number Format Data Type
  135. *
  136. * @return string
  137. */
  138. public function getAxisNumberFormat()
  139. {
  140. return $this->axisNumber['format'];
  141. }
  142. /**
  143. * Get Axis Number Source Linked
  144. *
  145. * @return string
  146. */
  147. public function getAxisNumberSourceLinked()
  148. {
  149. return (string) $this->axisNumber['source_linked'];
  150. }
  151. /**
  152. * Set Axis Options Properties
  153. *
  154. * @param string $axis_labels
  155. * @param string $horizontal_crosses_value
  156. * @param string $horizontal_crosses
  157. * @param string $axis_orientation
  158. * @param string $major_tmt
  159. * @param string $minor_tmt
  160. * @param string $minimum
  161. * @param string $maximum
  162. * @param string $major_unit
  163. * @param string $minor_unit
  164. *
  165. */
  166. public function setAxisOptionsProperties($axis_labels, $horizontal_crosses_value = null, $horizontal_crosses = null, $axis_orientation = null, $major_tmt = null, $minor_tmt = null, $minimum = null, $maximum = null, $major_unit = null, $minor_unit = null)
  167. {
  168. $this->axisOptions['axis_labels'] = (string) $axis_labels;
  169. ($horizontal_crosses_value !== null) ? $this->axisOptions['horizontal_crosses_value'] = (string) $horizontal_crosses_value : null;
  170. ($horizontal_crosses !== null) ? $this->axisOptions['horizontal_crosses'] = (string) $horizontal_crosses : null;
  171. ($axis_orientation !== null) ? $this->axisOptions['orientation'] = (string) $axis_orientation : null;
  172. ($major_tmt !== null) ? $this->axisOptions['major_tick_mark'] = (string) $major_tmt : null;
  173. ($minor_tmt !== null) ? $this->axisOptions['minor_tick_mark'] = (string) $minor_tmt : null;
  174. ($minor_tmt !== null) ? $this->axisOptions['minor_tick_mark'] = (string) $minor_tmt : null;
  175. ($minimum !== null) ? $this->axisOptions['minimum'] = (string) $minimum : null;
  176. ($maximum !== null) ? $this->axisOptions['maximum'] = (string) $maximum : null;
  177. ($major_unit !== null) ? $this->axisOptions['major_unit'] = (string) $major_unit : null;
  178. ($minor_unit !== null) ? $this->axisOptions['minor_unit'] = (string) $minor_unit : null;
  179. }
  180. /**
  181. * Get Axis Options Property
  182. *
  183. * @param string $property
  184. *
  185. * @return string
  186. */
  187. public function getAxisOptionsProperty($property)
  188. {
  189. return $this->axisOptions[$property];
  190. }
  191. /**
  192. * Set Axis Orientation Property
  193. *
  194. * @param string $orientation
  195. *
  196. */
  197. public function setAxisOrientation($orientation)
  198. {
  199. $this->orientation = (string) $orientation;
  200. }
  201. /**
  202. * Set Fill Property
  203. *
  204. * @param string $color
  205. * @param int $alpha
  206. * @param string $type
  207. *
  208. */
  209. public function setFillParameters($color, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_ARGB)
  210. {
  211. $this->fillProperties = $this->setColorProperties($color, $alpha, $type);
  212. }
  213. /**
  214. * Set Line Property
  215. *
  216. * @param string $color
  217. * @param int $alpha
  218. * @param string $type
  219. *
  220. */
  221. public function setLineParameters($color, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_ARGB)
  222. {
  223. $this->lineProperties = $this->setColorProperties($color, $alpha, $type);
  224. }
  225. /**
  226. * Get Fill Property
  227. *
  228. * @param string $property
  229. *
  230. * @return string
  231. */
  232. public function getFillProperty($property)
  233. {
  234. return $this->fillProperties[$property];
  235. }
  236. /**
  237. * Get Line Property
  238. *
  239. * @param string $property
  240. *
  241. * @return string
  242. */
  243. public function getLineProperty($property)
  244. {
  245. return $this->lineProperties[$property];
  246. }
  247. /**
  248. * Set Line Style Properties
  249. *
  250. * @param float $line_width
  251. * @param string $compound_type
  252. * @param string $dash_type
  253. * @param string $cap_type
  254. * @param string $join_type
  255. * @param string $head_arrow_type
  256. * @param string $head_arrow_size
  257. * @param string $end_arrow_type
  258. * @param string $end_arrow_size
  259. *
  260. */
  261. 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)
  262. {
  263. (!is_null($line_width)) ? $this->lineStyleProperties['width'] = $this->getExcelPointsWidth((float) $line_width) : null;
  264. (!is_null($compound_type)) ? $this->lineStyleProperties['compound'] = (string) $compound_type : null;
  265. (!is_null($dash_type)) ? $this->lineStyleProperties['dash'] = (string) $dash_type : null;
  266. (!is_null($cap_type)) ? $this->lineStyleProperties['cap'] = (string) $cap_type : null;
  267. (!is_null($join_type)) ? $this->lineStyleProperties['join'] = (string) $join_type : null;
  268. (!is_null($head_arrow_type)) ? $this->lineStyleProperties['arrow']['head']['type'] = (string) $head_arrow_type : null;
  269. (!is_null($head_arrow_size)) ? $this->lineStyleProperties['arrow']['head']['size'] = (string) $head_arrow_size : null;
  270. (!is_null($end_arrow_type)) ? $this->lineStyleProperties['arrow']['end']['type'] = (string) $end_arrow_type : null;
  271. (!is_null($end_arrow_size)) ? $this->lineStyleProperties['arrow']['end']['size'] = (string) $end_arrow_size : null;
  272. }
  273. /**
  274. * Get Line Style Property
  275. *
  276. * @param array|string $elements
  277. *
  278. * @return string
  279. */
  280. public function getLineStyleProperty($elements)
  281. {
  282. return $this->getArrayElementsValue($this->lineStyleProperties, $elements);
  283. }
  284. /**
  285. * Get Line Style Arrow Excel Width
  286. *
  287. * @param string $arrow
  288. *
  289. * @return string
  290. */
  291. public function getLineStyleArrowWidth($arrow)
  292. {
  293. return $this->getLineStyleArrowSize($this->lineStyleProperties['arrow'][$arrow]['size'], 'w');
  294. }
  295. /**
  296. * Get Line Style Arrow Excel Length
  297. *
  298. * @param string $arrow
  299. *
  300. * @return string
  301. */
  302. public function getLineStyleArrowLength($arrow)
  303. {
  304. return $this->getLineStyleArrowSize($this->lineStyleProperties['arrow'][$arrow]['size'], 'len');
  305. }
  306. /**
  307. * Set Shadow Properties
  308. *
  309. * @param int $shadow_presets
  310. * @param string $sh_color_value
  311. * @param string $sh_color_type
  312. * @param string $sh_color_alpha
  313. * @param float $sh_blur
  314. * @param int $sh_angle
  315. * @param float $sh_distance
  316. *
  317. */
  318. 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)
  319. {
  320. $this->setShadowPresetsProperties((int) $sh_presets)
  321. ->setShadowColor(
  322. is_null($sh_color_value) ? $this->shadowProperties['color']['value'] : $sh_color_value,
  323. is_null($sh_color_alpha) ? (int) $this->shadowProperties['color']['alpha'] : $sh_color_alpha,
  324. is_null($sh_color_type) ? $this->shadowProperties['color']['type'] : $sh_color_type
  325. )
  326. ->setShadowBlur($sh_blur)
  327. ->setShadowAngle($sh_angle)
  328. ->setShadowDistance($sh_distance);
  329. }
  330. /**
  331. * Set Shadow Color
  332. *
  333. * @param int $shadow_presets
  334. *
  335. * @return PHPExcel_Chart_Axis
  336. */
  337. private function setShadowPresetsProperties($shadow_presets)
  338. {
  339. $this->shadowProperties['presets'] = $shadow_presets;
  340. $this->setShadowProperiesMapValues($this->getShadowPresetsMap($shadow_presets));
  341. return $this;
  342. }
  343. /**
  344. * Set Shadow Properties from Maped Values
  345. *
  346. * @param array $properties_map
  347. * @param * $reference
  348. *
  349. * @return PHPExcel_Chart_Axis
  350. */
  351. private function setShadowProperiesMapValues(array $properties_map, &$reference = null)
  352. {
  353. $base_reference = $reference;
  354. foreach ($properties_map as $property_key => $property_val) {
  355. if (is_array($property_val)) {
  356. if ($reference === null) {
  357. $reference = & $this->shadowProperties[$property_key];
  358. } else {
  359. $reference = & $reference[$property_key];
  360. }
  361. $this->setShadowProperiesMapValues($property_val, $reference);
  362. } else {
  363. if ($base_reference === null) {
  364. $this->shadowProperties[$property_key] = $property_val;
  365. } else {
  366. $reference[$property_key] = $property_val;
  367. }
  368. }
  369. }
  370. return $this;
  371. }
  372. /**
  373. * Set Shadow Color
  374. *
  375. * @param string $color
  376. * @param int $alpha
  377. * @param string $type
  378. *
  379. * @return PHPExcel_Chart_Axis
  380. */
  381. private function setShadowColor($color, $alpha, $type)
  382. {
  383. $this->shadowProperties['color'] = $this->setColorProperties($color, $alpha, $type);
  384. return $this;
  385. }
  386. /**
  387. * Set Shadow Blur
  388. *
  389. * @param float $blur
  390. *
  391. * @return PHPExcel_Chart_Axis
  392. */
  393. private function setShadowBlur($blur)
  394. {
  395. if ($blur !== null) {
  396. $this->shadowProperties['blur'] = (string) $this->getExcelPointsWidth($blur);
  397. }
  398. return $this;
  399. }
  400. /**
  401. * Set Shadow Angle
  402. *
  403. * @param int $angle
  404. *
  405. * @return PHPExcel_Chart_Axis
  406. */
  407. private function setShadowAngle($angle)
  408. {
  409. if ($angle !== null) {
  410. $this->shadowProperties['direction'] = (string) $this->getExcelPointsAngle($angle);
  411. }
  412. return $this;
  413. }
  414. /**
  415. * Set Shadow Distance
  416. *
  417. * @param float $distance
  418. *
  419. * @return PHPExcel_Chart_Axis
  420. */
  421. private function setShadowDistance($distance)
  422. {
  423. if ($distance !== null) {
  424. $this->shadowProperties['distance'] = (string) $this->getExcelPointsWidth($distance);
  425. }
  426. return $this;
  427. }
  428. /**
  429. * Get Glow Property
  430. *
  431. * @param float $size
  432. * @param string $color_value
  433. * @param int $color_alpha
  434. * @param string $color_type
  435. */
  436. public function getShadowProperty($elements)
  437. {
  438. return $this->getArrayElementsValue($this->shadowProperties, $elements);
  439. }
  440. /**
  441. * Set Glow Properties
  442. *
  443. * @param float $size
  444. * @param string $color_value
  445. * @param int $color_alpha
  446. * @param string $color_type
  447. */
  448. public function setGlowProperties($size, $color_value = null, $color_alpha = null, $color_type = null)
  449. {
  450. $this->setGlowSize($size)
  451. ->setGlowColor(
  452. is_null($color_value) ? $this->glowProperties['color']['value'] : $color_value,
  453. is_null($color_alpha) ? (int) $this->glowProperties['color']['alpha'] : $color_alpha,
  454. is_null($color_type) ? $this->glowProperties['color']['type'] : $color_type
  455. );
  456. }
  457. /**
  458. * Get Glow Property
  459. *
  460. * @param array|string $property
  461. *
  462. * @return string
  463. */
  464. public function getGlowProperty($property)
  465. {
  466. return $this->getArrayElementsValue($this->glowProperties, $property);
  467. }
  468. /**
  469. * Set Glow Color
  470. *
  471. * @param float $size
  472. *
  473. * @return PHPExcel_Chart_Axis
  474. */
  475. private function setGlowSize($size)
  476. {
  477. if (!is_null($size)) {
  478. $this->glowProperties['size'] = $this->getExcelPointsWidth($size);
  479. }
  480. return $this;
  481. }
  482. /**
  483. * Set Glow Color
  484. *
  485. * @param string $color
  486. * @param int $alpha
  487. * @param string $type
  488. *
  489. * @return PHPExcel_Chart_Axis
  490. */
  491. private function setGlowColor($color, $alpha, $type)
  492. {
  493. $this->glowProperties['color'] = $this->setColorProperties($color, $alpha, $type);
  494. return $this;
  495. }
  496. /**
  497. * Set Soft Edges Size
  498. *
  499. * @param float $size
  500. */
  501. public function setSoftEdges($size)
  502. {
  503. if (!is_null($size)) {
  504. $softEdges['size'] = (string) $this->getExcelPointsWidth($size);
  505. }
  506. }
  507. /**
  508. * Get Soft Edges Size
  509. *
  510. * @return string
  511. */
  512. public function getSoftEdgesSize()
  513. {
  514. return $this->softEdges['size'];
  515. }
  516. }