|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* webtrees-lib: MyArtJaub library for webtrees |
|
5
|
|
|
* |
|
6
|
|
|
* @package MyArtJaub\Webtrees |
|
7
|
|
|
* @subpackage GeoDispersion |
|
8
|
|
|
* @author Jonathan Jaubart <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) 2021-2022, Jonathan Jaubart |
|
10
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
declare(strict_types=1); |
|
14
|
|
|
|
|
15
|
|
|
namespace MyArtJaub\Webtrees\Common\GeoDispersion\Config; |
|
16
|
|
|
|
|
17
|
|
|
use Spatie\Color\Color; |
|
18
|
|
|
use Spatie\Color\Rgb; |
|
19
|
|
|
use JsonSerializable; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Configuration for map colors |
|
23
|
|
|
*/ |
|
24
|
|
|
class MapColorsConfig implements JsonSerializable |
|
25
|
|
|
{ |
|
26
|
|
|
private Color $default; |
|
27
|
|
|
private Color $stroke; |
|
28
|
|
|
private Color $max_value; |
|
29
|
|
|
private Color $hover; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Constructor for MapColorsConfig |
|
33
|
|
|
* |
|
34
|
|
|
* @param Color $default |
|
35
|
|
|
* @param Color $stroke |
|
36
|
|
|
* @param Color $max_value |
|
37
|
|
|
* @param Color $hover |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct( |
|
40
|
|
|
Color $default, |
|
41
|
|
|
Color $stroke, |
|
42
|
|
|
Color $max_value, |
|
43
|
|
|
Color $hover |
|
44
|
|
|
) { |
|
45
|
|
|
$this->default = $default; |
|
46
|
|
|
$this->stroke = $stroke; |
|
47
|
|
|
$this->max_value = $max_value; |
|
48
|
|
|
$this->hover = $hover; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Get the default color for the features |
|
53
|
|
|
* |
|
54
|
|
|
* @return Color |
|
55
|
|
|
*/ |
|
56
|
|
|
public function defaultColor(): Color |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->default; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Get the color for the features' strokes |
|
63
|
|
|
* |
|
64
|
|
|
* @return Color |
|
65
|
|
|
*/ |
|
66
|
|
|
public function strokeColor(): Color |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->stroke; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get the color for the features with the lowest count |
|
73
|
|
|
* |
|
74
|
|
|
* @return Color |
|
75
|
|
|
*/ |
|
76
|
|
|
public function minValueColor(): Color |
|
77
|
|
|
{ |
|
78
|
|
|
return new Rgb(255, 255, 255); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Get the color for the features with the highest count |
|
83
|
|
|
* |
|
84
|
|
|
* @return Color |
|
85
|
|
|
*/ |
|
86
|
|
|
public function maxValueColor(): Color |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->max_value; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Get the color for feature hovering |
|
93
|
|
|
* |
|
94
|
|
|
* @return Color |
|
95
|
|
|
*/ |
|
96
|
|
|
public function hoverColor(): Color |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->hover; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* {@inheritDoc} |
|
103
|
|
|
* @see JsonSerializable::jsonSerialize() |
|
104
|
|
|
*/ |
|
105
|
|
|
#[\ReturnTypeWillChange] |
|
106
|
|
|
public function jsonSerialize() |
|
107
|
|
|
{ |
|
108
|
|
|
return [ |
|
109
|
|
|
'default' => (string) $this->defaultColor()->toHex(), |
|
110
|
|
|
'stroke' => (string) $this->strokeColor()->toHex(), |
|
111
|
|
|
'maxvalue' => (string) $this->maxValueColor()->toHex(), |
|
112
|
|
|
'hover' => (string) $this->hoverColor()->toHex(), |
|
113
|
|
|
]; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|