<?php
namespace PhpOffice\PhpSpreadsheet\Chart;
/**
* Created by PhpStorm.
* User: Wiktor Trzonkowski
* Date: 6/17/14
* Time: 12:11 PM.
*/
class Axis extends Properties
{
> const AXIS_TYPE_CATEGORY = 'catAx';
/**
> const AXIS_TYPE_DATE = 'dateAx';
* Axis Number.
> const AXIS_TYPE_VALUE = 'valAx';
*
>
* @var array of mixed
> const TIME_UNIT_DAYS = 'days';
*/
> const TIME_UNIT_MONTHS = 'months';
private $axisNumber = [
> const TIME_UNIT_YEARS = 'years';
'format' => self::FORMAT_CODE_GENERAL,
>
'source_linked' => 1,
> public function __construct()
];
> {
> parent::__construct();
/**
> $this->fillColor = new ChartColor();
* Axis Options.
> }
*
>
* @var array of mixed
> /**
*/
> * Chart Major Gridlines as.
private $axisOptions = [
> *
'minimum' => null,
> * @var ?GridLines
'maximum' => null,
> */
'major_unit' => null,
> private $majorGridlines;
'minor_unit' => null,
>
'orientation' => self::ORIENTATION_NORMAL,
> /**
'minor_tick_mark' => self::TICK_MARK_NONE,
> * Chart Minor Gridlines as.
'major_tick_mark' => self::TICK_MARK_NONE,
> *
'axis_labels' => self::AXIS_LABELS_NEXT_TO,
> * @var ?GridLines
'horizontal_crosses' => self::HORIZONTAL_CROSSES_AUTOZERO,
> */
'horizontal_crosses_value' => null,
> private $minorGridlines;
];
>
< * @var array of mixed
> * @var mixed[]
/**
> 'numeric' => null,
* Fill Properties.
> /** @var string */
*
> private $axisType = '';
* @var array of mixed
>
< * @var array of mixed
> * @var mixed[]
private $fillProperties = [
> 'textRotation' => null,
'type' => self::EXCEL_COLOR_TYPE_ARGB,
> 'hidden' => null,
'value' => null,
> 'majorTimeUnit' => self::TIME_UNIT_YEARS,
'alpha' => 0,
> 'minorTimeUnit' => self::TIME_UNIT_MONTHS,
];
> 'baseTimeUnit' => self::TIME_UNIT_DAYS,
< * @var array of mixed
< */
< private $fillProperties = [
< 'type' => self::EXCEL_COLOR_TYPE_ARGB,
< 'value' => null,
< 'alpha' => 0,
< ];
<
< /**
< * Line Properties.
< *
< * @var array of mixed
> * @var ChartColor
< private $lineProperties = [
< 'type' => self::EXCEL_COLOR_TYPE_ARGB,
< 'value' => null,
< 'alpha' => 0,
< ];
> private $fillColor;
< /**
< * Line Style Properties.
< *
< * @var array of mixed
< */
< private $lineStyleProperties = [
< 'width' => '9525',
< 'compound' => self::LINE_STYLE_COMPOUND_SIMPLE,
< 'dash' => self::LINE_STYLE_DASH_SOLID,
< 'cap' => self::LINE_STYLE_CAP_FLAT,
< 'join' => self::LINE_STYLE_JOIN_BEVEL,
< 'arrow' => [
< 'head' => [
< 'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW,
< 'size' => self::LINE_STYLE_ARROW_SIZE_5,
< ],
< 'end' => [
< 'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW,
< 'size' => self::LINE_STYLE_ARROW_SIZE_8,
< ],
< ],
< ];
<
< /**
< * Shadow Properties.
< *
< * @var array of mixed
< */
< private $shadowProperties = [
< 'presets' => self::SHADOW_PRESETS_NOSHADOW,
< 'effect' => null,
< 'color' => [
< 'type' => self::EXCEL_COLOR_TYPE_STANDARD,
< 'value' => 'black',
< 'alpha' => 40,
< ],
< 'size' => [
< 'sx' => null,
< 'sy' => null,
< 'kx' => null,
< ],
< 'blur' => null,
< 'direction' => null,
< 'distance' => null,
< 'algn' => null,
< 'rotWithShape' => null,
< ];
<
< /**
< * Glow Properties.
< *
< * @var array of mixed
< */
< private $glowProperties = [
< 'size' => null,
< 'color' => [
< 'type' => self::EXCEL_COLOR_TYPE_STANDARD,
< 'value' => 'black',
< 'alpha' => 40,
< ],
< ];
<
< /**
< * Soft Edge Properties.
< *
< * @var array of mixed
< */
< private $softEdges = [
< 'size' => null,
> private const NUMERIC_FORMAT = [
> Properties::FORMAT_CODE_NUMBER,
> Properties::FORMAT_CODE_DATE,
> Properties::FORMAT_CODE_DATE_ISO8601,
* @param mixed $format_code
< *
< * @return string
*/
< public function setAxisNumberProperties($format_code)
> public function setAxisNumberProperties($format_code, ?bool $numeric = null, int $sourceLinked = 0): void
{
< $this->axisNumber['format'] = (string) $format_code;
< $this->axisNumber['source_linked'] = 0;
> $format = (string) $format_code;
> $this->axisNumber['format'] = $format;
> $this->axisNumber['source_linked'] = $sourceLinked;
> if (is_bool($numeric)) {
> $this->axisNumber['numeric'] = $numeric;
> } elseif (in_array($format, self::NUMERIC_FORMAT, true)) {
> $this->axisNumber['numeric'] = true;
> }
}
/**
* Get Axis Number Format Data Type.
*
* @return string
*/
public function getAxisNumberFormat()
{
return $this->axisNumber['format'];
}
/**
* Get Axis Number Source Linked.
*
* @return string
*/
public function getAxisNumberSourceLinked()
{
return (string) $this->axisNumber['source_linked'];
}
> public function getAxisIsNumericFormat(): bool
/**
> {
* Set Axis Options Properties.
> return $this->axisType === self::AXIS_TYPE_DATE || (bool) $this->axisNumber['numeric'];
*
> }
* @param string $axis_labels
>
* @param string $horizontal_crosses_value
> public function setAxisOption(string $key, ?string $value): void
* @param string $horizontal_crosses
> {
* @param string $axis_orientation
> if ($value !== null && $value !== '') {
* @param string $major_tmt
> $this->axisOptions[$key] = $value;
* @param string $minor_tmt
> }
* @param string $minimum
> }
* @param string $maximum
>
< *
< * @param string $axis_labels
< * @param string $horizontal_crosses_value
< * @param string $horizontal_crosses
< * @param string $axis_orientation
< * @param string $major_tmt
< * @param string $minor_tmt
< * @param string $minimum
< * @param string $maximum
< * @param string $major_unit
< * @param string $minor_unit
< */
< 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): void
< {
< $this->axisOptions['axis_labels'] = (string) $axis_labels;
< ($horizontal_crosses_value !== null) ? $this->axisOptions['horizontal_crosses_value'] = (string) $horizontal_crosses_value : null;
< ($horizontal_crosses !== null) ? $this->axisOptions['horizontal_crosses'] = (string) $horizontal_crosses : null;
< ($axis_orientation !== null) ? $this->axisOptions['orientation'] = (string) $axis_orientation : null;
< ($major_tmt !== null) ? $this->axisOptions['major_tick_mark'] = (string) $major_tmt : null;
< ($minor_tmt !== null) ? $this->axisOptions['minor_tick_mark'] = (string) $minor_tmt : null;
< ($minor_tmt !== null) ? $this->axisOptions['minor_tick_mark'] = (string) $minor_tmt : null;
< ($minimum !== null) ? $this->axisOptions['minimum'] = (string) $minimum : null;
< ($maximum !== null) ? $this->axisOptions['maximum'] = (string) $maximum : null;
< ($major_unit !== null) ? $this->axisOptions['major_unit'] = (string) $major_unit : null;
< ($minor_unit !== null) ? $this->axisOptions['minor_unit'] = (string) $minor_unit : null;
> */
> public function setAxisOptionsProperties(
> string $axisLabels,
> ?string $horizontalCrossesValue = null,
> ?string $horizontalCrosses = null,
> ?string $axisOrientation = null,
> ?string $majorTmt = null,
> ?string $minorTmt = null,
> ?string $minimum = null,
> ?string $maximum = null,
> ?string $majorUnit = null,
> ?string $minorUnit = null,
> ?string $textRotation = null,
> ?string $hidden = null,
> ?string $baseTimeUnit = null,
> ?string $majorTimeUnit = null,
> ?string $minorTimeUnit = null
> ): void {
> $this->axisOptions['axis_labels'] = $axisLabels;
> $this->setAxisOption('horizontal_crosses_value', $horizontalCrossesValue);
> $this->setAxisOption('horizontal_crosses', $horizontalCrosses);
> $this->setAxisOption('orientation', $axisOrientation);
> $this->setAxisOption('major_tick_mark', $majorTmt);
> $this->setAxisOption('minor_tick_mark', $minorTmt);
> $this->setAxisOption('minimum', $minimum);
> $this->setAxisOption('maximum', $maximum);
> $this->setAxisOption('major_unit', $majorUnit);
> $this->setAxisOption('minor_unit', $minorUnit);
> $this->setAxisOption('textRotation', $textRotation);
> $this->setAxisOption('hidden', $hidden);
> $this->setAxisOption('baseTimeUnit', $baseTimeUnit);
> $this->setAxisOption('majorTimeUnit', $majorTimeUnit);
> $this->setAxisOption('minorTimeUnit', $minorTimeUnit);
< * @return string
> * @return ?string
{
return $this->axisOptions[$property];
}
/**
* Set Axis Orientation Property.
*
* @param string $orientation
*/
public function setAxisOrientation($orientation): void
{
$this->axisOptions['orientation'] = (string) $orientation;
}
< /**
< * Set Fill Property.
< *
< * @param string $color
< * @param int $alpha
< * @param string $type
< */
< public function setFillParameters($color, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_ARGB): void
< {
< $this->fillProperties = $this->setColorProperties($color, $alpha, $type);
< }
<
< /**
< * Set Line Property.
< *
< * @param string $color
< * @param int $alpha
< * @param string $type
< */
< public function setLineParameters($color, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_ARGB): void
< {
< $this->lineProperties = $this->setColorProperties($color, $alpha, $type);
< }
<
< /**
< * Get Fill Property.
< *
< * @param string $property
< *
< * @return string
< */
< public function getFillProperty($property)
< {
< return $this->fillProperties[$property];
< }
<
< /**
< * Get Line Property.
< *
< * @param string $property
< *
< * @return string
< */
< public function getLineProperty($property)
> public function getAxisType(): string
{
< return $this->lineProperties[$property];
> return $this->axisType;
}
< /**
< * Set Line Style Properties.
< *
< * @param float $line_width
< * @param string $compound_type
< * @param string $dash_type
< * @param string $cap_type
< * @param string $join_type
< * @param string $head_arrow_type
< * @param string $head_arrow_size
< * @param string $end_arrow_type
< * @param string $end_arrow_size
< */
< 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): void
> public function setAxisType(string $type): self
{
< ($line_width !== null) ? $this->lineStyleProperties['width'] = $this->getExcelPointsWidth((float) $line_width) : null;
< ($compound_type !== null) ? $this->lineStyleProperties['compound'] = (string) $compound_type : null;
< ($dash_type !== null) ? $this->lineStyleProperties['dash'] = (string) $dash_type : null;
< ($cap_type !== null) ? $this->lineStyleProperties['cap'] = (string) $cap_type : null;
< ($join_type !== null) ? $this->lineStyleProperties['join'] = (string) $join_type : null;
< ($head_arrow_type !== null) ? $this->lineStyleProperties['arrow']['head']['type'] = (string) $head_arrow_type : null;
< ($head_arrow_size !== null) ? $this->lineStyleProperties['arrow']['head']['size'] = (string) $head_arrow_size : null;
< ($end_arrow_type !== null) ? $this->lineStyleProperties['arrow']['end']['type'] = (string) $end_arrow_type : null;
< ($end_arrow_size !== null) ? $this->lineStyleProperties['arrow']['end']['size'] = (string) $end_arrow_size : null;
> if ($type === self::AXIS_TYPE_CATEGORY || $type === self::AXIS_TYPE_VALUE || $type === self::AXIS_TYPE_DATE) {
> $this->axisType = $type;
> } else {
> $this->axisType = '';
}
< /**
< * Get Line Style Property.
< *
< * @param array|string $elements
< *
< * @return string
< */
< public function getLineStyleProperty($elements)
< {
< return $this->getArrayElementsValue($this->lineStyleProperties, $elements);
> return $this;
}
/**
< * Get Line Style Arrow Excel Width.
< *
< * @param string $arrow
> * Set Fill Property.
*
< * @return string
> * @param ?string $color
> * @param ?int $alpha
> * @param ?string $AlphaType
*/
< public function getLineStyleArrowWidth($arrow)
> public function setFillParameters($color, $alpha = null, $AlphaType = ChartColor::EXCEL_COLOR_TYPE_RGB): void
{
< return $this->getLineStyleArrowSize($this->lineStyleProperties['arrow'][$arrow]['size'], 'w');
> $this->fillColor->setColorProperties($color, $alpha, $AlphaType);
}
/**
< * Get Line Style Arrow Excel Length.
> * Get Fill Property.
*
< * @param string $arrow
> * @param string $property
*
* @return string
*/
< public function getLineStyleArrowLength($arrow)
> public function getFillProperty($property)
{
< return $this->getLineStyleArrowSize($this->lineStyleProperties['arrow'][$arrow]['size'], 'len');
> return (string) $this->fillColor->getColorProperty($property);
}
< /**
< * Set Shadow Properties.
< *
< * @param int $sh_presets
< * @param string $sh_color_value
< * @param string $sh_color_type
< * @param string $sh_color_alpha
< * @param float $sh_blur
< * @param int $sh_angle
< * @param float $sh_distance
< */
< 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): void
> public function getFillColorObject(): ChartColor
{
< $this->setShadowPresetsProperties((int) $sh_presets)
< ->setShadowColor(
< $sh_color_value === null ? $this->shadowProperties['color']['value'] : $sh_color_value,
< $sh_color_alpha === null ? (int) $this->shadowProperties['color']['alpha'] : $sh_color_alpha,
< $sh_color_type === null ? $this->shadowProperties['color']['type'] : $sh_color_type
< )
< ->setShadowBlur($sh_blur)
< ->setShadowAngle($sh_angle)
< ->setShadowDistance($sh_distance);
> return $this->fillColor;
}
/**
< * Set Shadow Color.
< *
< * @param int $shadow_presets
> * Get Line Color Property.
*
< * @return $this
< */
< private function setShadowPresetsProperties($shadow_presets)
< {
< $this->shadowProperties['presets'] = $shadow_presets;
< $this->setShadowProperiesMapValues($this->getShadowPresetsMap($shadow_presets));
<
< return $this;
< }
<
< /**
< * Set Shadow Properties from Mapped Values.
> * @deprecated 1.24.0
> * Use the getLineColor property in the Properties class instead
> * @see Properties::getLineColorProperty()
*
< * @param mixed &$reference
> * @param string $propertyName
*
< * @return $this
> * @return null|int|string
*/
< private function setShadowProperiesMapValues(array $properties_map, &$reference = null)
> public function getLineProperty($propertyName)
{
< $base_reference = $reference;
< foreach ($properties_map as $property_key => $property_val) {
< if (is_array($property_val)) {
< if ($reference === null) {
< $reference = &$this->shadowProperties[$property_key];
< } else {
< $reference = &$reference[$property_key];
< }
< $this->setShadowProperiesMapValues($property_val, $reference);
< } else {
< if ($base_reference === null) {
< $this->shadowProperties[$property_key] = $property_val;
< } else {
< $reference[$property_key] = $property_val;
< }
< }
> return $this->getLineColorProperty($propertyName);
}
< return $this;
< }
> /** @var string */
> private $crossBetween = ''; // 'between' or 'midCat' might be better
< /**
< * Set Shadow Color.
< *
< * @param string $color
< * @param int $alpha
< * @param string $type
< *
< * @return $this
< */
< private function setShadowColor($color, $alpha, $type)
> public function setCrossBetween(string $crossBetween): self
{
< $this->shadowProperties['color'] = $this->setColorProperties($color, $alpha, $type);
> $this->crossBetween = $crossBetween;
return $this;
}
< /**
< * Set Shadow Blur.
< *
< * @param float $blur
< *
< * @return $this
< */
< private function setShadowBlur($blur)
> public function getCrossBetween(): string
{
< if ($blur !== null) {
< $this->shadowProperties['blur'] = (string) $this->getExcelPointsWidth($blur);
< }
<
< return $this;
> return $this->crossBetween;
}
< /**
< * Set Shadow Angle.
< *
< * @param int $angle
< *
< * @return $this
< */
< private function setShadowAngle($angle)
> public function getMajorGridlines(): ?GridLines
{
< if ($angle !== null) {
< $this->shadowProperties['direction'] = (string) $this->getExcelPointsAngle($angle);
< }
<
< return $this;
> return $this->majorGridlines;
}
< /**
< * Set Shadow Distance.
< *
< * @param float $distance
< *
< * @return $this
< */
< private function setShadowDistance($distance)
> public function getMinorGridlines(): ?GridLines
{
< if ($distance !== null) {
< $this->shadowProperties['distance'] = (string) $this->getExcelPointsWidth($distance);
> return $this->minorGridlines;
}
< return $this;
< }
<
< /**
< * Get Shadow Property.
< *
< * @param string|string[] $elements
< *
< * @return null|array|int|string
< */
< public function getShadowProperty($elements)
< {
< return $this->getArrayElementsValue($this->shadowProperties, $elements);
< }
<
< /**
< * Set Glow Properties.
< *
< * @param float $size
< * @param string $color_value
< * @param int $color_alpha
< * @param string $color_type
< */
< public function setGlowProperties($size, $color_value = null, $color_alpha = null, $color_type = null): void
< {
< $this->setGlowSize($size)
< ->setGlowColor(
< $color_value === null ? $this->glowProperties['color']['value'] : $color_value,
< $color_alpha === null ? (int) $this->glowProperties['color']['alpha'] : $color_alpha,
< $color_type === null ? $this->glowProperties['color']['type'] : $color_type
< );
< }
<
< /**
< * Get Glow Property.
< *
< * @param array|string $property
< *
< * @return string
< */
< public function getGlowProperty($property)
< {
< return $this->getArrayElementsValue($this->glowProperties, $property);
< }
<
< /**
< * Set Glow Color.
< *
< * @param float $size
< *
< * @return $this
< */
< private function setGlowSize($size)
> public function setMajorGridlines(?GridLines $gridlines): self
{
< if ($size !== null) {
< $this->glowProperties['size'] = $this->getExcelPointsWidth($size);
< }
> $this->majorGridlines = $gridlines;
return $this;
}
< /**
< * Set Glow Color.
< *
< * @param string $color
< * @param int $alpha
< * @param string $type
< *
< * @return $this
< */
< private function setGlowColor($color, $alpha, $type)
> public function setMinorGridlines(?GridLines $gridlines): self
{
< $this->glowProperties['color'] = $this->setColorProperties($color, $alpha, $type);
> $this->minorGridlines = $gridlines;
return $this;
< }
<
< /**
< * Set Soft Edges Size.
< *
< * @param float $size
< */
< public function setSoftEdges($size): void
< {
< if ($size !== null) {
< $softEdges['size'] = (string) $this->getExcelPointsWidth($size);
< }
< }
<
< /**
< * Get Soft Edges Size.
< *
< * @return string
< */
< public function getSoftEdgesSize()
< {
< return $this->softEdges['size'];
}
}