PHPExcel_Writer_Excel2007_Chart::_writePlotGroup()   F
last analyzed

Complexity

Conditions 40
Paths > 20000

Size

Total Lines 176
Code Lines 118

Duplication

Lines 14
Ratio 7.95 %

Importance

Changes 0
Metric Value
cc 40
eloc 118
c 0
b 0
f 0
nc 174097
nop 6
dl 14
loc 176
rs 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * PHPExcel
4
 *
5
 * Copyright (c) 2006 - 2012 PHPExcel
6
 *
7
 * This library is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * This library is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20
 *
21
 * @category   PHPExcel
22
 * @package    PHPExcel_Writer_Excel2007
23
 * @copyright  Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
24
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL
25
 * @version    1.7.7, 2012-05-19
26
 */
27
28
29
/**
30
 * PHPExcel_Writer_Excel2007_Chart
31
 *
32
 * @category   PHPExcel
33
 * @package    PHPExcel_Writer_Excel2007
34
 * @copyright  Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
35
 */
36
class PHPExcel_Writer_Excel2007_Chart extends PHPExcel_Writer_Excel2007_WriterPart
37
{
38
	/**
39
	 * Write charts to XML format
40
	 *
41
	 * @param 	PHPExcel_Chart				$pChart
42
	 * @return 	string 						XML Output
43
	 * @throws 	Exception
44
	 */
45
	public function writeChart(PHPExcel_Chart $pChart = null)
46
	{
47
		// Create XML writer
48
		$objWriter = null;
49 View Code Duplication
		if ($this->getParentWriter()->getUseDiskCaching()) {
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface PHPExcel_Writer_IWriter as the method getUseDiskCaching() does only exist in the following implementations of said interface: PHPExcel_Writer_Excel2007.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
50
			$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface PHPExcel_Writer_IWriter as the method getDiskCachingDirectory() does only exist in the following implementations of said interface: PHPExcel_Writer_Excel2007.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
51
		} else {
52
			$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
53
		}
54
		//	Ensure that data series values are up-to-date before we save
55
		$pChart->refresh();
0 ignored issues
show
Bug introduced by
It seems like $pChart is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
56
57
		// XML header
58
		$objWriter->startDocument('1.0','UTF-8','yes');
59
60
		// c:chartSpace
61
		$objWriter->startElement('c:chartSpace');
62
			$objWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart');
63
			$objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
64
			$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
65
66
			$objWriter->startElement('c:date1904');
67
				$objWriter->writeAttribute('val', 0);
68
			$objWriter->endElement();
69
			$objWriter->startElement('c:lang');
70
				$objWriter->writeAttribute('val', "en-GB");
71
			$objWriter->endElement();
72
			$objWriter->startElement('c:roundedCorners');
73
				$objWriter->writeAttribute('val', 0);
74
			$objWriter->endElement();
75
76
			$this->_writeAlternateContent($objWriter);
77
78
			$objWriter->startElement('c:chart');
79
80
				$this->_writeTitle($pChart->getTitle(), $objWriter);
81
82
				$objWriter->startElement('c:autoTitleDeleted');
83
					$objWriter->writeAttribute('val', 0);
84
				$objWriter->endElement();
85
86
				$this->_writePlotArea($pChart->getPlotArea(), $pChart->getXAxisLabel(), $pChart->getYAxisLabel(), $objWriter);
87
88
				$this->_writeLegend($pChart->getLegend(), $objWriter);
89
90
91
				$objWriter->startElement('c:plotVisOnly');
92
					$objWriter->writeAttribute('val', 1);
93
				$objWriter->endElement();
94
95
				$objWriter->startElement('c:dispBlanksAs');
96
					$objWriter->writeAttribute('val', "gap");
97
				$objWriter->endElement();
98
99
				$objWriter->startElement('c:showDLblsOverMax');
100
					$objWriter->writeAttribute('val', 0);
101
				$objWriter->endElement();
102
103
			$objWriter->endElement();
104
105
			$this->_writePrintSettings($objWriter);
106
107
		$objWriter->endElement();
108
109
		// Return
110
		return $objWriter->getData();
111
	}
112
113
	/**
114
	 * Write Chart Title
115
	 *
116
	 * @param	PHPExcel_Chart_Title		$title
117
	 * @param 	PHPExcel_Shared_XMLWriter 	$objWriter 		XML Writer
118
	 * @throws 	Exception
119
	 */
120
	private function _writeTitle(PHPExcel_Chart_Title $title = null, $objWriter)
121
	{
122
		if (is_null($title)) {
123
			return;
124
		}
125
126
		$objWriter->startElement('c:title');
127
			$objWriter->startElement('c:tx');
128
				$objWriter->startElement('c:rich');
129
130
					$objWriter->startElement('a:bodyPr');
131
					$objWriter->endElement();
132
133
					$objWriter->startElement('a:lstStyle');
134
					$objWriter->endElement();
135
136
					$objWriter->startElement('a:p');
137
138
						$caption = $title->getCaption();
139
						if ((is_array($caption)) && (count($caption) > 0))
140
							$caption = $caption[0];
141
						$this->getParentWriter()->getWriterPart('stringtable')->writeRichTextForCharts($objWriter, $caption, 'a');
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface PHPExcel_Writer_IWriter as the method getWriterPart() does only exist in the following implementations of said interface: PHPExcel_Writer_Excel2007.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
142
143
					$objWriter->endElement();
144
				$objWriter->endElement();
145
			$objWriter->endElement();
146
147
			$layout = $title->getLayout();
148
			$this->_writeLayout($layout, $objWriter);
149
150
			$objWriter->startElement('c:overlay');
151
				$objWriter->writeAttribute('val', 0);
152
			$objWriter->endElement();
153
154
		$objWriter->endElement();
155
	}
156
157
	/**
158
	 * Write Chart Legend
159
	 *
160
	 * @param	PHPExcel_Chart_Legend		$legend
161
	 * @param 	PHPExcel_Shared_XMLWriter 	$objWriter 		XML Writer
162
	 * @throws 	Exception
163
	 */
164
	private function _writeLegend(PHPExcel_Chart_Legend $legend = null, $objWriter)
165
	{
166
		if (is_null($legend)) {
167
			return;
168
		}
169
170
		$objWriter->startElement('c:legend');
171
172
			$objWriter->startElement('c:legendPos');
173
				$objWriter->writeAttribute('val', $legend->getPosition());
174
			$objWriter->endElement();
175
176
			$layout = $legend->getLayout();
177
			$this->_writeLayout($layout, $objWriter);
178
179
			$objWriter->startElement('c:overlay');
180
				$objWriter->writeAttribute('val', ($legend->getOverlay()) ? '1' : '0');
181
			$objWriter->endElement();
182
183
			$objWriter->startElement('c:txPr');
184
				$objWriter->startElement('a:bodyPr');
185
				$objWriter->endElement();
186
187
				$objWriter->startElement('a:lstStyle');
188
				$objWriter->endElement();
189
190
				$objWriter->startElement('a:p');
191
					$objWriter->startElement('a:pPr');
192
						$objWriter->writeAttribute('rtl', 0);
193
194
						$objWriter->startElement('a:defRPr');
195
						$objWriter->endElement();
196
					$objWriter->endElement();
197
198
					$objWriter->startElement('a:endParaRPr');
199
						$objWriter->writeAttribute('lang', "en-US");
200
					$objWriter->endElement();
201
202
				$objWriter->endElement();
203
			$objWriter->endElement();
204
205
		$objWriter->endElement();
206
	}
207
208
	/**
209
	 * Write Chart Plot Area
210
	 *
211
	 * @param	PHPExcel_Chart_PlotArea		$plotArea
212
	 * @param	PHPExcel_Chart_Title		$xAxisLabel
213
	 * @param	PHPExcel_Chart_Title		$yAxisLabel
214
	 * @param 	PHPExcel_Shared_XMLWriter 	$objWriter 		XML Writer
215
	 * @throws 	Exception
216
	 */
217
	private function _writePlotArea(PHPExcel_Chart_PlotArea $plotArea,
218
									PHPExcel_Chart_Title $xAxisLabel = NULL,
219
									PHPExcel_Chart_Title $yAxisLabel = NULL,
220
									$objWriter)
221
	{
222
		if (is_null($plotArea)) {
223
			return;
224
		}
225
226
		$id1 = $id2 = 0;
227
		$objWriter->startElement('c:plotArea');
228
229
			$layout = $plotArea->getLayout();
230
			$this->_writeLayout($layout, $objWriter);
231
232
			$chartTypes = self::_getChartType($plotArea);
233
			$catIsMultiLevelSeries = $valIsMultiLevelSeries = FALSE;
234
			$plotGroupingType = '';
235
			foreach($chartTypes as $chartType) {
0 ignored issues
show
Bug introduced by
The expression $chartTypes of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
236
				$objWriter->startElement('c:'.$chartType);
237
238
					$groupCount = $plotArea->getPlotGroupCount();
239
					for($i = 0; $i < $groupCount; ++$i) {
240
						$plotGroup = $plotArea->getPlotGroupByIndex($i);
241
						$groupType = $plotGroup->getPlotType();
242
						if ($groupType == $chartType) {
243
244
							$plotStyle = $plotGroup->getPlotStyle();
245
							if ($groupType === PHPExcel_Chart_DataSeries::TYPE_RADARCHART) {
246
								$objWriter->startElement('c:radarStyle');
247
									$objWriter->writeAttribute('val', $plotStyle );
248
								$objWriter->endElement();
249
							} elseif ($groupType === PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART) {
250
								$objWriter->startElement('c:scatterStyle');
251
									$objWriter->writeAttribute('val', $plotStyle );
252
								$objWriter->endElement();
253
							}
254
255
							$this->_writePlotGroup($plotGroup, $chartType, $objWriter, $catIsMultiLevelSeries, $valIsMultiLevelSeries, $plotGroupingType);
256
						}
257
					}
258
259
					$this->_writeDataLbls($objWriter);
260
261
					if ($chartType === PHPExcel_Chart_DataSeries::TYPE_LINECHART) {
262
						//	Line only, Line3D can't be smoothed
263
264
						$objWriter->startElement('c:smooth');
265
							$objWriter->writeAttribute('val', (integer) $plotGroup->getSmoothLine() );
0 ignored issues
show
Bug introduced by
The variable $plotGroup does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
266
						$objWriter->endElement();
267
					} elseif (($chartType === PHPExcel_Chart_DataSeries::TYPE_BARCHART) ||
268
						($chartType === PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D)) {
269
270
						$objWriter->startElement('c:gapWidth');
271
							$objWriter->writeAttribute('val', 150 );
272
						$objWriter->endElement();
273
274
						if ($plotGroupingType == 'percentStacked' ||
275
							$plotGroupingType == 'stacked') {
276
277
							$objWriter->startElement('c:overlap');
278
								$objWriter->writeAttribute('val', 100 );
279
							$objWriter->endElement();
280
						}
281 View Code Duplication
					} elseif ($chartType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) {
282
283
							$objWriter->startElement('c:bubbleScale');
284
								$objWriter->writeAttribute('val', 25 );
285
							$objWriter->endElement();
286
287
							$objWriter->startElement('c:showNegBubbles');
288
								$objWriter->writeAttribute('val', 0 );
289
							$objWriter->endElement();
290
					} elseif ($chartType === PHPExcel_Chart_DataSeries::TYPE_STOCKCHART) {
291
292
							$objWriter->startElement('c:hiLowLines');
293
							$objWriter->endElement();
294
					}
295
296
					//	Generate 2 unique numbers to use for axId values
297
//					$id1 = $id2 = rand(10000000,99999999);
298
//					do {
299
//						$id2 = rand(10000000,99999999);
300
//					} while ($id1 == $id2);
301
					$id1 = '75091328';
302
					$id2 = '75089408';
303
304
					if (($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART) &&
305
						($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) &&
306
						($chartType !== PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
307
308
						$objWriter->startElement('c:axId');
309
							$objWriter->writeAttribute('val', $id1 );
310
						$objWriter->endElement();
311
						$objWriter->startElement('c:axId');
312
							$objWriter->writeAttribute('val', $id2 );
313
						$objWriter->endElement();
314 View Code Duplication
					} else {
315
						$objWriter->startElement('c:firstSliceAng');
316
							$objWriter->writeAttribute('val', 0);
317
						$objWriter->endElement();
318
319
						if ($chartType === PHPExcel_Chart_DataSeries::TYPE_DONUTCHART) {
320
321
							$objWriter->startElement('c:holeSize');
322
								$objWriter->writeAttribute('val', 50);
323
							$objWriter->endElement();
324
						}
325
					}
326
327
				$objWriter->endElement();
328
			}
329
330
			if (($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART) &&
331
				($chartType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) &&
332
				($chartType !== PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
333
334
				if ($chartType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) {
335
					$this->_writeValAx($objWriter,$plotArea,$xAxisLabel,$chartType,$id1,$id2,$catIsMultiLevelSeries);
0 ignored issues
show
Bug introduced by
The variable $chartType seems to be defined by a foreach iteration on line 235. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
Bug introduced by
It seems like $xAxisLabel defined by parameter $xAxisLabel on line 218 can be null; however, PHPExcel_Writer_Excel2007_Chart::_writeValAx() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
336
				} else {
337
					$this->_writeCatAx($objWriter,$plotArea,$xAxisLabel,$chartType,$id1,$id2,$catIsMultiLevelSeries);
0 ignored issues
show
Bug introduced by
It seems like $xAxisLabel defined by parameter $xAxisLabel on line 218 can be null; however, PHPExcel_Writer_Excel2007_Chart::_writeCatAx() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
338
				}
339
340
				$this->_writeValAx($objWriter,$plotArea,$yAxisLabel,$chartType,$id1,$id2,$valIsMultiLevelSeries);
0 ignored issues
show
Bug introduced by
It seems like $yAxisLabel defined by parameter $yAxisLabel on line 219 can be null; however, PHPExcel_Writer_Excel2007_Chart::_writeValAx() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
341
			}
342
343
		$objWriter->endElement();
344
	}
345
346
	/**
347
	 * Write Data Labels
348
	 *
349
	 * @param 	PHPExcel_Shared_XMLWriter 	$objWriter 		XML Writer
350
	 * @throws 	Exception
351
	 */
352
	private function _writeDataLbls($objWriter)
353
	{
354
		$objWriter->startElement('c:dLbls');
355
356
			$objWriter->startElement('c:showLegendKey');
357
				$objWriter->writeAttribute('val', 0);
358
			$objWriter->endElement();
359
360
			$objWriter->startElement('c:showVal');
361
				$objWriter->writeAttribute('val', 0);
362
			$objWriter->endElement();
363
364
			$objWriter->startElement('c:showCatName');
365
				$objWriter->writeAttribute('val', 0);
366
			$objWriter->endElement();
367
368
			$objWriter->startElement('c:showSerName');
369
				$objWriter->writeAttribute('val', 0);
370
			$objWriter->endElement();
371
372
			$objWriter->startElement('c:showPercent');
373
				$objWriter->writeAttribute('val', 0);
374
			$objWriter->endElement();
375
376
			$objWriter->startElement('c:showBubbleSize');
377
				$objWriter->writeAttribute('val', 0);
378
			$objWriter->endElement();
379
380
			$objWriter->startElement('c:showLeaderLines');
381
				$objWriter->writeAttribute('val', 1);
382
			$objWriter->endElement();
383
384
		$objWriter->endElement();
385
	}
386
387
	/**
388
	 * Write Category Axis
389
	 *
390
	 * @param 	PHPExcel_Shared_XMLWriter 	$objWriter 		XML Writer
391
	 * @param 	PHPExcel_Chart_PlotArea		$plotArea
392
	 * @param 	PHPExcel_Chart_Title		$xAxisLabel
393
	 * @param 	string						$groupType		Chart type
394
	 * @param 	string						$id1
395
	 * @param 	string						$id2
396
	 * @param 	boolean						$isMultiLevelSeries
397
	 * @throws 	Exception
398
	 */
399
	private function _writeCatAx($objWriter, PHPExcel_Chart_PlotArea $plotArea, $xAxisLabel, $groupType, $id1, $id2, $isMultiLevelSeries)
0 ignored issues
show
Unused Code introduced by
The parameter $plotArea is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $groupType is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
400
	{
401
		$objWriter->startElement('c:catAx');
402
403
			if ($id1 > 0) {
404
				$objWriter->startElement('c:axId');
405
					$objWriter->writeAttribute('val', $id1);
406
				$objWriter->endElement();
407
			}
408
409
			$objWriter->startElement('c:scaling');
410
				$objWriter->startElement('c:orientation');
411
					$objWriter->writeAttribute('val', "minMax");
412
				$objWriter->endElement();
413
			$objWriter->endElement();
414
415
			$objWriter->startElement('c:delete');
416
				$objWriter->writeAttribute('val', 0);
417
			$objWriter->endElement();
418
419
			$objWriter->startElement('c:axPos');
420
				$objWriter->writeAttribute('val', "b");
421
			$objWriter->endElement();
422
423 View Code Duplication
			if (!is_null($xAxisLabel)) {
424
				$objWriter->startElement('c:title');
425
					$objWriter->startElement('c:tx');
426
						$objWriter->startElement('c:rich');
427
428
							$objWriter->startElement('a:bodyPr');
429
							$objWriter->endElement();
430
431
							$objWriter->startElement('a:lstStyle');
432
							$objWriter->endElement();
433
434
							$objWriter->startElement('a:p');
435
								$objWriter->startElement('a:r');
436
437
									$caption = $xAxisLabel->getCaption();
438
									if (is_array($caption))
439
										$caption = $caption[0];
440
									$objWriter->startElement('a:t');
441
										$objWriter->writeAttribute('xml:space', 'preserve');
442
										$objWriter->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML( $caption ));
443
									$objWriter->endElement();
444
445
								$objWriter->endElement();
446
							$objWriter->endElement();
447
						$objWriter->endElement();
448
					$objWriter->endElement();
449
450
					$objWriter->startElement('c:overlay');
451
						$objWriter->writeAttribute('val', 0);
452
					$objWriter->endElement();
453
454
					$layout = $xAxisLabel->getLayout();
455
					$this->_writeLayout($layout, $objWriter);
456
457
				$objWriter->endElement();
458
459
			}
460
461
			$objWriter->startElement('c:numFmt');
462
				$objWriter->writeAttribute('formatCode', "General");
463
				$objWriter->writeAttribute('sourceLinked', 1);
464
			$objWriter->endElement();
465
466
			$objWriter->startElement('c:majorTickMark');
467
				$objWriter->writeAttribute('val', "out");
468
			$objWriter->endElement();
469
470
			$objWriter->startElement('c:minorTickMark');
471
				$objWriter->writeAttribute('val', "none");
472
			$objWriter->endElement();
473
474
			$objWriter->startElement('c:tickLblPos');
475
				$objWriter->writeAttribute('val', "nextTo");
476
			$objWriter->endElement();
477
478
			if ($id2 > 0) {
479
					$objWriter->startElement('c:crossAx');
480
						$objWriter->writeAttribute('val', $id2);
481
					$objWriter->endElement();
482
483
					$objWriter->startElement('c:crosses');
484
						$objWriter->writeAttribute('val', "autoZero");
485
					$objWriter->endElement();
486
			}
487
488
			$objWriter->startElement('c:auto');
489
				$objWriter->writeAttribute('val', 1);
490
			$objWriter->endElement();
491
492
			$objWriter->startElement('c:lblAlgn');
493
				$objWriter->writeAttribute('val', "ctr");
494
			$objWriter->endElement();
495
496
			$objWriter->startElement('c:lblOffset');
497
				$objWriter->writeAttribute('val', 100);
498
			$objWriter->endElement();
499
500
			if ($isMultiLevelSeries) {
501
				$objWriter->startElement('c:noMultiLvlLbl');
502
					$objWriter->writeAttribute('val', 0);
503
				$objWriter->endElement();
504
			}
505
		$objWriter->endElement();
506
507
	}
508
509
510
	/**
511
	 * Write Value Axis
512
	 *
513
	 * @param 	PHPExcel_Shared_XMLWriter 	$objWriter 		XML Writer
514
	 * @param 	PHPExcel_Chart_PlotArea		$plotArea
515
	 * @param 	PHPExcel_Chart_Title		$yAxisLabel
516
	 * @param 	string						$groupType		Chart type
517
	 * @param 	string						$id1
518
	 * @param 	string						$id2
519
	 * @param 	boolean						$isMultiLevelSeries
520
	 * @throws 	Exception
521
	 */
522
	private function _writeValAx($objWriter, PHPExcel_Chart_PlotArea $plotArea, $yAxisLabel, $groupType, $id1, $id2, $isMultiLevelSeries)
0 ignored issues
show
Unused Code introduced by
The parameter $plotArea is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
523
	{
524
		$objWriter->startElement('c:valAx');
525
526
			if ($id2 > 0) {
527
				$objWriter->startElement('c:axId');
528
					$objWriter->writeAttribute('val', $id2);
529
				$objWriter->endElement();
530
			}
531
532
			$objWriter->startElement('c:scaling');
533
				$objWriter->startElement('c:orientation');
534
					$objWriter->writeAttribute('val', "minMax");
535
				$objWriter->endElement();
536
			$objWriter->endElement();
537
538
			$objWriter->startElement('c:delete');
539
				$objWriter->writeAttribute('val', 0);
540
			$objWriter->endElement();
541
542
			$objWriter->startElement('c:axPos');
543
				$objWriter->writeAttribute('val', "l");
544
			$objWriter->endElement();
545
546
			$objWriter->startElement('c:majorGridlines');
547
			$objWriter->endElement();
548
549 View Code Duplication
			if (!is_null($yAxisLabel)) {
550
				$objWriter->startElement('c:title');
551
					$objWriter->startElement('c:tx');
552
						$objWriter->startElement('c:rich');
553
554
							$objWriter->startElement('a:bodyPr');
555
							$objWriter->endElement();
556
557
							$objWriter->startElement('a:lstStyle');
558
							$objWriter->endElement();
559
560
							$objWriter->startElement('a:p');
561
								$objWriter->startElement('a:r');
562
563
									$caption = $yAxisLabel->getCaption();
564
									if (is_array($caption))
565
										$caption = $caption[0];
566
									$objWriter->startElement('a:t');
567
										$objWriter->writeAttribute('xml:space', 'preserve');
568
										$objWriter->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML( $caption ));
569
									$objWriter->endElement();
570
571
								$objWriter->endElement();
572
							$objWriter->endElement();
573
						$objWriter->endElement();
574
					$objWriter->endElement();
575
576
					$objWriter->startElement('c:overlay');
577
						$objWriter->writeAttribute('val', 0);
578
					$objWriter->endElement();
579
580
					if ($groupType !== PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) {
581
						$layout = $yAxisLabel->getLayout();
582
						$this->_writeLayout($layout, $objWriter);
583
					}
584
585
				$objWriter->endElement();
586
			}
587
588
			$objWriter->startElement('c:numFmt');
589
				$objWriter->writeAttribute('formatCode', "General");
590
				$objWriter->writeAttribute('sourceLinked', 1);
591
			$objWriter->endElement();
592
593
			$objWriter->startElement('c:majorTickMark');
594
				$objWriter->writeAttribute('val', "out");
595
			$objWriter->endElement();
596
597
			$objWriter->startElement('c:minorTickMark');
598
				$objWriter->writeAttribute('val', "none");
599
			$objWriter->endElement();
600
601
			$objWriter->startElement('c:tickLblPos');
602
				$objWriter->writeAttribute('val', "nextTo");
603
			$objWriter->endElement();
604
605
			if ($id1 > 0) {
606
					$objWriter->startElement('c:crossAx');
607
						$objWriter->writeAttribute('val', $id2);
608
					$objWriter->endElement();
609
610
					$objWriter->startElement('c:crosses');
611
						$objWriter->writeAttribute('val', "autoZero");
612
					$objWriter->endElement();
613
614
					$objWriter->startElement('c:crossBetween');
615
						$objWriter->writeAttribute('val', "midCat");
616
					$objWriter->endElement();
617
			}
618
619
			if ($isMultiLevelSeries) {
620
				if ($groupType !== PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) {
621
					$objWriter->startElement('c:noMultiLvlLbl');
622
						$objWriter->writeAttribute('val', 0);
623
					$objWriter->endElement();
624
				}
625
			}
626
		$objWriter->endElement();
627
628
	}
629
630
631
	/**
632
	 * Get the data series type(s) for a chart plot series
633
	 *
634
	 * @param 	PHPExcel_Chart_PlotArea		$plotArea
635
	 * @return	string|array
636
	 * @throws 	Exception
637
	 */
638
	private static function _getChartType($plotArea)
639
	{
640
		$groupCount = $plotArea->getPlotGroupCount();
641
642
		if ($groupCount == 1) {
643
			$chartType = array($plotArea->getPlotGroupByIndex(0)->getPlotType());
644
		} else {
645
			$chartTypes = array();
646
			for($i = 0; $i < $groupCount; ++$i) {
647
				$chartTypes[] = $plotArea->getPlotGroupByIndex($i)->getPlotType();
648
			}
649
			$chartType = array_unique($chartTypes);
650
			if (count($chartTypes) == 0) {
651
				throw new Exception('Chart is not yet implemented');
652
			}
653
		}
654
655
		return $chartType;
656
	}
657
658
	/**
659
	 * Write Plot Group (series of related plots)
660
	 *
661
	 * @param	PHPExcel_Chart_DataSeries		$plotGroup
662
	 * @param	string							$groupType				Type of plot for dataseries
663
	 * @param 	PHPExcel_Shared_XMLWriter 		$objWriter 				XML Writer
664
	 * @param	boolean							&$catIsMultiLevelSeries	Is category a multi-series category
665
	 * @param	boolean							&$valIsMultiLevelSeries	Is value set a multi-series set
666
	 * @param	string							&$plotGroupingType		Type of grouping for multi-series values
667
	 * @throws 	Exception
668
	 */
669
	private function _writePlotGroup($plotGroup, $groupType, $objWriter, &$catIsMultiLevelSeries, &$valIsMultiLevelSeries, &$plotGroupingType)
670
	{
671
		if (is_null($plotGroup)) {
672
			return;
673
		}
674
675
		if (($groupType == PHPExcel_Chart_DataSeries::TYPE_BARCHART) ||
676
			($groupType == PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D)) {
677
			$objWriter->startElement('c:barDir');
678
				$objWriter->writeAttribute('val', $plotGroup->getPlotDirection());
679
			$objWriter->endElement();
680
		}
681
682 View Code Duplication
		if (!is_null($plotGroup->getPlotGrouping())) {
683
			$plotGroupingType = $plotGroup->getPlotGrouping();
684
			$objWriter->startElement('c:grouping');
685
				$objWriter->writeAttribute('val', $plotGroupingType);
686
			$objWriter->endElement();
687
		}
688
689
		//	Get these details before the loop, because we can use the count to check for varyColors
690
		$plotSeriesOrder = $plotGroup->getPlotOrder();
691
		$plotSeriesCount = count($plotSeriesOrder);
692
693
		if (($groupType !== PHPExcel_Chart_DataSeries::TYPE_RADARCHART) &&
694
			($groupType !== PHPExcel_Chart_DataSeries::TYPE_STOCKCHART)) {
695
696
			if ($groupType !== PHPExcel_Chart_DataSeries::TYPE_LINECHART) {
697
				if (($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART) ||
698
					($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) ||
699
					($groupType == PHPExcel_Chart_DataSeries::TYPE_DONUTCHART) ||
700
					($plotSeriesCount > 1)) {
701
					$objWriter->startElement('c:varyColors');
702
						$objWriter->writeAttribute('val', 1);
703
					$objWriter->endElement();
704
				} else {
705
					$objWriter->startElement('c:varyColors');
706
						$objWriter->writeAttribute('val', 0);
707
					$objWriter->endElement();
708
				}
709
			}
710
		}
711
712
		foreach($plotSeriesOrder as $plotSeriesIdx => $plotSeriesRef) {
713
			$objWriter->startElement('c:ser');
714
715
				$objWriter->startElement('c:idx');
716
					$objWriter->writeAttribute('val', $plotSeriesIdx);
717
				$objWriter->endElement();
718
719
				$objWriter->startElement('c:order');
720
					$objWriter->writeAttribute('val', $plotSeriesRef);
721
				$objWriter->endElement();
722
723
				if (($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART) ||
724
					($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) ||
725
					($groupType == PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
726
727
					$objWriter->startElement('c:dPt');
728
						$objWriter->startElement('c:idx');
729
							$objWriter->writeAttribute('val', 3);
730
						$objWriter->endElement();
731
732
						$objWriter->startElement('c:bubble3D');
733
							$objWriter->writeAttribute('val', 0);
734
						$objWriter->endElement();
735
736
						$objWriter->startElement('c:spPr');
737
							$objWriter->startElement('a:solidFill');
738
								$objWriter->startElement('a:srgbClr');
739
									$objWriter->writeAttribute('val', 'FF9900');
740
								$objWriter->endElement();
741
							$objWriter->endElement();
742
						$objWriter->endElement();
743
					$objWriter->endElement();
744
				}
745
746
				//	Labels
747
				$plotSeriesLabel = $plotGroup->getPlotLabelByIndex($plotSeriesRef);
748
				if ($plotSeriesLabel && ($plotSeriesLabel->getPointCount() > 0)) {
749
					$objWriter->startElement('c:tx');
750
						$objWriter->startElement('c:strRef');
751
							$this->_writePlotSeriesLabel($plotSeriesLabel, $objWriter);
752
						$objWriter->endElement();
753
					$objWriter->endElement();
754
				}
755
756
				//	Formatting for the points
757
				if ($groupType == PHPExcel_Chart_DataSeries::TYPE_LINECHART) {
758
					$objWriter->startElement('c:spPr');
759
						$objWriter->startElement('a:ln');
760
							$objWriter->writeAttribute('w', 12700);
761
						$objWriter->endElement();
762
					$objWriter->endElement();
763
				}
764
765
				$plotSeriesValues = $plotGroup->getPlotValuesByIndex($plotSeriesRef);
766
				if ($plotSeriesValues) {
767
					$plotSeriesMarker = $plotSeriesValues->getPointMarker();
768
					if ($plotSeriesMarker) {
769
						$objWriter->startElement('c:marker');
770
							$objWriter->startElement('c:symbol');
771
								$objWriter->writeAttribute('val', $plotSeriesMarker);
772
							$objWriter->endElement();
773
774
							if ($plotSeriesMarker !== 'none') {
775
								$objWriter->startElement('c:size');
776
									$objWriter->writeAttribute('val', 3);
777
								$objWriter->endElement();
778
							}
779
						$objWriter->endElement();
780
					}
781
				}
782
783
				if (($groupType === PHPExcel_Chart_DataSeries::TYPE_BARCHART) ||
784
					($groupType === PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D) ||
785
					($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART)) {
786
787
					$objWriter->startElement('c:invertIfNegative');
788
						$objWriter->writeAttribute('val', 0);
789
					$objWriter->endElement();
790
				}
791
792
				//	Category Labels
793
				$plotSeriesCategory = $plotGroup->getPlotCategoryByIndex($plotSeriesRef);
794
				if ($plotSeriesCategory && ($plotSeriesCategory->getPointCount() > 0)) {
795
					$catIsMultiLevelSeries = $catIsMultiLevelSeries || $plotSeriesCategory->isMultiLevelSeries();
796
797
					if (($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART) ||
798
						($groupType == PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) ||
799
						($groupType == PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
800
801 View Code Duplication
						if (!is_null($plotGroup->getPlotStyle())) {
802
							$plotStyle = $plotGroup->getPlotStyle();
803
							if ($plotStyle) {
804
								$objWriter->startElement('c:explosion');
805
									$objWriter->writeAttribute('val', 25);
806
								$objWriter->endElement();
807
							}
808
						}
809
					}
810
811
					if (($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) ||
812
						($groupType === PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART)) {
813
						$objWriter->startElement('c:xVal');
814
					} else {
815
						$objWriter->startElement('c:cat');
816
					}
817
818
						$this->_writePlotSeriesValues($plotSeriesCategory, $objWriter, $groupType, 'str');
819
					$objWriter->endElement();
820
				}
821
822
				//	Values
823
				if ($plotSeriesValues) {
824
					$valIsMultiLevelSeries = $valIsMultiLevelSeries || $plotSeriesValues->isMultiLevelSeries();
825
826
					if (($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) ||
827
						($groupType === PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART)) {
828
						$objWriter->startElement('c:yVal');
829
					} else {
830
						$objWriter->startElement('c:val');
831
					}
832
833
						$this->_writePlotSeriesValues($plotSeriesValues, $objWriter, $groupType, 'num');
834
					$objWriter->endElement();
835
				}
836
837
				if ($groupType === PHPExcel_Chart_DataSeries::TYPE_BUBBLECHART) {
838
					$this->_writeBubbles($plotSeriesValues, $objWriter);
839
				}
840
841
			$objWriter->endElement();
842
843
		}
844
	}
845
846
	/**
847
	 * Write Plot Series Label
848
	 *
849
	 * @param	PHPExcel_Chart_DataSeriesValues		$plotSeriesLabel
850
	 * @param 	PHPExcel_Shared_XMLWriter 			$objWriter 			XML Writer
851
	 * @throws 	Exception
852
	 */
853
	private function _writePlotSeriesLabel($plotSeriesLabel, $objWriter)
854
	{
855
		if (is_null($plotSeriesLabel)) {
856
			return;
857
		}
858
859
		$objWriter->startElement('c:f');
860
			$objWriter->writeRawData($plotSeriesLabel->getDataSource());
861
		$objWriter->endElement();
862
863
		$objWriter->startElement('c:strCache');
864
			$objWriter->startElement('c:ptCount');
865
				$objWriter->writeAttribute('val', $plotSeriesLabel->getPointCount() );
866
			$objWriter->endElement();
867
868 View Code Duplication
			foreach($plotSeriesLabel->getDataValues() as $plotLabelKey => $plotLabelValue) {
869
				$objWriter->startElement('c:pt');
870
					$objWriter->writeAttribute('idx', $plotLabelKey );
871
872
					$objWriter->startElement('c:v');
873
						$objWriter->writeRawData( $plotLabelValue );
874
					$objWriter->endElement();
875
				$objWriter->endElement();
876
			}
877
		$objWriter->endElement();
878
879
	}
880
881
	/**
882
	 * Write Plot Series Values
883
	 *
884
	 * @param	PHPExcel_Chart_DataSeriesValues		$plotSeriesValues
885
	 * @param 	PHPExcel_Shared_XMLWriter 			$objWriter 			XML Writer
886
	 * @param	string								$groupType			Type of plot for dataseries
887
	 * @param	string								$dataType			Datatype of series values
888
	 * @throws 	Exception
889
	 */
890
	private function _writePlotSeriesValues($plotSeriesValues, $objWriter, $groupType, $dataType='str')
891
	{
892
		if (is_null($plotSeriesValues)) {
893
			return;
894
		}
895
896
		if ($plotSeriesValues->isMultiLevelSeries()) {
897
			$levelCount = $plotSeriesValues->multiLevelCount();
898
899
			$objWriter->startElement('c:multiLvlStrRef');
900
901
				$objWriter->startElement('c:f');
902
					$objWriter->writeRawData( $plotSeriesValues->getDataSource() );
903
				$objWriter->endElement();
904
905
				$objWriter->startElement('c:multiLvlStrCache');
906
907
					$objWriter->startElement('c:ptCount');
908
						$objWriter->writeAttribute('val', $plotSeriesValues->getPointCount() );
909
					$objWriter->endElement();
910
911
					for ($level = 0; $level < $levelCount; ++$level) {
912
						$objWriter->startElement('c:lvl');
913
914
						foreach($plotSeriesValues->getDataValues() as $plotSeriesKey => $plotSeriesValue) {
915
							if (isset($plotSeriesValue[$level])) {
916
								$objWriter->startElement('c:pt');
917
									$objWriter->writeAttribute('idx', $plotSeriesKey );
918
919
									$objWriter->startElement('c:v');
920
										$objWriter->writeRawData( $plotSeriesValue[$level] );
921
									$objWriter->endElement();
922
								$objWriter->endElement();
923
							}
924
						}
925
926
						$objWriter->endElement();
927
					}
928
929
				$objWriter->endElement();
930
931
			$objWriter->endElement();
932
		} else {
933
			$objWriter->startElement('c:'.$dataType.'Ref');
934
935
				$objWriter->startElement('c:f');
936
					$objWriter->writeRawData( $plotSeriesValues->getDataSource() );
937
				$objWriter->endElement();
938
939
				$objWriter->startElement('c:'.$dataType.'Cache');
940
941
					if (($groupType != PHPExcel_Chart_DataSeries::TYPE_PIECHART) &&
942
						($groupType != PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) &&
943
						($groupType != PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
944
945
						if ($plotSeriesValues->getFormatCode() !== NULL) {
946
							$objWriter->startElement('c:formatCode');
947
								$objWriter->writeRawData( $plotSeriesValues->getFormatCode() );
948
							$objWriter->endElement();
949
						}
950
					}
951
952
					$objWriter->startElement('c:ptCount');
953
						$objWriter->writeAttribute('val', $plotSeriesValues->getPointCount() );
954
					$objWriter->endElement();
955
956 View Code Duplication
					foreach($plotSeriesValues->getDataValues() as $plotSeriesKey => $plotSeriesValue) {
957
						$objWriter->startElement('c:pt');
958
							$objWriter->writeAttribute('idx', $plotSeriesKey );
959
960
							$objWriter->startElement('c:v');
961
								$objWriter->writeRawData( $plotSeriesValue );
962
							$objWriter->endElement();
963
						$objWriter->endElement();
964
					}
965
966
				$objWriter->endElement();
967
968
			$objWriter->endElement();
969
		}
970
	}
971
972
	/**
973
	 * Write Bubble Chart Details
974
	 *
975
	 * @param	PHPExcel_Chart_DataSeriesValues		$plotSeriesValues
976
	 * @param 	PHPExcel_Shared_XMLWriter 			$objWriter 			XML Writer
977
	 * @throws 	Exception
978
	 */
979
	private function _writeBubbles($plotSeriesValues, $objWriter)
980
	{
981
		if (is_null($plotSeriesValues)) {
982
			return;
983
		}
984
985
		$objWriter->startElement('c:bubbleSize');
986
			$objWriter->startElement('c:numLit');
987
988
				$objWriter->startElement('c:formatCode');
989
					$objWriter->writeRawData( 'General' );
990
				$objWriter->endElement();
991
992
				$objWriter->startElement('c:ptCount');
993
					$objWriter->writeAttribute('val', $plotSeriesValues->getPointCount() );
994
				$objWriter->endElement();
995
996 View Code Duplication
				foreach($plotSeriesValues->getDataValues() as $plotSeriesKey => $plotSeriesValue) {
997
					$objWriter->startElement('c:pt');
998
						$objWriter->writeAttribute('idx', $plotSeriesKey );
999
						$objWriter->startElement('c:v');
1000
							$objWriter->writeRawData( 1 );
1001
						$objWriter->endElement();
1002
					$objWriter->endElement();
1003
				}
1004
1005
			$objWriter->endElement();
1006
		$objWriter->endElement();
1007
1008
		$objWriter->startElement('c:bubble3D');
1009
			$objWriter->writeAttribute('val', 0 );
1010
		$objWriter->endElement();
1011
	}
1012
1013
	/**
1014
	 * Write Layout
1015
	 *
1016
	 * @param	PHPExcel_Chart_Layout		$layout
1017
	 * @param 	PHPExcel_Shared_XMLWriter 	$objWriter 		XML Writer
1018
	 * @throws 	Exception
1019
	 */
1020
	private function _writeLayout(PHPExcel_Chart_Layout $layout = NULL, $objWriter)
1021
	{
1022
		$objWriter->startElement('c:layout');
1023
1024
			if (!is_null($layout)) {
1025
				$objWriter->startElement('c:manualLayout');
1026
1027
					$layoutTarget = $layout->getLayoutTarget();
1028
					if (!is_null($layoutTarget)) {
1029
						$objWriter->startElement('c:layoutTarget');
1030
							$objWriter->writeAttribute('val', $layoutTarget);
1031
						$objWriter->endElement();
1032
					}
1033
1034
					$xMode = $layout->getXMode();
1035
					if (!is_null($xMode)) {
1036
						$objWriter->startElement('c:xMode');
1037
							$objWriter->writeAttribute('val', $xMode);
1038
						$objWriter->endElement();
1039
					}
1040
1041
					$yMode = $layout->getYMode();
1042
					if (!is_null($yMode)) {
1043
						$objWriter->startElement('c:yMode');
1044
							$objWriter->writeAttribute('val', $yMode);
1045
						$objWriter->endElement();
1046
					}
1047
1048
					$x = $layout->getXPosition();
1049
					if (!is_null($x)) {
1050
						$objWriter->startElement('c:x');
1051
							$objWriter->writeAttribute('val', $x);
1052
						$objWriter->endElement();
1053
					}
1054
1055
					$y = $layout->getYPosition();
1056
					if (!is_null($y)) {
1057
						$objWriter->startElement('c:y');
1058
							$objWriter->writeAttribute('val', $y);
1059
						$objWriter->endElement();
1060
					}
1061
1062
					$w = $layout->getWidth();
1063
					if (!is_null($w)) {
1064
						$objWriter->startElement('c:w');
1065
							$objWriter->writeAttribute('val', $w);
1066
						$objWriter->endElement();
1067
					}
1068
1069
					$h = $layout->getHeight();
1070
					if (!is_null($h)) {
1071
						$objWriter->startElement('c:h');
1072
							$objWriter->writeAttribute('val', $h);
1073
						$objWriter->endElement();
1074
					}
1075
1076
				$objWriter->endElement();
1077
			}
1078
1079
		$objWriter->endElement();
1080
	}
1081
1082
	/**
1083
	 * Write Alternate Content block
1084
	 *
1085
	 * @param 	PHPExcel_Shared_XMLWriter 	$objWriter 		XML Writer
1086
	 * @throws 	Exception
1087
	 */
1088
	private function _writeAlternateContent($objWriter)
1089
	{
1090
		$objWriter->startElement('mc:AlternateContent');
1091
			$objWriter->writeAttribute('xmlns:mc', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
1092
1093
			$objWriter->startElement('mc:Choice');
1094
				$objWriter->writeAttribute('xmlns:c14', 'http://schemas.microsoft.com/office/drawing/2007/8/2/chart');
1095
				$objWriter->writeAttribute('Requires', 'c14');
1096
1097
				$objWriter->startElement('c14:style');
1098
					$objWriter->writeAttribute('val', '102');
1099
				$objWriter->endElement();
1100
			$objWriter->endElement();
1101
1102
			$objWriter->startElement('mc:Fallback');
1103
				$objWriter->startElement('c:style');
1104
					$objWriter->writeAttribute('val', '2');
1105
				$objWriter->endElement();
1106
			$objWriter->endElement();
1107
1108
		$objWriter->endElement();
1109
	}
1110
1111
	/**
1112
	 * Write Printer Settings
1113
	 *
1114
	 * @param 	PHPExcel_Shared_XMLWriter 	$objWriter 		XML Writer
1115
	 * @throws 	Exception
1116
	 */
1117
	private function _writePrintSettings($objWriter)
1118
	{
1119
		$objWriter->startElement('c:printSettings');
1120
1121
			$objWriter->startElement('c:headerFooter');
1122
			$objWriter->endElement();
1123
1124
			$objWriter->startElement('c:pageMargins');
1125
				$objWriter->writeAttribute('footer', 0.3);
1126
				$objWriter->writeAttribute('header', 0.3);
1127
				$objWriter->writeAttribute('r', 0.7);
1128
				$objWriter->writeAttribute('l', 0.7);
1129
				$objWriter->writeAttribute('t', 0.75);
1130
				$objWriter->writeAttribute('b', 0.75);
1131
			$objWriter->endElement();
1132
1133
			$objWriter->startElement('c:pageSetup');
1134
				$objWriter->writeAttribute('orientation', "portrait");
1135
			$objWriter->endElement();
1136
1137
		$objWriter->endElement();
1138
	}
1139
1140
}
1141