Passed
Push — main ( 38376b...7b37bf )
by N.
03:15
created

Plotta   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 55
ccs 0
cts 26
cp 0
c 0
b 0
f 0
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A plotta_investeringar() 0 48 3
1
<?php
2
3
/**
4
 * Klass Plotta.
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 Plotta.
16
 */
17
class Plotta extends HamtaAlla {
18
	protected string $fil = '/investeringsgraf.png';
19
	protected Graf $graf;
20
21
	/**
22
	 * Plotta data för lagda spel; utgifter och vinster.
23
	 */
24
	protected function plotta_investeringar(): void {
25
		/**
26
		 * Skiss:
27
		 *	0, 0							2186, 0
28
		 *		100, 20					2100, 20
29
		 *					680 x 2000
30
		 *		100, 700				2100, 700
31
		 *	728, 0							2186, 0
32
33
		 * Axlar i gult.
34
		 */
35
		$this->graf->sätt_linje(100, 20, 100, 720, $this->graf->gul_v[1]);
36
		$this->graf->sätt_linje(80, 700, 2120, 700, $this->graf->gul_v[1]);
37
38
		/**
39
		 * Axeletiketter i blått.
40
		 */
41
		for ($index = 0; $index <= 4; $index++) {
42
			$ykoord = intval($index * 670 / 4 + 20);
43
			$text = strval(intval($this->maxvinst - $index * $this->maxvinst / 4));
44
			$this->graf->sätt_text(15, $ykoord, $text, $this->graf->blå);
45
		}
46
		$this->graf->sätt_text(120, 20, "Vinster", $this->graf->gul);
47
48
		/**
49
		 * Ringar i olika storlek och färg bereonde på vinstnivå.
50
		 */
51
		foreach ($this->investeringar as $index => $inv) {
52
			[$diameter, $färg] = match (true) {
53
				$inv[0] > 5000000 => [40, $this->graf->vit],
54
				$inv[0] > 1000000 => [35, $this->graf->blå],
55
				$inv[0] > 500000 => [28, $this->graf->lila],
56
				$inv[0] > 100000 => [22, $this->graf->röd],
57
				$inv[0] > 50000 => [18, $this->graf->grön],
58
				$inv[0] > 10000 => [14, $this->graf->gul],
59
				$inv[0] > 5000 => [10, $this->graf->gul_v[5]],
60
				$inv[0] > 1000 => [8, $this->graf->gul_v[4]],
61
				$inv[0] > 500 => [5, $this->graf->gul_v[3]],
62
				$inv[0] > 1 => [3, $this->graf->gul_v[2]],
63
				default => [2, $this->graf->gul_v[1]]
64
			};
65
			$xk1 = 100 + intval(2000 * $index / max(1, ($this->antal_investeringar - 1)));
66
			$yk1 = 700 - intval(680 * $inv[0] / $this->maxvinst);
67
68
			$this->graf->sätt_cirkel($xk1, $yk1, $diameter, $färg);
69
		}
70
71
		$this->graf->spara_tipsgraf($this->fil);
72
	}
73
}
74