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