|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Klass PlottaAck. |
|
5
|
|
|
* @author Niklas Dougherty |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Tips\Klasser\Investera; |
|
11
|
|
|
|
|
12
|
|
|
use Tips\Klasser\Graf; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Klass PlottaAck. |
|
16
|
|
|
* Graf för ackumulerat netto över tid. |
|
17
|
|
|
*/ |
|
18
|
|
|
class PlottaAck extends Plotta { |
|
19
|
|
|
protected Graf $ackumulerad_graf; |
|
20
|
|
|
protected string $fil_ack = '/ack_investeringsgraf.png'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Plotta ackumulerade investeringar. |
|
24
|
|
|
*/ |
|
25
|
1 |
|
protected function plotta_ackumulerad_investering(): void { |
|
26
|
1 |
|
imageantialias($this->ackumulerad_graf->graf, true); |
|
27
|
1 |
|
$acknetto = abs($this->ackmax - $this->ackmin); |
|
28
|
1 |
|
$delta = intval(abs($this->ackmin / $acknetto) * 680); |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Rita axlar i svag gul nyans. |
|
32
|
|
|
*/ |
|
33
|
1 |
|
$this->ackumulerad_graf->sätt_linje(100, 20, 100, 720, $this->graf->gul_v[1]); |
|
34
|
1 |
|
$this->ackumulerad_graf->sätt_linje(80, 700 - $delta, 2120, 700 - $delta, $this->graf->gul_v[1]); |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Indela axeln i segment. |
|
38
|
|
|
*/ |
|
39
|
1 |
|
for ($index = 0; $index <= 4; $index++) { |
|
40
|
1 |
|
$y = intval($index * (680 - $delta) / 4 + 20); |
|
41
|
1 |
|
$text = strval(intval($this->ackmax - $index * $this->ackmax / 4)); |
|
42
|
1 |
|
$this->ackumulerad_graf->sätt_text(15, $y, $text, $this->graf->blå); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Tabellrubrik i gult, axelvärden i blått. |
|
47
|
|
|
*/ |
|
48
|
1 |
|
$this->ackumulerad_graf->sätt_text(15, 690, "{$this->ackmin}", $this->graf->blå); |
|
49
|
1 |
|
$this->ackumulerad_graf->sätt_text(120, 20, "Ackumulerat netto", $this->graf->gul); |
|
50
|
|
|
|
|
51
|
1 |
|
$xk1 = -1; |
|
52
|
1 |
|
$yk1 = -1; |
|
53
|
1 |
|
$ack = 0; |
|
54
|
|
|
/** |
|
55
|
|
|
* Plotta netton över tid. |
|
56
|
|
|
*/ |
|
57
|
1 |
|
foreach ($this->investeringar as $index => $inv) { |
|
58
|
1 |
|
$ack += $inv[1]; |
|
59
|
1 |
|
$xk2 = 100 + intval(2000 * $index / max(1, ($this->antal_investeringar - 1))); |
|
60
|
1 |
|
$yk2 = 700 - $delta - intval(680 * $ack / $acknetto); |
|
61
|
1 |
|
$färg = ($ack > 0) ? $this->graf->gul : $this->graf->röd; |
|
62
|
|
|
|
|
63
|
1 |
|
if ($xk1 > 0) { |
|
64
|
1 |
|
$this->ackumulerad_graf->sätt_linje($xk1, $yk1, $xk2, $yk2, $färg); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
1 |
|
[$xk1, $yk1] = [$xk2, $yk2]; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
1 |
|
$this->ackumulerad_graf->spara_tipsgraf($this->fil_ack); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|