Completed
Push — develop ( 75d3bd...a06533 )
by Adrien
21:48
created

Chart::getPlotVisibleOnly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet;
4
5
/**
6
 * Copyright (c) 2006 - 2016 PhpSpreadsheet.
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with this library; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 *
22
 * @category    PhpSpreadsheet
23
 *
24
 * @copyright   Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
25
 * @license     http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
26
 */
27
class Chart
28
{
29
    /**
30
     * Chart Name.
31
     *
32
     * @var string
33
     */
34
    private $name = '';
35
36
    /**
37
     * Worksheet.
38
     *
39
     * @var Worksheet
40
     */
41
    private $worksheet;
42
43
    /**
44
     * Chart Title.
45
     *
46
     * @var Chart\Title
47
     */
48
    private $title;
49
50
    /**
51
     * Chart Legend.
52
     *
53
     * @var Chart\Legend
54
     */
55
    private $legend;
56
57
    /**
58
     * X-Axis Label.
59
     *
60
     * @var Chart\Title
61
     */
62
    private $xAxisLabel;
63
64
    /**
65
     * Y-Axis Label.
66
     *
67
     * @var Chart\Title
68
     */
69
    private $yAxisLabel;
70
71
    /**
72
     * Chart Plot Area.
73
     *
74
     * @var Chart\PlotArea
75
     */
76
    private $plotArea;
77
78
    /**
79
     * Plot Visible Only.
80
     *
81
     * @var bool
82
     */
83
    private $plotVisibleOnly = true;
84
85
    /**
86
     * Display Blanks as.
87
     *
88
     * @var string
89
     */
90
    private $displayBlanksAs = '0';
91
92
    /**
93
     * Chart Asix Y as.
94
     *
95
     * @var Chart\Axis
96
     */
97
    private $yAxis;
98
99
    /**
100
     * Chart Asix X as.
101
     *
102
     * @var Chart\Axis
103
     */
104
    private $xAxis;
105
106
    /**
107
     * Chart Major Gridlines as.
108
     *
109
     * @var Chart\GridLines
110
     */
111
    private $majorGridlines;
112
113
    /**
114
     * Chart Minor Gridlines as.
115
     *
116
     * @var Chart\GridLines
117
     */
118
    private $minorGridlines;
119
120
    /**
121
     * Top-Left Cell Position.
122
     *
123
     * @var string
124
     */
125
    private $topLeftCellRef = 'A1';
126
127
    /**
128
     * Top-Left X-Offset.
129
     *
130
     * @var int
131
     */
132
    private $topLeftXOffset = 0;
133
134
    /**
135
     * Top-Left Y-Offset.
136
     *
137
     * @var int
138
     */
139
    private $topLeftYOffset = 0;
140
141
    /**
142
     * Bottom-Right Cell Position.
143
     *
144
     * @var string
145
     */
146
    private $bottomRightCellRef = 'A1';
147
148
    /**
149
     * Bottom-Right X-Offset.
150
     *
151
     * @var int
152
     */
153
    private $bottomRightXOffset = 10;
154
155
    /**
156
     * Bottom-Right Y-Offset.
157
     *
158
     * @var int
159
     */
160
    private $bottomRightYOffset = 10;
161
162
    /**
163
     * Create a new Chart.
164
     *
165
     * @param mixed $name
166
     * @param mixed $plotVisibleOnly
167
     * @param mixed $displayBlanksAs
168
     */
169 14
    public function __construct($name, Chart\Title $title = null, Chart\Legend $legend = null, Chart\PlotArea $plotArea = null, $plotVisibleOnly = true, $displayBlanksAs = '0', Chart\Title $xAxisLabel = null, Chart\Title $yAxisLabel = null, Chart\Axis $xAxis = null, Chart\Axis $yAxis = null, Chart\GridLines $majorGridlines = null, Chart\GridLines $minorGridlines = null)
170
    {
171 14
        $this->name = $name;
172 14
        $this->title = $title;
173 14
        $this->legend = $legend;
174 14
        $this->xAxisLabel = $xAxisLabel;
175 14
        $this->yAxisLabel = $yAxisLabel;
176 14
        $this->plotArea = $plotArea;
177 14
        $this->plotVisibleOnly = $plotVisibleOnly;
178 14
        $this->displayBlanksAs = $displayBlanksAs;
179 14
        $this->xAxis = $xAxis;
180 14
        $this->yAxis = $yAxis;
181 14
        $this->majorGridlines = $majorGridlines;
182 14
        $this->minorGridlines = $minorGridlines;
183 14
    }
184
185
    /**
186
     * Get Name.
187
     *
188
     * @return string
189
     */
190 1
    public function getName()
191
    {
192 1
        return $this->name;
193
    }
194
195
    /**
196
     * Get Worksheet.
197
     *
198
     * @return Worksheet
199
     */
200 13
    public function getWorksheet()
201
    {
202 13
        return $this->worksheet;
203
    }
204
205
    /**
206
     * Set Worksheet.
207
     *
208
     * @param Worksheet $pValue
209
     *
210
     * @throws Chart\Exception
211
     *
212
     * @return Chart
213
     */
214 14
    public function setWorksheet(Worksheet $pValue = null)
215
    {
216 14
        $this->worksheet = $pValue;
217
218 14
        return $this;
219
    }
220
221
    /**
222
     * Get Title.
223
     *
224
     * @return Chart\Title
225
     */
226 13
    public function getTitle()
227
    {
228 13
        return $this->title;
229
    }
230
231
    /**
232
     * Set Title.
233
     *
234
     * @param Chart\Title $title
235
     *
236
     * @return Chart
237
     */
238
    public function setTitle(Chart\Title $title)
239
    {
240
        $this->title = $title;
241
242
        return $this;
243
    }
244
245
    /**
246
     * Get Legend.
247
     *
248
     * @return Chart\Legend
249
     */
250 13
    public function getLegend()
251
    {
252 13
        return $this->legend;
253
    }
254
255
    /**
256
     * Set Legend.
257
     *
258
     * @param Chart\Legend $legend
259
     *
260
     * @return Chart
261
     */
262
    public function setLegend(Chart\Legend $legend)
263
    {
264
        $this->legend = $legend;
265
266
        return $this;
267
    }
268
269
    /**
270
     * Get X-Axis Label.
271
     *
272
     * @return Chart\Title
273
     */
274 13
    public function getXAxisLabel()
275
    {
276 13
        return $this->xAxisLabel;
277
    }
278
279
    /**
280
     * Set X-Axis Label.
281
     *
282
     * @param Chart\Title $label
283
     *
284
     * @return Chart
285
     */
286
    public function setXAxisLabel(Chart\Title $label)
287
    {
288
        $this->xAxisLabel = $label;
289
290
        return $this;
291
    }
292
293
    /**
294
     * Get Y-Axis Label.
295
     *
296
     * @return Chart\Title
297
     */
298 13
    public function getYAxisLabel()
299
    {
300 13
        return $this->yAxisLabel;
301
    }
302
303
    /**
304
     * Set Y-Axis Label.
305
     *
306
     * @param Chart\Title $label
307
     *
308
     * @return Chart
309
     */
310
    public function setYAxisLabel(Chart\Title $label)
311
    {
312
        $this->yAxisLabel = $label;
313
314
        return $this;
315
    }
316
317
    /**
318
     * Get Plot Area.
319
     *
320
     * @return Chart\PlotArea
321
     */
322 13
    public function getPlotArea()
323
    {
324 13
        return $this->plotArea;
325
    }
326
327
    /**
328
     * Get Plot Visible Only.
329
     *
330
     * @return bool
331
     */
332
    public function getPlotVisibleOnly()
333
    {
334
        return $this->plotVisibleOnly;
335
    }
336
337
    /**
338
     * Set Plot Visible Only.
339
     *
340
     * @param bool $plotVisibleOnly
341
     *
342
     * @return Chart
343
     */
344
    public function setPlotVisibleOnly($plotVisibleOnly)
345
    {
346
        $this->plotVisibleOnly = $plotVisibleOnly;
347
348
        return $this;
349
    }
350
351
    /**
352
     * Get Display Blanks as.
353
     *
354
     * @return string
355
     */
356
    public function getDisplayBlanksAs()
357
    {
358
        return $this->displayBlanksAs;
359
    }
360
361
    /**
362
     * Set Display Blanks as.
363
     *
364
     * @param string $displayBlanksAs
365
     *
366
     * @return Chart
367
     */
368
    public function setDisplayBlanksAs($displayBlanksAs)
369
    {
370
        $this->displayBlanksAs = $displayBlanksAs;
371
    }
372
373
    /**
374
     * Get yAxis.
375
     *
376
     * @return Chart\Axis
377
     */
378 13
    public function getChartAxisY()
379
    {
380 13
        if ($this->yAxis !== null) {
381
            return $this->yAxis;
382
        }
383
384 13
        return new Chart\Axis();
385
    }
386
387
    /**
388
     * Get xAxis.
389
     *
390
     * @return Chart\Axis
391
     */
392 13
    public function getChartAxisX()
393
    {
394 13
        if ($this->xAxis !== null) {
395
            return $this->xAxis;
396
        }
397
398 13
        return new Chart\Axis();
399
    }
400
401
    /**
402
     * Get Major Gridlines.
403
     *
404
     * @return Chart\GridLines
405
     */
406 13
    public function getMajorGridlines()
407
    {
408 13
        if ($this->majorGridlines !== null) {
409
            return $this->majorGridlines;
410
        }
411
412 13
        return new Chart\GridLines();
413
    }
414
415
    /**
416
     * Get Minor Gridlines.
417
     *
418
     * @return Chart\GridLines
419
     */
420 13
    public function getMinorGridlines()
421
    {
422 13
        if ($this->minorGridlines !== null) {
423
            return $this->minorGridlines;
424
        }
425
426 13
        return new Chart\GridLines();
427
    }
428
429
    /**
430
     * Set the Top Left position for the chart.
431
     *
432
     * @param string $cell
433
     * @param int $xOffset
434
     * @param int $yOffset
435
     *
436
     * @return Chart
437
     */
438 14
    public function setTopLeftPosition($cell, $xOffset = null, $yOffset = null)
439
    {
440 14
        $this->topLeftCellRef = $cell;
441 14
        if (!is_null($xOffset)) {
442 1
            $this->setTopLeftXOffset($xOffset);
443
        }
444 14
        if (!is_null($yOffset)) {
445 1
            $this->setTopLeftYOffset($yOffset);
446
        }
447
448 14
        return $this;
449
    }
450
451
    /**
452
     * Get the top left position of the chart.
453
     *
454
     * @return array an associative array containing the cell address, X-Offset and Y-Offset from the top left of that cell
455
     */
456 13
    public function getTopLeftPosition()
457
    {
458
        return [
459 13
            'cell' => $this->topLeftCellRef,
460 13
            'xOffset' => $this->topLeftXOffset,
461 13
            'yOffset' => $this->topLeftYOffset,
462
        ];
463
    }
464
465
    /**
466
     * Get the cell address where the top left of the chart is fixed.
467
     *
468
     * @return string
469
     */
470
    public function getTopLeftCell()
471
    {
472
        return $this->topLeftCellRef;
473
    }
474
475
    /**
476
     * Set the Top Left cell position for the chart.
477
     *
478
     * @param string $cell
479
     *
480
     * @return Chart
481
     */
482
    public function setTopLeftCell($cell)
483
    {
484
        $this->topLeftCellRef = $cell;
485
486
        return $this;
487
    }
488
489
    /**
490
     * Set the offset position within the Top Left cell for the chart.
491
     *
492
     * @param int $xOffset
493
     * @param int $yOffset
494
     *
495
     * @return Chart
496
     */
497
    public function setTopLeftOffset($xOffset, $yOffset)
498
    {
499
        if (!is_null($xOffset)) {
500
            $this->setTopLeftXOffset($xOffset);
501
        }
502
503
        if (!is_null($yOffset)) {
504
            $this->setTopLeftYOffset($yOffset);
505
        }
506
507
        return $this;
508
    }
509
510
    /**
511
     * Get the offset position within the Top Left cell for the chart.
512
     *
513
     * @return int[]
514
     */
515
    public function getTopLeftOffset()
516
    {
517
        return [
518
            'X' => $this->topLeftXOffset,
519
            'Y' => $this->topLeftYOffset,
520
        ];
521
    }
522
523 1
    public function setTopLeftXOffset($xOffset)
524
    {
525 1
        $this->topLeftXOffset = $xOffset;
526
527 1
        return $this;
528
    }
529
530
    public function getTopLeftXOffset()
531
    {
532
        return $this->topLeftXOffset;
533
    }
534
535 1
    public function setTopLeftYOffset($yOffset)
536
    {
537 1
        $this->topLeftYOffset = $yOffset;
538
539 1
        return $this;
540
    }
541
542
    public function getTopLeftYOffset()
543
    {
544
        return $this->topLeftYOffset;
545
    }
546
547
    /**
548
     * Set the Bottom Right position of the chart.
549
     *
550
     * @param string $cell
551
     * @param int $xOffset
552
     * @param int $yOffset
553
     *
554
     * @return Chart
555
     */
556 14
    public function setBottomRightPosition($cell, $xOffset = null, $yOffset = null)
557
    {
558 14
        $this->bottomRightCellRef = $cell;
559 14
        if (!is_null($xOffset)) {
560 1
            $this->setBottomRightXOffset($xOffset);
561
        }
562 14
        if (!is_null($yOffset)) {
563 1
            $this->setBottomRightYOffset($yOffset);
564
        }
565
566 14
        return $this;
567
    }
568
569
    /**
570
     * Get the bottom right position of the chart.
571
     *
572
     * @return array an associative array containing the cell address, X-Offset and Y-Offset from the top left of that cell
573
     */
574 13
    public function getBottomRightPosition()
575
    {
576
        return [
577 13
            'cell' => $this->bottomRightCellRef,
578 13
            'xOffset' => $this->bottomRightXOffset,
579 13
            'yOffset' => $this->bottomRightYOffset,
580
        ];
581
    }
582
583
    public function setBottomRightCell($cell)
584
    {
585
        $this->bottomRightCellRef = $cell;
586
587
        return $this;
588
    }
589
590
    /**
591
     * Get the cell address where the bottom right of the chart is fixed.
592
     *
593
     * @return string
594
     */
595
    public function getBottomRightCell()
596
    {
597
        return $this->bottomRightCellRef;
598
    }
599
600
    /**
601
     * Set the offset position within the Bottom Right cell for the chart.
602
     *
603
     * @param int $xOffset
604
     * @param int $yOffset
605
     *
606
     * @return Chart
607
     */
608
    public function setBottomRightOffset($xOffset, $yOffset)
609
    {
610
        if (!is_null($xOffset)) {
611
            $this->setBottomRightXOffset($xOffset);
612
        }
613
614
        if (!is_null($yOffset)) {
615
            $this->setBottomRightYOffset($yOffset);
616
        }
617
618
        return $this;
619
    }
620
621
    /**
622
     * Get the offset position within the Bottom Right cell for the chart.
623
     *
624
     * @return int[]
625
     */
626
    public function getBottomRightOffset()
627
    {
628
        return [
629
            'X' => $this->bottomRightXOffset,
630
            'Y' => $this->bottomRightYOffset,
631
        ];
632
    }
633
634 1
    public function setBottomRightXOffset($xOffset)
635
    {
636 1
        $this->bottomRightXOffset = $xOffset;
637
638 1
        return $this;
639
    }
640
641
    public function getBottomRightXOffset()
642
    {
643
        return $this->bottomRightXOffset;
644
    }
645
646 1
    public function setBottomRightYOffset($yOffset)
647
    {
648 1
        $this->bottomRightYOffset = $yOffset;
649
650 1
        return $this;
651
    }
652
653
    public function getBottomRightYOffset()
654
    {
655
        return $this->bottomRightYOffset;
656
    }
657
658 13
    public function refresh()
659
    {
660 13
        if ($this->worksheet !== null) {
661 13
            $this->plotArea->refresh($this->worksheet);
662
        }
663 13
    }
664
665
    public function render($outputDestination = null)
666
    {
667
        $libraryName = Settings::getChartRendererName();
668
        if (is_null($libraryName)) {
669
            return false;
670
        }
671
        //    Ensure that data series values are up-to-date before we render
672
        $this->refresh();
673
674
        $libraryPath = Settings::getChartRendererPath();
675
        $includePath = str_replace('\\', '/', get_include_path());
676
        $rendererPath = str_replace('\\', '/', $libraryPath);
677
        if (strpos($rendererPath, $includePath) === false) {
678
            set_include_path(get_include_path() . PATH_SEPARATOR . $libraryPath);
679
        }
680
681
        $rendererName = '\\PhpOffice\\PhpSpreadsheet\\Chart\\Renderer\\' . $libraryName;
682
        $renderer = new $rendererName($this);
683
684
        if ($outputDestination == 'php://output') {
685
            $outputDestination = null;
686
        }
687
688
        return $renderer->render($outputDestination);
689
    }
690
}
691