Axis.php 16 KB

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