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