-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathchart-renderer.js
115 lines (104 loc) · 4.05 KB
/
chart-renderer.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
104
105
106
107
108
109
110
111
112
113
114
115
/* Icinga PDF Export | (c) 2024 Icinga GmbH | GPLv2 */
"use strict";
const FALLBACK_COLOR = 'green';
(() => {
Layout.registerPlugin('chart-renderer', () => {
document.querySelectorAll('.icinga-chart').forEach(element => {
console.log('ssss');
let attrs = element.dataset;
let chartData = JSON.parse(attrs.chartData);
let data = chartData.data;
let xAxisTicks = chartData.xAxisTicks;
let threshold = attrs.chartThreshold;
let lineColor = attrs.chartLineColor ?? FALLBACK_COLOR;
let belowThresholdColor = attrs.chartBelowThresholdColor ?? FALLBACK_COLOR;
let aboveThresholdColor = attrs.chartAboveThresholdColor ?? FALLBACK_COLOR;
let yAxisMax = Number(attrs.chartYAxisMax ?? 100);
let yAxisMin = Number(attrs.chartYAxisMin ?? 0);
var grid = {};
if ('chartShowThresholdLine' in attrs) {
grid = {
y: {
lines: [
{
value: threshold,
text: "threshold",
class: "threshold-mark",
},
]
},
};
}
console.log(attrs, grid);
let chartElement = document.createElement('div');
chartElement.classList.add('chart-element');
element.appendChild(chartElement);
bb.generate({
bindto: chartElement,
clipPath: false, // show line on 0 and 100
zoom: {
enabled: true,
type: "drag"
},
data: {
labels: {
rotate: 90,
format: (v, id, i, texts)=> {
return (v === yAxisMin || v === yAxisMax) ? '' : v;
},
},
type: attrs.chartType,
x: "xAxisTicks",
columns: [
["xAxisTicks"].concat(xAxisTicks),
[attrs.chartTooltipLabel].concat(data)
],
color: (color, datapoint) => {
if (! ("value" in datapoint)) {
return lineColor;
}
return datapoint.value <= threshold ? belowThresholdColor : aboveThresholdColor;
},
},
axis: {
y: {
max: yAxisMax,
min: yAxisMin,
padding: {
top: 0,
bottom: 0
},
label: {
text: attrs.chartYAxisLabel,
position: "outer-middle",
},
},
x: {
type: attrs.chartXAxisType,
label: {
text: attrs.chartXAxisLabel,
position: "outer-center",
},
tick: {
multiline: true,
rotate: 60,
culling: {
max: (xAxisTicks.length / 2) < 50 ? xAxisTicks.length : (xAxisTicks.length / 2)
},
//format:_this.getFormaterFunction(attrs, xAxisTicks),
},
clipPath: false,
padding: {
right: 30,
unit: "px"
}
}
},
legend: {
show: 'chartShowLegend' in attrs
},
grid : grid,
});
});
});
})();