diff --git a/Classes/PHPExcel/Chart.php b/Classes/PHPExcel/Chart.php index 2f3f19d..b9146b3 100644 --- a/Classes/PHPExcel/Chart.php +++ b/Classes/PHPExcel/Chart.php @@ -98,6 +98,33 @@ class PHPExcel_Chart */ private $_displayBlanksAs = '0'; + /** + * Chart Asix Y as + * + * @var PHPExcel_Chart_Axis + */ + private $_yAxis = null; + + /** + * Chart Asix X as + * + * @var PHPExcel_Chart_Axis + */ + private $_xAxis = null; + + /** + * Chart Major Gridlines as + * + * @var PHPExcel_Chart_Gridlines + */ + private $_majorGridlines = null; + + /** + * Chart Minor Gridlines as + * + * @var PHPExcel_Chart_Gridlines + */ + private $_minorGridlines = null; /** * Top-Left Cell Position @@ -150,7 +177,7 @@ class PHPExcel_Chart /** * Create a new PHPExcel_Chart */ - public function __construct($name, PHPExcel_Chart_Title $title = null, PHPExcel_Chart_Legend $legend = null, PHPExcel_Chart_PlotArea $plotArea = null, $plotVisibleOnly = true, $displayBlanksAs = '0', PHPExcel_Chart_Title $xAxisLabel = null, PHPExcel_Chart_Title $yAxisLabel = null) + public function __construct($name, PHPExcel_Chart_Title $title = null, PHPExcel_Chart_Legend $legend = null, PHPExcel_Chart_PlotArea $plotArea = null, $plotVisibleOnly = true, $displayBlanksAs = '0', PHPExcel_Chart_Title $xAxisLabel = null, PHPExcel_Chart_Title $yAxisLabel = null, PHPExcel_Chart_Axis $xAxis = null, PHPExcel_Chart_Axis $yAxis = null, PHPExcel_Chart_Gridlines $majorGridlines = null, PHPExcel_Chart_Gridlines $minorGridlines = null) { $this->_name = $name; $this->_title = $title; @@ -160,6 +187,10 @@ class PHPExcel_Chart $this->_plotArea = $plotArea; $this->_plotVisibleOnly = $plotVisibleOnly; $this->_displayBlanksAs = $displayBlanksAs; + $this->_xAxis = $xAxis; + $this->_yAxis = $yAxis; + $this->_majorGridlines = $majorGridlines; + $this->_minorGridlines = $minorGridlines; } /** @@ -327,6 +358,59 @@ class PHPExcel_Chart } + /** + * Get yAxis + * + * @return PHPExcel_Chart_Axis + */ + public function getChartAxisY() { + if($this->_yAxis !== NULL){ + return $this->_yAxis; + } + + return new PHPExcel_Chart_Axis(); + } + + /** + * Get xAxis + * + * @return PHPExcel_Chart_Axis + */ + public function getChartAxisX() { + if($this->_xAxis !== NULL){ + return $this->_xAxis; + } + + return new PHPExcel_Chart_Axis(); + } + + /** + * Get Major Gridlines + * + * @return PHPExcel_Chart_Gridlines + */ + public function getMajorGridlines() { + if($this->_majorGridlines !== NULL){ + return $this->_majorGridlines; + } + + return new PHPExcel_Chart_Gridlines(); + } + + /** + * Get Minor Gridlines + * + * @return PHPExcel_Chart_Gridlines + */ + public function getMinorGridlines() { + if($this->_minorGridlines !== NULL){ + return $this->_minorGridlines; + } + + return new PHPExcel_Chart_Gridlines(); + } + + /** * Set the Top Left position for the chart * diff --git a/Classes/PHPExcel/Chart/Axis.php b/Classes/PHPExcel/Chart/Axis.php new file mode 100644 index 0000000..efb39e9 --- /dev/null +++ b/Classes/PHPExcel/Chart/Axis.php @@ -0,0 +1,584 @@ + self::FORMAT_CODE_GENERAL, + 'source_linked' => 1 + ); + + /** + * Axis Options + * + * @var array of mixed + */ + + private $_axis_options = array( + 'minimum' => NULL, + 'maximum' => NULL, + 'major_unit' => NULL, + 'minor_unit' => NULL, + 'orientation' => self::ORIENTATION_NORMAL, + 'minor_tick_mark' => self::TICK_MARK_NONE, + 'major_tick_mark' => self::TICK_MARK_NONE, + 'axis_labels' => self::AXIS_LABELS_NEXT_TO, + 'horizontal_crosses' => self::HORIZONTAL_CROSSES_AUTOZERO, + 'horizontal_crosses_value' => NULL + ); + + /** + * Fill Properties + * + * @var array of mixed + */ + + private $_fill_properties = array( + 'type' => self::EXCEL_COLOR_TYPE_ARGB, + 'value' => NULL, + 'alpha' => 0 + ); + + /** + * Line Properties + * + * @var array of mixed + */ + + private $_line_properties = array( + 'type' => self::EXCEL_COLOR_TYPE_ARGB, + 'value' => NULL, + 'alpha' => 0 + ); + + /** + * Line Style Properties + * + * @var array of mixed + */ + + private $_line_style_properties = array( + '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' => array( + 'head' => array( + 'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW, + 'size' => self::LINE_STYLE_ARROW_SIZE_5 + ), + 'end' => array( + 'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW, + 'size' => self::LINE_STYLE_ARROW_SIZE_8 + ), + ) + ); + + /** + * Shadow Properties + * + * @var array of mixed + */ + + private $_shadow_properties = array( + 'presets' => self::SHADOW_PRESETS_NOSHADOW, + 'effect' => NULL, + 'color' => array( + 'type' => self::EXCEL_COLOR_TYPE_STANDARD, + 'value' => 'black', + 'alpha' => 40, + ), + 'size' => array( + 'sx' => NULL, + 'sy' => NULL, + 'kx' => NULL + ), + 'blur' => NULL, + 'direction' => NULL, + 'distance' => NULL, + 'algn' => NULL, + 'rotWithShape' => NULL + ); + + /** + * Glow Properties + * + * @var array of mixed + */ + + private $_glow_properties = array( + 'size' => NULL, + 'color' => array( + 'type' => self::EXCEL_COLOR_TYPE_STANDARD, + 'value' => 'black', + 'alpha' => 40 + ) + ); + + /** + * Soft Edge Properties + * + * @var array of mixed + */ + + private $_soft_edges = array( + 'size' => NULL + ); + + /** + * Get Series Data Type + * + * @return string + */ + + public function setAxisNumberProperties($format_code) { + $this->_axis_number['format'] = (string) $format_code; + $this->_axis_number['source_linked'] = 0; + } + + /** + * Get Axis Number Format Data Type + * + * @return string + */ + + public function getAxisNumberFormat() { + return $this->_axis_number['format']; + } + + /** + * Get Axis Number Source Linked + * + * @return string + */ + + public function getAxisNumberSourceLinked() { + return (string) $this->_axis_number['source_linked']; + } + + /** + * Set Axis Options Properties + * + * @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) { + + $this->_axis_options['axis_labels'] = (string) $axis_labels; + ($horizontal_crosses_value !== NULL) + ? $this->_axis_options['horizontal_crosses_value'] = (string) $horizontal_crosses_value : NULL; + ($horizontal_crosses !== NULL) ? $this->_axis_options['horizontal_crosses'] = (string) $horizontal_crosses : NULL; + ($axis_orientation !== NULL) ? $this->_axis_options['orientation'] = (string) $axis_orientation : NULL; + ($major_tmt !== NULL) ? $this->_axis_options['major_tick_mark'] = (string) $major_tmt : NULL; + ($minor_tmt !== NULL) ? $this->_axis_options['minor_tick_mark'] = (string) $minor_tmt : NULL; + ($minor_tmt !== NULL) ? $this->_axis_options['minor_tick_mark'] = (string) $minor_tmt : NULL; + ($minimum !== NULL) ? $this->_axis_options['minimum'] = (string) $minimum : NULL; + ($maximum !== NULL) ? $this->_axis_options['maximum'] = (string) $maximum : NULL; + ($major_unit !== NULL) ? $this->_axis_options['major_unit'] = (string) $major_unit : NULL; + ($minor_unit !== NULL) ? $this->_axis_options['minor_unit'] = (string) $minor_unit : NULL; + } + + /** + * Get Axis Options Property + * + * @param string $property + * + * @return string + */ + + public function getAxisOptionsProperty($property) { + return $this->_axis_options[$property]; + } + + /** + * Set Axis Orientation Property + * + * @param string $orientation + * + */ + + public function setAxisOrientation($orientation) { + $this->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) { + $this->_fill_properties = $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) { + $this->_line_properties = $this->setColorProperties($color, $alpha, $type); + } + + /** + * Get Fill Property + * + * @param string $property + * + * @return string + */ + + public function getFillProperty($property) { + return $this->_fill_properties[$property]; + } + + /** + * Get Line Property + * + * @param string $property + * + * @return string + */ + + public function getLineProperty($property) { + return $this->_line_properties[$property]; + } + + /** + * 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) { + + (!is_null($line_width)) ? $this->_line_style_properties['width'] = $this->getExcelPointsWidth((float) $line_width) + : NULL; + (!is_null($compound_type)) ? $this->_line_style_properties['compound'] = (string) $compound_type : NULL; + (!is_null($dash_type)) ? $this->_line_style_properties['dash'] = (string) $dash_type : NULL; + (!is_null($cap_type)) ? $this->_line_style_properties['cap'] = (string) $cap_type : NULL; + (!is_null($join_type)) ? $this->_line_style_properties['join'] = (string) $join_type : NULL; + (!is_null($head_arrow_type)) ? $this->_line_style_properties['arrow']['head']['type'] = (string) $head_arrow_type + : NULL; + (!is_null($head_arrow_size)) ? $this->_line_style_properties['arrow']['head']['size'] = (string) $head_arrow_size + : NULL; + (!is_null($end_arrow_type)) ? $this->_line_style_properties['arrow']['end']['type'] = (string) $end_arrow_type + : NULL; + (!is_null($end_arrow_size)) ? $this->_line_style_properties['arrow']['end']['size'] = (string) $end_arrow_size + : NULL; + } + + /** + * Get Line Style Property + * + * @param array|string $elements + * + * @return string + */ + + public function getLineStyleProperty($elements) { + return $this->getArrayElementsValue($this->_line_style_properties, $elements); + } + + /** + * Get Line Style Arrow Excel Width + * + * @param string $arrow + * + * @return string + */ + + public function getLineStyleArrowWidth($arrow) { + return $this->getLineStyleArrowSize($this->_line_style_properties['arrow'][$arrow]['size'], 'w'); + } + + /** + * Get Line Style Arrow Excel Length + * + * @param string $arrow + * + * @return string + */ + + public function getLineStyleArrowLength($arrow) { + return $this->getLineStyleArrowSize($this->_line_style_properties['arrow'][$arrow]['size'], 'len'); + } + + /** + * Set Shadow Properties + * + * @param int $shadow_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) { + $this + ->_setShadowPresetsProperties((int) $sh_presets) + ->_setShadowColor( + is_null($sh_color_value) ? $this->_shadow_properties['color']['value'] : $sh_color_value + , is_null($sh_color_alpha) ? (int) $this->_shadow_properties['color']['alpha'] : $sh_color_alpha + , is_null($sh_color_type) ? $this->_shadow_properties['color']['type'] : $sh_color_type) + ->_setShadowBlur($sh_blur) + ->_setShadowAngle($sh_angle) + ->_setShadowDistance($sh_distance); + } + + /** + * Set Shadow Color + * + * @param int $shadow_presets + * + * @return PHPExcel_Chart_Axis + */ + + private function _setShadowPresetsProperties($shadow_presets) { + $this->_shadow_properties['presets'] = $shadow_presets; + $this->_setShadowProperiesMapValues($this->getShadowPresetsMap($shadow_presets)); + + return $this; + } + + /** + * Set Shadow Properties from Maped Values + * + * @param array $properties_map + * @param * $reference + * + * @return PHPExcel_Chart_Axis + */ + + private function _setShadowProperiesMapValues(array $properties_map, &$reference = NULL) { + $base_reference = $reference; + foreach ($properties_map as $property_key => $property_val) { + if (is_array($property_val)) { + if ($reference === NULL) { + $reference = & $this->_shadow_properties[$property_key]; + } else { + $reference = & $reference[$property_key]; + } + $this->_setShadowProperiesMapValues($property_val, $reference); + } else { + if ($base_reference === NULL) { + $this->_shadow_properties[$property_key] = $property_val; + } else { + $reference[$property_key] = $property_val; + } + } + } + + return $this; + } + + /** + * Set Shadow Color + * + * @param string $color + * @param int $alpha + * @param string $type + * + * @return PHPExcel_Chart_Axis + */ + + private function _setShadowColor($color, $alpha, $type) { + $this->_shadow_properties['color'] = $this->setColorProperties($color, $alpha, $type); + + return $this; + } + + /** + * Set Shadow Blur + * + * @param float $blur + * + * @return PHPExcel_Chart_Axis + */ + + private function _setShadowBlur($blur) { + if ($blur !== NULL) { + $this->_shadow_properties['blur'] = (string) $this->getExcelPointsWidth($blur); + } + + return $this; + } + + /** + * Set Shadow Angle + * + * @param int $angle + * + * @return PHPExcel_Chart_Axis + */ + + private function _setShadowAngle($angle) { + if ($angle !== NULL) { + $this->_shadow_properties['direction'] = (string) $this->getExcelPointsAngle($angle); + } + + return $this; + } + + /** + * Set Shadow Distance + * + * @param float $distance + * + * @return PHPExcel_Chart_Axis + */ + + private function _setShadowDistance($distance) { + if ($distance !== NULL) { + $this->_shadow_properties['distance'] = (string) $this->getExcelPointsWidth($distance); + } + + return $this; + } + + /** + * Get Glow Property + * + * @param float $size + * @param string $color_value + * @param int $color_alpha + * @param string $color_type + */ + + public function getShadowProperty($elements) { + return $this->getArrayElementsValue($this->_shadow_properties, $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) { + $this + ->_setGlowSize($size) + ->_setGlowColor( + is_null($color_value) ? $this->_glow_properties['color']['value'] : $color_value + , is_null($color_alpha) ? (int) $this->_glow_properties['color']['alpha'] : $color_alpha + , is_null($color_type) ? $this->_glow_properties['color']['type'] : $color_type); + } + + /** + * Get Glow Property + * + * @param array|string $property + * + * @return string + */ + + public function getGlowProperty($property) { + return $this->getArrayElementsValue($this->_glow_properties, $property); + } + + /** + * Set Glow Color + * + * @param float $size + * + * @return PHPExcel_Chart_Axis + */ + + private function _setGlowSize($size) { + if (!is_null($size)) { + $this->_glow_properties['size'] = $this->getExcelPointsWidth($size); + } + + return $this; + } + + /** + * Set Glow Color + * + * @param string $color + * @param int $alpha + * @param string $type + * + * @return PHPExcel_Chart_Axis + */ + + private function _setGlowColor($color, $alpha, $type) { + $this->_glow_properties['color'] = $this->setColorProperties($color, $alpha, $type); + + return $this; + } + + /** + * Set Soft Edges Size + * + * @param float $size + */ + + public function setSoftEdges($size) { + if (!is_null($size)) { + $_soft_edges['size'] = (string) $this->getExcelPointsWidth($size); + } + } + + /** + * Get Soft Edges Size + * + * @return string + */ + + public function getSoftEdgesSize() { + return $this->_soft_edges['size']; + } +} \ No newline at end of file diff --git a/Classes/PHPExcel/Chart/GridLines.php b/Classes/PHPExcel/Chart/GridLines.php new file mode 100644 index 0000000..7467ea7 --- /dev/null +++ b/Classes/PHPExcel/Chart/GridLines.php @@ -0,0 +1,458 @@ + array( + 'type' => self::EXCEL_COLOR_TYPE_STANDARD, + 'value' => NULL, + 'alpha' => 0 + ), + 'style' => array( + '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' => array( + 'head' => array( + 'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW, + 'size' => self::LINE_STYLE_ARROW_SIZE_5 + ), + 'end' => array( + 'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW, + 'size' => self::LINE_STYLE_ARROW_SIZE_8 + ), + ) + ) + ), + $_shadow_properties = array( + 'presets' => self::SHADOW_PRESETS_NOSHADOW, + 'effect' => NULL, + 'color' => array( + 'type' => self::EXCEL_COLOR_TYPE_STANDARD, + 'value' => 'black', + 'alpha' => 85, + ), + 'size' => array( + 'sx' => NULL, + 'sy' => NULL, + 'kx' => NULL + ), + 'blur' => NULL, + 'direction' => NULL, + 'distance' => NULL, + 'algn' => NULL, + 'rotWithShape' => NULL + ), + $_glow_properties = array( + 'size' => NULL, + 'color' => array( + 'type' => self::EXCEL_COLOR_TYPE_STANDARD, + 'value' => 'black', + 'alpha' => 40 + ) + ), + $_soft_edges = array( + 'size' => NULL + ); + + /** + * Get Object State + * + * @return bool + */ + + public function getObjectState() { + return $this->_object_state; + } + + /** + * Change Object State to True + * + * @return PHPExcel_Chart_Gridlines + */ + + private function _activateObject() { + $this->_object_state = TRUE; + + return $this; + } + + /** + * Set Line Color Properties + * + * @param string $value + * @param int $alpha + * @param string $type + */ + + public function setLineColorProperties($value, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_STANDARD) { + $this + ->_activateObject() + ->_line_properties['color'] = $this->setColorProperties( + $value, + $alpha, + $type); + } + + /** + * Set Line Color 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) { + $this->_activateObject(); + (!is_null($line_width)) + ? $this->_line_properties['style']['width'] = $this->getExcelPointsWidth((float) $line_width) + : NULL; + (!is_null($compound_type)) + ? $this->_line_properties['style']['compound'] = (string) $compound_type + : NULL; + (!is_null($dash_type)) + ? $this->_line_properties['style']['dash'] = (string) $dash_type + : NULL; + (!is_null($cap_type)) + ? $this->_line_properties['style']['cap'] = (string) $cap_type + : NULL; + (!is_null($join_type)) + ? $this->_line_properties['style']['join'] = (string) $join_type + : NULL; + (!is_null($head_arrow_type)) + ? $this->_line_properties['style']['arrow']['head']['type'] = (string) $head_arrow_type + : NULL; + (!is_null($head_arrow_size)) + ? $this->_line_properties['style']['arrow']['head']['size'] = (string) $head_arrow_size + : NULL; + (!is_null($end_arrow_type)) + ? $this->_line_properties['style']['arrow']['end']['type'] = (string) $end_arrow_type + : NULL; + (!is_null($end_arrow_size)) + ? $this->_line_properties['style']['arrow']['end']['size'] = (string) $end_arrow_size + : NULL; + } + + /** + * Get Line Color Property + * + * @param string $parameter + * + * @return string + */ + + public function getLineColorProperty($parameter) { + return $this->_line_properties['color'][$parameter]; + } + + /** + * Get Line Style Property + * + * @param array|string $elements + * + * @return string + */ + + public function getLineStyleProperty($elements) { + return $this->getArrayElementsValue($this->_line_properties['style'], $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) { + $this + ->_activateObject() + ->_setGlowSize($size) + ->_setGlowColor($color_value, $color_alpha, $color_type); + } + + /** + * Get Glow Color Property + * + * @param string $property + * + * @return string + */ + + public function getGlowColor($property) { + return $this->_glow_properties['color'][$property]; + } + + /** + * Get Glow Size + * + * @return string + */ + + public function getGlowSize() { + return $this->_glow_properties['size']; + } + + /** + * Set Glow Size + * + * @param float $size + * + * @return PHPExcel_Chart_Gridlines + */ + + private function _setGlowSize($size) { + $this->_glow_properties['size'] = $this->getExcelPointsWidth((float) $size); + + return $this; + } + + /** + * Set Glow Color + * + * @param string $color + * @param int $alpha + * @param string $type + * + * @return PHPExcel_Chart_Gridlines + */ + + private function _setGlowColor($color, $alpha, $type) { + if (!is_null($color)) { + $this->_glow_properties['color']['value'] = (string) $color; + } + if (!is_null($alpha)) { + $this->_glow_properties['color']['alpha'] = $this->getTrueAlpha((int) $alpha); + } + if (!is_null($type)) { + $this->_glow_properties['color']['type'] = (string) $type; + } + + return $this; + } + + /** + * Get Line Style Arrow Parameters + * + * @param string $arrow_selector + * @param string $property_selector + * + * @return string + */ + + public function getLineStyleArrowParameters($arrow_selector, $property_selector) { + return $this->getLineStyleArrowSize($this->_line_properties['style']['arrow'][$arrow_selector]['size'], $property_selector); + } + + /** + * Set Shadow Properties + * + * @param int $sh_presets + * @param string $sh_color_value + * @param string $sh_color_type + * @param int $sh_color_alpha + * @param string $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) { + $this + ->_activateObject() + ->_setShadowPresetsProperties((int) $sh_presets) + ->_setShadowColor( + is_null($sh_color_value) ? $this->_shadow_properties['color']['value'] : $sh_color_value + , is_null($sh_color_alpha) ? (int) $this->_shadow_properties['color']['alpha'] + : $this->getTrueAlpha($sh_color_alpha) + , is_null($sh_color_type) ? $this->_shadow_properties['color']['type'] : $sh_color_type) + ->_setShadowBlur($sh_blur) + ->_setShadowAngle($sh_angle) + ->_setShadowDistance($sh_distance); + } + + /** + * Set Shadow Presets Properties + * + * @param int $shadow_presets + * + * @return PHPExcel_Chart_Gridlines + */ + + private function _setShadowPresetsProperties($shadow_presets) { + $this->_shadow_properties['presets'] = $shadow_presets; + $this->_setShadowProperiesMapValues($this->getShadowPresetsMap($shadow_presets)); + + return $this; + } + + /** + * Set Shadow Properties Values + * + * @param array $properties_map + * @param * $reference + * + * @return PHPExcel_Chart_Gridlines + */ + + private function _setShadowProperiesMapValues(array $properties_map, &$reference = NULL) { + $base_reference = $reference; + foreach ($properties_map as $property_key => $property_val) { + if (is_array($property_val)) { + if ($reference === NULL) { + $reference = & $this->_shadow_properties[$property_key]; + } else { + $reference = & $reference[$property_key]; + } + $this->_setShadowProperiesMapValues($property_val, $reference); + } else { + if ($base_reference === NULL) { + $this->_shadow_properties[$property_key] = $property_val; + } else { + $reference[$property_key] = $property_val; + } + } + } + + return $this; + } + + /** + * Set Shadow Color + * + * @param string $color + * @param int $alpha + * @param string $type + * + * @return PHPExcel_Chart_Gridlines + */ + + private function _setShadowColor($color, $alpha, $type) { + if (!is_null($color)) { + $this->_shadow_properties['color']['value'] = (string) $color; + } + if (!is_null($alpha)) { + $this->_shadow_properties['color']['alpha'] = $this->getTrueAlpha((int) $alpha); + } + if (!is_null($type)) { + $this->_shadow_properties['color']['type'] = (string) $type; + } + + return $this; + } + + /** + * Set Shadow Blur + * + * @param float $blur + * + * @return PHPExcel_Chart_Gridlines + */ + + private function _setShadowBlur($blur) { + if ($blur !== NULL) { + $this->_shadow_properties['blur'] = (string) $this->getExcelPointsWidth($blur); + } + + return $this; + } + + /** + * Set Shadow Angle + * + * @param int $angle + * + * @return PHPExcel_Chart_Gridlines + */ + + private function _setShadowAngle($angle) { + if ($angle !== NULL) { + $this->_shadow_properties['direction'] = (string) $this->getExcelPointsAngle($angle); + } + + return $this; + } + + /** + * Set Shadow Distance + * + * @param float $distance + * + * @return PHPExcel_Chart_Gridlines + */ + + private function _setShadowDistance($distance) { + if ($distance !== NULL) { + $this->_shadow_properties['distance'] = (string) $this->getExcelPointsWidth($distance); + } + + return $this; + } + + /** + * Get Shadow Property + * + * @param string $elements + * @param array $elements + * + * @return string + */ + + public function getShadowProperty($elements) { + return $this->getArrayElementsValue($this->_shadow_properties, $elements); + } + + /** + * Set Soft Edges Size + * + * @param float $size + */ + + public function setSoftEdgesSize($size) { + if (!is_null($size)) { + $this->_activateObject(); + $_soft_edges['size'] = (string) $this->getExcelPointsWidth($size); + } + } + + /** + * Get Soft Edges Size + * + * @return string + */ + + public function getSoftEdgesSize() { + return $this->_soft_edges['size']; + } +} \ No newline at end of file diff --git a/Classes/PHPExcel/Chart/Properties.php b/Classes/PHPExcel/Chart/Properties.php new file mode 100644 index 0000000..7593983 --- /dev/null +++ b/Classes/PHPExcel/Chart/Properties.php @@ -0,0 +1,359 @@ + (string) $type, + 'value' => (string) $color, + 'alpha' => (string) $this->getTrueAlpha($alpha) + ); + } + + protected function getLineStyleArrowSize($array_selector, $array_kay_selector) { + $sizes = array( + 1 => array('w' => 'sm', 'len' => 'sm'), + 2 => array('w' => 'sm', 'len' => 'med'), + 3 => array('w' => 'sm', 'len' => 'lg'), + 4 => array('w' => 'med', 'len' => 'sm'), + 5 => array('w' => 'med', 'len' => 'med'), + 6 => array('w' => 'med', 'len' => 'lg'), + 7 => array('w' => 'lg', 'len' => 'sm'), + 8 => array('w' => 'lg', 'len' => 'med'), + 9 => array('w' => 'lg', 'len' => 'lg') + ); + + return $sizes[$array_selector][$array_kay_selector]; + } + + protected function getShadowPresetsMap($shadow_presets_option) { + $presets_options = array( + //OUTER + 1 => array( + 'effect' => 'outerShdw', + 'blur' => '50800', + 'distance' => '38100', + 'direction' => '2700000', + 'algn' => 'tl', + 'rotWithShape' => '0' + ), + 2 => array( + 'effect' => 'outerShdw', + 'blur' => '50800', + 'distance' => '38100', + 'direction' => '5400000', + 'algn' => 't', + 'rotWithShape' => '0' + ), + 3 => array( + 'effect' => 'outerShdw', + 'blur' => '50800', + 'distance' => '38100', + 'direction' => '8100000', + 'algn' => 'tr', + 'rotWithShape' => '0' + ), + 4 => array( + 'effect' => 'outerShdw', + 'blur' => '50800', + 'distance' => '38100', + 'algn' => 'l', + 'rotWithShape' => '0' + ), + 5 => array( + 'effect' => 'outerShdw', + 'size' => array( + 'sx' => '102000', + 'sy' => '102000' + ) + , + 'blur' => '63500', + 'distance' => '38100', + 'algn' => 'ctr', + 'rotWithShape' => '0' + ), + 6 => array( + 'effect' => 'outerShdw', + 'blur' => '50800', + 'distance' => '38100', + 'direction' => '10800000', + 'algn' => 'r', + 'rotWithShape' => '0' + ), + 7 => array( + 'effect' => 'outerShdw', + 'blur' => '50800', + 'distance' => '38100', + 'direction' => '18900000', + 'algn' => 'bl', + 'rotWithShape' => '0' + ), + 8 => array( + 'effect' => 'outerShdw', + 'blur' => '50800', + 'distance' => '38100', + 'direction' => '16200000', + 'rotWithShape' => '0' + ), + 9 => array( + 'effect' => 'outerShdw', + 'blur' => '50800', + 'distance' => '38100', + 'direction' => '13500000', + 'algn' => 'br', + 'rotWithShape' => '0' + ), + //INNER + 10 => array( + 'effect' => 'innerShdw', + 'blur' => '63500', + 'distance' => '50800', + 'direction' => '2700000', + ), + 11 => array( + 'effect' => 'innerShdw', + 'blur' => '63500', + 'distance' => '50800', + 'direction' => '5400000', + ), + 12 => array( + 'effect' => 'innerShdw', + 'blur' => '63500', + 'distance' => '50800', + 'direction' => '8100000', + ), + 13 => array( + 'effect' => 'innerShdw', + 'blur' => '63500', + 'distance' => '50800', + ), + 14 => array( + 'effect' => 'innerShdw', + 'blur' => '114300', + ), + 15 => array( + 'effect' => 'innerShdw', + 'blur' => '63500', + 'distance' => '50800', + 'direction' => '10800000', + ), + 16 => array( + 'effect' => 'innerShdw', + 'blur' => '63500', + 'distance' => '50800', + 'direction' => '18900000', + ), + 17 => array( + 'effect' => 'innerShdw', + 'blur' => '63500', + 'distance' => '50800', + 'direction' => '16200000', + ), + 18 => array( + 'effect' => 'innerShdw', + 'blur' => '63500', + 'distance' => '50800', + 'direction' => '13500000', + ), + //perspective + 19 => array( + 'effect' => 'outerShdw', + 'blur' => '152400', + 'distance' => '317500', + 'size' => array( + 'sx' => '90000', + 'sy' => '-19000', + ), + 'direction' => '5400000', + 'rotWithShape' => '0', + ), + 20 => array( + 'effect' => 'outerShdw', + 'blur' => '76200', + 'direction' => '18900000', + 'size' => array( + 'sy' => '23000', + 'kx' => '-1200000', + ), + 'algn' => 'bl', + 'rotWithShape' => '0', + ), + 21 => array( + 'effect' => 'outerShdw', + 'blur' => '76200', + 'direction' => '13500000', + 'size' => array( + 'sy' => '23000', + 'kx' => '1200000', + ), + 'algn' => 'br', + 'rotWithShape' => '0', + ), + 22 => array( + 'effect' => 'outerShdw', + 'blur' => '76200', + 'distance' => '12700', + 'direction' => '2700000', + 'size' => array( + 'sy' => '-23000', + 'kx' => '-800400', + ), + 'algn' => 'bl', + 'rotWithShape' => '0', + ), + 23 => array( + 'effect' => 'outerShdw', + 'blur' => '76200', + 'distance' => '12700', + 'direction' => '8100000', + 'size' => array( + 'sy' => '-23000', + 'kx' => '800400', + ), + 'algn' => 'br', + 'rotWithShape' => '0', + ), + ); + + return $presets_options[$shadow_presets_option]; + } + + protected function getArrayElementsValue($properties, $elements) { + $reference = & $properties; + if (!is_array($elements)) { + return $reference[$elements]; + } else { + foreach ($elements as $keys) { + $reference = & $reference[$keys]; + } + + return $reference; + } + + return $this; + } + +} \ No newline at end of file diff --git a/Classes/PHPExcel/Writer/Excel2007/Chart.php b/Classes/PHPExcel/Writer/Excel2007/Chart.php index 0b686b9..d863734 100644 --- a/Classes/PHPExcel/Writer/Excel2007/Chart.php +++ b/Classes/PHPExcel/Writer/Excel2007/Chart.php @@ -25,7 +25,6 @@ * @version ##VERSION##, ##DATE## */ - /** * PHPExcel_Writer_Excel2007_Chart * @@ -33,1171 +32,1575 @@ * @package PHPExcel_Writer_Excel2007 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) */ -class PHPExcel_Writer_Excel2007_Chart extends PHPExcel_Writer_Excel2007_WriterPart -{ - /** - * Write charts to XML format - * - * @param PHPExcel_Chart $pChart - * @return string XML Output - * @throws PHPExcel_Writer_Exception - */ - public function writeChart(PHPExcel_Chart $pChart = null) - { - // Create XML writer - $objWriter = null; - if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); - } else { - $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); - } - // Ensure that data series values are up-to-date before we save - $pChart->refresh(); - - // XML header - $objWriter->startDocument('1.0','UTF-8','yes'); - - // c:chartSpace - $objWriter->startElement('c:chartSpace'); - $objWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart'); - $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main'); - $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); - - $objWriter->startElement('c:date1904'); - $objWriter->writeAttribute('val', 0); - $objWriter->endElement(); - $objWriter->startElement('c:lang'); - $objWriter->writeAttribute('val', "en-GB"); - $objWriter->endElement(); - $objWriter->startElement('c:roundedCorners'); - $objWriter->writeAttribute('val', 0); - $objWriter->endElement(); - - $this->_writeAlternateContent($objWriter); - - $objWriter->startElement('c:chart'); - - $this->_writeTitle($pChart->getTitle(), $objWriter); - - $objWriter->startElement('c:autoTitleDeleted'); - $objWriter->writeAttribute('val', 0); - $objWriter->endElement(); - - $this->_writePlotArea($pChart->getPlotArea(), - $pChart->getXAxisLabel(), - $pChart->getYAxisLabel(), - $objWriter, - $pChart->getWorksheet() - ); - - $this->_writeLegend($pChart->getLegend(), $objWriter); - - - $objWriter->startElement('c:plotVisOnly'); - $objWriter->writeAttribute('val', 1); - $objWriter->endElement(); - - $objWriter->startElement('c:dispBlanksAs'); - $objWriter->writeAttribute('val', "gap"); - $objWriter->endElement(); - - $objWriter->startElement('c:showDLblsOverMax'); - $objWriter->writeAttribute('val', 0); - $objWriter->endElement(); - - $objWriter->endElement(); - - $this->_writePrintSettings($objWriter); - - $objWriter->endElement(); - - // Return - return $objWriter->getData(); - } - - /** - * Write Chart Title - * - * @param PHPExcel_Chart_Title $title - * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer - * @throws PHPExcel_Writer_Exception - */ - private function _writeTitle(PHPExcel_Chart_Title $title = null, $objWriter) - { - if (is_null($title)) { - return; - } - - $objWriter->startElement('c:title'); - $objWriter->startElement('c:tx'); - $objWriter->startElement('c:rich'); - - $objWriter->startElement('a:bodyPr'); - $objWriter->endElement(); - - $objWriter->startElement('a:lstStyle'); - $objWriter->endElement(); - - $objWriter->startElement('a:p'); - - $caption = $title->getCaption(); - if ((is_array($caption)) && (count($caption) > 0)) - $caption = $caption[0]; - $this->getParentWriter()->getWriterPart('stringtable')->writeRichTextForCharts($objWriter, $caption, 'a'); - - $objWriter->endElement(); - $objWriter->endElement(); - $objWriter->endElement(); - - $layout = $title->getLayout(); - $this->_writeLayout($layout, $objWriter); - - $objWriter->startElement('c:overlay'); - $objWriter->writeAttribute('val', 0); - $objWriter->endElement(); - - $objWriter->endElement(); - } - - /** - * Write Chart Legend - * - * @param PHPExcel_Chart_Legend $legend - * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer - * @throws PHPExcel_Writer_Exception - */ - private function _writeLegend(PHPExcel_Chart_Legend $legend = null, $objWriter) - { - if (is_null($legend)) { - return; - } - - $objWriter->startElement('c:legend'); - - $objWriter->startElement('c:legendPos'); - $objWriter->writeAttribute('val', $legend->getPosition()); - $objWriter->endElement(); - - $layout = $legend->getLayout(); - $this->_writeLayout($layout, $objWriter); - - $objWriter->startElement('c:overlay'); - $objWriter->writeAttribute('val', ($legend->getOverlay()) ? '1' : '0'); - $objWriter->endElement(); - - $objWriter->startElement('c:txPr'); - $objWriter->startElement('a:bodyPr'); - $objWriter->endElement(); - - $objWriter->startElement('a:lstStyle'); - $objWriter->endElement(); - - $objWriter->startElement('a:p'); - $objWriter->startElement('a:pPr'); - $objWriter->writeAttribute('rtl', 0); - - $objWriter->startElement('a:defRPr'); - $objWriter->endElement(); - $objWriter->endElement(); - - $objWriter->startElement('a:endParaRPr'); - $objWriter->writeAttribute('lang', "en-US"); - $objWriter->endElement(); - - $objWriter->endElement(); - $objWriter->endElement(); - - $objWriter->endElement(); - } - - /** - * Write Chart Plot Area - * - * @param PHPExcel_Chart_PlotArea $plotArea - * @param PHPExcel_Chart_Title $xAxisLabel - * @param PHPExcel_Chart_Title $yAxisLabel - * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer - * @throws PHPExcel_Writer_Exception - */ - private function _writePlotArea(PHPExcel_Chart_PlotArea $plotArea, - PHPExcel_Chart_Title $xAxisLabel = NULL, - PHPExcel_Chart_Title $yAxisLabel = NULL, - $objWriter, - PHPExcel_Worksheet $pSheet) - { - if (is_null($plotArea)) { - return; - } - - $id1 = $id2 = 0; - $this->_seriesIndex = 0; - $objWriter->startElement('c:plotArea'); - - $layout = $plotArea->getLayout(); - - $this->_writeLayout($layout, $objWriter); - - $chartTypes = self::_getChartType($plotArea); - $catIsMultiLevelSeries = $valIsMultiLevelSeries = FALSE; - $plotGroupingType = ''; - foreach($chartTypes as $chartType) { - $objWriter->startElement('c:'.$chartType); - - $groupCount = $plotArea->getPlotGroupCount(); - for($i = 0; $i < $groupCount; ++$i) { - $plotGroup = $plotArea->getPlotGroupByIndex($i); - $groupType = $plotGroup->getPlotType(); - if ($groupType == $chartType) { - - $plotStyle = $plotGroup->getPlotStyle(); - if ($groupType === PHPExcel_Chart_DataSeries::TYPE_RADARCHART) { - $objWriter->startElement('c:radarStyle'); - $objWriter->writeAttribute('val', $plotStyle ); - $objWriter->endElement(); - } elseif ($groupType === PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART) { - $objWriter->startElement('c:scatterStyle'); - $objWriter->writeAttribute('val', $plotStyle ); - $objWriter->endElement(); - } - - $this->_writePlotGroup($plotGroup, $chartType, $objWriter, $catIsMultiLevelSeries, $valIsMultiLevelSeries, $plotGroupingType, $pSheet); - } - } - - $this->_writeDataLbls($objWriter, $layout); - - if ($chartType === PHPExcel_Chart_DataSeries::TYPE_LINECHART) { - // Line only, Line3D can't be smoothed - - $objWriter->startElement('c:smooth'); - $objWriter->writeAttribute('val', (integer) $plotGroup->getSmoothLine() ); - $objWriter->endElement(); - } elseif (($chartType === PHPExcel_Chart_DataSeries::TYPE_BARCHART) || - ($chartType === PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D)) { - - $objWriter->startElement('c:gapWidth'); - $objWriter->writeAttribute('val', 150 ); - $objWriter->endElement(); - - if ($plotGroupingType == 'percentStacked' || - $plotGroupingType == 'stacked') { - - $objWriter->startElement('c:overlap'); - $objWriter->writeAttribute('val', 100 ); - $objWriter->endElement(); - } - } elseif ($chartType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) { - - $objWriter->startElement('c:bubbleScale'); - $objWriter->writeAttribute('val', 25 ); - $objWriter->endElement(); - - $objWriter->startElement('c:showNegBubbles'); - $objWriter->writeAttribute('val', 0 ); - $objWriter->endElement(); - } elseif ($chartType === PHPExcel_Chart_DataSeries::TYPE_STOCKCHART) { - - $objWriter->startElement('c:hiLowLines'); - $objWriter->endElement(); - - $objWriter->startElement( 'c:upDownBars' ); - - $objWriter->startElement( 'c:gapWidth' ); - $objWriter->writeAttribute('val', 300); - $objWriter->endElement(); - - $objWriter->startElement( 'c:upBars' ); - $objWriter->endElement(); - - $objWriter->startElement( 'c:downBars' ); - $objWriter->endElement(); - - $objWriter->endElement(); - } - - // Generate 2 unique numbers to use for axId values -// $id1 = $id2 = rand(10000000,99999999); -// do { -// $id2 = rand(10000000,99999999); -// } while ($id1 == $id2); - $id1 = '75091328'; - $id2 = '75089408'; - - if (($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART) && - ($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) && - ($chartType !== PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) { - - $objWriter->startElement('c:axId'); - $objWriter->writeAttribute('val', $id1 ); - $objWriter->endElement(); - $objWriter->startElement('c:axId'); - $objWriter->writeAttribute('val', $id2 ); - $objWriter->endElement(); - } else { - $objWriter->startElement('c:firstSliceAng'); - $objWriter->writeAttribute('val', 0); - $objWriter->endElement(); - - if ($chartType === PHPExcel_Chart_DataSeries::TYPE_DONUTCHART) { - - $objWriter->startElement('c:holeSize'); - $objWriter->writeAttribute('val', 50); - $objWriter->endElement(); - } - } - - $objWriter->endElement(); - } - - if (($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART) && - ($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) && - ($chartType !== PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) { - - if ($chartType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) { - $this->_writeValAx($objWriter,$plotArea,$xAxisLabel,$chartType,$id1,$id2,$catIsMultiLevelSeries); - } else { - $this->_writeCatAx($objWriter,$plotArea,$xAxisLabel,$chartType,$id1,$id2,$catIsMultiLevelSeries); - } - - $this->_writeValAx($objWriter,$plotArea,$yAxisLabel,$chartType,$id1,$id2,$valIsMultiLevelSeries); - } - - $objWriter->endElement(); - } - - /** - * Write Data Labels - * - * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer - * @param PHPExcel_Chart_Layout $chartLayout Chart layout - * @throws PHPExcel_Writer_Exception - */ - private function _writeDataLbls($objWriter, $chartLayout) - { - $objWriter->startElement('c:dLbls'); - - $objWriter->startElement('c:showLegendKey'); - $showLegendKey = (empty($chartLayout)) ? 0 : $chartLayout->getShowLegendKey(); - $objWriter->writeAttribute('val', ((empty($showLegendKey)) ? 0 : 1) ); - $objWriter->endElement(); - - - $objWriter->startElement('c:showVal'); - $showVal = (empty($chartLayout)) ? 0 : $chartLayout->getShowVal(); - $objWriter->writeAttribute('val', ((empty($showVal)) ? 0 : 1) ); - $objWriter->endElement(); - - $objWriter->startElement('c:showCatName'); - $showCatName = (empty($chartLayout)) ? 0 : $chartLayout->getShowCatName(); - $objWriter->writeAttribute('val', ((empty($showCatName)) ? 0 : 1) ); - $objWriter->endElement(); - - $objWriter->startElement('c:showSerName'); - $showSerName = (empty($chartLayout)) ? 0 : $chartLayout->getShowSerName(); - $objWriter->writeAttribute('val', ((empty($showSerName)) ? 0 : 1) ); - $objWriter->endElement(); - - $objWriter->startElement('c:showPercent'); - $showPercent = (empty($chartLayout)) ? 0 : $chartLayout->getShowPercent(); - $objWriter->writeAttribute('val', ((empty($showPercent)) ? 0 : 1) ); - $objWriter->endElement(); - - $objWriter->startElement('c:showBubbleSize'); - $showBubbleSize = (empty($chartLayout)) ? 0 : $chartLayout->getShowBubbleSize(); - $objWriter->writeAttribute('val', ((empty($showBubbleSize)) ? 0 : 1) ); - $objWriter->endElement(); - - $objWriter->startElement('c:showLeaderLines'); - $showLeaderLines = (empty($chartLayout)) ? 1 : $chartLayout->getShowLeaderLines(); - $objWriter->writeAttribute('val', ((empty($showLeaderLines)) ? 0 : 1) ); - $objWriter->endElement(); - - $objWriter->endElement(); - } - - /** - * Write Category Axis - * - * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer - * @param PHPExcel_Chart_PlotArea $plotArea - * @param PHPExcel_Chart_Title $xAxisLabel - * @param string $groupType Chart type - * @param string $id1 - * @param string $id2 - * @param boolean $isMultiLevelSeries - * @throws PHPExcel_Writer_Exception - */ - private function _writeCatAx($objWriter, PHPExcel_Chart_PlotArea $plotArea, $xAxisLabel, $groupType, $id1, $id2, $isMultiLevelSeries) - { - $objWriter->startElement('c:catAx'); - - if ($id1 > 0) { - $objWriter->startElement('c:axId'); - $objWriter->writeAttribute('val', $id1); - $objWriter->endElement(); - } - - $objWriter->startElement('c:scaling'); - $objWriter->startElement('c:orientation'); - $objWriter->writeAttribute('val', "minMax"); - $objWriter->endElement(); - $objWriter->endElement(); - - $objWriter->startElement('c:delete'); - $objWriter->writeAttribute('val', 0); - $objWriter->endElement(); - - $objWriter->startElement('c:axPos'); - $objWriter->writeAttribute('val', "b"); - $objWriter->endElement(); - - if (!is_null($xAxisLabel)) { - $objWriter->startElement('c:title'); - $objWriter->startElement('c:tx'); - $objWriter->startElement('c:rich'); - - $objWriter->startElement('a:bodyPr'); - $objWriter->endElement(); - - $objWriter->startElement('a:lstStyle'); - $objWriter->endElement(); - - $objWriter->startElement('a:p'); - $objWriter->startElement('a:r'); - - $caption = $xAxisLabel->getCaption(); - if (is_array($caption)) - $caption = $caption[0]; - $objWriter->startElement('a:t'); -// $objWriter->writeAttribute('xml:space', 'preserve'); - $objWriter->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML( $caption )); - $objWriter->endElement(); - - $objWriter->endElement(); - $objWriter->endElement(); - $objWriter->endElement(); - $objWriter->endElement(); - - $layout = $xAxisLabel->getLayout(); - $this->_writeLayout($layout, $objWriter); - - $objWriter->startElement('c:overlay'); - $objWriter->writeAttribute('val', 0); - $objWriter->endElement(); - - $objWriter->endElement(); - - } - - $objWriter->startElement('c:numFmt'); - $objWriter->writeAttribute('formatCode', "General"); - $objWriter->writeAttribute('sourceLinked', 1); - $objWriter->endElement(); - - $objWriter->startElement('c:majorTickMark'); - $objWriter->writeAttribute('val', "out"); - $objWriter->endElement(); - - $objWriter->startElement('c:minorTickMark'); - $objWriter->writeAttribute('val', "none"); - $objWriter->endElement(); - - $objWriter->startElement('c:tickLblPos'); - $objWriter->writeAttribute('val', "nextTo"); - $objWriter->endElement(); - - if ($id2 > 0) { - $objWriter->startElement('c:crossAx'); - $objWriter->writeAttribute('val', $id2); - $objWriter->endElement(); - - $objWriter->startElement('c:crosses'); - $objWriter->writeAttribute('val', "autoZero"); - $objWriter->endElement(); - } - - $objWriter->startElement('c:auto'); - $objWriter->writeAttribute('val', 1); - $objWriter->endElement(); - - $objWriter->startElement('c:lblAlgn'); - $objWriter->writeAttribute('val', "ctr"); - $objWriter->endElement(); - - $objWriter->startElement('c:lblOffset'); - $objWriter->writeAttribute('val', 100); - $objWriter->endElement(); - - if ($isMultiLevelSeries) { - $objWriter->startElement('c:noMultiLvlLbl'); - $objWriter->writeAttribute('val', 0); - $objWriter->endElement(); - } - $objWriter->endElement(); - - } - - - /** - * Write Value Axis - * - * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer - * @param PHPExcel_Chart_PlotArea $plotArea - * @param PHPExcel_Chart_Title $yAxisLabel - * @param string $groupType Chart type - * @param string $id1 - * @param string $id2 - * @param boolean $isMultiLevelSeries - * @throws PHPExcel_Writer_Exception - */ - private function _writeValAx($objWriter, PHPExcel_Chart_PlotArea $plotArea, $yAxisLabel, $groupType, $id1, $id2, $isMultiLevelSeries) - { - $objWriter->startElement('c:valAx'); - - if ($id2 > 0) { - $objWriter->startElement('c:axId'); - $objWriter->writeAttribute('val', $id2); - $objWriter->endElement(); - } - - $objWriter->startElement('c:scaling'); - $objWriter->startElement('c:orientation'); - $objWriter->writeAttribute('val', "minMax"); - $objWriter->endElement(); - $objWriter->endElement(); - - $objWriter->startElement('c:delete'); - $objWriter->writeAttribute('val', 0); - $objWriter->endElement(); - - $objWriter->startElement('c:axPos'); - $objWriter->writeAttribute('val', "l"); - $objWriter->endElement(); - - $objWriter->startElement('c:majorGridlines'); - $objWriter->endElement(); - - if (!is_null($yAxisLabel)) { - $objWriter->startElement('c:title'); - $objWriter->startElement('c:tx'); - $objWriter->startElement('c:rich'); - - $objWriter->startElement('a:bodyPr'); - $objWriter->endElement(); - - $objWriter->startElement('a:lstStyle'); - $objWriter->endElement(); - - $objWriter->startElement('a:p'); - $objWriter->startElement('a:r'); - - $caption = $yAxisLabel->getCaption(); - if (is_array($caption)) - $caption = $caption[0]; - $objWriter->startElement('a:t'); -// $objWriter->writeAttribute('xml:space', 'preserve'); - $objWriter->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML( $caption )); - $objWriter->endElement(); - - $objWriter->endElement(); - $objWriter->endElement(); - $objWriter->endElement(); - $objWriter->endElement(); - - if ($groupType !== PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) { - $layout = $yAxisLabel->getLayout(); - $this->_writeLayout($layout, $objWriter); - } - - $objWriter->startElement('c:overlay'); - $objWriter->writeAttribute('val', 0); - $objWriter->endElement(); - - $objWriter->endElement(); - } - - $objWriter->startElement('c:numFmt'); - $objWriter->writeAttribute('formatCode', "General"); - $objWriter->writeAttribute('sourceLinked', 1); - $objWriter->endElement(); - - $objWriter->startElement('c:majorTickMark'); - $objWriter->writeAttribute('val', "out"); - $objWriter->endElement(); - - $objWriter->startElement('c:minorTickMark'); - $objWriter->writeAttribute('val', "none"); - $objWriter->endElement(); - - $objWriter->startElement('c:tickLblPos'); - $objWriter->writeAttribute('val', "nextTo"); - $objWriter->endElement(); - - if ($id1 > 0) { - $objWriter->startElement('c:crossAx'); - $objWriter->writeAttribute('val', $id2); - $objWriter->endElement(); - - $objWriter->startElement('c:crosses'); - $objWriter->writeAttribute('val', "autoZero"); - $objWriter->endElement(); - - $objWriter->startElement('c:crossBetween'); - $objWriter->writeAttribute('val', "midCat"); - $objWriter->endElement(); - } - - if ($isMultiLevelSeries) { - if ($groupType !== PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) { - $objWriter->startElement('c:noMultiLvlLbl'); - $objWriter->writeAttribute('val', 0); - $objWriter->endElement(); - } - } - $objWriter->endElement(); - - } - - - /** - * Get the data series type(s) for a chart plot series - * - * @param PHPExcel_Chart_PlotArea $plotArea - * @return string|array - * @throws PHPExcel_Writer_Exception - */ - private static function _getChartType($plotArea) - { - $groupCount = $plotArea->getPlotGroupCount(); - - if ($groupCount == 1) { - $chartType = array($plotArea->getPlotGroupByIndex(0)->getPlotType()); - } else { - $chartTypes = array(); - for($i = 0; $i < $groupCount; ++$i) { - $chartTypes[] = $plotArea->getPlotGroupByIndex($i)->getPlotType(); - } - $chartType = array_unique($chartTypes); - if (count($chartTypes) == 0) { - throw new PHPExcel_Writer_Exception('Chart is not yet implemented'); - } - } - - return $chartType; - } - - /** - * Write Plot Group (series of related plots) - * - * @param PHPExcel_Chart_DataSeries $plotGroup - * @param string $groupType Type of plot for dataseries - * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer - * @param boolean &$catIsMultiLevelSeries Is category a multi-series category - * @param boolean &$valIsMultiLevelSeries Is value set a multi-series set - * @param string &$plotGroupingType Type of grouping for multi-series values - * @param PHPExcel_Worksheet $pSheet - * @throws PHPExcel_Writer_Exception - */ - private function _writePlotGroup( $plotGroup, - $groupType, - $objWriter, - &$catIsMultiLevelSeries, - &$valIsMultiLevelSeries, - &$plotGroupingType, - PHPExcel_Worksheet $pSheet - ) - { - if (is_null($plotGroup)) { - return; - } - - if (($groupType == PHPExcel_Chart_DataSeries::TYPE_BARCHART) || - ($groupType == PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D)) { - $objWriter->startElement('c:barDir'); - $objWriter->writeAttribute('val', $plotGroup->getPlotDirection()); - $objWriter->endElement(); - } - - if (!is_null($plotGroup->getPlotGrouping())) { - $plotGroupingType = $plotGroup->getPlotGrouping(); - $objWriter->startElement('c:grouping'); - $objWriter->writeAttribute('val', $plotGroupingType); - $objWriter->endElement(); - } - - // Get these details before the loop, because we can use the count to check for varyColors - $plotSeriesOrder = $plotGroup->getPlotOrder(); - $plotSeriesCount = count($plotSeriesOrder); - - if (($groupType !== PHPExcel_Chart_DataSeries::TYPE_RADARCHART) && - ($groupType !== PHPExcel_Chart_DataSeries::TYPE_STOCKCHART)) { - - if ($groupType !== PHPExcel_Chart_DataSeries::TYPE_LINECHART) { - if (($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART) || - ($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) || - ($groupType == PHPExcel_Chart_DataSeries::TYPE_DONUTCHART) || - ($plotSeriesCount > 1)) { - $objWriter->startElement('c:varyColors'); - $objWriter->writeAttribute('val', 1); - $objWriter->endElement(); - } else { - $objWriter->startElement('c:varyColors'); - $objWriter->writeAttribute('val', 0); - $objWriter->endElement(); - } - } - } - - foreach($plotSeriesOrder as $plotSeriesIdx => $plotSeriesRef) { - $objWriter->startElement('c:ser'); - - $objWriter->startElement('c:idx'); - $objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesIdx); - $objWriter->endElement(); - - $objWriter->startElement('c:order'); - $objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesRef); - $objWriter->endElement(); - - if (($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART) || - ($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) || - ($groupType == PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) { - - $objWriter->startElement('c:dPt'); - $objWriter->startElement('c:idx'); - $objWriter->writeAttribute('val', 3); - $objWriter->endElement(); - - $objWriter->startElement('c:bubble3D'); - $objWriter->writeAttribute('val', 0); - $objWriter->endElement(); - - $objWriter->startElement('c:spPr'); - $objWriter->startElement('a:solidFill'); - $objWriter->startElement('a:srgbClr'); - $objWriter->writeAttribute('val', 'FF9900'); - $objWriter->endElement(); - $objWriter->endElement(); - $objWriter->endElement(); - $objWriter->endElement(); - } - - // Labels - $plotSeriesLabel = $plotGroup->getPlotLabelByIndex($plotSeriesRef); - if ($plotSeriesLabel && ($plotSeriesLabel->getPointCount() > 0)) { - $objWriter->startElement('c:tx'); - $objWriter->startElement('c:strRef'); - $this->_writePlotSeriesLabel($plotSeriesLabel, $objWriter); - $objWriter->endElement(); - $objWriter->endElement(); - } - - // Formatting for the points - if (($groupType == PHPExcel_Chart_DataSeries::TYPE_LINECHART) || - ($groupType == PHPExcel_Chart_DataSeries::TYPE_STOCKCHART)) { - $objWriter->startElement('c:spPr'); - $objWriter->startElement('a:ln'); - $objWriter->writeAttribute('w', 12700); - if ($groupType == PHPExcel_Chart_DataSeries::TYPE_STOCKCHART) { - $objWriter->startElement('a:noFill'); - $objWriter->endElement(); - } - $objWriter->endElement(); - $objWriter->endElement(); - } - - $plotSeriesValues = $plotGroup->getPlotValuesByIndex($plotSeriesRef); - if ($plotSeriesValues) { - $plotSeriesMarker = $plotSeriesValues->getPointMarker(); - if ($plotSeriesMarker) { - $objWriter->startElement('c:marker'); - $objWriter->startElement('c:symbol'); - $objWriter->writeAttribute('val', $plotSeriesMarker); - $objWriter->endElement(); - - if ($plotSeriesMarker !== 'none') { - $objWriter->startElement('c:size'); - $objWriter->writeAttribute('val', 3); - $objWriter->endElement(); - } - $objWriter->endElement(); - } - } - - if (($groupType === PHPExcel_Chart_DataSeries::TYPE_BARCHART) || - ($groupType === PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D) || - ($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART)) { - - $objWriter->startElement('c:invertIfNegative'); - $objWriter->writeAttribute('val', 0); - $objWriter->endElement(); - } - - // Category Labels - $plotSeriesCategory = $plotGroup->getPlotCategoryByIndex($plotSeriesRef); - if ($plotSeriesCategory && ($plotSeriesCategory->getPointCount() > 0)) { - $catIsMultiLevelSeries = $catIsMultiLevelSeries || $plotSeriesCategory->isMultiLevelSeries(); - - if (($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART) || - ($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) || - ($groupType == PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) { - - if (!is_null($plotGroup->getPlotStyle())) { - $plotStyle = $plotGroup->getPlotStyle(); - if ($plotStyle) { - $objWriter->startElement('c:explosion'); - $objWriter->writeAttribute('val', 25); - $objWriter->endElement(); - } - } - } - - if (($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) || - ($groupType === PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART)) { - $objWriter->startElement('c:xVal'); - } else { - $objWriter->startElement('c:cat'); - } - - $this->_writePlotSeriesValues($plotSeriesCategory, $objWriter, $groupType, 'str', $pSheet); - $objWriter->endElement(); - } - - // Values - if ($plotSeriesValues) { - $valIsMultiLevelSeries = $valIsMultiLevelSeries || $plotSeriesValues->isMultiLevelSeries(); - - if (($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) || - ($groupType === PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART)) { - $objWriter->startElement('c:yVal'); - } else { - $objWriter->startElement('c:val'); - } - - $this->_writePlotSeriesValues($plotSeriesValues, $objWriter, $groupType, 'num', $pSheet); - $objWriter->endElement(); - } - - if ($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) { - $this->_writeBubbles($plotSeriesValues, $objWriter, $pSheet); - } - - $objWriter->endElement(); - - } - - $this->_seriesIndex += $plotSeriesIdx + 1; - } - - /** - * Write Plot Series Label - * - * @param PHPExcel_Chart_DataSeriesValues $plotSeriesLabel - * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer - * @throws PHPExcel_Writer_Exception - */ - private function _writePlotSeriesLabel($plotSeriesLabel, $objWriter) - { - if (is_null($plotSeriesLabel)) { - return; - } - - $objWriter->startElement('c:f'); - $objWriter->writeRawData($plotSeriesLabel->getDataSource()); - $objWriter->endElement(); - - $objWriter->startElement('c:strCache'); - $objWriter->startElement('c:ptCount'); - $objWriter->writeAttribute('val', $plotSeriesLabel->getPointCount() ); - $objWriter->endElement(); - - foreach($plotSeriesLabel->getDataValues() as $plotLabelKey => $plotLabelValue) { - $objWriter->startElement('c:pt'); - $objWriter->writeAttribute('idx', $plotLabelKey ); - - $objWriter->startElement('c:v'); - $objWriter->writeRawData( $plotLabelValue ); - $objWriter->endElement(); - $objWriter->endElement(); - } - $objWriter->endElement(); - - } - - /** - * Write Plot Series Values - * - * @param PHPExcel_Chart_DataSeriesValues $plotSeriesValues - * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer - * @param string $groupType Type of plot for dataseries - * @param string $dataType Datatype of series values - * @param PHPExcel_Worksheet $pSheet - * @throws PHPExcel_Writer_Exception - */ - private function _writePlotSeriesValues( $plotSeriesValues, - $objWriter, - $groupType, - $dataType='str', - PHPExcel_Worksheet $pSheet - ) - { - if (is_null($plotSeriesValues)) { - return; - } - - if ($plotSeriesValues->isMultiLevelSeries()) { - $levelCount = $plotSeriesValues->multiLevelCount(); - - $objWriter->startElement('c:multiLvlStrRef'); - - $objWriter->startElement('c:f'); - $objWriter->writeRawData( $plotSeriesValues->getDataSource() ); - $objWriter->endElement(); - - $objWriter->startElement('c:multiLvlStrCache'); - - $objWriter->startElement('c:ptCount'); - $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount() ); - $objWriter->endElement(); - - for ($level = 0; $level < $levelCount; ++$level) { - $objWriter->startElement('c:lvl'); - - foreach($plotSeriesValues->getDataValues() as $plotSeriesKey => $plotSeriesValue) { - if (isset($plotSeriesValue[$level])) { - $objWriter->startElement('c:pt'); - $objWriter->writeAttribute('idx', $plotSeriesKey ); - - $objWriter->startElement('c:v'); - $objWriter->writeRawData( $plotSeriesValue[$level] ); - $objWriter->endElement(); - $objWriter->endElement(); - } - } - - $objWriter->endElement(); - } - - $objWriter->endElement(); - - $objWriter->endElement(); - } else { - $objWriter->startElement('c:'.$dataType.'Ref'); - - $objWriter->startElement('c:f'); - $objWriter->writeRawData( $plotSeriesValues->getDataSource() ); - $objWriter->endElement(); - - $objWriter->startElement('c:'.$dataType.'Cache'); - - if (($groupType != PHPExcel_Chart_DataSeries::TYPE_PIECHART) && - ($groupType != PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) && - ($groupType != PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) { - - if (($plotSeriesValues->getFormatCode() !== NULL) && - ($plotSeriesValues->getFormatCode() !== '')) { - $objWriter->startElement('c:formatCode'); - $objWriter->writeRawData( $plotSeriesValues->getFormatCode() ); - $objWriter->endElement(); - } - } - - $objWriter->startElement('c:ptCount'); - $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount() ); - $objWriter->endElement(); - - $dataValues = $plotSeriesValues->getDataValues(); - if (!empty($dataValues)) { - if (is_array($dataValues)) { - foreach($dataValues as $plotSeriesKey => $plotSeriesValue) { - $objWriter->startElement('c:pt'); - $objWriter->writeAttribute('idx', $plotSeriesKey ); - - $objWriter->startElement('c:v'); - $objWriter->writeRawData( $plotSeriesValue ); - $objWriter->endElement(); - $objWriter->endElement(); - } - } - } - - $objWriter->endElement(); - - $objWriter->endElement(); - } - } - - /** - * Write Bubble Chart Details - * - * @param PHPExcel_Chart_DataSeriesValues $plotSeriesValues - * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer - * @throws PHPExcel_Writer_Exception - */ - private function _writeBubbles($plotSeriesValues, $objWriter, PHPExcel_Worksheet $pSheet) - { - if (is_null($plotSeriesValues)) { - return; - } - - $objWriter->startElement('c:bubbleSize'); - $objWriter->startElement('c:numLit'); - - $objWriter->startElement('c:formatCode'); - $objWriter->writeRawData( 'General' ); - $objWriter->endElement(); - - $objWriter->startElement('c:ptCount'); - $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount() ); - $objWriter->endElement(); - - $dataValues = $plotSeriesValues->getDataValues(); - if (!empty($dataValues)) { - if (is_array($dataValues)) { - foreach($dataValues as $plotSeriesKey => $plotSeriesValue) { - $objWriter->startElement('c:pt'); - $objWriter->writeAttribute('idx', $plotSeriesKey ); - $objWriter->startElement('c:v'); - $objWriter->writeRawData( 1 ); - $objWriter->endElement(); - $objWriter->endElement(); - } - } - } - - $objWriter->endElement(); - $objWriter->endElement(); - - $objWriter->startElement('c:bubble3D'); - $objWriter->writeAttribute('val', 0 ); - $objWriter->endElement(); - } - - /** - * Write Layout - * - * @param PHPExcel_Chart_Layout $layout - * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer - * @throws PHPExcel_Writer_Exception - */ - private function _writeLayout(PHPExcel_Chart_Layout $layout = NULL, $objWriter) - { - $objWriter->startElement('c:layout'); - - if (!is_null($layout)) { - $objWriter->startElement('c:manualLayout'); - - $layoutTarget = $layout->getLayoutTarget(); - if (!is_null($layoutTarget)) { - $objWriter->startElement('c:layoutTarget'); - $objWriter->writeAttribute('val', $layoutTarget); - $objWriter->endElement(); - } - - $xMode = $layout->getXMode(); - if (!is_null($xMode)) { - $objWriter->startElement('c:xMode'); - $objWriter->writeAttribute('val', $xMode); - $objWriter->endElement(); - } - - $yMode = $layout->getYMode(); - if (!is_null($yMode)) { - $objWriter->startElement('c:yMode'); - $objWriter->writeAttribute('val', $yMode); - $objWriter->endElement(); - } - - $x = $layout->getXPosition(); - if (!is_null($x)) { - $objWriter->startElement('c:x'); - $objWriter->writeAttribute('val', $x); - $objWriter->endElement(); - } - - $y = $layout->getYPosition(); - if (!is_null($y)) { - $objWriter->startElement('c:y'); - $objWriter->writeAttribute('val', $y); - $objWriter->endElement(); - } - - $w = $layout->getWidth(); - if (!is_null($w)) { - $objWriter->startElement('c:w'); - $objWriter->writeAttribute('val', $w); - $objWriter->endElement(); - } - - $h = $layout->getHeight(); - if (!is_null($h)) { - $objWriter->startElement('c:h'); - $objWriter->writeAttribute('val', $h); - $objWriter->endElement(); - } - - $objWriter->endElement(); - } - - $objWriter->endElement(); - } - - /** - * Write Alternate Content block - * - * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer - * @throws PHPExcel_Writer_Exception - */ - private function _writeAlternateContent($objWriter) - { - $objWriter->startElement('mc:AlternateContent'); - $objWriter->writeAttribute('xmlns:mc', 'http://schemas.openxmlformats.org/markup-compatibility/2006'); - - $objWriter->startElement('mc:Choice'); - $objWriter->writeAttribute('xmlns:c14', 'http://schemas.microsoft.com/office/drawing/2007/8/2/chart'); - $objWriter->writeAttribute('Requires', 'c14'); - - $objWriter->startElement('c14:style'); - $objWriter->writeAttribute('val', '102'); - $objWriter->endElement(); - $objWriter->endElement(); - - $objWriter->startElement('mc:Fallback'); - $objWriter->startElement('c:style'); - $objWriter->writeAttribute('val', '2'); - $objWriter->endElement(); - $objWriter->endElement(); - - $objWriter->endElement(); - } - - /** - * Write Printer Settings - * - * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer - * @throws PHPExcel_Writer_Exception - */ - private function _writePrintSettings($objWriter) - { - $objWriter->startElement('c:printSettings'); - - $objWriter->startElement('c:headerFooter'); - $objWriter->endElement(); - - $objWriter->startElement('c:pageMargins'); - $objWriter->writeAttribute('footer', 0.3); - $objWriter->writeAttribute('header', 0.3); - $objWriter->writeAttribute('r', 0.7); - $objWriter->writeAttribute('l', 0.7); - $objWriter->writeAttribute('t', 0.75); - $objWriter->writeAttribute('b', 0.75); - $objWriter->endElement(); - - $objWriter->startElement('c:pageSetup'); - $objWriter->writeAttribute('orientation', "portrait"); - $objWriter->endElement(); - - $objWriter->endElement(); - } +class PHPExcel_Writer_Excel2007_Chart extends + PHPExcel_Writer_Excel2007_WriterPart { + + /** + * Write charts to XML format + * + * @param PHPExcel_Chart $pChart + * + * @return string XML Output + * @throws PHPExcel_Writer_Exception + */ + public function writeChart(PHPExcel_Chart $pChart = NULL) { + // Create XML writer + $objWriter = NULL; + if ($this->getParentWriter() + ->getUseDiskCaching() + ) { + $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter() + ->getDiskCachingDirectory()); + } else { + $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); + } + // Ensure that data series values are up-to-date before we save + $pChart->refresh(); + + // XML header + $objWriter->startDocument('1.0', 'UTF-8', 'yes'); + + // c:chartSpace + $objWriter->startElement('c:chartSpace'); + $objWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart'); + $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main'); + $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); + + $objWriter->startElement('c:date1904'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + $objWriter->startElement('c:lang'); + $objWriter->writeAttribute('val', "en-GB"); + $objWriter->endElement(); + $objWriter->startElement('c:roundedCorners'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + + $this->_writeAlternateContent($objWriter); + + $objWriter->startElement('c:chart'); + + $this->_writeTitle($pChart->getTitle(), $objWriter); + + $objWriter->startElement('c:autoTitleDeleted'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + + $this->_writePlotArea( + $pChart->getPlotArea(), + $pChart->getXAxisLabel(), + $pChart->getYAxisLabel(), + $objWriter, + $pChart->getWorksheet(), + $pChart->getChartAxisX(), + $pChart->getChartAxisY(), + $pChart->getMajorGridlines(), + $pChart->getMinorGridlines() + ); + + $this->_writeLegend($pChart->getLegend(), $objWriter); + + $objWriter->startElement('c:plotVisOnly'); + $objWriter->writeAttribute('val', 1); + $objWriter->endElement(); + + $objWriter->startElement('c:dispBlanksAs'); + $objWriter->writeAttribute('val', "gap"); + $objWriter->endElement(); + + $objWriter->startElement('c:showDLblsOverMax'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + + $objWriter->endElement(); + + $this->_writePrintSettings($objWriter); + + $objWriter->endElement(); + + // Return + return $objWriter->getData(); + } + + /** + * Write Chart Title + * + * @param PHPExcel_Chart_Title $title + * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer + * + * @throws PHPExcel_Writer_Exception + */ + private function _writeTitle(PHPExcel_Chart_Title $title = NULL, $objWriter) { + if (is_null($title)) { + return; + } + + $objWriter->startElement('c:title'); + $objWriter->startElement('c:tx'); + $objWriter->startElement('c:rich'); + + $objWriter->startElement('a:bodyPr'); + $objWriter->endElement(); + + $objWriter->startElement('a:lstStyle'); + $objWriter->endElement(); + + $objWriter->startElement('a:p'); + + $caption = $title->getCaption(); + if ((is_array($caption)) && (count($caption) > 0)) { + $caption = $caption[0]; + } + $this->getParentWriter() + ->getWriterPart('stringtable') + ->writeRichTextForCharts($objWriter, $caption, 'a'); + + $objWriter->endElement(); + $objWriter->endElement(); + $objWriter->endElement(); + + $layout = $title->getLayout(); + $this->_writeLayout($layout, $objWriter); + + $objWriter->startElement('c:overlay'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + + $objWriter->endElement(); + } + + /** + * Write Chart Legend + * + * @param PHPExcel_Chart_Legend $legend + * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer + * + * @throws PHPExcel_Writer_Exception + */ + private function _writeLegend(PHPExcel_Chart_Legend $legend = NULL, $objWriter) { + if (is_null($legend)) { + return; + } + + $objWriter->startElement('c:legend'); + + $objWriter->startElement('c:legendPos'); + $objWriter->writeAttribute('val', $legend->getPosition()); + $objWriter->endElement(); + + $layout = $legend->getLayout(); + $this->_writeLayout($layout, $objWriter); + + $objWriter->startElement('c:overlay'); + $objWriter->writeAttribute('val', ($legend->getOverlay()) ? '1' : '0'); + $objWriter->endElement(); + + $objWriter->startElement('c:txPr'); + $objWriter->startElement('a:bodyPr'); + $objWriter->endElement(); + + $objWriter->startElement('a:lstStyle'); + $objWriter->endElement(); + + $objWriter->startElement('a:p'); + $objWriter->startElement('a:pPr'); + $objWriter->writeAttribute('rtl', 0); + + $objWriter->startElement('a:defRPr'); + $objWriter->endElement(); + $objWriter->endElement(); + + $objWriter->startElement('a:endParaRPr'); + $objWriter->writeAttribute('lang', "en-US"); + $objWriter->endElement(); + + $objWriter->endElement(); + $objWriter->endElement(); + + $objWriter->endElement(); + } + + /** + * Write Chart Plot Area + * + * @param PHPExcel_Chart_PlotArea $plotArea + * @param PHPExcel_Chart_Title $xAxisLabel + * @param PHPExcel_Chart_Title $yAxisLabel + * @param PHPExcel_Chart_Axis $xAxis + * @param PHPExcel_Chart_Axis $yAxis + * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer + * + * @throws PHPExcel_Writer_Exception + */ + private function _writePlotArea(PHPExcel_Chart_PlotArea $plotArea, + PHPExcel_Chart_Title $xAxisLabel = NULL, + PHPExcel_Chart_Title $yAxisLabel = NULL, + $objWriter, + PHPExcel_Worksheet $pSheet, + PHPExcel_Chart_Axis $xAxis, + PHPExcel_Chart_Axis $yAxis, + PHPExcel_Chart_Gridlines $majorGridlines, + PHPExcel_Chart_Gridlines $minorGridlines + ) { + if (is_null($plotArea)) { + return; + } + + $id1 = $id2 = 0; + $this->_seriesIndex = 0; + $objWriter->startElement('c:plotArea'); + + $layout = $plotArea->getLayout(); + + $this->_writeLayout($layout, $objWriter); + + $chartTypes = self::_getChartType($plotArea); + $catIsMultiLevelSeries = $valIsMultiLevelSeries = FALSE; + $plotGroupingType = ''; + foreach ($chartTypes as $chartType) { + $objWriter->startElement('c:' . $chartType); + + $groupCount = $plotArea->getPlotGroupCount(); + for ($i = 0; $i < $groupCount; ++$i) { + $plotGroup = $plotArea->getPlotGroupByIndex($i); + $groupType = $plotGroup->getPlotType(); + if ($groupType == $chartType) { + + $plotStyle = $plotGroup->getPlotStyle(); + if ($groupType === PHPExcel_Chart_DataSeries::TYPE_RADARCHART) { + $objWriter->startElement('c:radarStyle'); + $objWriter->writeAttribute('val', $plotStyle); + $objWriter->endElement(); + } elseif ($groupType === PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART) { + $objWriter->startElement('c:scatterStyle'); + $objWriter->writeAttribute('val', $plotStyle); + $objWriter->endElement(); + } + + $this->_writePlotGroup($plotGroup, $chartType, $objWriter, $catIsMultiLevelSeries, $valIsMultiLevelSeries, $plotGroupingType, $pSheet); + } + } + + $this->_writeDataLbls($objWriter, $layout); + + if ($chartType === PHPExcel_Chart_DataSeries::TYPE_LINECHART) { + // Line only, Line3D can't be smoothed + + $objWriter->startElement('c:smooth'); + $objWriter->writeAttribute('val', (integer) $plotGroup->getSmoothLine()); + $objWriter->endElement(); + } elseif (($chartType === PHPExcel_Chart_DataSeries::TYPE_BARCHART) || + ($chartType === PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D) + ) { + + $objWriter->startElement('c:gapWidth'); + $objWriter->writeAttribute('val', 150); + $objWriter->endElement(); + + if ($plotGroupingType == 'percentStacked' || + $plotGroupingType == 'stacked' + ) { + + $objWriter->startElement('c:overlap'); + $objWriter->writeAttribute('val', 100); + $objWriter->endElement(); + } + } elseif ($chartType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) { + + $objWriter->startElement('c:bubbleScale'); + $objWriter->writeAttribute('val', 25); + $objWriter->endElement(); + + $objWriter->startElement('c:showNegBubbles'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + } elseif ($chartType === PHPExcel_Chart_DataSeries::TYPE_STOCKCHART) { + + $objWriter->startElement('c:hiLowLines'); + $objWriter->endElement(); + + $objWriter->startElement('c:upDownBars'); + + $objWriter->startElement('c:gapWidth'); + $objWriter->writeAttribute('val', 300); + $objWriter->endElement(); + + $objWriter->startElement('c:upBars'); + $objWriter->endElement(); + + $objWriter->startElement('c:downBars'); + $objWriter->endElement(); + + $objWriter->endElement(); + } + + // Generate 2 unique numbers to use for axId values + // $id1 = $id2 = rand(10000000,99999999); + // do { + // $id2 = rand(10000000,99999999); + // } while ($id1 == $id2); + $id1 = '75091328'; + $id2 = '75089408'; + + if (($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART) && + ($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) && + ($chartType !== PHPExcel_Chart_DataSeries::TYPE_DONUTCHART) + ) { + + $objWriter->startElement('c:axId'); + $objWriter->writeAttribute('val', $id1); + $objWriter->endElement(); + $objWriter->startElement('c:axId'); + $objWriter->writeAttribute('val', $id2); + $objWriter->endElement(); + } else { + $objWriter->startElement('c:firstSliceAng'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + + if ($chartType === PHPExcel_Chart_DataSeries::TYPE_DONUTCHART) { + + $objWriter->startElement('c:holeSize'); + $objWriter->writeAttribute('val', 50); + $objWriter->endElement(); + } + } + + $objWriter->endElement(); + } + + if (($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART) && + ($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) && + ($chartType !== PHPExcel_Chart_DataSeries::TYPE_DONUTCHART) + ) { + + if ($chartType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) { + $this->_writeValAx($objWriter, $plotArea, $xAxisLabel, $chartType, $id1, $id2, $catIsMultiLevelSeries, $xAxis, $yAxis, $majorGridlines, $minorGridlines); + } else { + $this->_writeCatAx($objWriter, $plotArea, $xAxisLabel, $chartType, $id1, $id2, $catIsMultiLevelSeries, $xAxis, $yAxis); + } + + $this->_writeValAx($objWriter, $plotArea, $yAxisLabel, $chartType, $id1, $id2, $valIsMultiLevelSeries, $xAxis, $yAxis, $majorGridlines, $minorGridlines); + } + + $objWriter->endElement(); + } + + /** + * Write Data Labels + * + * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer + * @param PHPExcel_Chart_Layout $chartLayout Chart layout + * + * @throws PHPExcel_Writer_Exception + */ + private function _writeDataLbls($objWriter, $chartLayout) { + $objWriter->startElement('c:dLbls'); + + $objWriter->startElement('c:showLegendKey'); + $showLegendKey = (empty($chartLayout)) ? 0 : $chartLayout->getShowLegendKey(); + $objWriter->writeAttribute('val', ((empty($showLegendKey)) ? 0 : 1)); + $objWriter->endElement(); + + $objWriter->startElement('c:showVal'); + $showVal = (empty($chartLayout)) ? 0 : $chartLayout->getShowVal(); + $objWriter->writeAttribute('val', ((empty($showVal)) ? 0 : 1)); + $objWriter->endElement(); + + $objWriter->startElement('c:showCatName'); + $showCatName = (empty($chartLayout)) ? 0 : $chartLayout->getShowCatName(); + $objWriter->writeAttribute('val', ((empty($showCatName)) ? 0 : 1)); + $objWriter->endElement(); + + $objWriter->startElement('c:showSerName'); + $showSerName = (empty($chartLayout)) ? 0 : $chartLayout->getShowSerName(); + $objWriter->writeAttribute('val', ((empty($showSerName)) ? 0 : 1)); + $objWriter->endElement(); + + $objWriter->startElement('c:showPercent'); + $showPercent = (empty($chartLayout)) ? 0 : $chartLayout->getShowPercent(); + $objWriter->writeAttribute('val', ((empty($showPercent)) ? 0 : 1)); + $objWriter->endElement(); + + $objWriter->startElement('c:showBubbleSize'); + $showBubbleSize = (empty($chartLayout)) ? 0 : $chartLayout->getShowBubbleSize(); + $objWriter->writeAttribute('val', ((empty($showBubbleSize)) ? 0 : 1)); + $objWriter->endElement(); + + $objWriter->startElement('c:showLeaderLines'); + $showLeaderLines = (empty($chartLayout)) ? 1 : $chartLayout->getShowLeaderLines(); + $objWriter->writeAttribute('val', ((empty($showLeaderLines)) ? 0 : 1)); + $objWriter->endElement(); + + $objWriter->endElement(); + } + + /** + * Write Category Axis + * + * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer + * @param PHPExcel_Chart_PlotArea $plotArea + * @param PHPExcel_Chart_Title $xAxisLabel + * @param string $groupType Chart type + * @param string $id1 + * @param string $id2 + * @param boolean $isMultiLevelSeries + * + * @throws PHPExcel_Writer_Exception + */ + private function _writeCatAx($objWriter, PHPExcel_Chart_PlotArea $plotArea, $xAxisLabel, $groupType, $id1, $id2, $isMultiLevelSeries, $xAxis, $yAxis) { + $objWriter->startElement('c:catAx'); + + if ($id1 > 0) { + $objWriter->startElement('c:axId'); + $objWriter->writeAttribute('val', $id1); + $objWriter->endElement(); + } + + $objWriter->startElement('c:scaling'); + $objWriter->startElement('c:orientation'); + $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('orientation')); + $objWriter->endElement(); + $objWriter->endElement(); + + $objWriter->startElement('c:delete'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + + $objWriter->startElement('c:axPos'); + $objWriter->writeAttribute('val', "b"); + $objWriter->endElement(); + + if (!is_null($xAxisLabel)) { + $objWriter->startElement('c:title'); + $objWriter->startElement('c:tx'); + $objWriter->startElement('c:rich'); + + $objWriter->startElement('a:bodyPr'); + $objWriter->endElement(); + + $objWriter->startElement('a:lstStyle'); + $objWriter->endElement(); + + $objWriter->startElement('a:p'); + $objWriter->startElement('a:r'); + + $caption = $xAxisLabel->getCaption(); + if (is_array($caption)) { + $caption = $caption[0]; + } + $objWriter->startElement('a:t'); + // $objWriter->writeAttribute('xml:space', 'preserve'); + $objWriter->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML($caption)); + $objWriter->endElement(); + + $objWriter->endElement(); + $objWriter->endElement(); + $objWriter->endElement(); + $objWriter->endElement(); + + $layout = $xAxisLabel->getLayout(); + $this->_writeLayout($layout, $objWriter); + + $objWriter->startElement('c:overlay'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + + $objWriter->endElement(); + + } + + $objWriter->startElement('c:numFmt'); + $objWriter->writeAttribute('formatCode', $yAxis->getAxisNumberFormat()); + $objWriter->writeAttribute('sourceLinked', $yAxis->getAxisNumberSourceLinked()); + $objWriter->endElement(); + + $objWriter->startElement('c:majorTickMark'); + $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('major_tick_mark')); + $objWriter->endElement(); + + $objWriter->startElement('c:minorTickMark'); + $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('minor_tick_mark')); + $objWriter->endElement(); + + $objWriter->startElement('c:tickLblPos'); + $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('axis_labels')); + $objWriter->endElement(); + + if ($id2 > 0) { + $objWriter->startElement('c:crossAx'); + $objWriter->writeAttribute('val', $id2); + $objWriter->endElement(); + + $objWriter->startElement('c:crosses'); + $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('horizontal_crosses')); + $objWriter->endElement(); + } + + $objWriter->startElement('c:auto'); + $objWriter->writeAttribute('val', 1); + $objWriter->endElement(); + + $objWriter->startElement('c:lblAlgn'); + $objWriter->writeAttribute('val', "ctr"); + $objWriter->endElement(); + + $objWriter->startElement('c:lblOffset'); + $objWriter->writeAttribute('val', 100); + $objWriter->endElement(); + + if ($isMultiLevelSeries) { + $objWriter->startElement('c:noMultiLvlLbl'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + } + $objWriter->endElement(); + } + + /** + * Write Value Axis + * + * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer + * @param PHPExcel_Chart_PlotArea $plotArea + * @param PHPExcel_Chart_Title $yAxisLabel + * @param string $groupType Chart type + * @param string $id1 + * @param string $id2 + * @param boolean $isMultiLevelSeries + * + * @throws PHPExcel_Writer_Exception + */ + private function _writeValAx($objWriter, PHPExcel_Chart_PlotArea $plotArea, $yAxisLabel, $groupType, $id1, $id2, $isMultiLevelSeries, $xAxis, $yAxis, $majorGridlines, $minorGridlines) { + $objWriter->startElement('c:valAx'); + + if ($id2 > 0) { + $objWriter->startElement('c:axId'); + $objWriter->writeAttribute('val', $id2); + $objWriter->endElement(); + } + + $objWriter->startElement('c:scaling'); + $objWriter->startElement('c:orientation'); + $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('orientation')); + + if (!is_null($xAxis->getAxisOptionsProperty('maximum'))) { + $objWriter->startElement('c:max'); + $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('maximum')); + $objWriter->endElement(); + } + + if (!is_null($xAxis->getAxisOptionsProperty('minimum'))) { + $objWriter->startElement('c:min'); + $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('minimum')); + $objWriter->endElement(); + } + + $objWriter->endElement(); + $objWriter->endElement(); + + $objWriter->startElement('c:delete'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + + $objWriter->startElement('c:axPos'); + $objWriter->writeAttribute('val', "l"); + $objWriter->endElement(); + + $objWriter->startElement('c:majorGridlines'); + $objWriter->startElement('c:spPr'); + + if (!is_null($majorGridlines->getLineColorProperty('value'))) { + $objWriter->startElement('a:ln'); + $objWriter->writeAttribute('w', $majorGridlines->getLineStyleProperty('width')); + $objWriter->startElement('a:solidFill'); + $objWriter->startElement("a:{$majorGridlines->getLineColorProperty('type')}"); + $objWriter->writeAttribute('val', $majorGridlines->getLineColorProperty('value')); + $objWriter->startElement('a:alpha'); + $objWriter->writeAttribute('val', $majorGridlines->getLineColorProperty('alpha')); + $objWriter->endElement(); //end alpha + $objWriter->endElement(); //end srgbClr + $objWriter->endElement(); //end solidFill + + $objWriter->startElement('a:prstDash'); + $objWriter->writeAttribute('val', $majorGridlines->getLineStyleProperty('dash')); + $objWriter->endElement(); + + if ($majorGridlines->getLineStyleProperty('join') == 'miter') { + $objWriter->startElement('a:miter'); + $objWriter->writeAttribute('lim', '800000'); + $objWriter->endElement(); + } else { + $objWriter->startElement('a:bevel'); + $objWriter->endElement(); + } + + if (!is_null($majorGridlines->getLineStyleProperty(['arrow', 'head', 'type']))) { + $objWriter->startElement('a:headEnd'); + $objWriter->writeAttribute('type', $majorGridlines->getLineStyleProperty(['arrow', 'head', 'type'])); + $objWriter->writeAttribute('w', $majorGridlines->getLineStyleArrowParameters('head', 'w')); + $objWriter->writeAttribute('len', $majorGridlines->getLineStyleArrowParameters('head', 'len')); + $objWriter->endElement(); + } + + if (!is_null($majorGridlines->getLineStyleProperty(['arrow', 'end', 'type']))) { + $objWriter->startElement('a:tailEnd'); + $objWriter->writeAttribute('type', $majorGridlines->getLineStyleProperty(['arrow', 'end', 'type'])); + $objWriter->writeAttribute('w', $majorGridlines->getLineStyleArrowParameters('end', 'w')); + $objWriter->writeAttribute('len', $majorGridlines->getLineStyleArrowParameters('end', 'len')); + $objWriter->endElement(); + } + $objWriter->endElement(); //end ln + } + $objWriter->startElement('a:effectLst'); + + if (!is_null($majorGridlines->getGlowSize())) { + $objWriter->startElement('a:glow'); + $objWriter->writeAttribute('rad', $majorGridlines->getGlowSize()); + $objWriter->startElement("a:{$majorGridlines->getGlowColor('type')}"); + $objWriter->writeAttribute('val', $majorGridlines->getGlowColor('value')); + $objWriter->startElement('a:alpha'); + $objWriter->writeAttribute('val', $majorGridlines->getGlowColor('alpha')); + $objWriter->endElement(); //end alpha + $objWriter->endElement(); //end schemeClr + $objWriter->endElement(); //end glow + } + + if (!is_null($majorGridlines->getShadowProperty('presets'))) { + $objWriter->startElement("a:{$majorGridlines->getShadowProperty('effect')}"); + if (!is_null($majorGridlines->getShadowProperty('blur'))) { + $objWriter->writeAttribute('blurRad', $majorGridlines->getShadowProperty('blur')); + } + if (!is_null($majorGridlines->getShadowProperty('distance'))) { + $objWriter->writeAttribute('dist', $majorGridlines->getShadowProperty('distance')); + } + if (!is_null($majorGridlines->getShadowProperty('direction'))) { + $objWriter->writeAttribute('dir', $majorGridlines->getShadowProperty('direction')); + } + if (!is_null($majorGridlines->getShadowProperty('algn'))) { + $objWriter->writeAttribute('algn', $majorGridlines->getShadowProperty('algn')); + } + if (!is_null($majorGridlines->getShadowProperty(['size', 'sx']))) { + $objWriter->writeAttribute('sx', $majorGridlines->getShadowProperty(['size', 'sx'])); + } + if (!is_null($majorGridlines->getShadowProperty(['size', 'sy']))) { + $objWriter->writeAttribute('sy', $majorGridlines->getShadowProperty(['size', 'sy'])); + } + if (!is_null($majorGridlines->getShadowProperty(['size', 'kx']))) { + $objWriter->writeAttribute('kx', $majorGridlines->getShadowProperty(['size', 'kx'])); + } + if (!is_null($majorGridlines->getShadowProperty('rotWithShape'))) { + $objWriter->writeAttribute('rotWithShape', $majorGridlines->getShadowProperty('rotWithShape')); + } + $objWriter->startElement("a:{$majorGridlines->getShadowProperty(['color', 'type'])}"); + $objWriter->writeAttribute('val', $majorGridlines->getShadowProperty(['color', 'value'])); + + $objWriter->startElement('a:alpha'); + $objWriter->writeAttribute('val', $majorGridlines->getShadowProperty(['color', 'alpha'])); + $objWriter->endElement(); //end alpha + + $objWriter->endElement(); //end color:type + $objWriter->endElement(); //end shadow + } + + if (!is_null($majorGridlines->getSoftEdgesSize())) { + $objWriter->startElement('a:softEdge'); + $objWriter->writeAttribute('rad', $majorGridlines->getSoftEdgesSize()); + $objWriter->endElement(); //end softEdge + } + + $objWriter->endElement(); //end effectLst + $objWriter->endElement(); //end spPr + $objWriter->endElement(); //end majorGridLines + + if ($minorGridlines->getObjectState()) { + $objWriter->startElement('c:minorGridlines'); + $objWriter->startElement('c:spPr'); + + if (!is_null($minorGridlines->getLineColorProperty('value'))) { + $objWriter->startElement('a:ln'); + $objWriter->writeAttribute('w', $minorGridlines->getLineStyleProperty('width')); + $objWriter->startElement('a:solidFill'); + $objWriter->startElement("a:{$minorGridlines->getLineColorProperty('type')}"); + $objWriter->writeAttribute('val', $minorGridlines->getLineColorProperty('value')); + $objWriter->startElement('a:alpha'); + $objWriter->writeAttribute('val', $minorGridlines->getLineColorProperty('alpha')); + $objWriter->endElement(); //end alpha + $objWriter->endElement(); //end srgbClr + $objWriter->endElement(); //end solidFill + + $objWriter->startElement('a:prstDash'); + $objWriter->writeAttribute('val', $minorGridlines->getLineStyleProperty('dash')); + $objWriter->endElement(); + + if ($minorGridlines->getLineStyleProperty('join') == 'miter') { + $objWriter->startElement('a:miter'); + $objWriter->writeAttribute('lim', '800000'); + $objWriter->endElement(); + } else { + $objWriter->startElement('a:bevel'); + $objWriter->endElement(); + } + + if (!is_null($minorGridlines->getLineStyleProperty(['arrow', 'head', 'type']))) { + $objWriter->startElement('a:headEnd'); + $objWriter->writeAttribute('type', $minorGridlines->getLineStyleProperty(['arrow', 'head', 'type'])); + $objWriter->writeAttribute('w', $minorGridlines->getLineStyleArrowParameters('head', 'w')); + $objWriter->writeAttribute('len', $minorGridlines->getLineStyleArrowParameters('head', 'len')); + $objWriter->endElement(); + } + + if (!is_null($minorGridlines->getLineStyleProperty(['arrow', 'end', 'type']))) { + $objWriter->startElement('a:tailEnd'); + $objWriter->writeAttribute('type', $minorGridlines->getLineStyleProperty(['arrow', 'end', 'type'])); + $objWriter->writeAttribute('w', $minorGridlines->getLineStyleArrowParameters('end', 'w')); + $objWriter->writeAttribute('len', $minorGridlines->getLineStyleArrowParameters('end', 'len')); + $objWriter->endElement(); + } + $objWriter->endElement(); //end ln + } + + $objWriter->startElement('a:effectLst'); + + if (!is_null($minorGridlines->getGlowSize())) { + $objWriter->startElement('a:glow'); + $objWriter->writeAttribute('rad', $minorGridlines->getGlowSize()); + $objWriter->startElement("a:{$minorGridlines->getGlowColor('type')}"); + $objWriter->writeAttribute('val', $minorGridlines->getGlowColor('value')); + $objWriter->startElement('a:alpha'); + $objWriter->writeAttribute('val', $minorGridlines->getGlowColor('alpha')); + $objWriter->endElement(); //end alpha + $objWriter->endElement(); //end schemeClr + $objWriter->endElement(); //end glow + } + + if (!is_null($minorGridlines->getShadowProperty('presets'))) { + $objWriter->startElement("a:{$minorGridlines->getShadowProperty('effect')}"); + if (!is_null($minorGridlines->getShadowProperty('blur'))) { + $objWriter->writeAttribute('blurRad', $minorGridlines->getShadowProperty('blur')); + } + if (!is_null($minorGridlines->getShadowProperty('distance'))) { + $objWriter->writeAttribute('dist', $minorGridlines->getShadowProperty('distance')); + } + if (!is_null($minorGridlines->getShadowProperty('direction'))) { + $objWriter->writeAttribute('dir', $minorGridlines->getShadowProperty('direction')); + } + if (!is_null($minorGridlines->getShadowProperty('algn'))) { + $objWriter->writeAttribute('algn', $minorGridlines->getShadowProperty('algn')); + } + if (!is_null($minorGridlines->getShadowProperty(['size', 'sx']))) { + $objWriter->writeAttribute('sx', $minorGridlines->getShadowProperty(['size', 'sx'])); + } + if (!is_null($minorGridlines->getShadowProperty(['size', 'sy']))) { + $objWriter->writeAttribute('sy', $minorGridlines->getShadowProperty(['size', 'sy'])); + } + if (!is_null($minorGridlines->getShadowProperty(['size', 'kx']))) { + $objWriter->writeAttribute('kx', $minorGridlines->getShadowProperty(['size', 'kx'])); + } + if (!is_null($minorGridlines->getShadowProperty('rotWithShape'))) { + $objWriter->writeAttribute('rotWithShape', $minorGridlines->getShadowProperty('rotWithShape')); + } + $objWriter->startElement("a:{$minorGridlines->getShadowProperty(['color', 'type'])}"); + $objWriter->writeAttribute('val', $minorGridlines->getShadowProperty(['color', 'value'])); + $objWriter->startElement('a:alpha'); + $objWriter->writeAttribute('val', $minorGridlines->getShadowProperty(['color', 'alpha'])); + $objWriter->endElement(); //end alpha + $objWriter->endElement(); //end color:type + $objWriter->endElement(); //end shadow + } + + if (!is_null($minorGridlines->getSoftEdgesSize())) { + $objWriter->startElement('a:softEdge'); + $objWriter->writeAttribute('rad', $minorGridlines->getSoftEdgesSize()); + $objWriter->endElement(); //end softEdge + } + + $objWriter->endElement(); //end effectLst + $objWriter->endElement(); //end spPr + $objWriter->endElement(); //end minorGridLines + } + + if (!is_null($yAxisLabel)) { + + $objWriter->startElement('c:title'); + $objWriter->startElement('c:tx'); + $objWriter->startElement('c:rich'); + + $objWriter->startElement('a:bodyPr'); + $objWriter->endElement(); + + $objWriter->startElement('a:lstStyle'); + $objWriter->endElement(); + + $objWriter->startElement('a:p'); + $objWriter->startElement('a:r'); + + $caption = $yAxisLabel->getCaption(); + if (is_array($caption)) { + $caption = $caption[0]; + } + + $objWriter->startElement('a:t'); + // $objWriter->writeAttribute('xml:space', 'preserve'); + $objWriter->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML($caption)); + $objWriter->endElement(); + + $objWriter->endElement(); + $objWriter->endElement(); + $objWriter->endElement(); + $objWriter->endElement(); + + if ($groupType !== PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) { + $layout = $yAxisLabel->getLayout(); + $this->_writeLayout($layout, $objWriter); + } + + $objWriter->startElement('c:overlay'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + + $objWriter->endElement(); + } + + $objWriter->startElement('c:numFmt'); + $objWriter->writeAttribute('formatCode', $xAxis->getAxisNumberFormat()); + $objWriter->writeAttribute('sourceLinked', $xAxis->getAxisNumberSourceLinked()); + $objWriter->endElement(); + + $objWriter->startElement('c:majorTickMark'); + $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('major_tick_mark')); + $objWriter->endElement(); + + $objWriter->startElement('c:minorTickMark'); + $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('minor_tick_mark')); + $objWriter->endElement(); + + $objWriter->startElement('c:tickLblPos'); + $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('axis_labels')); + $objWriter->endElement(); + + $objWriter->startElement('c:spPr'); + + if (!is_null($xAxis->getFillProperty('value'))) { + $objWriter->startElement('a:solidFill'); + $objWriter->startElement("a:" . $xAxis->getFillProperty('type')); + $objWriter->writeAttribute('val', $xAxis->getFillProperty('value')); + $objWriter->startElement('a:alpha'); + $objWriter->writeAttribute('val', $xAxis->getFillProperty('alpha')); + $objWriter->endElement(); + $objWriter->endElement(); + $objWriter->endElement(); + } + + $objWriter->startElement('a:ln'); + + $objWriter->writeAttribute('w', $xAxis->getLineStyleProperty('width')); + $objWriter->writeAttribute('cap', $xAxis->getLineStyleProperty('cap')); + $objWriter->writeAttribute('cmpd', $xAxis->getLineStyleProperty('compound')); + + if (!is_null($xAxis->getLineProperty('value'))) { + $objWriter->startElement('a:solidFill'); + $objWriter->startElement("a:" . $xAxis->getLineProperty('type')); + $objWriter->writeAttribute('val', $xAxis->getLineProperty('value')); + $objWriter->startElement('a:alpha'); + $objWriter->writeAttribute('val', $xAxis->getLineProperty('alpha')); + $objWriter->endElement(); + $objWriter->endElement(); + $objWriter->endElement(); + } + + $objWriter->startElement('a:prstDash'); + $objWriter->writeAttribute('val', $xAxis->getLineStyleProperty('dash')); + $objWriter->endElement(); + + if ($xAxis->getLineStyleProperty('join') == 'miter') { + $objWriter->startElement('a:miter'); + $objWriter->writeAttribute('lim', '800000'); + $objWriter->endElement(); + } else { + $objWriter->startElement('a:bevel'); + $objWriter->endElement(); + } + + if (!is_null($xAxis->getLineStyleProperty(['arrow', 'head', 'type']))) { + $objWriter->startElement('a:headEnd'); + $objWriter->writeAttribute('type', $xAxis->getLineStyleProperty(['arrow', 'head', 'type'])); + $objWriter->writeAttribute('w', $xAxis->getLineStyleArrowWidth('head')); + $objWriter->writeAttribute('len', $xAxis->getLineStyleArrowLength('head')); + $objWriter->endElement(); + } + + if (!is_null($xAxis->getLineStyleProperty(['arrow', 'end', 'type']))) { + $objWriter->startElement('a:tailEnd'); + $objWriter->writeAttribute('type', $xAxis->getLineStyleProperty(['arrow', 'end', 'type'])); + $objWriter->writeAttribute('w', $xAxis->getLineStyleArrowWidth('end')); + $objWriter->writeAttribute('len', $xAxis->getLineStyleArrowLength('end')); + $objWriter->endElement(); + } + + $objWriter->endElement(); + + $objWriter->startElement('a:effectLst'); + + if (!is_null($xAxis->getGlowProperty('size'))) { + $objWriter->startElement('a:glow'); + $objWriter->writeAttribute('rad', $xAxis->getGlowProperty('size')); + $objWriter->startElement("a:{$xAxis->getGlowProperty(['color','type'])}"); + $objWriter->writeAttribute('val', $xAxis->getGlowProperty(['color','value'])); + $objWriter->startElement('a:alpha'); + $objWriter->writeAttribute('val', $xAxis->getGlowProperty(['color','alpha'])); + $objWriter->endElement(); + $objWriter->endElement(); + $objWriter->endElement(); + } + + if (!is_null($xAxis->getShadowProperty('presets'))) { + $objWriter->startElement("a:{$xAxis->getShadowProperty('effect')}"); + + if (!is_null($xAxis->getShadowProperty('blur'))) { + $objWriter->writeAttribute('blurRad', $xAxis->getShadowProperty('blur')); + } + if (!is_null($xAxis->getShadowProperty('distance'))) { + $objWriter->writeAttribute('dist', $xAxis->getShadowProperty('distance')); + } + if (!is_null($xAxis->getShadowProperty('direction'))) { + $objWriter->writeAttribute('dir', $xAxis->getShadowProperty('direction')); + } + if (!is_null($xAxis->getShadowProperty('algn'))) { + $objWriter->writeAttribute('algn', $xAxis->getShadowProperty('algn')); + } + if (!is_null($xAxis->getShadowProperty(['size','sx']))) { + $objWriter->writeAttribute('sx', $xAxis->getShadowProperty(['size','sx'])); + } + if (!is_null($xAxis->getShadowProperty(['size','sy']))) { + $objWriter->writeAttribute('sy', $xAxis->getShadowProperty(['size','sy'])); + } + if (!is_null($xAxis->getShadowProperty(['size','kx']))) { + $objWriter->writeAttribute('kx', $xAxis->getShadowProperty(['size','kx'])); + } + if (!is_null($xAxis->getShadowProperty('rotWithShape'))) { + $objWriter->writeAttribute('rotWithShape', $xAxis->getShadowProperty('rotWithShape')); + } + + $objWriter->startElement("a:{$xAxis->getShadowProperty(['color','type'])}"); + $objWriter->writeAttribute('val', $xAxis->getShadowProperty(['color','value'])); + $objWriter->startElement('a:alpha'); + $objWriter->writeAttribute('val', $xAxis->getShadowProperty(['color','alpha'])); + $objWriter->endElement(); + $objWriter->endElement(); + + $objWriter->endElement(); + } + + if (!is_null($xAxis->getSoftEdgesSize())) { + $objWriter->startElement('a:softEdge'); + $objWriter->writeAttribute('rad', $xAxis->getSoftEdgesSize()); + $objWriter->endElement(); + } + + $objWriter->endElement(); //effectList + $objWriter->endElement(); //end spPr + + if ($id1 > 0) { + $objWriter->startElement('c:crossAx'); + $objWriter->writeAttribute('val', $id2); + $objWriter->endElement(); + + if (!is_null($xAxis->getAxisOptionsProperty('horizontal_crosses_value'))) { + $objWriter->startElement('c:crossesAt'); + $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('horizontal_crosses_value')); + $objWriter->endElement(); + } else { + $objWriter->startElement('c:crosses'); + $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('horizontal_crosses')); + $objWriter->endElement(); + } + + $objWriter->startElement('c:crossBetween'); + $objWriter->writeAttribute('val', "midCat"); + $objWriter->endElement(); + + if (!is_null($xAxis->getAxisOptionsProperty('major_unit'))) { + $objWriter->startElement('c:majorUnit'); + $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('major_unit')); + $objWriter->endElement(); + } + + if (!is_null($xAxis->getAxisOptionsProperty('minor_unit'))) { + $objWriter->startElement('c:minorUnit'); + $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('minor_unit')); + $objWriter->endElement(); + } + + } + + if ($isMultiLevelSeries) { + if ($groupType !== PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) { + $objWriter->startElement('c:noMultiLvlLbl'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + } + } + + $objWriter->endElement(); + + } + + /** + * Get the data series type(s) for a chart plot series + * + * @param PHPExcel_Chart_PlotArea $plotArea + * + * @return string|array + * @throws PHPExcel_Writer_Exception + */ + private + static function _getChartType($plotArea) { + $groupCount = $plotArea->getPlotGroupCount(); + + if ($groupCount == 1) { + $chartType = array( + $plotArea->getPlotGroupByIndex(0) + ->getPlotType() + ); + } else { + $chartTypes = array(); + for ($i = 0; $i < $groupCount; ++$i) { + $chartTypes[] = $plotArea->getPlotGroupByIndex($i) + ->getPlotType(); + } + $chartType = array_unique($chartTypes); + if (count($chartTypes) == 0) { + throw new PHPExcel_Writer_Exception('Chart is not yet implemented'); + } + } + + return $chartType; + } + + /** + * Write Plot Group (series of related plots) + * + * @param PHPExcel_Chart_DataSeries $plotGroup + * @param string $groupType Type of plot for dataseries + * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer + * @param boolean &$catIsMultiLevelSeries Is category a multi-series category + * @param boolean &$valIsMultiLevelSeries Is value set a multi-series set + * @param string &$plotGroupingType Type of grouping for multi-series values + * @param PHPExcel_Worksheet $pSheet + * + * @throws PHPExcel_Writer_Exception + */ + private function _writePlotGroup($plotGroup, + $groupType, + $objWriter, + &$catIsMultiLevelSeries, + &$valIsMultiLevelSeries, + &$plotGroupingType, + PHPExcel_Worksheet $pSheet + ) { + if (is_null($plotGroup)) { + return; + } + + if (($groupType == PHPExcel_Chart_DataSeries::TYPE_BARCHART) || + ($groupType == PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D) + ) { + $objWriter->startElement('c:barDir'); + $objWriter->writeAttribute('val', $plotGroup->getPlotDirection()); + $objWriter->endElement(); + } + + if (!is_null($plotGroup->getPlotGrouping())) { + $plotGroupingType = $plotGroup->getPlotGrouping(); + $objWriter->startElement('c:grouping'); + $objWriter->writeAttribute('val', $plotGroupingType); + $objWriter->endElement(); + } + + // Get these details before the loop, because we can use the count to check for varyColors + $plotSeriesOrder = $plotGroup->getPlotOrder(); + $plotSeriesCount = count($plotSeriesOrder); + + if (($groupType !== PHPExcel_Chart_DataSeries::TYPE_RADARCHART) && + ($groupType !== PHPExcel_Chart_DataSeries::TYPE_STOCKCHART) + ) { + + if ($groupType !== PHPExcel_Chart_DataSeries::TYPE_LINECHART) { + if (($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART) || + ($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) || + ($groupType == PHPExcel_Chart_DataSeries::TYPE_DONUTCHART) || + ($plotSeriesCount > 1) + ) { + $objWriter->startElement('c:varyColors'); + $objWriter->writeAttribute('val', 1); + $objWriter->endElement(); + } else { + $objWriter->startElement('c:varyColors'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + } + } + } + + foreach ($plotSeriesOrder as $plotSeriesIdx => $plotSeriesRef) { + $objWriter->startElement('c:ser'); + + $objWriter->startElement('c:idx'); + $objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesIdx); + $objWriter->endElement(); + + $objWriter->startElement('c:order'); + $objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesRef); + $objWriter->endElement(); + + if (($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART) || + ($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) || + ($groupType == PHPExcel_Chart_DataSeries::TYPE_DONUTCHART) + ) { + + $objWriter->startElement('c:dPt'); + $objWriter->startElement('c:idx'); + $objWriter->writeAttribute('val', 3); + $objWriter->endElement(); + + $objWriter->startElement('c:bubble3D'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + + $objWriter->startElement('c:spPr'); + $objWriter->startElement('a:solidFill'); + $objWriter->startElement('a:srgbClr'); + $objWriter->writeAttribute('val', 'FF9900'); + $objWriter->endElement(); + $objWriter->endElement(); + $objWriter->endElement(); + $objWriter->endElement(); + } + + // Labels + $plotSeriesLabel = $plotGroup->getPlotLabelByIndex($plotSeriesRef); + if ($plotSeriesLabel && ($plotSeriesLabel->getPointCount() > 0)) { + $objWriter->startElement('c:tx'); + $objWriter->startElement('c:strRef'); + $this->_writePlotSeriesLabel($plotSeriesLabel, $objWriter); + $objWriter->endElement(); + $objWriter->endElement(); + } + + // Formatting for the points + if (($groupType == PHPExcel_Chart_DataSeries::TYPE_LINECHART) || + ($groupType == PHPExcel_Chart_DataSeries::TYPE_STOCKCHART) + ) { + $objWriter->startElement('c:spPr'); + $objWriter->startElement('a:ln'); + $objWriter->writeAttribute('w', 12700); + if ($groupType == PHPExcel_Chart_DataSeries::TYPE_STOCKCHART) { + $objWriter->startElement('a:noFill'); + $objWriter->endElement(); + } + $objWriter->endElement(); + $objWriter->endElement(); + } + + $plotSeriesValues = $plotGroup->getPlotValuesByIndex($plotSeriesRef); + if ($plotSeriesValues) { + $plotSeriesMarker = $plotSeriesValues->getPointMarker(); + if ($plotSeriesMarker) { + $objWriter->startElement('c:marker'); + $objWriter->startElement('c:symbol'); + $objWriter->writeAttribute('val', $plotSeriesMarker); + $objWriter->endElement(); + + if ($plotSeriesMarker !== 'none') { + $objWriter->startElement('c:size'); + $objWriter->writeAttribute('val', 3); + $objWriter->endElement(); + } + + $objWriter->endElement(); + } + } + + if (($groupType === PHPExcel_Chart_DataSeries::TYPE_BARCHART) || + ($groupType === PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D) || + ($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) + ) { + + $objWriter->startElement('c:invertIfNegative'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + } + + // Category Labels + $plotSeriesCategory = $plotGroup->getPlotCategoryByIndex($plotSeriesRef); + if ($plotSeriesCategory && ($plotSeriesCategory->getPointCount() > 0)) { + $catIsMultiLevelSeries = $catIsMultiLevelSeries || $plotSeriesCategory->isMultiLevelSeries(); + + if (($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART) || + ($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) || + ($groupType == PHPExcel_Chart_DataSeries::TYPE_DONUTCHART) + ) { + + if (!is_null($plotGroup->getPlotStyle())) { + $plotStyle = $plotGroup->getPlotStyle(); + if ($plotStyle) { + $objWriter->startElement('c:explosion'); + $objWriter->writeAttribute('val', 25); + $objWriter->endElement(); + } + } + } + + if (($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) || + ($groupType === PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART) + ) { + $objWriter->startElement('c:xVal'); + } else { + $objWriter->startElement('c:cat'); + } + + $this->_writePlotSeriesValues($plotSeriesCategory, $objWriter, $groupType, 'str', $pSheet); + $objWriter->endElement(); + } + + // Values + if ($plotSeriesValues) { + $valIsMultiLevelSeries = $valIsMultiLevelSeries || $plotSeriesValues->isMultiLevelSeries(); + + if (($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) || + ($groupType === PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART) + ) { + $objWriter->startElement('c:yVal'); + } else { + $objWriter->startElement('c:val'); + } + + $this->_writePlotSeriesValues($plotSeriesValues, $objWriter, $groupType, 'num', $pSheet); + $objWriter->endElement(); + } + + if ($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) { + $this->_writeBubbles($plotSeriesValues, $objWriter, $pSheet); + } + + $objWriter->endElement(); + + } + + $this->_seriesIndex += $plotSeriesIdx + 1; + } + + /** + * Write Plot Series Label + * + * @param PHPExcel_Chart_DataSeriesValues $plotSeriesLabel + * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer + * + * @throws PHPExcel_Writer_Exception + */ + private function _writePlotSeriesLabel($plotSeriesLabel, $objWriter) { + if (is_null($plotSeriesLabel)) { + return; + } + + $objWriter->startElement('c:f'); + $objWriter->writeRawData($plotSeriesLabel->getDataSource()); + $objWriter->endElement(); + + $objWriter->startElement('c:strCache'); + $objWriter->startElement('c:ptCount'); + $objWriter->writeAttribute('val', $plotSeriesLabel->getPointCount()); + $objWriter->endElement(); + + foreach ($plotSeriesLabel->getDataValues() as $plotLabelKey => $plotLabelValue) { + $objWriter->startElement('c:pt'); + $objWriter->writeAttribute('idx', $plotLabelKey); + + $objWriter->startElement('c:v'); + $objWriter->writeRawData($plotLabelValue); + $objWriter->endElement(); + $objWriter->endElement(); + } + $objWriter->endElement(); + + } + + /** + * Write Plot Series Values + * + * @param PHPExcel_Chart_DataSeriesValues $plotSeriesValues + * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer + * @param string $groupType Type of plot for dataseries + * @param string $dataType Datatype of series values + * @param PHPExcel_Worksheet $pSheet + * + * @throws PHPExcel_Writer_Exception + */ + private function _writePlotSeriesValues($plotSeriesValues, + $objWriter, + $groupType, + $dataType = 'str', + PHPExcel_Worksheet $pSheet + ) { + if (is_null($plotSeriesValues)) { + return; + } + + if ($plotSeriesValues->isMultiLevelSeries()) { + $levelCount = $plotSeriesValues->multiLevelCount(); + + $objWriter->startElement('c:multiLvlStrRef'); + + $objWriter->startElement('c:f'); + $objWriter->writeRawData($plotSeriesValues->getDataSource()); + $objWriter->endElement(); + + $objWriter->startElement('c:multiLvlStrCache'); + + $objWriter->startElement('c:ptCount'); + $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount()); + $objWriter->endElement(); + + for ($level = 0; $level < $levelCount; ++$level) { + $objWriter->startElement('c:lvl'); + + foreach ($plotSeriesValues->getDataValues() as $plotSeriesKey => $plotSeriesValue) { + if (isset($plotSeriesValue[$level])) { + $objWriter->startElement('c:pt'); + $objWriter->writeAttribute('idx', $plotSeriesKey); + + $objWriter->startElement('c:v'); + $objWriter->writeRawData($plotSeriesValue[$level]); + $objWriter->endElement(); + $objWriter->endElement(); + } + } + + $objWriter->endElement(); + } + + $objWriter->endElement(); + + $objWriter->endElement(); + } else { + $objWriter->startElement('c:' . $dataType . 'Ref'); + + $objWriter->startElement('c:f'); + $objWriter->writeRawData($plotSeriesValues->getDataSource()); + $objWriter->endElement(); + + $objWriter->startElement('c:' . $dataType . 'Cache'); + + if (($groupType != PHPExcel_Chart_DataSeries::TYPE_PIECHART) && + ($groupType != PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) && + ($groupType != PHPExcel_Chart_DataSeries::TYPE_DONUTCHART) + ) { + + if (($plotSeriesValues->getFormatCode() !== NULL) && + ($plotSeriesValues->getFormatCode() !== '') + ) { + $objWriter->startElement('c:formatCode'); + $objWriter->writeRawData($plotSeriesValues->getFormatCode()); + $objWriter->endElement(); + } + } + + $objWriter->startElement('c:ptCount'); + $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount()); + $objWriter->endElement(); + + $dataValues = $plotSeriesValues->getDataValues(); + if (!empty($dataValues)) { + if (is_array($dataValues)) { + foreach ($dataValues as $plotSeriesKey => $plotSeriesValue) { + $objWriter->startElement('c:pt'); + $objWriter->writeAttribute('idx', $plotSeriesKey); + + $objWriter->startElement('c:v'); + $objWriter->writeRawData($plotSeriesValue); + $objWriter->endElement(); + $objWriter->endElement(); + } + } + } + + $objWriter->endElement(); + + $objWriter->endElement(); + } + } + + /** + * Write Bubble Chart Details + * + * @param PHPExcel_Chart_DataSeriesValues $plotSeriesValues + * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer + * + * @throws PHPExcel_Writer_Exception + */ + private function _writeBubbles($plotSeriesValues, $objWriter, PHPExcel_Worksheet $pSheet) { + if (is_null($plotSeriesValues)) { + return; + } + + $objWriter->startElement('c:bubbleSize'); + $objWriter->startElement('c:numLit'); + + $objWriter->startElement('c:formatCode'); + $objWriter->writeRawData('General'); + $objWriter->endElement(); + + $objWriter->startElement('c:ptCount'); + $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount()); + $objWriter->endElement(); + + $dataValues = $plotSeriesValues->getDataValues(); + if (!empty($dataValues)) { + if (is_array($dataValues)) { + foreach ($dataValues as $plotSeriesKey => $plotSeriesValue) { + $objWriter->startElement('c:pt'); + $objWriter->writeAttribute('idx', $plotSeriesKey); + $objWriter->startElement('c:v'); + $objWriter->writeRawData(1); + $objWriter->endElement(); + $objWriter->endElement(); + } + } + } + + $objWriter->endElement(); + $objWriter->endElement(); + + $objWriter->startElement('c:bubble3D'); + $objWriter->writeAttribute('val', 0); + $objWriter->endElement(); + } + + /** + * Write Layout + * + * @param PHPExcel_Chart_Layout $layout + * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer + * + * @throws PHPExcel_Writer_Exception + */ + private function _writeLayout(PHPExcel_Chart_Layout $layout = NULL, $objWriter) { + $objWriter->startElement('c:layout'); + + if (!is_null($layout)) { + $objWriter->startElement('c:manualLayout'); + + $layoutTarget = $layout->getLayoutTarget(); + if (!is_null($layoutTarget)) { + $objWriter->startElement('c:layoutTarget'); + $objWriter->writeAttribute('val', $layoutTarget); + $objWriter->endElement(); + } + + $xMode = $layout->getXMode(); + if (!is_null($xMode)) { + $objWriter->startElement('c:xMode'); + $objWriter->writeAttribute('val', $xMode); + $objWriter->endElement(); + } + + $yMode = $layout->getYMode(); + if (!is_null($yMode)) { + $objWriter->startElement('c:yMode'); + $objWriter->writeAttribute('val', $yMode); + $objWriter->endElement(); + } + + $x = $layout->getXPosition(); + if (!is_null($x)) { + $objWriter->startElement('c:x'); + $objWriter->writeAttribute('val', $x); + $objWriter->endElement(); + } + + $y = $layout->getYPosition(); + if (!is_null($y)) { + $objWriter->startElement('c:y'); + $objWriter->writeAttribute('val', $y); + $objWriter->endElement(); + } + + $w = $layout->getWidth(); + if (!is_null($w)) { + $objWriter->startElement('c:w'); + $objWriter->writeAttribute('val', $w); + $objWriter->endElement(); + } + + $h = $layout->getHeight(); + if (!is_null($h)) { + $objWriter->startElement('c:h'); + $objWriter->writeAttribute('val', $h); + $objWriter->endElement(); + } + + $objWriter->endElement(); + } + + $objWriter->endElement(); + } + + /** + * Write Alternate Content block + * + * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer + * + * @throws PHPExcel_Writer_Exception + */ + private function _writeAlternateContent($objWriter) { + $objWriter->startElement('mc:AlternateContent'); + $objWriter->writeAttribute('xmlns:mc', 'http://schemas.openxmlformats.org/markup-compatibility/2006'); + + $objWriter->startElement('mc:Choice'); + $objWriter->writeAttribute('xmlns:c14', 'http://schemas.microsoft.com/office/drawing/2007/8/2/chart'); + $objWriter->writeAttribute('Requires', 'c14'); + + $objWriter->startElement('c14:style'); + $objWriter->writeAttribute('val', '102'); + $objWriter->endElement(); + $objWriter->endElement(); + + $objWriter->startElement('mc:Fallback'); + $objWriter->startElement('c:style'); + $objWriter->writeAttribute('val', '2'); + $objWriter->endElement(); + $objWriter->endElement(); + + $objWriter->endElement(); + } + + /** + * Write Printer Settings + * + * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer + * + * @throws PHPExcel_Writer_Exception + */ + private function _writePrintSettings($objWriter) { + $objWriter->startElement('c:printSettings'); + + $objWriter->startElement('c:headerFooter'); + $objWriter->endElement(); + + $objWriter->startElement('c:pageMargins'); + $objWriter->writeAttribute('footer', 0.3); + $objWriter->writeAttribute('header', 0.3); + $objWriter->writeAttribute('r', 0.7); + $objWriter->writeAttribute('l', 0.7); + $objWriter->writeAttribute('t', 0.75); + $objWriter->writeAttribute('b', 0.75); + $objWriter->endElement(); + + $objWriter->startElement('c:pageSetup'); + $objWriter->writeAttribute('orientation', "portrait"); + $objWriter->endElement(); + + $objWriter->endElement(); + } }