-
Notifications
You must be signed in to change notification settings - Fork 5
/
DashboardPanelChart.module
executable file
·82 lines (71 loc) · 2.06 KB
/
DashboardPanelChart.module
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
<?php namespace Daun\Dashboard;
use function ProcessWire\__;
// Include abstract panel base class
require_once dirname(__DIR__).'/Dashboard/DashboardPanel.class.php';
class DashboardPanelChart extends DashboardPanel
{
public static function getModuleInfo()
{
return array_merge(
parent::getModuleInfo(),
[
'title' => __('Dashboard Panel: Chart', __FILE__),
'summary' => __('Display a customizable chart from any data source', __FILE__),
'author' => 'Philipp Daun',
'version' => '1.5.7',
]
);
}
public function getIcon()
{
return 'pie-chart';
}
public function getContent()
{
return $this->view('panels/chart', [
'theme' => $this->theme,
'default' => $this->defaultTheme,
'chart' => $this->chart,
'padding' => $this->padding,
]);
}
public function setup()
{
parent::setup();
$this->theme = $this->data['theme'] ?? false;
$this->defaultTheme = $this->getDefaultTheme();
$this->chart = $this->parseChartData($this->data['chart'] ?? []);
$this->aspectRatio = $this->chart['options']['aspectRatio'] ?? 0;
$this->padding = $this->aspectRatioPadding($this->aspectRatio);
}
public function getScripts()
{
return ['https://cdn.jsdelivr.net/npm/chart.js@2.9.4'];
}
/**
* Manipulate the chart data if necessary.
*/
public function ___parseChartData($data)
{
return $data;
}
/**
* Get the name of the default color theme.
*/
public function ___getDefaultTheme()
{
return 'processwire';
}
/**
* Calculate bottom padding for aspect ratio placeholder.
*/
protected function aspectRatioPadding($ratio)
{
if ($ratio <= 0) {
return '';
}
$padding = 100 / $ratio;
$padding = number_format($padding, 2, '.', '');
return "padding-bottom: {$padding}%;";
}
}