ba238a05fc997f11bd4c4051c0f225d72a4bac53.svn-base 14 KB

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