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 |
||
| 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 | 24 | } |
|
| 62 | 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 | 22 | } |
|
| 89 | 22 | if (empty($this->arrayData[$inc])) { |
|
| 90 | 22 | $this->arrayData[$inc][] = $key; |
|
| 91 | 22 | } |
|
| 92 | 22 | $this->arrayData[$inc][] = $value; |
|
| 93 | 22 | $inc++; |
|
| 94 | 22 | } |
|
| 95 | 22 | if ($inc > $this->numData) { |
|
| 96 | 22 | $this->numData = $inc; |
|
| 97 | 22 | } |
|
| 98 | 24 | } |
|
| 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 | // Chart |
||
| 143 | 24 | $this->writeChartStyle($chart); |
|
| 144 | |||
| 145 | // Axis |
||
| 146 | 24 | $this->writeAxisStyle($chart); |
|
| 147 | |||
| 148 | // Series |
||
| 149 | 24 | $this->numSeries = 0; |
|
| 150 | 24 | foreach ($chartType->getSeries() as $series) { |
|
| 151 | 22 | $this->writeSeriesStyle($chart, $series); |
|
| 152 | |||
| 153 | 22 | $this->numSeries++; |
|
| 154 | 24 | } |
|
| 155 | |||
| 156 | // Floor |
||
| 157 | 24 | $this->writeFloorStyle(); |
|
| 158 | |||
| 159 | // Legend |
||
| 160 | 24 | $this->writeLegendStyle($chart); |
|
| 161 | |||
| 162 | // PlotArea |
||
| 163 | 24 | $this->writePlotAreaStyle($chart); |
|
| 164 | |||
| 165 | // Title |
||
| 166 | 24 | $this->writeTitleStyle($chart->getTitle()); |
|
| 167 | |||
| 168 | // Wall |
||
| 169 | 24 | $this->writeWallStyle($chart); |
|
| 170 | |||
| 171 | // > office:automatic-styles |
||
| 172 | 24 | $this->xmlContent->endElement(); |
|
| 173 | |||
| 174 | // office:body |
||
| 175 | 24 | $this->xmlContent->startElement('office:body'); |
|
| 176 | // office:chart |
||
| 177 | 24 | $this->xmlContent->startElement('office:chart'); |
|
| 178 | // office:chart |
||
| 179 | 24 | $this->xmlContent->startElement('chart:chart'); |
|
| 180 | 24 | $this->xmlContent->writeAttribute('svg:width', Text::numberFormat(CommonDrawing::pixelsToCentimeters($chart->getWidth()), 3) . 'cm'); |
|
| 181 | 24 | $this->xmlContent->writeAttribute('svg:height', Text::numberFormat(CommonDrawing::pixelsToCentimeters($chart->getHeight()), 3) . 'cm'); |
|
| 182 | 24 | $this->xmlContent->writeAttribute('xlink:href', '.'); |
|
| 183 | 24 | $this->xmlContent->writeAttribute('xlink:type', 'simple'); |
|
| 184 | 24 | $this->xmlContent->writeAttribute('chart:style-name', 'styleChart'); |
|
| 185 | 24 | $this->xmlContent->writeAttributeIf($chartType instanceof Area, 'chart:class', 'chart:area'); |
|
| 186 | 24 | $this->xmlContent->writeAttributeIf($chartType instanceof AbstractTypeBar, 'chart:class', 'chart:bar'); |
|
| 187 | 24 | if (!($chartType instanceof Doughnut)) { |
|
| 188 | 23 | $this->xmlContent->writeAttributeIf($chartType instanceof AbstractTypePie, 'chart:class', 'chart:circle'); |
|
| 189 | 23 | } |
|
| 190 | 24 | $this->xmlContent->writeAttributeIf($chartType instanceof Doughnut, 'chart:class', 'chart:ring'); |
|
| 191 | 24 | $this->xmlContent->writeAttributeIf($chartType instanceof Line, 'chart:class', 'chart:line'); |
|
| 192 | 24 | $this->xmlContent->writeAttributeIf($chartType instanceof Scatter, 'chart:class', 'chart:scatter'); |
|
| 193 | |||
| 194 | //**** Title **** |
||
| 195 | 24 | $this->writeTitle($chart->getTitle()); |
|
| 196 | |||
| 197 | //**** Legend **** |
||
| 198 | 24 | $this->writeLegend($chart); |
|
| 199 | |||
| 200 | //**** Plotarea **** |
||
| 201 | 24 | $this->writePlotArea($chart); |
|
| 202 | |||
| 203 | //**** Table **** |
||
| 204 | 24 | $this->writeTable(); |
|
| 205 | |||
| 206 | // > chart:chart |
||
| 207 | 24 | $this->xmlContent->endElement(); |
|
| 208 | // > office:chart |
||
| 209 | 24 | $this->xmlContent->endElement(); |
|
| 210 | // > office:body |
||
| 211 | 24 | $this->xmlContent->endElement(); |
|
| 212 | // > office:document-content |
||
| 213 | 24 | $this->xmlContent->endElement(); |
|
| 214 | |||
| 215 | 24 | return $this->xmlContent->getData(); |
|
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @param Chart $chart |
||
| 220 | * @throws \Exception |
||
| 221 | */ |
||
| 222 | 24 | private function writeAxis(Chart $chart) |
|
| 223 | { |
||
| 224 | 24 | $chartType = $chart->getPlotArea()->getType(); |
|
| 225 | |||
| 226 | // chart:axis |
||
| 227 | 24 | $this->xmlContent->startElement('chart:axis'); |
|
| 228 | 24 | $this->xmlContent->writeAttribute('chart:dimension', 'x'); |
|
| 229 | 24 | $this->xmlContent->writeAttribute('chart:name', 'primary-x'); |
|
| 230 | 24 | $this->xmlContent->writeAttribute('chartooo:axis-type', 'text'); |
|
| 231 | 24 | $this->xmlContent->writeAttribute('chart:style-name', 'styleAxisX'); |
|
| 232 | // chart:axis > chart:categories |
||
| 233 | 24 | $this->xmlContent->startElement('chart:categories'); |
|
| 234 | 24 | $this->xmlContent->writeAttribute('table:cell-range-address', 'table-local.$A$2:.$A$'.($this->numData+1)); |
|
| 235 | 24 | $this->xmlContent->endElement(); |
|
| 236 | // chart:axis > chart:grid |
||
| 237 | 24 | $this->writeGridline($chart->getPlotArea()->getAxisX()->getMajorGridlines(), 'styleAxisXGridlinesMajor', 'major'); |
|
| 238 | // chart:axis > chart:grid |
||
| 239 | 24 | $this->writeGridline($chart->getPlotArea()->getAxisX()->getMinorGridlines(), 'styleAxisXGridlinesMinor', 'minor'); |
|
| 240 | // ##chart:axis |
||
| 241 | 24 | $this->xmlContent->endElement(); |
|
| 242 | |||
| 243 | // chart:axis |
||
| 244 | 24 | $this->xmlContent->startElement('chart:axis'); |
|
| 245 | 24 | $this->xmlContent->writeAttribute('chart:dimension', 'y'); |
|
| 246 | 24 | $this->xmlContent->writeAttribute('chart:name', 'primary-y'); |
|
| 247 | 24 | $this->xmlContent->writeAttribute('chart:style-name', 'styleAxisY'); |
|
| 248 | // chart:axis > chart:grid |
||
| 249 | 24 | $this->writeGridline($chart->getPlotArea()->getAxisY()->getMajorGridlines(), 'styleAxisYGridlinesMajor', 'major'); |
|
| 250 | // chart:axis > chart:grid |
||
| 251 | 24 | $this->writeGridline($chart->getPlotArea()->getAxisY()->getMinorGridlines(), 'styleAxisYGridlinesMinor', 'minor'); |
|
| 252 | // ##chart:axis |
||
| 253 | 24 | $this->xmlContent->endElement(); |
|
| 254 | |||
| 255 | 24 | if ($chartType instanceof Bar3D || $chartType instanceof Pie3D) { |
|
| 256 | // chart:axis |
||
| 257 | 5 | $this->xmlContent->startElement('chart:axis'); |
|
| 258 | 5 | $this->xmlContent->writeAttribute('chart:dimension', 'z'); |
|
| 259 | 5 | $this->xmlContent->writeAttribute('chart:name', 'primary-z'); |
|
| 260 | // > chart:axis |
||
| 261 | 5 | $this->xmlContent->endElement(); |
|
| 262 | 5 | } |
|
| 263 | 24 | } |
|
| 264 | |||
| 265 | 24 | protected function writeGridline($oGridlines, $styleName, $chartClass) |
|
| 276 | |||
| 277 | /** |
||
| 278 | * @param Chart $chart |
||
| 279 | * @throws \Exception |
||
| 280 | * @todo Set function in \PhpPresentation\Shape\Chart\Axis for defining width and color of the axis |
||
| 281 | */ |
||
| 282 | 24 | protected function writeAxisStyle(Chart $chart) |
|
| 283 | { |
||
| 284 | 24 | $chartType = $chart->getPlotArea()->getType(); |
|
| 285 | |||
| 286 | // AxisX |
||
| 287 | // style:style |
||
| 288 | 24 | $this->xmlContent->startElement('style:style'); |
|
| 289 | 24 | $this->xmlContent->writeAttribute('style:name', 'styleAxisX'); |
|
| 290 | 24 | $this->xmlContent->writeAttribute('style:family', 'chart'); |
|
| 291 | // style:style > style:chart-properties |
||
| 292 | 24 | $this->xmlContent->startElement('style:chart-properties'); |
|
| 293 | 24 | $this->xmlContent->writeAttribute('chart:display-label', 'true'); |
|
| 294 | 24 | $this->xmlContent->writeAttribute('chart:tick-marks-major-inner', 'false'); |
|
| 295 | 24 | $this->xmlContent->writeAttribute('chart:tick-marks-major-outer', 'false'); |
|
| 296 | 24 | if ($chartType instanceof AbstractTypePie) { |
|
| 297 | 5 | $this->xmlContent->writeAttribute('chart:reverse-direction', 'true'); |
|
| 298 | 5 | } |
|
| 299 | 24 | if ($chart->getPlotArea()->getAxisX()->getMinBounds() != null) { |
|
|
|
|||
| 300 | 1 | $this->xmlContent->writeAttribute('chart:minimum', $chart->getPlotArea()->getAxisX()->getMinBounds()); |
|
| 301 | 1 | } |
|
| 302 | 24 | if ($chart->getPlotArea()->getAxisX()->getMaxBounds() != null) { |
|
| 303 | 1 | $this->xmlContent->writeAttribute('chart:maximum', $chart->getPlotArea()->getAxisX()->getMaxBounds()); |
|
| 304 | 1 | } |
|
| 305 | 24 | $this->xmlContent->endElement(); |
|
| 306 | // style:style > style:text-properties |
||
| 307 | 24 | $oFont = $chart->getPlotArea()->getAxisX()->getFont(); |
|
| 308 | 24 | $this->xmlContent->startElement('style:text-properties'); |
|
| 309 | 24 | $this->xmlContent->writeAttribute('fo:color', '#'.$oFont->getColor()->getRGB()); |
|
| 310 | 24 | $this->xmlContent->writeAttribute('fo:font-family', $oFont->getName()); |
|
| 311 | 24 | $this->xmlContent->writeAttribute('fo:font-size', $oFont->getSize().'pt'); |
|
| 312 | 24 | $this->xmlContent->writeAttribute('fo:font-style', $oFont->isItalic() ? 'italic' : 'normal'); |
|
| 313 | 24 | $this->xmlContent->endElement(); |
|
| 314 | // style:style > style:graphic-properties |
||
| 315 | 24 | $this->xmlContent->startElement('style:graphic-properties'); |
|
| 316 | 24 | $this->xmlContent->writeAttribute('svg:stroke-width', '0.026cm'); |
|
| 317 | 24 | $this->xmlContent->writeAttribute('svg:stroke-color', '#878787'); |
|
| 318 | 24 | $this->xmlContent->endElement(); |
|
| 319 | // ##style:style |
||
| 320 | 24 | $this->xmlContent->endElement(); |
|
| 321 | |||
| 322 | // AxisX GridLines Major |
||
| 323 | 24 | $this->writeGridlineStyle($chart->getPlotArea()->getAxisX()->getMajorGridlines(), 'styleAxisXGridlinesMajor'); |
|
| 324 | |||
| 325 | // AxisX GridLines Minor |
||
| 326 | 24 | $this->writeGridlineStyle($chart->getPlotArea()->getAxisX()->getMinorGridlines(), 'styleAxisXGridlinesMinor'); |
|
| 327 | |||
| 328 | // AxisY |
||
| 329 | // style:style |
||
| 330 | 24 | $this->xmlContent->startElement('style:style'); |
|
| 331 | 24 | $this->xmlContent->writeAttribute('style:name', 'styleAxisY'); |
|
| 332 | 24 | $this->xmlContent->writeAttribute('style:family', 'chart'); |
|
| 333 | // style:style > style:chart-properties |
||
| 334 | 24 | $this->xmlContent->startElement('style:chart-properties'); |
|
| 335 | 24 | $this->xmlContent->writeAttribute('chart:display-label', 'true'); |
|
| 336 | 24 | $this->xmlContent->writeAttribute('chart:tick-marks-major-inner', 'false'); |
|
| 337 | 24 | $this->xmlContent->writeAttribute('chart:tick-marks-major-outer', 'false'); |
|
| 338 | 24 | if ($chartType instanceof AbstractTypePie) { |
|
| 339 | 5 | $this->xmlContent->writeAttribute('chart:reverse-direction', 'true'); |
|
| 340 | 5 | } |
|
| 341 | 24 | if ($chart->getPlotArea()->getAxisY()->getMinBounds() != null) { |
|
| 342 | $this->xmlContent->writeAttribute('chart:minimum', $chart->getPlotArea()->getAxisY()->getMinBounds()); |
||
| 343 | } |
||
| 344 | 24 | if ($chart->getPlotArea()->getAxisY()->getMaxBounds() != null) { |
|
| 345 | $this->xmlContent->writeAttribute('chart:maximum', $chart->getPlotArea()->getAxisY()->getMaxBounds()); |
||
| 346 | } |
||
| 347 | 24 | $this->xmlContent->endElement(); |
|
| 348 | // style:style > style:text-properties |
||
| 349 | 24 | $oFont = $chart->getPlotArea()->getAxisY()->getFont(); |
|
| 350 | 24 | $this->xmlContent->startElement('style:text-properties'); |
|
| 351 | 24 | $this->xmlContent->writeAttribute('fo:color', '#'.$oFont->getColor()->getRGB()); |
|
| 352 | 24 | $this->xmlContent->writeAttribute('fo:font-family', $oFont->getName()); |
|
| 353 | 24 | $this->xmlContent->writeAttribute('fo:font-size', $oFont->getSize().'pt'); |
|
| 354 | 24 | $this->xmlContent->writeAttribute('fo:font-style', $oFont->isItalic() ? 'italic' : 'normal'); |
|
| 355 | 24 | $this->xmlContent->endElement(); |
|
| 356 | // style:graphic-properties |
||
| 357 | 24 | $this->xmlContent->startElement('style:graphic-properties'); |
|
| 358 | 24 | $this->xmlContent->writeAttribute('svg:stroke-width', '0.026cm'); |
|
| 359 | 24 | $this->xmlContent->writeAttribute('svg:stroke-color', '#878787'); |
|
| 360 | 24 | $this->xmlContent->endElement(); |
|
| 361 | // ## style:style |
||
| 362 | 24 | $this->xmlContent->endElement(); |
|
| 363 | |||
| 364 | // AxisY GridLines Major |
||
| 365 | 24 | $this->writeGridlineStyle($chart->getPlotArea()->getAxisY()->getMajorGridlines(), 'styleAxisYGridlinesMajor'); |
|
| 366 | |||
| 367 | // AxisY GridLines Minor |
||
| 368 | 24 | $this->writeGridlineStyle($chart->getPlotArea()->getAxisY()->getMinorGridlines(), 'styleAxisYGridlinesMinor'); |
|
| 369 | 24 | } |
|
| 370 | |||
| 371 | /** |
||
| 372 | * @param Chart\Gridlines $oGridlines |
||
| 373 | * @param string $styleName |
||
| 374 | */ |
||
| 375 | 24 | protected function writeGridlineStyle($oGridlines, $styleName) |
|
| 392 | |||
| 393 | /** |
||
| 394 | * @param Chart $chart |
||
| 395 | */ |
||
| 396 | 24 | private function writeChartStyle(Chart $chart) |
|
| 411 | |||
| 412 | 24 | private function writeFloor() |
|
| 420 | |||
| 421 | 24 | private function writeFloorStyle() |
|
| 439 | |||
| 440 | /** |
||
| 441 | * @param Chart $chart |
||
| 442 | */ |
||
| 443 | 24 | private function writeLegend(Chart $chart) |
|
| 444 | { |
||
| 445 | // chart:legend |
||
| 446 | 24 | $this->xmlContent->startElement('chart:legend'); |
|
| 447 | 24 | switch ($chart->getLegend()->getPosition()) { |
|
| 448 | 24 | case Chart\Legend::POSITION_BOTTOM: |
|
| 449 | 1 | $position = 'bottom'; |
|
| 450 | 1 | break; |
|
| 451 | 24 | case Chart\Legend::POSITION_LEFT: |
|
| 452 | 1 | $position = 'start'; |
|
| 453 | 1 | break; |
|
| 454 | 24 | case Chart\Legend::POSITION_TOP: |
|
| 455 | 1 | $position = 'top'; |
|
| 456 | 1 | break; |
|
| 457 | 24 | case Chart\Legend::POSITION_TOPRIGHT: |
|
| 458 | 1 | $position = 'top-end'; |
|
| 459 | 1 | break; |
|
| 460 | 24 | case Chart\Legend::POSITION_RIGHT: |
|
| 461 | 24 | default: |
|
| 462 | 24 | $position = 'end'; |
|
| 463 | 24 | break; |
|
| 464 | 24 | } |
|
| 465 | 24 | $this->xmlContent->writeAttribute('chart:legend-position', $position); |
|
| 466 | 24 | $this->xmlContent->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($chart->getLegend()->getOffsetX()), 3) . 'cm'); |
|
| 467 | 24 | $this->xmlContent->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($chart->getLegend()->getOffsetY()), 3) . 'cm'); |
|
| 468 | 24 | $this->xmlContent->writeAttribute('style:legend-expansion', 'high'); |
|
| 469 | 24 | $this->xmlContent->writeAttribute('chart:style-name', 'styleLegend'); |
|
| 470 | // > chart:legend |
||
| 471 | 24 | $this->xmlContent->endElement(); |
|
| 472 | 24 | } |
|
| 473 | |||
| 474 | /** |
||
| 475 | * @param Chart $chart |
||
| 476 | */ |
||
| 477 | 24 | private function writeLegendStyle(Chart $chart) |
|
| 499 | |||
| 500 | /** |
||
| 501 | * @param Chart $chart |
||
| 502 | * @throws \Exception |
||
| 503 | */ |
||
| 504 | 24 | private function writePlotArea(Chart $chart) |
|
| 505 | { |
||
| 506 | 24 | $chartType = $chart->getPlotArea()->getType(); |
|
| 507 | |||
| 508 | // chart:plot-area |
||
| 509 | 24 | $this->xmlContent->startElement('chart:plot-area'); |
|
| 510 | 24 | $this->xmlContent->writeAttribute('chart:style-name', 'stylePlotArea'); |
|
| 511 | 24 | if ($chartType instanceof Bar3D || $chartType instanceof Pie3D) { |
|
| 512 | 5 | $this->xmlContent->writeAttribute('dr3d:ambient-color', '#cccccc'); |
|
| 513 | 5 | $this->xmlContent->writeAttribute('dr3d:lighting-mode', 'true'); |
|
| 514 | 5 | } |
|
| 515 | 24 | if ($chartType instanceof Bar3D || $chartType instanceof Pie3D) { |
|
| 516 | // dr3d:light |
||
| 517 | $arrayLight = array( |
||
| 518 | 5 | array('#808080', '(0 0 1)', 'false', 'true'), |
|
| 519 | 5 | array('#666666', '(0.2 0.4 1)', 'true', 'false'), |
|
| 520 | 5 | array('#808080', '(0 0 1)', 'false', 'false'), |
|
| 521 | 5 | array('#808080', '(0 0 1)', 'false', 'false'), |
|
| 522 | 5 | array('#808080', '(0 0 1)', 'false', 'false'), |
|
| 523 | 5 | array('#808080', '(0 0 1)', 'false', 'false'), |
|
| 524 | 5 | array('#808080', '(0 0 1)', 'false', 'false'), |
|
| 525 | 5 | ); |
|
| 526 | 5 | foreach ($arrayLight as $light) { |
|
| 527 | 5 | $this->xmlContent->startElement('dr3d:light'); |
|
| 528 | 5 | $this->xmlContent->writeAttribute('dr3d:diffuse-color', $light[0]); |
|
| 529 | 5 | $this->xmlContent->writeAttribute('dr3d:direction', $light[1]); |
|
| 530 | 5 | $this->xmlContent->writeAttribute('dr3d:enabled', $light[2]); |
|
| 531 | 5 | $this->xmlContent->writeAttribute('dr3d:specular', $light[3]); |
|
| 532 | 5 | $this->xmlContent->endElement(); |
|
| 533 | 5 | } |
|
| 534 | 5 | } |
|
| 535 | |||
| 536 | //**** Axis **** |
||
| 537 | 24 | $this->writeAxis($chart); |
|
| 538 | |||
| 539 | //**** Series **** |
||
| 540 | 24 | $this->rangeCol = 'B'; |
|
| 541 | 24 | $this->numSeries = 0; |
|
| 542 | 24 | foreach ($chartType->getSeries() as $series) { |
|
| 543 | 22 | $this->writeSeries($chart, $series); |
|
| 544 | 22 | $this->rangeCol++; |
|
| 545 | 22 | $this->numSeries++; |
|
| 546 | 24 | } |
|
| 547 | |||
| 548 | //**** Wall **** |
||
| 549 | 24 | $this->writeWall(); |
|
| 550 | //**** Floor **** |
||
| 551 | 24 | $this->writeFloor(); |
|
| 552 | // > chart:plot-area |
||
| 553 | 24 | $this->xmlContent->endElement(); |
|
| 554 | 24 | } |
|
| 555 | |||
| 556 | /** |
||
| 557 | * @param Chart $chart |
||
| 558 | * @throws \Exception |
||
| 559 | * @link : http://books.evc-cit.info/odbook/ch08.html#chart-plot-area-section |
||
| 560 | */ |
||
| 561 | 24 | private function writePlotAreaStyle(Chart $chart) |
|
| 562 | { |
||
| 563 | 24 | $chartType = $chart->getPlotArea()->getType(); |
|
| 564 | |||
| 565 | // style:style |
||
| 566 | 24 | $this->xmlContent->startElement('style:style'); |
|
| 567 | 24 | $this->xmlContent->writeAttribute('style:name', 'stylePlotArea'); |
|
| 568 | 24 | $this->xmlContent->writeAttribute('style:family', 'chart'); |
|
| 569 | // style:text-properties |
||
| 570 | 24 | $this->xmlContent->startElement('style:chart-properties'); |
|
| 571 | 24 | if ($chartType instanceof Bar3D) { |
|
| 572 | 3 | $this->xmlContent->writeAttribute('chart:three-dimensional', 'true'); |
|
| 573 | 3 | $this->xmlContent->writeAttribute('chart:right-angled-axes', 'true'); |
|
| 574 | 24 | } elseif ($chartType instanceof Pie3D) { |
|
| 575 | 2 | $this->xmlContent->writeAttribute('chart:three-dimensional', 'true'); |
|
| 576 | 2 | $this->xmlContent->writeAttribute('chart:right-angled-axes', 'true'); |
|
| 577 | 2 | } |
|
| 578 | 24 | if ($chartType instanceof AbstractTypeBar) { |
|
| 579 | 8 | $chartVertical = 'false'; |
|
| 580 | 8 | if ($chartType->getBarDirection() == AbstractTypeBar::DIRECTION_HORIZONTAL) { |
|
| 581 | 2 | $chartVertical = 'true'; |
|
| 582 | 2 | } |
|
| 583 | 8 | $this->xmlContent->writeAttribute('chart:vertical', $chartVertical); |
|
| 584 | 8 | if ($chartType->getBarGrouping() == Bar::GROUPING_CLUSTERED) { |
|
| 585 | 6 | $this->xmlContent->writeAttribute('chart:stacked', 'false'); |
|
| 586 | 6 | $this->xmlContent->writeAttribute('chart:overlap', '0'); |
|
| 587 | 8 | } elseif ($chartType->getBarGrouping() == Bar::GROUPING_STACKED) { |
|
| 588 | 1 | $this->xmlContent->writeAttribute('chart:stacked', 'true'); |
|
| 589 | 1 | $this->xmlContent->writeAttribute('chart:overlap', '100'); |
|
| 590 | 2 | } elseif ($chartType->getBarGrouping() == Bar::GROUPING_PERCENTSTACKED) { |
|
| 591 | 1 | $this->xmlContent->writeAttribute('chart:stacked', 'true'); |
|
| 592 | 1 | $this->xmlContent->writeAttribute('chart:overlap', '100'); |
|
| 593 | 1 | $this->xmlContent->writeAttribute('chart:percentage', 'true'); |
|
| 594 | 1 | } |
|
| 595 | 8 | } |
|
| 596 | 24 | $labelFormat = 'value'; |
|
| 597 | 24 | if ($chartType instanceof AbstractTypeBar) { |
|
| 598 | 8 | if ($chartType->getBarGrouping() == Bar::GROUPING_PERCENTSTACKED) { |
|
| 599 | 1 | $labelFormat = 'percentage'; |
|
| 600 | 1 | } |
|
| 601 | 8 | } |
|
| 602 | 24 | $this->xmlContent->writeAttribute('chart:data-label-number', $labelFormat); |
|
| 603 | |||
| 604 | // > style:text-properties |
||
| 605 | 24 | $this->xmlContent->endElement(); |
|
| 606 | // > style:style |
||
| 607 | 24 | $this->xmlContent->endElement(); |
|
| 608 | 24 | } |
|
| 609 | |||
| 610 | /** |
||
| 611 | * @param Chart $chart |
||
| 612 | * @param Chart\Series $series |
||
| 613 | * @throws \Exception |
||
| 614 | */ |
||
| 615 | 22 | private function writeSeries(Chart $chart, Chart\Series $series) |
|
| 616 | { |
||
| 617 | 22 | $chartType = $chart->getPlotArea()->getType(); |
|
| 618 | |||
| 619 | 22 | $numRange = count($series->getValues()); |
|
| 620 | // chart:series |
||
| 621 | 22 | $this->xmlContent->startElement('chart:series'); |
|
| 622 | 22 | $this->xmlContent->writeAttribute('chart:values-cell-range-address', 'table-local.$'.$this->rangeCol.'$2:.$'.$this->rangeCol.'$'.($numRange+1)); |
|
| 623 | 22 | $this->xmlContent->writeAttribute('chart:label-cell-address', 'table-local.$'.$this->rangeCol.'$1'); |
|
| 624 | 22 | if ($chartType instanceof Area) { |
|
| 625 | 1 | $this->xmlContent->writeAttribute('chart:class', 'chart:area'); |
|
| 626 | 22 | } elseif ($chartType instanceof AbstractTypeBar) { |
|
| 627 | 7 | $this->xmlContent->writeAttribute('chart:class', 'chart:bar'); |
|
| 628 | 21 | } elseif ($chartType instanceof Line) { |
|
| 629 | 6 | $this->xmlContent->writeAttribute('chart:class', 'chart:line'); |
|
| 630 | 14 | } elseif ($chartType instanceof AbstractTypePie) { |
|
| 631 | 5 | $this->xmlContent->writeAttribute('chart:class', 'chart:circle'); |
|
| 632 | 8 | } elseif ($chartType instanceof Scatter) { |
|
| 633 | 3 | $this->xmlContent->writeAttribute('chart:class', 'chart:scatter'); |
|
| 634 | 3 | } |
|
| 635 | 22 | $this->xmlContent->writeAttribute('chart:style-name', 'styleSeries'.$this->numSeries); |
|
| 636 | 22 | if ($chartType instanceof Area || $chartType instanceof AbstractTypeBar || $chartType instanceof Line || $chartType instanceof Scatter) { |
|
| 637 | 17 | $dataPointFills = $series->getDataPointFills(); |
|
| 638 | |||
| 639 | 17 | $incRepeat = $numRange; |
|
| 640 | 17 | if (!empty($dataPointFills)) { |
|
| 641 | 4 | $inc = 0; |
|
| 642 | 4 | $incRepeat = 0; |
|
| 643 | 4 | $newFill = new Fill(); |
|
| 644 | do { |
||
| 645 | 4 | if ($series->getDataPointFill($inc)->getHashCode() != $newFill->getHashCode()) { |
|
| 646 | // chart:data-point |
||
| 647 | 4 | $this->xmlContent->startElement('chart:data-point'); |
|
| 648 | 4 | $this->xmlContent->writeAttribute('chart:repeated', $incRepeat); |
|
| 649 | // > chart:data-point |
||
| 650 | 4 | $this->xmlContent->endElement(); |
|
| 651 | 4 | $incRepeat = 0; |
|
| 652 | |||
| 653 | // chart:data-point |
||
| 654 | 4 | $this->xmlContent->startElement('chart:data-point'); |
|
| 655 | 4 | $this->xmlContent->writeAttribute('chart:style-name', 'styleSeries'.$this->numSeries.'_'.$inc); |
|
| 656 | // > chart:data-point |
||
| 657 | 4 | $this->xmlContent->endElement(); |
|
| 658 | 4 | } |
|
| 659 | 4 | $inc++; |
|
| 660 | 4 | $incRepeat++; |
|
| 661 | 4 | } while ($inc < $numRange); |
|
| 662 | 4 | $incRepeat--; |
|
| 663 | 4 | } |
|
| 664 | // chart:data-point |
||
| 665 | 17 | $this->xmlContent->startElement('chart:data-point'); |
|
| 666 | 17 | $this->xmlContent->writeAttribute('chart:repeated', $incRepeat); |
|
| 667 | // > chart:data-point |
||
| 668 | 17 | $this->xmlContent->endElement(); |
|
| 669 | 22 | } elseif ($chartType instanceof AbstractTypePie) { |
|
| 670 | 5 | $count = count($series->getDataPointFills()); |
|
| 671 | 5 | for ($inc = 0; $inc < $count; $inc++) { |
|
| 672 | // chart:data-point |
||
| 673 | 3 | $this->xmlContent->startElement('chart:data-point'); |
|
| 674 | 3 | $this->xmlContent->writeAttribute('chart:style-name', 'styleSeries'.$this->numSeries.'_'.$inc); |
|
| 675 | // > chart:data-point |
||
| 676 | 3 | $this->xmlContent->endElement(); |
|
| 677 | 3 | } |
|
| 678 | 5 | } |
|
| 679 | |||
| 680 | // > chart:series |
||
| 681 | 22 | $this->xmlContent->endElement(); |
|
| 682 | 22 | } |
|
| 683 | |||
| 684 | /** |
||
| 685 | * @param Chart $chart |
||
| 686 | * @param Chart\Series $series |
||
| 687 | * @throws \Exception |
||
| 688 | */ |
||
| 689 | 22 | private function writeSeriesStyle(Chart $chart, Chart\Series $series) |
|
| 690 | { |
||
| 691 | 22 | $chartType = $chart->getPlotArea()->getType(); |
|
| 692 | |||
| 693 | // style:style |
||
| 694 | 22 | $this->xmlContent->startElement('style:style'); |
|
| 695 | 22 | $this->xmlContent->writeAttribute('style:name', 'styleSeries'.$this->numSeries); |
|
| 696 | 22 | $this->xmlContent->writeAttribute('style:family', 'chart'); |
|
| 697 | // style:chart-properties |
||
| 698 | 22 | $this->xmlContent->startElement('style:chart-properties'); |
|
| 699 | 22 | if ($series->hasShowValue()) { |
|
| 700 | 22 | if ($series->hasShowPercentage()) { |
|
| 701 | 1 | $this->xmlContent->writeAttribute('chart:data-label-number', 'value-and-percentage'); |
|
| 702 | 1 | } else { |
|
| 703 | 22 | $this->xmlContent->writeAttribute('chart:data-label-number', 'value'); |
|
| 704 | } |
||
| 705 | 22 | } else { |
|
| 706 | 1 | if ($series->hasShowPercentage()) { |
|
| 707 | 1 | $this->xmlContent->writeAttribute('chart:data-label-number', 'percentage'); |
|
| 708 | 1 | } |
|
| 709 | } |
||
| 710 | 22 | if ($series->hasShowCategoryName()) { |
|
| 711 | 1 | $this->xmlContent->writeAttribute('chart:data-label-text', 'true'); |
|
| 712 | 1 | } |
|
| 713 | 22 | $this->xmlContent->writeAttribute('chart:label-position', 'center'); |
|
| 714 | 22 | if ($chartType instanceof AbstractTypePie) { |
|
| 715 | 5 | $this->xmlContent->writeAttribute('chart:pie-offset', $chartType->getExplosion()); |
|
| 716 | 5 | } |
|
| 717 | 22 | if ($chartType instanceof Line || $chartType instanceof Scatter) { |
|
| 718 | 9 | $oMarker = $series->getMarker(); |
|
| 719 | /** |
||
| 720 | * @link : http://www.datypic.com/sc/odf/a-chart_symbol-type.html |
||
| 721 | */ |
||
| 722 | 9 | $this->xmlContent->writeAttributeIf($oMarker->getSymbol() == Chart\Marker::SYMBOL_NONE, 'chart:symbol-type', 'none'); |
|
| 723 | /** |
||
| 724 | * @link : http://www.datypic.com/sc/odf/a-chart_symbol-name.html |
||
| 725 | */ |
||
| 726 | 9 | $this->xmlContent->writeAttributeIf($oMarker->getSymbol() != Chart\Marker::SYMBOL_NONE, 'chart:symbol-type', 'named-symbol'); |
|
| 727 | 9 | if ($oMarker->getSymbol() != Chart\Marker::SYMBOL_NONE) { |
|
| 728 | 2 | switch ($oMarker->getSymbol()) { |
|
| 729 | 2 | case Chart\Marker::SYMBOL_DASH: |
|
| 730 | 2 | $symbolName = 'horizontal-bar'; |
|
| 731 | 2 | break; |
|
| 732 | 2 | case Chart\Marker::SYMBOL_DOT: |
|
| 733 | 2 | $symbolName = 'circle'; |
|
| 734 | 2 | break; |
|
| 735 | 2 | case Chart\Marker::SYMBOL_TRIANGLE: |
|
| 736 | 2 | $symbolName = 'arrow-up'; |
|
| 737 | 2 | break; |
|
| 738 | 2 | default: |
|
| 739 | 2 | $symbolName = $oMarker->getSymbol(); |
|
| 740 | 2 | break; |
|
| 741 | 2 | } |
|
| 742 | 2 | $this->xmlContent->writeAttribute('chart:symbol-name', $symbolName); |
|
| 743 | 2 | $symbolSize = number_format(CommonDrawing::pointsToCentimeters($oMarker->getSize()), 2, '.', ''); |
|
| 744 | 2 | $this->xmlContent->writeAttribute('chart:symbol-width', $symbolSize.'cm'); |
|
| 745 | 2 | $this->xmlContent->writeAttribute('chart:symbol-height', $symbolSize.'cm'); |
|
| 746 | 2 | } |
|
| 747 | 9 | } |
|
| 748 | |||
| 749 | 22 | $separator = $series->getSeparator(); |
|
| 750 | 22 | if (!empty($separator)) { |
|
| 751 | // style:chart-properties/chart:label-separator |
||
| 752 | 1 | $this->xmlContent->startElement('chart:label-separator'); |
|
| 753 | 1 | if ($separator == PHP_EOL) { |
|
| 754 | $this->xmlContent->writeRaw('<text:p><text:line-break /></text:p>'); |
||
| 755 | } else { |
||
| 756 | 1 | $this->xmlContent->writeElement('text:p', $separator); |
|
| 757 | } |
||
| 758 | 1 | $this->xmlContent->endElement(); |
|
| 759 | 1 | } |
|
| 760 | |||
| 761 | // > style:chart-properties |
||
| 762 | 22 | $this->xmlContent->endElement(); |
|
| 763 | // style:graphic-properties |
||
| 764 | 22 | $this->xmlContent->startElement('style:graphic-properties'); |
|
| 765 | 22 | if ($chartType instanceof Line || $chartType instanceof Scatter) { |
|
| 766 | 9 | $outlineWidth = ''; |
|
| 767 | 9 | $outlineColor = ''; |
|
| 768 | |||
| 769 | 9 | $oOutline = $series->getOutline(); |
|
| 770 | 9 | if ($oOutline instanceof Outline) { |
|
| 771 | 2 | $outlineWidth = $oOutline->getWidth(); |
|
| 772 | 2 | if (!empty($outlineWidth)) { |
|
| 773 | 2 | $outlineWidth = number_format(CommonDrawing::pointsToCentimeters($outlineWidth), 3, '.', ''); |
|
| 774 | 2 | } |
|
| 775 | 2 | $outlineColor = $oOutline->getFill()->getStartColor()->getRGB(); |
|
| 776 | 2 | } |
|
| 777 | 9 | if (empty($outlineWidth)) { |
|
| 778 | 9 | $outlineWidth = '0.079'; |
|
| 779 | 9 | } |
|
| 780 | 9 | if (empty($outlineColor)) { |
|
| 781 | 9 | $outlineColor = '4a7ebb'; |
|
| 782 | 9 | } |
|
| 783 | 9 | $this->xmlContent->writeAttribute('svg:stroke-width', $outlineWidth.'cm'); |
|
| 784 | 9 | $this->xmlContent->writeAttribute('svg:stroke-color', '#'.$outlineColor); |
|
| 785 | 9 | } else { |
|
| 786 | 13 | $this->xmlContent->writeAttribute('draw:stroke', 'none'); |
|
| 787 | 13 | if (!($chartType instanceof Area)) { |
|
| 788 | 12 | $this->xmlContent->writeAttribute('draw:fill', $series->getFill()->getFillType()); |
|
| 789 | 12 | } |
|
| 790 | } |
||
| 791 | 22 | $this->xmlContent->writeAttribute('draw:fill-color', '#'.$series->getFill()->getStartColor()->getRGB()); |
|
| 792 | // > style:graphic-properties |
||
| 793 | 22 | $this->xmlContent->endElement(); |
|
| 794 | // style:text-properties |
||
| 795 | 22 | $this->xmlContent->startElement('style:text-properties'); |
|
| 796 | 22 | $this->xmlContent->writeAttribute('fo:color', '#'.$series->getFont()->getColor()->getRGB()); |
|
| 797 | 22 | $this->xmlContent->writeAttribute('fo:font-family', $series->getFont()->getName()); |
|
| 798 | 22 | $this->xmlContent->writeAttribute('fo:font-size', $series->getFont()->getSize().'pt'); |
|
| 799 | // > style:text-properties |
||
| 800 | 22 | $this->xmlContent->endElement(); |
|
| 801 | |||
| 802 | // > style:style |
||
| 803 | 22 | $this->xmlContent->endElement(); |
|
| 804 | |||
| 805 | 22 | foreach ($series->getDataPointFills() as $idx => $oFill) { |
|
| 806 | // style:style |
||
| 807 | 7 | $this->xmlContent->startElement('style:style'); |
|
| 808 | 7 | $this->xmlContent->writeAttribute('style:name', 'styleSeries'.$this->numSeries.'_'.$idx); |
|
| 809 | 7 | $this->xmlContent->writeAttribute('style:family', 'chart'); |
|
| 810 | // style:graphic-properties |
||
| 811 | 7 | $this->xmlContent->startElement('style:graphic-properties'); |
|
| 812 | 7 | $this->xmlContent->writeAttribute('draw:fill', $oFill->getFillType()); |
|
| 813 | 7 | $this->xmlContent->writeAttribute('draw:fill-color', '#'.$oFill->getStartColor()->getRGB()); |
|
| 814 | // > style:graphic-properties |
||
| 815 | 7 | $this->xmlContent->endElement(); |
|
| 816 | // > style:style |
||
| 817 | 7 | $this->xmlContent->endElement(); |
|
| 818 | 22 | } |
|
| 819 | 22 | } |
|
| 820 | |||
| 821 | /** |
||
| 822 | */ |
||
| 823 | 24 | private function writeTable() |
|
| 824 | { |
||
| 825 | // table:table |
||
| 826 | 24 | $this->xmlContent->startElement('table:table'); |
|
| 827 | 24 | $this->xmlContent->writeAttribute('table:name', 'table-local'); |
|
| 828 | |||
| 829 | // table:table-header-columns |
||
| 830 | 24 | $this->xmlContent->startElement('table:table-header-columns'); |
|
| 831 | // table:table-column |
||
| 832 | 24 | $this->xmlContent->startElement('table:table-column'); |
|
| 833 | // > table:table-column |
||
| 834 | 24 | $this->xmlContent->endElement(); |
|
| 835 | // > table:table-header-columns |
||
| 836 | 24 | $this->xmlContent->endElement(); |
|
| 837 | |||
| 838 | // table:table-columns |
||
| 839 | 24 | $this->xmlContent->startElement('table:table-columns'); |
|
| 840 | // table:table-column |
||
| 841 | 24 | $this->xmlContent->startElement('table:table-column'); |
|
| 842 | 24 | if (!empty($this->arrayData)) { |
|
| 843 | 22 | $rowFirst = reset($this->arrayData); |
|
| 844 | 22 | $this->xmlContent->writeAttribute('table:number-columns-repeated', count($rowFirst) - 1); |
|
| 845 | 22 | } |
|
| 846 | // > table:table-column |
||
| 847 | 24 | $this->xmlContent->endElement(); |
|
| 848 | // > table:table-columns |
||
| 849 | 24 | $this->xmlContent->endElement(); |
|
| 850 | |||
| 851 | // table:table-header-rows |
||
| 852 | 24 | $this->xmlContent->startElement('table:table-header-rows'); |
|
| 853 | // table:table-row |
||
| 854 | 24 | $this->xmlContent->startElement('table:table-row'); |
|
| 855 | 24 | if (!empty($this->arrayData)) { |
|
| 856 | 22 | $rowFirst = reset($this->arrayData); |
|
| 857 | 22 | foreach ($rowFirst as $key => $cell) { |
|
| 858 | // table:table-cell |
||
| 859 | 22 | $this->xmlContent->startElement('table:table-cell'); |
|
| 860 | 22 | if (isset($this->arrayTitle[$key - 1])) { |
|
| 861 | 22 | $this->xmlContent->writeAttribute('office:value-type', 'string'); |
|
| 862 | 22 | } |
|
| 863 | // text:p |
||
| 864 | 22 | $this->xmlContent->startElement('text:p'); |
|
| 865 | 22 | if (isset($this->arrayTitle[$key - 1])) { |
|
| 866 | 22 | $this->xmlContent->text($this->arrayTitle[$key - 1]); |
|
| 867 | 22 | } |
|
| 868 | // > text:p |
||
| 869 | 22 | $this->xmlContent->endElement(); |
|
| 870 | // > table:table-cell |
||
| 871 | 22 | $this->xmlContent->endElement(); |
|
| 872 | 22 | } |
|
| 873 | 22 | } |
|
| 874 | // > table:table-row |
||
| 875 | 24 | $this->xmlContent->endElement(); |
|
| 876 | // > table:table-header-rows |
||
| 877 | 24 | $this->xmlContent->endElement(); |
|
| 878 | |||
| 879 | // table:table-rows |
||
| 880 | 24 | $this->xmlContent->startElement('table:table-rows'); |
|
| 881 | |||
| 882 | 24 | foreach ($this->arrayData as $row) { |
|
| 883 | // table:table-row |
||
| 884 | 22 | $this->xmlContent->startElement('table:table-row'); |
|
| 885 | 22 | foreach ($row as $cell) { |
|
| 886 | // table:table-cell |
||
| 887 | 22 | $this->xmlContent->startElement('table:table-cell'); |
|
| 888 | |||
| 889 | 22 | $cellNumeric = is_numeric($cell); |
|
| 890 | 22 | $this->xmlContent->writeAttributeIf(!$cellNumeric, 'office:value-type', 'string'); |
|
| 891 | 22 | $this->xmlContent->writeAttributeIf($cellNumeric, 'office:value-type', 'float'); |
|
| 892 | 22 | $this->xmlContent->writeAttributeIf($cellNumeric, 'office:value', $cell); |
|
| 893 | // text:p |
||
| 894 | 22 | $this->xmlContent->startElement('text:p'); |
|
| 895 | 22 | $this->xmlContent->text($cell); |
|
| 896 | // > text:p |
||
| 897 | 22 | $this->xmlContent->endElement(); |
|
| 898 | // > table:table-cell |
||
| 899 | 22 | $this->xmlContent->endElement(); |
|
| 900 | 22 | } |
|
| 901 | // > table:table-row |
||
| 902 | 22 | $this->xmlContent->endElement(); |
|
| 903 | 24 | } |
|
| 904 | |||
| 905 | // > table:table-rows |
||
| 906 | 24 | $this->xmlContent->endElement(); |
|
| 907 | // > table:table |
||
| 908 | 24 | $this->xmlContent->endElement(); |
|
| 909 | 24 | } |
|
| 910 | |||
| 911 | /** |
||
| 912 | * @param Title $oTitle |
||
| 913 | */ |
||
| 914 | 24 | private function writeTitle(Title $oTitle) |
|
| 932 | |||
| 933 | /** |
||
| 934 | * @param Title $oTitle |
||
| 935 | */ |
||
| 936 | 24 | private function writeTitleStyle(Title $oTitle) |
|
| 956 | |||
| 957 | 24 | private function writeWall() |
|
| 965 | |||
| 966 | /** |
||
| 967 | * @param Chart $chart |
||
| 968 | * @throws \Exception |
||
| 969 | */ |
||
| 970 | 24 | private function writeWallStyle(Chart $chart) |
|
| 971 | { |
||
| 972 | 24 | $chartType = $chart->getPlotArea()->getType(); |
|
| 973 | |||
| 974 | // style:style |
||
| 975 | 24 | $this->xmlContent->startElement('style:style'); |
|
| 995 | } |
||
| 996 |