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