-
Notifications
You must be signed in to change notification settings - Fork 15
/
chartjsUrweb.js
103 lines (83 loc) · 2.27 KB
/
chartjsUrweb.js
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
function list_in(l) {
var out = [];
for (; l; l = l._2)
out.push(l._1);
return out;
}
function dataset_in(l) {
var out = [];
for (; l; l = l._2)
out.push({label: l._1._Label, data: list_in(l._1._Values)});
return out;
}
function list_xy_in(l) {
var out = [];
for (; l; l = l._2)
out.push({x: l._1._x, y: l._1._y});
return out;
}
function scatter_dataset_in(l) {
var out = [];
for (; l; l = l._2)
out.push({label: l._1._Label, data: list_xy_in(l._1._Values)});
return out;
}
function list_xyr_in(l) {
var out = [];
for (; l; l = l._2)
out.push({x: l._1._x, y: l._1._y, r: l._1._r});
return out;
}
function bubble_dataset_in(l) {
var out = [];
for (; l; l = l._2)
out.push({label: l._1._Label, data: list_xyr_in(l._1._Values)});
return out;
}
function uw_set_chartjs(id, gr) {
var parentDiv = document.getElementById(id);
var canvas = document.createElement('canvas');
parentDiv.appendChild(canvas);
switch (gr.n) {
case 'Pie':
case 'Doughnut':
case 'PolarArea':
case 'Radar':
parentDiv.style["aspect-ratio"] = "1 / 1";
break;
default:
parentDiv.style["aspect-ratio"] = "2 / 1";
}
switch (gr.n) {
case 'Bar':
case 'StackedBar':
case 'Line':
case 'Pie':
case 'Doughnut':
case 'PolarArea':
case 'Radar':
var gtype = (gr.n == 'StackedBar') ? 'bar' : gr.n.toLowerCase();
var options = (gr.n == 'StackedBar') ? {scales: {x: {stacked: true }, y: { stacked: true } } } : {};
var labels = list_in(gr.v._1);
var datasets = dataset_in(gr.v._2);
return new Chart(canvas,
{type: gtype,
options: options,
data: {
labels: labels,
datasets: datasets}});
case 'Scatter':
return new Chart(canvas,
{type: 'scatter',
data: {datasets: scatter_dataset_in(gr.v)}});
case 'Bubble':
return new Chart(canvas,
{type: 'scatter',
data: {datasets: bubble_dataset_in(gr.v)}});
default:
throw 'Unknown chart type';
}
}
function uw_update_chartjs(ch) {
ch.update();
}