Completed
Pull Request — develop (#565)
by
unknown
07:15
created

ObjectsChart   F

Complexity

Total Complexity 105

Size/Duplication

Total Lines 960
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 20

Test Coverage

Coverage 99.46%

Importance

Changes 0
Metric Value
wmc 105
lcom 1
cbo 20
dl 0
loc 960
ccs 549
cts 552
cp 0.9946
rs 1.64
c 0
b 0
f 0

20 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 12 3
C writeContentPart() 0 123 8
A writeAxis() 0 41 3
A writeChartStyle() 0 15 1
A writeGridline() 0 11 2
C writeAxisStyle() 0 90 9
A writeGridlineStyle() 0 17 2
A writeFloor() 0 8 1
A writeFloorStyle() 0 18 1
B writeLegend() 0 30 6
A writeLegendStyle() 0 22 2
B writePlotArea() 0 51 7
B writePlotAreaStyle() 0 48 10
C writeSeries() 0 68 10
F writeSeriesStyle() 0 129 22
C writeTable() 0 94 9
A writeTitle() 0 17 2
A writeTitleStyle() 0 20 3
A writeWall() 0 7 1
A writeWallStyle() 0 25 3

How to fix   Complexity   

Complex Class

Complex classes like ObjectsChart often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ObjectsChart, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace PhpOffice\PhpPresentation\Writer\ODPresentation;
4
5
use PhpOffice\Common\Adapter\Zip\ZipInterface;
6
use PhpOffice\Common\Drawing as CommonDrawing;
7
use PhpOffice\Common\Text;
8
use PhpOffice\Common\XMLWriter;
9
use PhpOffice\PhpPresentation\Shape\Chart;
10
use PhpOffice\PhpPresentation\Shape\Chart\Title;
11
use PhpOffice\PhpPresentation\Shape\Chart\Type\AbstractTypeBar;
12
use PhpOffice\PhpPresentation\Shape\Chart\Type\AbstractTypePie;
13
use PhpOffice\PhpPresentation\Shape\Chart\Type\Area;
14
use PhpOffice\PhpPresentation\Shape\Chart\Type\Bar;
15
use PhpOffice\PhpPresentation\Shape\Chart\Type\Bar3D;
16
use PhpOffice\PhpPresentation\Shape\Chart\Type\Doughnut;
17
use PhpOffice\PhpPresentation\Shape\Chart\Type\Line;
18
use PhpOffice\PhpPresentation\Shape\Chart\Type\Pie3D;
19
use PhpOffice\PhpPresentation\Shape\Chart\Type\Scatter;
20
use PhpOffice\PhpPresentation\Style\Fill;
21
use PhpOffice\PhpPresentation\Style\Outline;
22
23
class ObjectsChart extends AbstractDecoratorWriter
24
{
25
    /**
26
     * @var XMLWriter
27
     */
28
    protected $xmlContent;
29
    /**
30
     * @var mixed
31
     */
32
    protected $arrayData;
33
    /**
34
     * @var mixed
35
     */
36
    protected $arrayTitle;
37
    /**
38
     * @var integer
39
     */
40
    protected $numData;
41
    /**
42
     * @var integer
43
     */
44
    protected $numSeries;
45
    /**
46
     * @var string
47
     */
48
    protected $rangeCol;
49
50
    /**
51
     * @return ZipInterface
52
     * @throws \Exception
53
     */
54 62
    public function render()
55
    {
56 62
        foreach ($this->getArrayChart() as $keyChart => $shapeChart) {
57 24
            $content = $this->writeContentPart($shapeChart);
58
59 24
            if (!empty($content)) {
60 24
                $this->getZip()->addFromString('Object '.$keyChart.'/content.xml', $content);
61
            }
62
        }
63
64 62
        return $this->getZip();
65
    }
66
67
    /**
68
     * @param Chart $chart
69
     * @return string
70
     * @throws \Exception
71
     */
72 24
    protected function writeContentPart(Chart $chart)
73
    {
74 24
        $this->xmlContent = new XMLWriter(XMLWriter::STORAGE_MEMORY);
75
76 24
        $chartType = $chart->getPlotArea()->getType();
77
78
        // Data
79 24
        $this->arrayData = array();
80 24
        $this->arrayTitle = array();
81 24
        $this->numData = 0;
82 24
        foreach ($chartType->getSeries() as $series) {
83 22
            $inc = 0;
84 22
            $this->arrayTitle[] = $series->getTitle();
85 22
            foreach ($series->getValues() as $key => $value) {
86 22
                if (!isset($this->arrayData[$inc])) {
87 22
                    $this->arrayData[$inc] = array();
88
                }
89 22
                if (empty($this->arrayData[$inc])) {
90 22
                    $this->arrayData[$inc][] = $key;
91
                }
92 22
                $this->arrayData[$inc][] = $value;
93 22
                $inc++;
94
            }
95 22
            if ($inc > $this->numData) {
96 22
                $this->numData = $inc;
97
            }
98
        }
99
100
        // office:document-content
101 24
        $this->xmlContent->startElement('office:document-content');
102 24
        $this->xmlContent->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
103 24
        $this->xmlContent->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
104 24
        $this->xmlContent->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
105 24
        $this->xmlContent->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
106 24
        $this->xmlContent->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
107 24
        $this->xmlContent->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
108 24
        $this->xmlContent->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
109 24
        $this->xmlContent->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
110 24
        $this->xmlContent->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
111 24
        $this->xmlContent->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
112 24
        $this->xmlContent->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
113 24
        $this->xmlContent->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
114 24
        $this->xmlContent->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
115 24
        $this->xmlContent->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
116 24
        $this->xmlContent->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
117 24
        $this->xmlContent->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
118 24
        $this->xmlContent->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
119 24
        $this->xmlContent->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
120 24
        $this->xmlContent->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
121 24
        $this->xmlContent->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
122 24
        $this->xmlContent->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
123 24
        $this->xmlContent->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
124 24
        $this->xmlContent->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
125 24
        $this->xmlContent->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
126 24
        $this->xmlContent->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
127 24
        $this->xmlContent->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
128 24
        $this->xmlContent->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
129 24
        $this->xmlContent->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
130 24
        $this->xmlContent->writeAttribute('xmlns:chartooo', 'http://openoffice.org/2010/chart');
131 24
        $this->xmlContent->writeAttribute('xmlns:drawooo', 'http://openoffice.org/2010/draw');
132 24
        $this->xmlContent->writeAttribute('xmlns:calcext', 'urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0');
133 24
        $this->xmlContent->writeAttribute('xmlns:loext', 'urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0');
134 24
        $this->xmlContent->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
135 24
        $this->xmlContent->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0');
136 24
        $this->xmlContent->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
137 24
        $this->xmlContent->writeAttribute('office:version', '1.2');
138
139
        // office:automatic-styles
140 24
        $this->xmlContent->startElement('office:automatic-styles');
141
142
        // Styles
143 24
        $this->writeChartStyle($chart);
144 24
        $this->writeAxisStyle($chart);
145 24
        $this->numSeries = 0;
146 24
        foreach ($chartType->getSeries() as $series) {
147 22
            $this->writeSeriesStyle($chart, $series);
148 22
            $this->numSeries++;
149
        }
150 24
        $this->writeFloorStyle();
151 24
        $this->writeLegendStyle($chart);
152 24
        $this->writePlotAreaStyle($chart);
153 24
        $this->writeTitleStyle($chart->getTitle());
154 24
        $this->writeWallStyle($chart);
155
156
        // > office:automatic-styles
157 24
        $this->xmlContent->endElement();
158
159
        // office:body
160 24
        $this->xmlContent->startElement('office:body');
161
        // office:chart
162 24
        $this->xmlContent->startElement('office:chart');
163
        // office:chart
164 24
        $this->xmlContent->startElement('chart:chart');
165 24
        $this->xmlContent->writeAttribute('svg:width', Text::numberFormat(CommonDrawing::pixelsToCentimeters($chart->getWidth()), 3) . 'cm');
166 24
        $this->xmlContent->writeAttribute('svg:height', Text::numberFormat(CommonDrawing::pixelsToCentimeters($chart->getHeight()), 3) . 'cm');
167 24
        $this->xmlContent->writeAttribute('xlink:href', '.');
168 24
        $this->xmlContent->writeAttribute('xlink:type', 'simple');
169 24
        $this->xmlContent->writeAttribute('chart:style-name', 'styleChart');
170 24
        $this->xmlContent->writeAttributeIf($chartType instanceof Area, 'chart:class', 'chart:area');
171 24
        $this->xmlContent->writeAttributeIf($chartType instanceof AbstractTypeBar, 'chart:class', 'chart:bar');
172 24
        if (!($chartType instanceof Doughnut)) {
173 23
            $this->xmlContent->writeAttributeIf($chartType instanceof AbstractTypePie, 'chart:class', 'chart:circle');
174
        }
175 24
        $this->xmlContent->writeAttributeIf($chartType instanceof Doughnut, 'chart:class', 'chart:ring');
176 24
        $this->xmlContent->writeAttributeIf($chartType instanceof Line, 'chart:class', 'chart:line');
177 24
        $this->xmlContent->writeAttributeIf($chartType instanceof Scatter, 'chart:class', 'chart:scatter');
178
179 24
        $this->writeTitle($chart->getTitle());
180 24
        $this->writeLegend($chart);
181 24
        $this->writePlotArea($chart);
182 24
        $this->writeTable();
183
184
        // > chart:chart
185 24
        $this->xmlContent->endElement();
186
        // > office:chart
187 24
        $this->xmlContent->endElement();
188
        // > office:body
189 24
        $this->xmlContent->endElement();
190
        // > office:document-content
191 24
        $this->xmlContent->endElement();
192
193 24
        return $this->xmlContent->getData();
194
    }
195
196
    /**
197
     * @param Chart $chart
198
     * @throws \Exception
199
     */
200 24
    private function writeAxis(Chart $chart)
201
    {
202 24
        $chartType = $chart->getPlotArea()->getType();
203
204
        // chart:axis
205 24
        $this->xmlContent->startElement('chart:axis');
206 24
        $this->xmlContent->writeAttribute('chart:dimension', 'x');
207 24
        $this->xmlContent->writeAttribute('chart:name', 'primary-x');
208 24
        $this->xmlContent->writeAttribute('chart:style-name', 'styleAxisX');
209
        // chart:axis > chart:categories
210 24
        $this->xmlContent->startElement('chart:categories');
211 24
        $this->xmlContent->writeAttribute('table:cell-range-address', 'table-local.$A$2:.$A$'.($this->numData+1));
212 24
        $this->xmlContent->endElement();
213
        // chart:axis > chart:grid
214 24
        $this->writeGridline($chart->getPlotArea()->getAxisX()->getMajorGridlines(), 'styleAxisXGridlinesMajor', 'major');
215
        // chart:axis > chart:grid
216 24
        $this->writeGridline($chart->getPlotArea()->getAxisX()->getMinorGridlines(), 'styleAxisXGridlinesMinor', 'minor');
217
        // ##chart:axis
218 24
        $this->xmlContent->endElement();
219
220
        // chart:axis
221 24
        $this->xmlContent->startElement('chart:axis');
222 24
        $this->xmlContent->writeAttribute('chart:dimension', 'y');
223 24
        $this->xmlContent->writeAttribute('chart:name', 'primary-y');
224 24
        $this->xmlContent->writeAttribute('chart:style-name', 'styleAxisY');
225
        // chart:axis > chart:grid
226 24
        $this->writeGridline($chart->getPlotArea()->getAxisY()->getMajorGridlines(), 'styleAxisYGridlinesMajor', 'major');
227
        // chart:axis > chart:grid
228 24
        $this->writeGridline($chart->getPlotArea()->getAxisY()->getMinorGridlines(), 'styleAxisYGridlinesMinor', 'minor');
229
        // ##chart:axis
230 24
        $this->xmlContent->endElement();
231
232 24
        if ($chartType instanceof Bar3D || $chartType instanceof Pie3D) {
233
            // chart:axis
234 5
            $this->xmlContent->startElement('chart:axis');
235 5
            $this->xmlContent->writeAttribute('chart:dimension', 'z');
236 5
            $this->xmlContent->writeAttribute('chart:name', 'primary-z');
237
            // > chart:axis
238 5
            $this->xmlContent->endElement();
239
        }
240 24
    }
241
242
    /**
243
     * @param Chart\Gridlines|null $oGridlines
244
     * @param string $styleName
245
     * @param string $chartClass
246
     */
247 24
    protected function writeGridline($oGridlines, $styleName, $chartClass)
248
    {
249 24
        if (!($oGridlines instanceof Chart\Gridlines)) {
250 24
            return ;
251
        }
252
253 1
        $this->xmlContent->startElement('chart:grid');
254 1
        $this->xmlContent->writeAttribute('chart:style-name', $styleName);
255 1
        $this->xmlContent->writeAttribute('chart:class', $chartClass);
256 1
        $this->xmlContent->endElement();
257 1
    }
258
259
    /**
260
     * @param Chart $chart
261
     * @throws \Exception
262
     * @todo Set function in \PhpPresentation\Shape\Chart\Axis for defining width and color of the axis
263
     */
264 24
    protected function writeAxisStyle(Chart $chart)
265
    {
266 24
        $chartType = $chart->getPlotArea()->getType();
267
268
        // AxisX
269
        // style:style
270 24
        $this->xmlContent->startElement('style:style');
271 24
        $this->xmlContent->writeAttribute('style:name', 'styleAxisX');
272 24
        $this->xmlContent->writeAttribute('style:family', 'chart');
273
        // style:style > style:chart-properties
274 24
        $this->xmlContent->startElement('style:chart-properties');
275 24
        $this->xmlContent->writeAttribute('chart:display-label', 'true');
276 24
        $this->xmlContent->writeAttribute('chart:tick-marks-major-inner', 'false');
277 24
        $this->xmlContent->writeAttribute('chart:tick-marks-major-outer', 'false');
278 24
        if ($chartType instanceof AbstractTypePie) {
279 5
            $this->xmlContent->writeAttribute('chart:reverse-direction', 'true');
280
        }
281 24
        if ($chart->getPlotArea()->getAxisX()->getMinBounds() != null) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $chart->getPlotArea()->getAxisX()->getMinBounds() of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison !== instead.
Loading history...
282 1
            $this->xmlContent->writeAttribute('chart:minimum', $chart->getPlotArea()->getAxisX()->getMinBounds());
283
        }
284 24
        if ($chart->getPlotArea()->getAxisX()->getMaxBounds() != null) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $chart->getPlotArea()->getAxisX()->getMaxBounds() of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison !== instead.
Loading history...
285 1
            $this->xmlContent->writeAttribute('chart:maximum', $chart->getPlotArea()->getAxisX()->getMaxBounds());
286
        }
287 24
        $this->xmlContent->endElement();
288
        // style:style > style:graphic-properties
289 24
        $this->xmlContent->startElement('style:graphic-properties');
290 24
        $this->xmlContent->writeAttribute('draw:stroke', 'solid');
291 24
        $this->xmlContent->writeAttribute('svg:stroke-width', '0.026cm');
292 24
        $this->xmlContent->writeAttribute('svg:stroke-color', '#878787');
293 24
        $this->xmlContent->endElement();
294
        // style:style > style:text-properties
295 24
        $oFont = $chart->getPlotArea()->getAxisX()->getFont();
296 24
        $this->xmlContent->startElement('style:text-properties');
297 24
        $this->xmlContent->writeAttribute('fo:color', '#'.$oFont->getColor()->getRGB());
298 24
        $this->xmlContent->writeAttribute('fo:font-family', $oFont->getName());
299 24
        $this->xmlContent->writeAttribute('fo:font-size', $oFont->getSize().'pt');
300 24
        $this->xmlContent->writeAttribute('fo:font-style', $oFont->isItalic() ? 'italic' : 'normal');
301 24
        $this->xmlContent->endElement();
302
        // ##style:style
303 24
        $this->xmlContent->endElement();
304
305
        // AxisX GridLines Major
306 24
        $this->writeGridlineStyle($chart->getPlotArea()->getAxisX()->getMajorGridlines(), 'styleAxisXGridlinesMajor');
307
308
        // AxisX GridLines Minor
309 24
        $this->writeGridlineStyle($chart->getPlotArea()->getAxisX()->getMinorGridlines(), 'styleAxisXGridlinesMinor');
310
311
        // AxisY
312
        // style:style
313 24
        $this->xmlContent->startElement('style:style');
314 24
        $this->xmlContent->writeAttribute('style:name', 'styleAxisY');
315 24
        $this->xmlContent->writeAttribute('style:family', 'chart');
316
        // style:style > style:chart-properties
317 24
        $this->xmlContent->startElement('style:chart-properties');
318 24
        $this->xmlContent->writeAttribute('chart:display-label', 'true');
319 24
        $this->xmlContent->writeAttribute('chart:tick-marks-major-inner', 'false');
320 24
        $this->xmlContent->writeAttribute('chart:tick-marks-major-outer', 'false');
321 24
        if ($chartType instanceof AbstractTypePie) {
322 5
            $this->xmlContent->writeAttribute('chart:reverse-direction', 'true');
323
        }
324 24
        if ($chart->getPlotArea()->getAxisY()->getMinBounds() !== null) {
325
            $this->xmlContent->writeAttribute('chart:minimum', $chart->getPlotArea()->getAxisY()->getMinBounds());
326
        }
327 24
        if ($chart->getPlotArea()->getAxisY()->getMaxBounds() !== null) {
328
            $this->xmlContent->writeAttribute('chart:maximum', $chart->getPlotArea()->getAxisY()->getMaxBounds());
329
        }
330 24
        $this->xmlContent->endElement();
331
        // style:graphic-properties
332 24
        $this->xmlContent->startElement('style:graphic-properties');
333 24
        $this->xmlContent->writeAttribute('draw:stroke', 'solid');
334 24
        $this->xmlContent->writeAttribute('svg:stroke-width', '0.026cm');
335 24
        $this->xmlContent->writeAttribute('svg:stroke-color', '#878787');
336 24
        $this->xmlContent->endElement();
337
        // style:style > style:text-properties
338 24
        $oFont = $chart->getPlotArea()->getAxisY()->getFont();
339 24
        $this->xmlContent->startElement('style:text-properties');
340 24
        $this->xmlContent->writeAttribute('fo:color', '#'.$oFont->getColor()->getRGB());
341 24
        $this->xmlContent->writeAttribute('fo:font-family', $oFont->getName());
342 24
        $this->xmlContent->writeAttribute('fo:font-size', $oFont->getSize().'pt');
343 24
        $this->xmlContent->writeAttribute('fo:font-style', $oFont->isItalic() ? 'italic' : 'normal');
344 24
        $this->xmlContent->endElement();
345
        // ## style:style
346 24
        $this->xmlContent->endElement();
347
348
        // AxisY GridLines Major
349 24
        $this->writeGridlineStyle($chart->getPlotArea()->getAxisY()->getMajorGridlines(), 'styleAxisYGridlinesMajor');
350
351
        // AxisY GridLines Minor
352 24
        $this->writeGridlineStyle($chart->getPlotArea()->getAxisY()->getMinorGridlines(), 'styleAxisYGridlinesMinor');
353 24
    }
354
355
    /**
356
     * @param Chart\Gridlines|null $oGridlines
357
     * @param string $styleName
358
     */
359 24
    protected function writeGridlineStyle($oGridlines, $styleName)
360
    {
361 24
        if (!($oGridlines instanceof Chart\Gridlines)) {
362 24
            return;
363
        }
364
        // style:style
365 1
        $this->xmlContent->startElement('style:style');
366 1
        $this->xmlContent->writeAttribute('style:name', $styleName);
367 1
        $this->xmlContent->writeAttribute('style:family', 'chart');
368
        // style:style > style:graphic-properties
369 1
        $this->xmlContent->startElement('style:graphic-properties');
370 1
        $this->xmlContent->writeAttribute('svg:stroke-width', number_format(CommonDrawing::pointsToCentimeters($oGridlines->getOutline()->getWidth()), 2, '.', '').'cm');
371 1
        $this->xmlContent->writeAttribute('svg:stroke-color', '#'.$oGridlines->getOutline()->getFill()->getStartColor()->getRGB());
372 1
        $this->xmlContent->endElement();
373
        // ##style:style
374 1
        $this->xmlContent->endElement();
375 1
    }
376
377
    /**
378
     * @param Chart $chart
379
     */
380 24
    private function writeChartStyle(Chart $chart)
381
    {
382
        // style:style
383 24
        $this->xmlContent->startElement('style:style');
384 24
        $this->xmlContent->writeAttribute('style:name', 'styleChart');
385 24
        $this->xmlContent->writeAttribute('style:family', 'chart');
386
        // style:graphic-properties
387 24
        $this->xmlContent->startElement('style:graphic-properties');
388 24
        $this->xmlContent->writeAttribute('draw:stroke', $chart->getFill()->getFillType());
389 24
        $this->xmlContent->writeAttribute('draw:fill-color', '#'.$chart->getFill()->getStartColor()->getRGB());
390
        // > style:graphic-properties
391 24
        $this->xmlContent->endElement();
392
        // > style:style
393 24
        $this->xmlContent->endElement();
394 24
    }
395
396 24
    private function writeFloor()
397
    {
398
        // chart:floor
399 24
        $this->xmlContent->startElement('chart:floor');
400 24
        $this->xmlContent->writeAttribute('chart:style-name', 'styleFloor');
401
        // > chart:floor
402 24
        $this->xmlContent->endElement();
403 24
    }
404
405 24
    private function writeFloorStyle()
406
    {
407
        // style:style
408 24
        $this->xmlContent->startElement('style:style');
409 24
        $this->xmlContent->writeAttribute('style:name', 'styleFloor');
410 24
        $this->xmlContent->writeAttribute('style:family', 'chart');
411
        // style:chart-properties
412 24
        $this->xmlContent->startElement('style:graphic-properties');
413 24
        $this->xmlContent->writeAttribute('draw:fill', 'none');
414
        //@todo : Permit edit color and size border of floor
415 24
        $this->xmlContent->writeAttribute('draw:stroke', 'solid');
416 24
        $this->xmlContent->writeAttribute('svg:stroke-width', '0.026cm');
417 24
        $this->xmlContent->writeAttribute('svg:stroke-color', '#878787');
418
        // > style:chart-properties
419 24
        $this->xmlContent->endElement();
420
        // > style:style
421 24
        $this->xmlContent->endElement();
422 24
    }
423
424
    /**
425
     * @param Chart $chart
426
     */
427 24
    private function writeLegend(Chart $chart)
428
    {
429
        // chart:legend
430 24
        $this->xmlContent->startElement('chart:legend');
431 24
        switch ($chart->getLegend()->getPosition()) {
432 24
            case Chart\Legend::POSITION_BOTTOM:
433 1
                $position = 'bottom';
434 1
                break;
435 24
            case Chart\Legend::POSITION_LEFT:
436 1
                $position = 'start';
437 1
                break;
438 24
            case Chart\Legend::POSITION_TOP:
439 1
                $position = 'top';
440 1
                break;
441 24
            case Chart\Legend::POSITION_TOPRIGHT:
442 1
                $position = 'top-end';
443 1
                break;
444 24
            case Chart\Legend::POSITION_RIGHT:
445
            default:
446 24
                $position = 'end';
447 24
                break;
448
        }
449 24
        $this->xmlContent->writeAttribute('chart:legend-position', $position);
450 24
        $this->xmlContent->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($chart->getLegend()->getOffsetX()), 3) . 'cm');
451 24
        $this->xmlContent->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($chart->getLegend()->getOffsetY()), 3) . 'cm');
452 24
        $this->xmlContent->writeAttribute('style:legend-expansion', 'high');
453 24
        $this->xmlContent->writeAttribute('chart:style-name', 'styleLegend');
454
        // > chart:legend
455 24
        $this->xmlContent->endElement();
456 24
    }
457
458
    /**
459
     * @param Chart $chart
460
     */
461 24
    private function writeLegendStyle(Chart $chart)
462
    {
463
        // style:style
464 24
        $this->xmlContent->startElement('style:style');
465 24
        $this->xmlContent->writeAttribute('style:name', 'styleLegend');
466 24
        $this->xmlContent->writeAttribute('style:family', 'chart');
467
        // style:chart-properties
468 24
        $this->xmlContent->startElement('style:chart-properties');
469 24
        $this->xmlContent->writeAttribute('chart:auto-position', 'true');
470
        // > style:chart-properties
471 24
        $this->xmlContent->endElement();
472
        // style:text-properties
473 24
        $this->xmlContent->startElement('style:text-properties');
474 24
        $this->xmlContent->writeAttribute('fo:color', '#'.$chart->getLegend()->getFont()->getColor()->getRGB());
475 24
        $this->xmlContent->writeAttribute('fo:font-family', $chart->getLegend()->getFont()->getName());
476 24
        $this->xmlContent->writeAttribute('fo:font-size', $chart->getLegend()->getFont()->getSize().'pt');
477 24
        $this->xmlContent->writeAttribute('fo:font-style', $chart->getLegend()->getFont()->isItalic() ? 'italic' : 'normal');
478
        // > style:text-properties
479 24
        $this->xmlContent->endElement();
480
        // > style:style
481 24
        $this->xmlContent->endElement();
482 24
    }
483
484
    /**
485
     * @param Chart $chart
486
     * @throws \Exception
487
     */
488 24
    private function writePlotArea(Chart $chart)
489
    {
490 24
        $chartType = $chart->getPlotArea()->getType();
491
492
        // chart:plot-area
493 24
        $this->xmlContent->startElement('chart:plot-area');
494 24
        $this->xmlContent->writeAttribute('chart:style-name', 'stylePlotArea');
495 24
        if ($chartType instanceof Bar3D || $chartType instanceof Pie3D) {
496 5
            $this->xmlContent->writeAttribute('dr3d:ambient-color', '#cccccc');
497 5
            $this->xmlContent->writeAttribute('dr3d:lighting-mode', 'true');
498
        }
499 24
        if ($chartType instanceof Bar3D || $chartType instanceof Pie3D) {
500
            // dr3d:light
501
            $arrayLight = array(
502 5
                array('#808080', '(0 0 1)', 'false', 'true'),
503
                array('#666666', '(0.2 0.4 1)', 'true', 'false'),
504
                array('#808080', '(0 0 1)', 'false', 'false'),
505
                array('#808080', '(0 0 1)', 'false', 'false'),
506
                array('#808080', '(0 0 1)', 'false', 'false'),
507
                array('#808080', '(0 0 1)', 'false', 'false'),
508
                array('#808080', '(0 0 1)', 'false', 'false'),
509
            );
510 5
            foreach ($arrayLight as $light) {
511 5
                $this->xmlContent->startElement('dr3d:light');
512 5
                $this->xmlContent->writeAttribute('dr3d:diffuse-color', $light[0]);
513 5
                $this->xmlContent->writeAttribute('dr3d:direction', $light[1]);
514 5
                $this->xmlContent->writeAttribute('dr3d:enabled', $light[2]);
515 5
                $this->xmlContent->writeAttribute('dr3d:specular', $light[3]);
516 5
                $this->xmlContent->endElement();
517
            }
518
        }
519
520
        //**** Axis ****
521 24
        $this->writeAxis($chart);
522
523
        //**** Series ****
524 24
        $this->rangeCol = 'B';
525 24
        $this->numSeries = 0;
526 24
        foreach ($chartType->getSeries() as $series) {
527 22
            $this->writeSeries($chart, $series);
528 22
            $this->rangeCol++;
529 22
            $this->numSeries++;
530
        }
531
532
        //**** Wall ****
533 24
        $this->writeWall();
534
        //**** Floor ****
535 24
        $this->writeFloor();
536
        // > chart:plot-area
537 24
        $this->xmlContent->endElement();
538 24
    }
539
540
    /**
541
     * @param Chart $chart
542
     * @throws \Exception
543
     * @link : http://books.evc-cit.info/odbook/ch08.html#chart-plot-area-section
544
     */
545 24
    private function writePlotAreaStyle(Chart $chart)
546
    {
547 24
        $chartType = $chart->getPlotArea()->getType();
548
549
        // style:style
550 24
        $this->xmlContent->startElement('style:style');
551 24
        $this->xmlContent->writeAttribute('style:name', 'stylePlotArea');
552 24
        $this->xmlContent->writeAttribute('style:family', 'chart');
553
        // style:text-properties
554 24
        $this->xmlContent->startElement('style:chart-properties');
555 24
        if ($chartType instanceof Bar3D) {
556 3
            $this->xmlContent->writeAttribute('chart:three-dimensional', 'true');
557 3
            $this->xmlContent->writeAttribute('chart:right-angled-axes', 'true');
558 21
        } elseif ($chartType instanceof Pie3D) {
559 2
            $this->xmlContent->writeAttribute('chart:three-dimensional', 'true');
560 2
            $this->xmlContent->writeAttribute('chart:right-angled-axes', 'true');
561
        }
562 24
        if ($chartType instanceof AbstractTypeBar) {
563 8
            $chartVertical = 'false';
564 8
            if ($chartType->getBarDirection() == AbstractTypeBar::DIRECTION_HORIZONTAL) {
565 2
                $chartVertical = 'true';
566
            }
567 8
            $this->xmlContent->writeAttribute('chart:vertical', $chartVertical);
568 8
            if ($chartType->getBarGrouping() == Bar::GROUPING_CLUSTERED) {
569 6
                $this->xmlContent->writeAttribute('chart:stacked', 'false');
570 6
                $this->xmlContent->writeAttribute('chart:overlap', '0');
571 2
            } elseif ($chartType->getBarGrouping() == Bar::GROUPING_STACKED) {
572 1
                $this->xmlContent->writeAttribute('chart:stacked', 'true');
573 1
                $this->xmlContent->writeAttribute('chart:overlap', '100');
574 1
            } elseif ($chartType->getBarGrouping() == Bar::GROUPING_PERCENTSTACKED) {
575 1
                $this->xmlContent->writeAttribute('chart:stacked', 'true');
576 1
                $this->xmlContent->writeAttribute('chart:overlap', '100');
577 1
                $this->xmlContent->writeAttribute('chart:percentage', 'true');
578
            }
579
        }
580 24
        $labelFormat = 'value';
581 24
        if ($chartType instanceof AbstractTypeBar) {
582 8
            if ($chartType->getBarGrouping() == Bar::GROUPING_PERCENTSTACKED) {
583 1
                $labelFormat = 'percentage';
584
            }
585
        }
586 24
        $this->xmlContent->writeAttribute('chart:data-label-number', $labelFormat);
587
588
        // > style:text-properties
589 24
        $this->xmlContent->endElement();
590
        // > style:style
591 24
        $this->xmlContent->endElement();
592 24
    }
593
594
    /**
595
     * @param Chart $chart
596
     * @param Chart\Series $series
597
     * @throws \Exception
598
     */
599 22
    private function writeSeries(Chart $chart, Chart\Series $series)
600
    {
601 22
        $chartType = $chart->getPlotArea()->getType();
602
603 22
        $numRange = count($series->getValues());
604
        // chart:series
605 22
        $this->xmlContent->startElement('chart:series');
606 22
        $this->xmlContent->writeAttribute('chart:values-cell-range-address', 'table-local.$'.$this->rangeCol.'$2:.$'.$this->rangeCol.'$'.($numRange+1));
607 22
        $this->xmlContent->writeAttribute('chart:label-cell-address', 'table-local.$'.$this->rangeCol.'$1');
608
        // if ($chartType instanceof Area) {
609
        //     $this->xmlContent->writeAttribute('chart:class', 'chart:area');
610
        // } elseif ($chartType instanceof AbstractTypeBar) {
611
        //     $this->xmlContent->writeAttribute('chart:class', 'chart:bar');
612
        // } elseif ($chartType instanceof Line) {
613
        //     $this->xmlContent->writeAttribute('chart:class', 'chart:line');
614
        // } elseif ($chartType instanceof AbstractTypePie) {
615
        //     $this->xmlContent->writeAttribute('chart:class', 'chart:circle');
616
        // } elseif ($chartType instanceof Scatter) {
617
        //     $this->xmlContent->writeAttribute('chart:class', 'chart:scatter');
618
        // }
619 22
        $this->xmlContent->writeAttribute('chart:style-name', 'styleSeries'.$this->numSeries);
620 22
        if ($chartType instanceof Area || $chartType instanceof AbstractTypeBar || $chartType instanceof Line || $chartType instanceof Scatter) {
621 17
            $dataPointFills = $series->getDataPointFills();
622
623 17
            $incRepeat = $numRange;
624 17
            if (!empty($dataPointFills)) {
625 4
                $inc = 0;
626 4
                $incRepeat = 1;
627 4
                $newFill = new Fill();
628
                do {
629 4
                    if ($series->getDataPointFill($inc)->getHashCode() !== $newFill->getHashCode()) {
630
                        // chart:data-point
631 4
                        $this->xmlContent->startElement('chart:data-point');
632 4
                        $this->xmlContent->writeAttribute('chart:repeated', $incRepeat);
633
                        // > chart:data-point
634 4
                        $this->xmlContent->endElement();
635 4
                        $incRepeat = 1;
636
637
                        // chart:data-point
638 4
                        $this->xmlContent->startElement('chart:data-point');
639 4
                        $this->xmlContent->writeAttribute('chart:style-name', 'styleSeries'.$this->numSeries.'_'.$inc);
640
                        // > chart:data-point
641 4
                        $this->xmlContent->endElement();
642
                    }
643 4
                    $inc++;
644 4
                    $incRepeat++;
645 4
                } while ($inc < $numRange);
646 4
                $incRepeat--;
647
            }
648
            // chart:data-point
649 17
            $this->xmlContent->startElement('chart:data-point');
650 17
            $this->xmlContent->writeAttribute('chart:repeated', $incRepeat);
651
            // > chart:data-point
652 17
            $this->xmlContent->endElement();
653 5
        } elseif ($chartType instanceof AbstractTypePie) {
654 5
            $count = count($series->getDataPointFills());
655 5
            for ($inc = 0; $inc < $count; $inc++) {
656
                // chart:data-point
657 3
                $this->xmlContent->startElement('chart:data-point');
658 3
                $this->xmlContent->writeAttribute('chart:style-name', 'styleSeries'.$this->numSeries.'_'.$inc);
659
                // > chart:data-point
660 3
                $this->xmlContent->endElement();
661
            }
662
        }
663
664
        // > chart:series
665 22
        $this->xmlContent->endElement();
666 22
    }
667
668
    /**
669
     * @param Chart $chart
670
     * @param Chart\Series $series
671
     * @throws \Exception
672
     */
673 22
    private function writeSeriesStyle(Chart $chart, Chart\Series $series)
674
    {
675 22
        $chartType = $chart->getPlotArea()->getType();
676
677
        // style:style
678 22
        $this->xmlContent->startElement('style:style');
679 22
        $this->xmlContent->writeAttribute('style:name', 'styleSeries'.$this->numSeries);
680 22
        $this->xmlContent->writeAttribute('style:family', 'chart');
681
        // style:chart-properties
682 22
        $this->xmlContent->startElement('style:chart-properties');
683 22
        if ($series->hasShowValue()) {
684 22
            if ($series->hasShowPercentage()) {
685 1
                $this->xmlContent->writeAttribute('chart:data-label-number', 'value-and-percentage');
686
            } else {
687 22
                $this->xmlContent->writeAttribute('chart:data-label-number', 'value');
688
            }
689 1
        } elseif ($series->hasShowPercentage()) {
690 1
            $this->xmlContent->writeAttribute('chart:data-label-number', 'percentage');
691
        }
692 22
        if ($series->hasShowCategoryName()) {
693 1
            $this->xmlContent->writeAttribute('chart:data-label-text', 'true');
694
        }
695 22
        $this->xmlContent->writeAttribute('chart:label-position', 'center');
696 22
        if ($chartType instanceof AbstractTypePie) {
697 5
            $this->xmlContent->writeAttribute('chart:pie-offset', $chartType->getExplosion());
698
        }
699 22
        if ($chartType instanceof Line || $chartType instanceof Scatter) {
700 9
            $oMarker = $series->getMarker();
701
            /**
702
             * @link : http://www.datypic.com/sc/odf/a-chart_symbol-type.html
703
             */
704 9
            $this->xmlContent->writeAttributeIf($oMarker->getSymbol() == Chart\Marker::SYMBOL_NONE, 'chart:symbol-type', 'none');
705
            /**
706
             * @link : http://www.datypic.com/sc/odf/a-chart_symbol-name.html
707
             */
708 9
            $this->xmlContent->writeAttributeIf($oMarker->getSymbol() != Chart\Marker::SYMBOL_NONE, 'chart:symbol-type', 'named-symbol');
709 9
            if ($oMarker->getSymbol() != Chart\Marker::SYMBOL_NONE) {
710 2
                switch ($oMarker->getSymbol()) {
711 2
                    case Chart\Marker::SYMBOL_DASH:
712 2
                        $symbolName = 'horizontal-bar';
713 2
                        break;
714 2
                    case Chart\Marker::SYMBOL_DOT:
715 2
                        $symbolName = 'circle';
716 2
                        break;
717 2
                    case Chart\Marker::SYMBOL_TRIANGLE:
718 2
                        $symbolName = 'arrow-up';
719 2
                        break;
720
                    default:
721 2
                        $symbolName = $oMarker->getSymbol();
722 2
                        break;
723
                }
724 2
                $this->xmlContent->writeAttribute('chart:symbol-name', $symbolName);
725 2
                $symbolSize = number_format(CommonDrawing::pointsToCentimeters($oMarker->getSize()), 2, '.', '');
726 2
                $this->xmlContent->writeAttribute('chart:symbol-width', $symbolSize.'cm');
727 2
                $this->xmlContent->writeAttribute('chart:symbol-height', $symbolSize.'cm');
728
            }
729
        }
730
731 22
        $separator = $series->getSeparator();
732 22
        if (!empty($separator)) {
733
            // style:chart-properties/chart:label-separator
734 1
            $this->xmlContent->startElement('chart:label-separator');
735 1
            if ($separator == PHP_EOL) {
736
                $this->xmlContent->writeRaw('<text:p><text:line-break /></text:p>');
737
            } else {
738 1
                $this->xmlContent->writeElement('text:p', $separator);
739
            }
740 1
            $this->xmlContent->endElement();
741
        }
742
743
        // > style:chart-properties
744 22
        $this->xmlContent->endElement();
745
        // style:graphic-properties
746 22
        $this->xmlContent->startElement('style:graphic-properties');
747 22
        if ($chartType instanceof Line || $chartType instanceof Scatter) {
748 9
            $outlineWidth = '';
749 9
            $outlineColor = '';
750
751 9
            $oOutline = $series->getOutline();
752 9
            if ($oOutline instanceof Outline) {
753 2
                $outlineWidth = $oOutline->getWidth();
754 2
                if (!empty($outlineWidth)) {
755 2
                    $outlineWidth = number_format(CommonDrawing::pointsToCentimeters($outlineWidth), 3, '.', '');
756
                }
757 2
                $outlineColor = $oOutline->getFill()->getStartColor()->getRGB();
758
            }
759 9
            if (empty($outlineWidth)) {
760 9
                $outlineWidth = '0.079';
761
            }
762 9
            if (empty($outlineColor)) {
763 9
                $outlineColor = '4a7ebb';
764
            }
765 9
            $this->xmlContent->writeAttribute('svg:stroke-width', $outlineWidth.'cm');
766 9
            $this->xmlContent->writeAttribute('svg:stroke-color', '#'.$outlineColor);
767
        } else {
768 13
            $this->xmlContent->writeAttribute('draw:stroke', 'none');
769 13
            if (!($chartType instanceof Area)) {
770 12
                $this->xmlContent->writeAttribute('draw:fill', $series->getFill()->getFillType());
771
            }
772
        }
773 22
        $this->xmlContent->writeAttribute('draw:fill-color', '#'.$series->getFill()->getStartColor()->getRGB());
774
        // > style:graphic-properties
775 22
        $this->xmlContent->endElement();
776
        // style:text-properties
777 22
        $this->xmlContent->startElement('style:text-properties');
778 22
        $this->xmlContent->writeAttribute('fo:color', '#'.$series->getFont()->getColor()->getRGB());
779 22
        $this->xmlContent->writeAttribute('fo:font-family', $series->getFont()->getName());
780 22
        $this->xmlContent->writeAttribute('fo:font-size', $series->getFont()->getSize().'pt');
781
        // > style:text-properties
782 22
        $this->xmlContent->endElement();
783
784
        // > style:style
785 22
        $this->xmlContent->endElement();
786
787 22
        foreach ($series->getDataPointFills() as $idx => $oFill) {
788
            // style:style
789 7
            $this->xmlContent->startElement('style:style');
790 7
            $this->xmlContent->writeAttribute('style:name', 'styleSeries'.$this->numSeries.'_'.$idx);
791 7
            $this->xmlContent->writeAttribute('style:family', 'chart');
792
            // style:graphic-properties
793 7
            $this->xmlContent->startElement('style:graphic-properties');
794 7
            $this->xmlContent->writeAttribute('draw:fill', $oFill->getFillType());
795 7
            $this->xmlContent->writeAttribute('draw:fill-color', '#'.$oFill->getStartColor()->getRGB());
796
            // > style:graphic-properties
797 7
            $this->xmlContent->endElement();
798
            // > style:style
799 7
            $this->xmlContent->endElement();
800
        }
801 22
    }
802
803
    /**
804
     */
805 24
    private function writeTable()
806
    {
807
        // table:table
808 24
        $this->xmlContent->startElement('table:table');
809 24
        $this->xmlContent->writeAttribute('table:name', 'table-local');
810
811
        // table:table-columns
812 24
        $this->xmlContent->startElement('table:table-columns');
813
        // table:table-column
814 24
        $this->xmlContent->startElement('table:table-column');
815 24
        if (!empty($this->arrayData)) {
816 22
            $rowFirst = reset($this->arrayData);
817 22
            $this->xmlContent->writeAttribute('table:number-columns-repeated', count($rowFirst) - 1);
818
        }
819
        // > table:table-column
820 24
        $this->xmlContent->endElement();
821
        // > table:table-columns
822 24
        $this->xmlContent->endElement();
823
824
        // table:table-header-columns
825 24
        $this->xmlContent->startElement('table:table-header-columns');
826
        // table:table-column
827 24
        $this->xmlContent->writeElement('table:table-column');
828
        // > table:table-header-columns
829 24
        $this->xmlContent->endElement();
830
831
        // table:table-rows
832 24
        $this->xmlContent->startElement('table:table-rows');
833 24
        if (empty($this->arrayData)) {
834 2
            $this->xmlContent->startElement('table:table-row');
835 2
            $this->xmlContent->startElement('table:table-cell');
836 2
            $this->xmlContent->endElement();
837 2
            $this->xmlContent->endElement();
838
        } else {
839 22
            foreach ($this->arrayData as $row) {
840
                // table:table-row
841 22
                $this->xmlContent->startElement('table:table-row');
842 22
                foreach ($row as $cell) {
843
                    // table:table-cell
844 22
                    $this->xmlContent->startElement('table:table-cell');
845
846 22
                    $cellNumeric = is_numeric($cell);
847 22
                    $this->xmlContent->writeAttributeIf(!$cellNumeric, 'office:value-type', 'string');
848 22
                    $this->xmlContent->writeAttributeIf($cellNumeric, 'office:value-type', 'float');
849 22
                    $this->xmlContent->writeAttributeIf($cellNumeric, 'office:value', $cell);
850
                    // text:p
851 22
                    $this->xmlContent->startElement('text:p');
852 22
                    $this->xmlContent->text($cell);
853
                    // > text:p
854 22
                    $this->xmlContent->endElement();
855
                    // > table:table-cell
856 22
                    $this->xmlContent->endElement();
857
                }
858
                // > table:table-row
859 22
                $this->xmlContent->endElement();
860
            }
861
        }
862
        // > table:table-rows
863 24
        $this->xmlContent->endElement();
864
865
        // table:table-header-rows
866 24
        $this->xmlContent->startElement('table:table-header-rows');
867
        // table:table-row
868 24
        $this->xmlContent->startElement('table:table-row');
869 24
        if (empty($this->arrayData)) {
870 2
            $this->xmlContent->startElement('table:table-cell');
871 2
            $this->xmlContent->endElement();
872
        } else {
873 22
            $rowFirst = reset($this->arrayData);
874 22
            foreach ($rowFirst as $key => $cell) {
875
                // table:table-cell
876 22
                $this->xmlContent->startElement('table:table-cell');
877 22
                if (isset($this->arrayTitle[$key - 1])) {
878 22
                    $this->xmlContent->writeAttribute('office:value-type', 'string');
879
                }
880
                // text:p
881 22
                $this->xmlContent->startElement('text:p');
882 22
                if (isset($this->arrayTitle[$key - 1])) {
883 22
                    $this->xmlContent->text($this->arrayTitle[$key - 1]);
884
                }
885
                // > text:p
886 22
                $this->xmlContent->endElement();
887
                // > table:table-cell
888 22
                $this->xmlContent->endElement();
889
            }
890
        }
891
        // > table:table-row
892 24
        $this->xmlContent->endElement();
893
        // > table:table-header-rows
894 24
        $this->xmlContent->endElement();
895
896
        // > table:table
897 24
        $this->xmlContent->endElement();
898 24
    }
899
900
    /**
901
     * @param Title $oTitle
902
     */
903 24
    private function writeTitle(Title $oTitle)
904
    {
905 24
        if (!$oTitle->isVisible()) {
906 1
            return;
907
        }
908
        // chart:title
909 24
        $this->xmlContent->startElement('chart:title');
910 24
        $this->xmlContent->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($oTitle->getOffsetX()), 3) . 'cm');
911 24
        $this->xmlContent->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($oTitle->getOffsetY()), 3) . 'cm');
912 24
        $this->xmlContent->writeAttribute('chart:style-name', 'styleTitle');
913
        // > text:p
914 24
        $this->xmlContent->startElement('text:p');
915 24
        $this->xmlContent->text($oTitle->getText());
916 24
        $this->xmlContent->endElement();
917
        // > chart:title
918 24
        $this->xmlContent->endElement();
919 24
    }
920
921
    /**
922
     * @param Title $oTitle
923
     */
924 24
    private function writeTitleStyle(Title $oTitle)
925
    {
926 24
        if (!$oTitle->isVisible()) {
927 1
            return;
928
        }
929
        // style:style
930 24
        $this->xmlContent->startElement('style:style');
931 24
        $this->xmlContent->writeAttribute('style:name', 'styleTitle');
932 24
        $this->xmlContent->writeAttribute('style:family', 'chart');
933
        // style:text-properties
934 24
        $this->xmlContent->startElement('style:text-properties');
935 24
        $this->xmlContent->writeAttribute('fo:color', '#'.$oTitle->getFont()->getColor()->getRGB());
936 24
        $this->xmlContent->writeAttribute('fo:font-family', $oTitle->getFont()->getName());
937 24
        $this->xmlContent->writeAttribute('fo:font-size', $oTitle->getFont()->getSize().'pt');
938 24
        $this->xmlContent->writeAttribute('fo:font-style', $oTitle->getFont()->isItalic() ? 'italic' : 'normal');
939
        // > style:text-properties
940 24
        $this->xmlContent->endElement();
941
        // > style:style
942 24
        $this->xmlContent->endElement();
943 24
    }
944
945 24
    private function writeWall()
946
    {
947
        // chart:wall
948 24
        $this->xmlContent->startElement('chart:wall');
949 24
        $this->xmlContent->writeAttribute('chart:style-name', 'styleWall');
950 24
        $this->xmlContent->endElement();
951 24
    }
952
953
    /**
954
     * @param Chart $chart
955
     * @throws \Exception
956
     */
957 24
    private function writeWallStyle(Chart $chart)
958
    {
959 24
        $chartType = $chart->getPlotArea()->getType();
960
961
        // style:style
962 24
        $this->xmlContent->startElement('style:style');
963 24
        $this->xmlContent->writeAttribute('style:name', 'styleWall');
964 24
        $this->xmlContent->writeAttribute('style:family', 'chart');
965
        // style:chart-properties
966 24
        $this->xmlContent->startElement('style:graphic-properties');
967
        //@todo : Permit edit color and size border of wall
968 24
        if ($chartType instanceof Line || $chartType instanceof Scatter) {
969 10
            $this->xmlContent->writeAttribute('draw:fill', 'solid');
970 10
            $this->xmlContent->writeAttribute('draw:fill-color', '#FFFFFF');
971
        } else {
972 14
            $this->xmlContent->writeAttribute('draw:fill', 'none');
973 14
            $this->xmlContent->writeAttribute('draw:stroke', 'solid');
974 14
            $this->xmlContent->writeAttribute('svg:stroke-width', '0.026cm');
975 14
            $this->xmlContent->writeAttribute('svg:stroke-color', '#878787');
976
        }
977
        // > style:chart-properties
978 24
        $this->xmlContent->endElement();
979
        // > style:style
980 24
        $this->xmlContent->endElement();
981 24
    }
982
}
983