GridLines.php 13 KB

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