-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
AreaChart.php
107 lines (87 loc) · 2.89 KB
/
AreaChart.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace Coroowicaksono\ChartJsIntegration;
use Laravel\Nova\Card;
class AreaChart extends Card
{
/**
* The width of the card (1/3, 1/2, or full).
*
* @var string
*/
public $width = 'full';
public function __construct($component = null)
{
parent::__construct($component);
}
/**
* Get the component name for the element.
*
* @return string
*/
public function component()
{
return 'stripe-chart';
}
public function series(array $series): self
{
foreach ($series as $key => $data) {
if (isset($data['backgroundColor'])) {
if (empty($data['borderColor'])) {
$series[$key]['borderColor'] = $this->adjustBrightness($data['backgroundColor'], '-40');
}
}
}
return $this->withMeta(['series' => $series]);
}
public function type(string $type): self
{
return $this->withMeta(['type' => $type]);
}
public function options(array $options): self
{
return $this->withMeta(['options' => (object) $options]);
}
public function animations(array $animations): self
{
return $this->withMeta(['animations' => $animations]);
}
public function title(string $title): self
{
return $this->withMeta(['title' => $title]);
}
public function model(string $model): self
{
return $this->withMeta(['model' => $model]);
}
public function col_xaxis(string $col_xaxis): self
{
return $this->withMeta(['col_xaxis' => $col_xaxis]);
}
public function uriKey(string $uriKey)
{
return $this->withMeta(['uriKey' => $uriKey]);
}
private function adjustBrightness($hex, $steps)
{
// Steps should be between -255 and 255. Negative = darker, positive = lighter
$steps = max(-255, min(255, $steps));
// Normalize into a six character long hex string
$hex = str_replace('#', '', $hex);
if (strlen($hex) == 3) {
$hex = str_repeat(substr($hex, 0, 1), 2) . str_repeat(substr($hex, 1, 1), 2) . str_repeat(substr($hex, 2, 1), 2);
}
// Split into three parts: R, G and B
$color_parts = str_split($hex, 2);
$return = '#';
foreach ($color_parts as $color) {
$color = hexdec($color); // Convert to decimal
$color = max(0, min(255, $color + $steps)); // Adjust color
$return .= str_pad(dechex($color), 2, '0', STR_PAD_LEFT); // Make two char hex code
}
return $return;
}
public function join(string $joinTable, string $joinColumnFirst, string $joinEqual, string $joinColumnSecond): self
{
return $this->withMeta(['join' => ['joinTable' => $joinTable, 'joinColumnFirst' => $joinColumnFirst, 'joinEqual' => $joinEqual, 'joinColumnSecond' => $joinColumnSecond]]);
}
}