-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathSharpGraphWidget.php
More file actions
73 lines (58 loc) · 1.72 KB
/
SharpGraphWidget.php
File metadata and controls
73 lines (58 loc) · 1.72 KB
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
<?php
namespace Code16\Sharp\Dashboard\Widgets;
use Code16\Sharp\Dashboard\Widgets\Graph\NumberFormatOptions;
abstract class SharpGraphWidget extends SharpWidget
{
protected ?string $display = null;
protected array $ratio = [16, 9];
protected ?int $height = null;
protected bool $showLegend = true;
protected bool $minimal = false;
protected ?NumberFormatOptions $formatOptions = null;
public function setRatio(string $ratio): self
{
$this->ratio = explode(':', $ratio);
return $this;
}
public function setHeight(int $height): self
{
$this->height = $height;
return $this;
}
public function setShowLegend(bool $showLegend = true): self
{
$this->showLegend = $showLegend;
return $this;
}
public function setMinimal(bool $minimal = true): self
{
$this->minimal = $minimal;
return $this;
}
public function setTooltipValueFormat(NumberFormatOptions $formatOptions): self
{
$this->formatOptions = $formatOptions;
return $this;
}
public function toArray(): array
{
return parent::buildArray([
'display' => $this->display,
'ratioX' => $this->ratio ? (int) $this->ratio[0] : null,
'ratioY' => $this->ratio ? (int) $this->ratio[1] : null,
'height' => $this->height,
'minimal' => $this->minimal,
'showLegend' => $this->showLegend,
'formatOptions' => $this->formatOptions,
]);
}
protected function validationRules(): array
{
return [
'display' => [
'required',
'in:bar,line,pie,area',
],
];
}
}