| 1 |
<?php |
| 2 |
|
| 3 |
namespace PhpOffice\PhpSpreadsheet\Chart; |
| 4 |
|
| 5 |
class TrendLine extends Properties |
| 6 |
{ |
| 7 |
const TRENDLINE_EXPONENTIAL = 'exp'; |
| 8 |
const TRENDLINE_LINEAR = 'linear'; |
| 9 |
const TRENDLINE_LOGARITHMIC = 'log'; |
| 10 |
const TRENDLINE_POLYNOMIAL = 'poly'; // + 'order' |
| 11 |
const TRENDLINE_POWER = 'power'; |
| 12 |
const TRENDLINE_MOVING_AVG = 'movingAvg'; // + 'period' |
| 13 |
const TRENDLINE_TYPES = [ |
| 14 |
self::TRENDLINE_EXPONENTIAL, |
| 15 |
self::TRENDLINE_LINEAR, |
| 16 |
self::TRENDLINE_LOGARITHMIC, |
| 17 |
self::TRENDLINE_POLYNOMIAL, |
| 18 |
self::TRENDLINE_POWER, |
| 19 |
self::TRENDLINE_MOVING_AVG, |
| 20 |
]; |
| 21 |
|
| 22 |
/** @var string */ |
| 23 |
private $trendLineType = 'linear'; // TRENDLINE_LINEAR |
| 24 |
|
| 25 |
/** @var int */ |
| 26 |
private $order = 2; |
| 27 |
|
| 28 |
/** @var int */ |
| 29 |
private $period = 3; |
| 30 |
|
| 31 |
/** @var bool */ |
| 32 |
private $dispRSqr = false; |
| 33 |
|
| 34 |
/** @var bool */ |
| 35 |
private $dispEq = false; |
| 36 |
|
| 37 |
/** @var string */ |
| 38 |
private $name = ''; |
| 39 |
|
| 40 |
/** @var float */ |
| 41 |
private $backward = 0.0; |
| 42 |
|
| 43 |
/** @var float */ |
| 44 |
private $forward = 0.0; |
| 45 |
|
| 46 |
/** @var float */ |
| 47 |
private $intercept = 0.0; |
| 48 |
|
| 49 |
/** |
| 50 |
* Create a new TrendLine object. |
| 51 |
*/ |
| 52 |
public function __construct( |
| 53 |
string $trendLineType = '', |
| 54 |
?int $order = null, |
| 55 |
?int $period = null, |
| 56 |
bool $dispRSqr = false, |
| 57 |
bool $dispEq = false, |
| 58 |
?float $backward = null, |
| 59 |
?float $forward = null, |
| 60 |
?float $intercept = null, |
| 61 |
?string $name = null |
| 62 |
) { |
| 63 |
parent::__construct(); |
| 64 |
$this->setTrendLineProperties( |
| 65 |
$trendLineType, |
| 66 |
$order, |
| 67 |
$period, |
| 68 |
$dispRSqr, |
| 69 |
$dispEq, |
| 70 |
$backward, |
| 71 |
$forward, |
| 72 |
$intercept, |
| 73 |
$name |
| 74 |
); |
| 75 |
} |
| 76 |
|
| 77 |
public function getTrendLineType(): string |
| 78 |
{ |
| 79 |
return $this->trendLineType; |
| 80 |
} |
| 81 |
|
| 82 |
public function setTrendLineType(string $trendLineType): self |
| 83 |
{ |
| 84 |
$this->trendLineType = $trendLineType; |
| 85 |
|
| 86 |
return $this; |
| 87 |
} |
| 88 |
|
| 89 |
public function getOrder(): int |
| 90 |
{ |
| 91 |
return $this->order; |
| 92 |
} |
| 93 |
|
| 94 |
public function setOrder(int $order): self |
| 95 |
{ |
| 96 |
$this->order = $order; |
| 97 |
|
| 98 |
return $this; |
| 99 |
} |
| 100 |
|
| 101 |
public function getPeriod(): int |
| 102 |
{ |
| 103 |
return $this->period; |
| 104 |
} |
| 105 |
|
| 106 |
public function setPeriod(int $period): self |
| 107 |
{ |
| 108 |
$this->period = $period; |
| 109 |
|
| 110 |
return $this; |
| 111 |
} |
| 112 |
|
| 113 |
public function getDispRSqr(): bool |
| 114 |
{ |
| 115 |
return $this->dispRSqr; |
| 116 |
} |
| 117 |
|
| 118 |
public function setDispRSqr(bool $dispRSqr): self |
| 119 |
{ |
| 120 |
$this->dispRSqr = $dispRSqr; |
| 121 |
|
| 122 |
return $this; |
| 123 |
} |
| 124 |
|
| 125 |
public function getDispEq(): bool |
| 126 |
{ |
| 127 |
return $this->dispEq; |
| 128 |
} |
| 129 |
|
| 130 |
public function setDispEq(bool $dispEq): self |
| 131 |
{ |
| 132 |
$this->dispEq = $dispEq; |
| 133 |
|
| 134 |
return $this; |
| 135 |
} |
| 136 |
|
| 137 |
public function getName(): string |
| 138 |
{ |
| 139 |
return $this->name; |
| 140 |
} |
| 141 |
|
| 142 |
public function setName(string $name): self |
| 143 |
{ |
| 144 |
$this->name = $name; |
| 145 |
|
| 146 |
return $this; |
| 147 |
} |
| 148 |
|
| 149 |
public function getBackward(): float |
| 150 |
{ |
| 151 |
return $this->backward; |
| 152 |
} |
| 153 |
|
| 154 |
public function setBackward(float $backward): self |
| 155 |
{ |
| 156 |
$this->backward = $backward; |
| 157 |
|
| 158 |
return $this; |
| 159 |
} |
| 160 |
|
| 161 |
public function getForward(): float |
| 162 |
{ |
| 163 |
return $this->forward; |
| 164 |
} |
| 165 |
|
| 166 |
public function setForward(float $forward): self |
| 167 |
{ |
| 168 |
$this->forward = $forward; |
| 169 |
|
| 170 |
return $this; |
| 171 |
} |
| 172 |
|
| 173 |
public function getIntercept(): float |
| 174 |
{ |
| 175 |
return $this->intercept; |
| 176 |
} |
| 177 |
|
| 178 |
public function setIntercept(float $intercept): self |
| 179 |
{ |
| 180 |
$this->intercept = $intercept; |
| 181 |
|
| 182 |
return $this; |
| 183 |
} |
| 184 |
|
| 185 |
public function setTrendLineProperties( |
| 186 |
?string $trendLineType = null, |
| 187 |
?int $order = 0, |
| 188 |
?int $period = 0, |
| 189 |
?bool $dispRSqr = false, |
| 190 |
?bool $dispEq = false, |
| 191 |
?float $backward = null, |
| 192 |
?float $forward = null, |
| 193 |
?float $intercept = null, |
| 194 |
?string $name = null |
| 195 |
): self { |
| 196 |
if (!empty($trendLineType)) { |
| 197 |
$this->setTrendLineType($trendLineType); |
| 198 |
} |
| 199 |
if ($order !== null) { |
| 200 |
$this->setOrder($order); |
| 201 |
} |
| 202 |
if ($period !== null) { |
| 203 |
$this->setPeriod($period); |
| 204 |
} |
| 205 |
if ($dispRSqr !== null) { |
| 206 |
$this->setDispRSqr($dispRSqr); |
| 207 |
} |
| 208 |
if ($dispEq !== null) { |
| 209 |
$this->setDispEq($dispEq); |
| 210 |
} |
| 211 |
if ($backward !== null) { |
| 212 |
$this->setBackward($backward); |
| 213 |
} |
| 214 |
if ($forward !== null) { |
| 215 |
$this->setForward($forward); |
| 216 |
} |
| 217 |
if ($intercept !== null) { |
| 218 |
$this->setIntercept($intercept); |
| 219 |
} |
| 220 |
if ($name !== null) { |
| 221 |
$this->setName($name); |
| 222 |
} |
| 223 |
|
| 224 |
return $this; |
| 225 |
} |
| 226 |
} |
| 227 |
|