@@ -252,20 +252,29 @@ private function writeAxis(Chart $chart)
252
252
$ this ->xmlContent ->writeAttribute ('chart:name ' , 'primary-x ' );
253
253
$ this ->xmlContent ->writeAttribute ('chartooo:axis-type ' , 'text ' );
254
254
$ this ->xmlContent ->writeAttribute ('chart:style-name ' , 'styleAxisX ' );
255
- // chart:categories
255
+ // chart:axis > chart: categories
256
256
$ this ->xmlContent ->startElement ('chart:categories ' );
257
257
$ this ->xmlContent ->writeAttribute ('table:cell-range-address ' , 'table-local.$A$2:.$A$ ' .($ this ->numData +1 ));
258
- // > chart:categories
259
258
$ this ->xmlContent ->endElement ();
260
- // > chart:axis
259
+ // chart:axis > chart:grid
260
+ $ this ->writeGridline ($ chart ->getPlotArea ()->getAxisX ()->getMajorGridlines (), 'styleAxisXGridlinesMajor ' , 'major ' );
261
+ // chart:axis > chart:grid
262
+ $ this ->writeGridline ($ chart ->getPlotArea ()->getAxisX ()->getMinorGridlines (), 'styleAxisXGridlinesMinor ' , 'minor ' );
263
+ // ##chart:axis
261
264
$ this ->xmlContent ->endElement ();
265
+
262
266
// chart:axis
263
267
$ this ->xmlContent ->startElement ('chart:axis ' );
264
268
$ this ->xmlContent ->writeAttribute ('chart:dimension ' , 'y ' );
265
269
$ this ->xmlContent ->writeAttribute ('chart:name ' , 'primary-y ' );
266
270
$ this ->xmlContent ->writeAttribute ('chart:style-name ' , 'styleAxisY ' );
267
- // > chart:axis
271
+ // chart:axis > chart:grid
272
+ $ this ->writeGridline ($ chart ->getPlotArea ()->getAxisY ()->getMajorGridlines (), 'styleAxisYGridlinesMajor ' , 'major ' );
273
+ // chart:axis > chart:grid
274
+ $ this ->writeGridline ($ chart ->getPlotArea ()->getAxisY ()->getMinorGridlines (), 'styleAxisYGridlinesMinor ' , 'minor ' );
275
+ // ##chart:axis
268
276
$ this ->xmlContent ->endElement ();
277
+
269
278
if ($ chartType instanceof Bar3D || $ chartType instanceof Pie3D) {
270
279
// chart:axis
271
280
$ this ->xmlContent ->startElement ('chart:axis ' );
@@ -275,77 +284,117 @@ private function writeAxis(Chart $chart)
275
284
$ this ->xmlContent ->endElement ();
276
285
}
277
286
}
287
+
288
+ protected function writeGridline ($ oGridlines , $ styleName , $ chartClass )
289
+ {
290
+ if (!($ oGridlines instanceof Chart \Gridlines)) {
291
+ return ;
292
+ }
293
+
294
+ $ this ->xmlContent ->startElement ('chart:grid ' );
295
+ $ this ->xmlContent ->writeAttribute ('chart:style-name ' , $ styleName );
296
+ $ this ->xmlContent ->writeAttribute ('chart:class ' , $ chartClass );
297
+ $ this ->xmlContent ->endElement ();
298
+ }
278
299
279
300
/**
280
301
* @param Chart $chart
281
302
* @todo Set function in \PhpPresentation\Shape\Chart\Axis for defining width and color of the axis
282
303
*/
283
- private function writeAxisStyle (Chart $ chart )
304
+ protected function writeAxisStyle (Chart $ chart )
284
305
{
285
306
$ chartType = $ chart ->getPlotArea ()->getType ();
286
-
307
+
287
308
// AxisX
288
309
// style:style
289
310
$ this ->xmlContent ->startElement ('style:style ' );
290
311
$ this ->xmlContent ->writeAttribute ('style:name ' , 'styleAxisX ' );
291
312
$ this ->xmlContent ->writeAttribute ('style:family ' , 'chart ' );
292
- // style:chart-properties
313
+ // style:style > style: chart-properties
293
314
$ this ->xmlContent ->startElement ('style:chart-properties ' );
294
315
$ this ->xmlContent ->writeAttribute ('chart:display-label ' , 'true ' );
295
316
$ this ->xmlContent ->writeAttribute ('chart:tick-marks-major-inner ' , 'false ' );
296
317
$ this ->xmlContent ->writeAttribute ('chart:tick-marks-major-outer ' , 'false ' );
297
318
if ($ chartType instanceof AbstractTypePie) {
298
319
$ this ->xmlContent ->writeAttribute ('chart:reverse-direction ' , 'true ' );
299
320
}
300
- // > style:chart-properties
301
321
$ this ->xmlContent ->endElement ();
302
- // style:text-properties
322
+ // style:style > style: text-properties
303
323
$ this ->xmlContent ->startElement ('style:text-properties ' );
304
324
$ this ->xmlContent ->writeAttribute ('fo:color ' , '# ' .$ chart ->getPlotArea ()->getAxisX ()->getFont ()->getColor ()->getRGB ());
305
325
$ this ->xmlContent ->writeAttribute ('fo:font-family ' , $ chart ->getPlotArea ()->getAxisX ()->getFont ()->getName ());
306
326
$ this ->xmlContent ->writeAttribute ('fo:font-size ' , $ chart ->getPlotArea ()->getAxisX ()->getFont ()->getSize ().'pt ' );
307
327
$ this ->xmlContent ->writeAttribute ('fo:font-style ' , $ chart ->getPlotArea ()->getAxisX ()->getFont ()->isItalic () ? 'italic ' : 'normal ' );
308
- // > style:text-properties
309
328
$ this ->xmlContent ->endElement ();
310
- // style:graphic-properties
329
+ // style:style > style: graphic-properties
311
330
$ this ->xmlContent ->startElement ('style:graphic-properties ' );
312
331
$ this ->xmlContent ->writeAttribute ('svg:stroke-width ' , '0.026cm ' );
313
332
$ this ->xmlContent ->writeAttribute ('svg:stroke-color ' , '#878787 ' );
314
- // > style:graphic-properties
315
333
$ this ->xmlContent ->endElement ();
316
- // > style:style
334
+ // ## style:style
317
335
$ this ->xmlContent ->endElement ();
336
+
337
+ // AxisX GridLines Major
338
+ $ this ->writeGridlineStyle ($ chart ->getPlotArea ()->getAxisX ()->getMajorGridlines (), 'styleAxisXGridlinesMajor ' );
339
+
340
+ // AxisX GridLines Minor
341
+ $ this ->writeGridlineStyle ($ chart ->getPlotArea ()->getAxisX ()->getMinorGridlines (), 'styleAxisXGridlinesMinor ' );
318
342
319
343
// AxisY
320
344
// style:style
321
345
$ this ->xmlContent ->startElement ('style:style ' );
322
346
$ this ->xmlContent ->writeAttribute ('style:name ' , 'styleAxisY ' );
323
347
$ this ->xmlContent ->writeAttribute ('style:family ' , 'chart ' );
324
- // style:chart-properties
348
+ // style:style > style: chart-properties
325
349
$ this ->xmlContent ->startElement ('style:chart-properties ' );
326
350
$ this ->xmlContent ->writeAttribute ('chart:display-label ' , 'true ' );
327
351
$ this ->xmlContent ->writeAttribute ('chart:tick-marks-major-inner ' , 'false ' );
328
352
$ this ->xmlContent ->writeAttribute ('chart:tick-marks-major-outer ' , 'false ' );
329
353
if ($ chartType instanceof AbstractTypePie) {
330
354
$ this ->xmlContent ->writeAttribute ('chart:reverse-direction ' , 'true ' );
331
355
}
332
- // > style:chart-properties
333
356
$ this ->xmlContent ->endElement ();
334
- // style:text-properties
357
+ // style:style > style: text-properties
335
358
$ this ->xmlContent ->startElement ('style:text-properties ' );
336
359
$ this ->xmlContent ->writeAttribute ('fo:color ' , '# ' .$ chart ->getPlotArea ()->getAxisY ()->getFont ()->getColor ()->getRGB ());
337
360
$ this ->xmlContent ->writeAttribute ('fo:font-family ' , $ chart ->getPlotArea ()->getAxisY ()->getFont ()->getName ());
338
361
$ this ->xmlContent ->writeAttribute ('fo:font-size ' , $ chart ->getPlotArea ()->getAxisY ()->getFont ()->getSize ().'pt ' );
339
362
$ this ->xmlContent ->writeAttribute ('fo:font-style ' , $ chart ->getPlotArea ()->getAxisY ()->getFont ()->isItalic () ? 'italic ' : 'normal ' );
340
- // > style:text-properties
341
363
$ this ->xmlContent ->endElement ();
342
364
// style:graphic-properties
343
365
$ this ->xmlContent ->startElement ('style:graphic-properties ' );
344
366
$ this ->xmlContent ->writeAttribute ('svg:stroke-width ' , '0.026cm ' );
345
367
$ this ->xmlContent ->writeAttribute ('svg:stroke-color ' , '#878787 ' );
346
- // > style:graphic-properties
347
368
$ this ->xmlContent ->endElement ();
348
- // > style:style
369
+ // ## style:style
370
+ $ this ->xmlContent ->endElement ();
371
+
372
+ // AxisY GridLines Major
373
+ $ this ->writeGridlineStyle ($ chart ->getPlotArea ()->getAxisY ()->getMajorGridlines (), 'styleAxisYGridlinesMajor ' );
374
+
375
+ // AxisY GridLines Minor
376
+ $ this ->writeGridlineStyle ($ chart ->getPlotArea ()->getAxisY ()->getMinorGridlines (), 'styleAxisYGridlinesMinor ' );
377
+ }
378
+
379
+ /**
380
+ * @param Chart\Gridlines $oGridlines
381
+ * @param string $styleName
382
+ */
383
+ protected function writeGridlineStyle ($ oGridlines , $ styleName )
384
+ {
385
+ if (!($ oGridlines instanceof Chart \Gridlines)) {
386
+ return ;
387
+ }
388
+ // style:style
389
+ $ this ->xmlContent ->startElement ('style:style ' );
390
+ $ this ->xmlContent ->writeAttribute ('style:name ' , $ styleName );
391
+ $ this ->xmlContent ->writeAttribute ('style:family ' , 'chart ' );
392
+ // style:style > style:graphic-properties
393
+ $ this ->xmlContent ->startElement ('style:graphic-properties ' );
394
+ $ this ->xmlContent ->writeAttribute ('svg:stroke-width ' , number_format (CommonDrawing::pointsToCentimeters ($ oGridlines ->getOutline ()->getWidth ()), 2 , '. ' , '' ).'cm ' );
395
+ $ this ->xmlContent ->writeAttribute ('svg:stroke-color ' , '# ' .$ oGridlines ->getOutline ()->getFill ()->getStartColor ()->getRGB ());
396
+ $ this ->xmlContent ->endElement ();
397
+ // ##style:style
349
398
$ this ->xmlContent ->endElement ();
350
399
}
351
400
0 commit comments