Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
23 / 23 |
|
100.00% |
12 / 12 |
CRAP | |
100.00% |
1 / 1 |
| Chart | |
100.00% |
23 / 23 |
|
100.00% |
12 / 12 |
14 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| __clone | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| getDisplayBlankAs | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getTitle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLegend | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPlotArea | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getView3D | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasIncludedSpreadsheet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setDisplayBlankAs | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| setIncludeSpreadsheet | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getIndexedFilename | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getHashCode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * This file is part of PHPPresentation - A pure PHP library for reading and writing |
| 4 | * presentations documents. |
| 5 | * |
| 6 | * PHPPresentation is free software distributed under the terms of the GNU Lesser |
| 7 | * General Public License version 3 as published by the Free Software Foundation. |
| 8 | * |
| 9 | * For the full copyright and license information, please read the LICENSE |
| 10 | * file that was distributed with this source code. For the full list of |
| 11 | * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors. |
| 12 | * |
| 13 | * @see https://github.com/PHPOffice/PHPPresentation |
| 14 | * |
| 15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace PhpOffice\PhpPresentation\Shape; |
| 21 | |
| 22 | use PhpOffice\PhpPresentation\ComparableInterface; |
| 23 | use PhpOffice\PhpPresentation\Shape\Chart\Legend; |
| 24 | use PhpOffice\PhpPresentation\Shape\Chart\PlotArea; |
| 25 | use PhpOffice\PhpPresentation\Shape\Chart\Title; |
| 26 | use PhpOffice\PhpPresentation\Shape\Chart\View3D; |
| 27 | |
| 28 | /** |
| 29 | * Chart element. |
| 30 | */ |
| 31 | class Chart extends AbstractGraphic implements ComparableInterface |
| 32 | { |
| 33 | public const BLANKAS_GAP = 'gap'; |
| 34 | public const BLANKAS_ZERO = 'zero'; |
| 35 | public const BLANKAS_SPAN = 'span'; |
| 36 | |
| 37 | /** |
| 38 | * Title. |
| 39 | * |
| 40 | * @var Title |
| 41 | */ |
| 42 | private $title; |
| 43 | |
| 44 | /** |
| 45 | * Legend. |
| 46 | * |
| 47 | * @var Legend |
| 48 | */ |
| 49 | private $legend; |
| 50 | |
| 51 | /** |
| 52 | * Plot area. |
| 53 | * |
| 54 | * @var PlotArea |
| 55 | */ |
| 56 | private $plotArea; |
| 57 | |
| 58 | /** |
| 59 | * View 3D. |
| 60 | * |
| 61 | * @var View3D |
| 62 | */ |
| 63 | private $view3D; |
| 64 | |
| 65 | /** |
| 66 | * Is the spreadsheet included for editing data ? |
| 67 | * |
| 68 | * @var bool |
| 69 | */ |
| 70 | private $includeSpreadsheet = false; |
| 71 | |
| 72 | /** |
| 73 | * How to display blank (missing) values? Not set by default. |
| 74 | * |
| 75 | * @var string |
| 76 | */ |
| 77 | private $displayBlankAs = self::BLANKAS_ZERO; |
| 78 | |
| 79 | /** |
| 80 | * Create a new Chart. |
| 81 | */ |
| 82 | public function __construct() |
| 83 | { |
| 84 | // Initialize |
| 85 | $this->title = new Title(); |
| 86 | $this->legend = new Legend(); |
| 87 | $this->plotArea = new PlotArea(); |
| 88 | $this->view3D = new View3D(); |
| 89 | |
| 90 | // Initialize parent |
| 91 | parent::__construct(); |
| 92 | } |
| 93 | |
| 94 | public function __clone() |
| 95 | { |
| 96 | parent::__clone(); |
| 97 | |
| 98 | $this->title = clone $this->title; |
| 99 | $this->legend = clone $this->legend; |
| 100 | $this->plotArea = clone $this->plotArea; |
| 101 | $this->view3D = clone $this->view3D; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * How missing/blank values are displayed on chart (dispBlanksAs property). |
| 106 | */ |
| 107 | public function getDisplayBlankAs(): string |
| 108 | { |
| 109 | return $this->displayBlankAs; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Get Title. |
| 114 | */ |
| 115 | public function getTitle(): Title |
| 116 | { |
| 117 | return $this->title; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Get Legend. |
| 122 | */ |
| 123 | public function getLegend(): Legend |
| 124 | { |
| 125 | return $this->legend; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Get PlotArea. |
| 130 | */ |
| 131 | public function getPlotArea(): PlotArea |
| 132 | { |
| 133 | return $this->plotArea; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Get View3D. |
| 138 | */ |
| 139 | public function getView3D(): View3D |
| 140 | { |
| 141 | return $this->view3D; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Is the spreadsheet included for editing data ? |
| 146 | */ |
| 147 | public function hasIncludedSpreadsheet(): bool |
| 148 | { |
| 149 | return $this->includeSpreadsheet; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Define a way to display missing/blank values (dispBlanksAs property). |
| 154 | */ |
| 155 | public function setDisplayBlankAs(string $value): self |
| 156 | { |
| 157 | if (in_array($value, [self::BLANKAS_GAP, self::BLANKAS_SPAN, self::BLANKAS_ZERO])) { |
| 158 | $this->displayBlankAs = $value; |
| 159 | } |
| 160 | |
| 161 | return $this; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Is the spreadsheet included for editing data ? |
| 166 | */ |
| 167 | public function setIncludeSpreadsheet(bool $value = false): self |
| 168 | { |
| 169 | $this->includeSpreadsheet = $value; |
| 170 | |
| 171 | return $this; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Get indexed filename (using image index). |
| 176 | */ |
| 177 | public function getIndexedFilename(): string |
| 178 | { |
| 179 | return 'chart' . $this->getImageIndex() . '.xml'; |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Get hash code. |
| 184 | * |
| 185 | * @return string Hash code |
| 186 | */ |
| 187 | public function getHashCode(): string |
| 188 | { |
| 189 | return md5(parent::getHashCode() . $this->title->getHashCode() . $this->legend->getHashCode() . $this->plotArea->getHashCode() . $this->view3D->getHashCode() . ($this->includeSpreadsheet ? 1 : 0) . __CLASS__); |
| 190 | } |
| 191 | } |