• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHPOffice / PHPWord / 13025401639

29 Jan 2025 05:48AM UTC coverage: 96.825% (-0.4%) from 97.217%
13025401639

Pull #2562

github

web-flow
Merge ebe3e5dac into 2d2759585
Pull Request #2562: TemplateProcessor SetComplexBlock/Value and Sections

6 of 7 new or added lines in 1 file covered. (85.71%)

245 existing lines in 40 files now uncovered.

12227 of 12628 relevant lines covered (96.82%)

34.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.64
/src/PhpWord/Style/Chart.php
1
<?php
2

3
/**
4
 * This file is part of PHPWord - A pure PHP library for reading and writing
5
 * word processing documents.
6
 *
7
 * PHPWord is free software distributed under the terms of the GNU Lesser
8
 * General Public License version 3 as published by the Free Software Foundation.
9
 *
10
 * For the full copyright and license information, please read the LICENSE
11
 * file that was distributed with this source code. For the full list of
12
 * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
13
 *
14
 * @see         https://github.com/PHPOffice/PHPWord
15
 *
16
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17
 */
18

19
namespace PhpOffice\PhpWord\Style;
20

21
/**
22
 * Chart style.
23
 *
24
 * @since 0.12.0
25
 */
26
class Chart extends AbstractStyle
27
{
28
    /**
29
     * Width (in EMU).
30
     *
31
     * @var int
32
     */
33
    private $width = 1000000;
34

35
    /**
36
     * Height (in EMU).
37
     *
38
     * @var int
39
     */
40
    private $height = 1000000;
41

42
    /**
43
     * Is 3D; applies to pie, bar, line, area.
44
     *
45
     * @var bool
46
     */
47
    private $is3d = false;
48

49
    /**
50
     * A list of colors to use in the chart.
51
     *
52
     * @var array
53
     */
54
    private $colors = [];
55

56
    /**
57
     * Chart title.
58
     *
59
     * @var string
60
     */
61
    private $title;
62

63
    /**
64
     * Chart legend visibility.
65
     *
66
     * @var bool
67
     */
68
    private $showLegend = false;
69

70
    /**
71
     * Chart legend Position.
72
     * Possible values are 'r', 't', 'b', 'l', 'tr'.
73
     *
74
     * @var string
75
     */
76
    private $legendPosition = 'r';
77

78
    /**
79
     * A list of display options for data labels.
80
     *
81
     * @var array
82
     */
83
    private $dataLabelOptions = [
84
        'showVal' => true, // value
85
        'showCatName' => true, // category name
86
        'showLegendKey' => false, //show the cart legend
87
        'showSerName' => false, // series name
88
        'showPercent' => false,
89
        'showLeaderLines' => false,
90
        'showBubbleSize' => false,
91
    ];
92

93
    /**
94
     * A string that tells the writer where to write chart labels or to skip
95
     * "nextTo" - sets labels next to the axis (bar graphs on the left) (default)
96
     * "low" - labels on the left side of the graph
97
     * "high" - labels on the right side of the graph.
98
     *
99
     * @var string
100
     */
101
    private $categoryLabelPosition = 'nextTo';
102

103
    /**
104
     * A string that tells the writer where to write chart labels or to skip
105
     * "nextTo" - sets labels next to the axis (bar graphs on the bottom) (default)
106
     * "low" - labels are below the graph
107
     * "high" - labels above the graph.
108
     *
109
     * @var string
110
     */
111
    private $valueLabelPosition = 'nextTo';
112

113
    /**
114
     * @var string
115
     */
116
    private $categoryAxisTitle;
117

118
    /**
119
     * @var string
120
     */
121
    private $valueAxisTitle;
122

123
    /**
124
     * The position for major tick marks
125
     * Possible values are 'in', 'out', 'cross', 'none'.
126
     *
127
     * @var string
128
     */
129
    private $majorTickMarkPos = 'none';
130

131
    /**
132
     * Show labels for axis.
133
     *
134
     * @var bool
135
     */
136
    private $showAxisLabels = false;
137

138
    /**
139
     * Show Gridlines for Y-Axis.
140
     *
141
     * @var bool
142
     */
143
    private $gridY = false;
144

145
    /**
146
     * Show Gridlines for X-Axis.
147
     *
148
     * @var bool
149
     */
150
    private $gridX = false;
151

152
    /**
153
     * Create a new instance.
154
     *
155
     * @param array $style
156
     */
157
    public function __construct($style = [])
158
    {
159
        $this->setStyleByArray($style);
14✔
160
    }
161

162
    /**
163
     * Get width.
164
     *
165
     * @return int
166
     */
167
    public function getWidth()
168
    {
169
        return $this->width;
6✔
170
    }
171

172
    /**
173
     * Set width.
174
     *
175
     * @param int $value
176
     *
177
     * @return self
178
     */
179
    public function setWidth($value = null)
180
    {
181
        $this->width = $this->setIntVal($value, $this->width);
6✔
182

183
        return $this;
6✔
184
    }
185

186
    /**
187
     * Get height.
188
     *
189
     * @return int
190
     */
191
    public function getHeight()
192
    {
193
        return $this->height;
6✔
194
    }
195

196
    /**
197
     * Set height.
198
     *
199
     * @param int $value
200
     *
201
     * @return self
202
     */
203
    public function setHeight($value = null)
204
    {
205
        $this->height = $this->setIntVal($value, $this->height);
6✔
206

207
        return $this;
6✔
208
    }
209

210
    /**
211
     * Is 3D.
212
     *
213
     * @return bool
214
     */
215
    public function is3d()
216
    {
217
        return $this->is3d;
6✔
218
    }
219

220
    /**
221
     * Set 3D.
222
     *
223
     * @param bool $value
224
     *
225
     * @return self
226
     */
227
    public function set3d($value = true)
228
    {
229
        $this->is3d = $this->setBoolVal($value, $this->is3d);
2✔
230

231
        return $this;
2✔
232
    }
233

234
    /**
235
     * Get the list of colors to use in a chart.
236
     *
237
     * @return array
238
     */
239
    public function getColors()
240
    {
241
        return $this->colors;
6✔
242
    }
243

244
    /**
245
     * Set the colors to use in a chart.
246
     *
247
     * @param array $value a list of colors to use in the chart
248
     *
249
     * @return self
250
     */
251
    public function setColors($value = [])
252
    {
253
        $this->colors = $value;
2✔
254

255
        return $this;
2✔
256
    }
257

258
    /**
259
     * Get the chart title.
260
     *
261
     * @return string
262
     */
263
    public function getTitle()
264
    {
265
        return $this->title;
5✔
266
    }
267

268
    /**
269
     * Set the chart title.
270
     *
271
     * @param string $value
272
     *
273
     * @return self
274
     */
275
    public function setTitle($value = null)
276
    {
277
        $this->title = $value;
1✔
278

279
        return $this;
1✔
280
    }
281

282
    /**
283
     * Get chart legend visibility.
284
     *
285
     * @return bool
286
     */
287
    public function isShowLegend()
288
    {
289
        return $this->showLegend;
5✔
290
    }
291

292
    /**
293
     * Set chart legend visibility.
294
     *
295
     * @param bool $value
296
     *
297
     * @return self
298
     */
299
    public function setShowLegend($value = false)
300
    {
301
        $this->showLegend = $value;
5✔
302

303
        return $this;
5✔
304
    }
305

306
    /**
307
     * Get chart legend position.
308
     *
309
     * @return string
310
     */
311
    public function getLegendPosition()
312
    {
313
        return $this->legendPosition;
5✔
314
    }
315

316
    /**
317
     * Set chart legend position. choices:
318
     * "r" - right of chart
319
     * "b" - bottom of chart
320
     * "t" - top of chart
321
     * "l" - left of chart
322
     * "tr" - top right of chart.
323
     *
324
     * default: right
325
     *
326
     * @param string $legendPosition
327
     *
328
     * @return self
329
     */
330
    public function setLegendPosition($legendPosition = 'r')
331
    {
332
        $enum = ['r', 'b', 't', 'l', 'tr'];
×
UNCOV
333
        $this->legendPosition = $this->setEnumVal($legendPosition, $enum, $this->legendPosition);
×
334

UNCOV
335
        return $this;
×
336
    }
337

338
    /*
339
     * Show labels for axis
340
     *
341
     * @return bool
342
     */
343
    public function showAxisLabels()
344
    {
345
        return $this->showAxisLabels;
5✔
346
    }
347

348
    /**
349
     * Set show Gridlines for Y-Axis.
350
     *
351
     * @param bool $value
352
     *
353
     * @return self
354
     */
355
    public function setShowAxisLabels($value = true)
356
    {
357
        $this->showAxisLabels = $this->setBoolVal($value, $this->showAxisLabels);
5✔
358

359
        return $this;
5✔
360
    }
361

362
    /**
363
     * get the list of options for data labels.
364
     *
365
     * @return array
366
     */
367
    public function getDataLabelOptions()
368
    {
369
        return $this->dataLabelOptions;
6✔
370
    }
371

372
    /**
373
     * Set values for data label options.
374
     * This will only change values for options defined in $this->dataLabelOptions, and cannot create new ones.
375
     *
376
     * @param array $values [description]
377
     */
378
    public function setDataLabelOptions($values = []): void
379
    {
380
        foreach (array_keys($this->dataLabelOptions) as $option) {
1✔
381
            if (isset($values[$option])) {
1✔
382
                $this->dataLabelOptions[$option] = $this->setBoolVal(
1✔
383
                    $values[$option],
1✔
384
                    $this->dataLabelOptions[$option]
1✔
385
                );
1✔
386
            }
387
        }
388
    }
389

390
    /*
391
     * Show Gridlines for Y-Axis
392
     *
393
     * @return bool
394
     */
395
    public function showGridY()
396
    {
397
        return $this->gridY;
5✔
398
    }
399

400
    /**
401
     * Set show Gridlines for Y-Axis.
402
     *
403
     * @param bool $value
404
     *
405
     * @return self
406
     */
407
    public function setShowGridY($value = true)
408
    {
409
        $this->gridY = $this->setBoolVal($value, $this->gridY);
5✔
410

411
        return $this;
5✔
412
    }
413

414
    /**
415
     * Get the categoryLabelPosition setting.
416
     *
417
     * @return string
418
     */
419
    public function getCategoryLabelPosition()
420
    {
421
        return $this->categoryLabelPosition;
5✔
422
    }
423

424
    /**
425
     * Set the categoryLabelPosition setting
426
     * "none" - skips writing  labels
427
     * "nextTo" - sets labels next to the  (bar graphs on the left)
428
     * "low" - labels on the left side of the graph
429
     * "high" - labels on the right side of the graph.
430
     *
431
     * @param mixed $labelPosition
432
     *
433
     * @return self
434
     */
435
    public function setCategoryLabelPosition($labelPosition)
436
    {
437
        $enum = ['nextTo', 'low', 'high'];
1✔
438
        $this->categoryLabelPosition = $this->setEnumVal($labelPosition, $enum, $this->categoryLabelPosition);
1✔
439

440
        return $this;
1✔
441
    }
442

443
    /**
444
     * Get the valueAxisLabelPosition setting.
445
     *
446
     * @return string
447
     */
448
    public function getValueLabelPosition()
449
    {
450
        return $this->valueLabelPosition;
5✔
451
    }
452

453
    /**
454
     * Set the valueLabelPosition setting
455
     * "none" - skips writing labels
456
     * "nextTo" - sets labels next to the value
457
     * "low" - sets labels are below the graph
458
     * "high" - sets labels above the graph.
459
     *
460
     * @param string
461
     * @param mixed $labelPosition
462
     */
463
    public function setValueLabelPosition($labelPosition)
464
    {
465
        $enum = ['nextTo', 'low', 'high'];
1✔
466
        $this->valueLabelPosition = $this->setEnumVal($labelPosition, $enum, $this->valueLabelPosition);
1✔
467

468
        return $this;
1✔
469
    }
470

471
    /**
472
     * Get the categoryAxisTitle.
473
     *
474
     * @return string
475
     */
476
    public function getCategoryAxisTitle()
477
    {
478
        return $this->categoryAxisTitle;
6✔
479
    }
480

481
    /**
482
     * Set the title that appears on the category side of the chart.
483
     *
484
     * @param string $axisTitle
485
     */
486
    public function setCategoryAxisTitle($axisTitle)
487
    {
488
        $this->categoryAxisTitle = $axisTitle;
1✔
489

490
        return $this;
1✔
491
    }
492

493
    /**
494
     * Get the valueAxisTitle.
495
     *
496
     * @return string
497
     */
498
    public function getValueAxisTitle()
499
    {
500
        return $this->valueAxisTitle;
6✔
501
    }
502

503
    /**
504
     * Set the title that appears on the value side of the chart.
505
     *
506
     * @param string $axisTitle
507
     */
508
    public function setValueAxisTitle($axisTitle)
509
    {
510
        $this->valueAxisTitle = $axisTitle;
5✔
511

512
        return $this;
5✔
513
    }
514

515
    public function getMajorTickPosition()
516
    {
517
        return $this->majorTickMarkPos;
5✔
518
    }
519

520
    /**
521
     * Set the position for major tick marks.
522
     *
523
     * @param string $position
524
     */
525
    public function setMajorTickPosition($position): void
526
    {
527
        $enum = ['in', 'out', 'cross', 'none'];
1✔
528
        $this->majorTickMarkPos = $this->setEnumVal($position, $enum, $this->majorTickMarkPos);
1✔
529
    }
530

531
    /**
532
     * Show Gridlines for X-Axis.
533
     *
534
     * @return bool
535
     */
536
    public function showGridX()
537
    {
538
        return $this->gridX;
5✔
539
    }
540

541
    /**
542
     * Set show Gridlines for X-Axis.
543
     *
544
     * @param bool $value
545
     *
546
     * @return self
547
     */
548
    public function setShowGridX($value = true)
549
    {
550
        $this->gridX = $this->setBoolVal($value, $this->gridX);
5✔
551

552
        return $this;
5✔
553
    }
554
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc