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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
// ----------------------------------------------------------------------------------------------------------------
// sparkline
NETDATA.sparklineInitialize = function (callback) {
if (typeof netdataNoSparklines === 'undefined' || !netdataNoSparklines) {
$.ajax({
url: NETDATA.sparkline_js,
cache: true,
dataType: "script",
xhrFields: {withCredentials: true} // required for the cookie
})
.done(function () {
NETDATA.registerChartLibrary('sparkline', NETDATA.sparkline_js);
})
.fail(function () {
NETDATA.chartLibraries.sparkline.enabled = false;
NETDATA.error(100, NETDATA.sparkline_js);
})
.always(function () {
if (typeof callback === "function") {
return callback();
}
});
} else {
NETDATA.chartLibraries.sparkline.enabled = false;
if (typeof callback === "function") {
return callback();
}
}
};
NETDATA.sparklineChartUpdate = function (state, data) {
state.sparkline_options.width = state.chartWidth();
state.sparkline_options.height = state.chartHeight();
$(state.element_chart).sparkline(data.result, state.sparkline_options);
return true;
};
NETDATA.sparklineChartCreate = function (state, data) {
let type = NETDATA.dataAttribute(state.element, 'sparkline-type', 'line');
let lineColor = NETDATA.dataAttribute(state.element, 'sparkline-linecolor', state.chartCustomColors()[0]);
let fillColor = NETDATA.dataAttribute(state.element, 'sparkline-fillcolor', ((state.chart.chart_type === 'line') ? NETDATA.themes.current.background : NETDATA.colorLuminance(lineColor, NETDATA.chartDefaults.fill_luminance)));
let chartRangeMin = NETDATA.dataAttribute(state.element, 'sparkline-chartrangemin', undefined);
let chartRangeMax = NETDATA.dataAttribute(state.element, 'sparkline-chartrangemax', undefined);
let composite = NETDATA.dataAttribute(state.element, 'sparkline-composite', undefined);
let enableTagOptions = NETDATA.dataAttribute(state.element, 'sparkline-enabletagoptions', undefined);
let tagOptionPrefix = NETDATA.dataAttribute(state.element, 'sparkline-tagoptionprefix', undefined);
let tagValuesAttribute = NETDATA.dataAttribute(state.element, 'sparkline-tagvaluesattribute', undefined);
let disableHiddenCheck = NETDATA.dataAttribute(state.element, 'sparkline-disablehiddencheck', undefined);
let defaultPixelsPerValue = NETDATA.dataAttribute(state.element, 'sparkline-defaultpixelspervalue', undefined);
let spotColor = NETDATA.dataAttribute(state.element, 'sparkline-spotcolor', undefined);
let minSpotColor = NETDATA.dataAttribute(state.element, 'sparkline-minspotcolor', undefined);
let maxSpotColor = NETDATA.dataAttribute(state.element, 'sparkline-maxspotcolor', undefined);
let spotRadius = NETDATA.dataAttribute(state.element, 'sparkline-spotradius', undefined);
let valueSpots = NETDATA.dataAttribute(state.element, 'sparkline-valuespots', undefined);
let highlightSpotColor = NETDATA.dataAttribute(state.element, 'sparkline-highlightspotcolor', undefined);
let highlightLineColor = NETDATA.dataAttribute(state.element, 'sparkline-highlightlinecolor', undefined);
let lineWidth = NETDATA.dataAttribute(state.element, 'sparkline-linewidth', undefined);
let normalRangeMin = NETDATA.dataAttribute(state.element, 'sparkline-normalrangemin', undefined);
let normalRangeMax = NETDATA.dataAttribute(state.element, 'sparkline-normalrangemax', undefined);
let drawNormalOnTop = NETDATA.dataAttribute(state.element, 'sparkline-drawnormalontop', undefined);
let xvalues = NETDATA.dataAttribute(state.element, 'sparkline-xvalues', undefined);
let chartRangeClip = NETDATA.dataAttribute(state.element, 'sparkline-chartrangeclip', undefined);
let chartRangeMinX = NETDATA.dataAttribute(state.element, 'sparkline-chartrangeminx', undefined);
let chartRangeMaxX = NETDATA.dataAttribute(state.element, 'sparkline-chartrangemaxx', undefined);
let disableInteraction = NETDATA.dataAttributeBoolean(state.element, 'sparkline-disableinteraction', false);
let disableTooltips = NETDATA.dataAttributeBoolean(state.element, 'sparkline-disabletooltips', false);
let disableHighlight = NETDATA.dataAttributeBoolean(state.element, 'sparkline-disablehighlight', false);
let highlightLighten = NETDATA.dataAttribute(state.element, 'sparkline-highlightlighten', 1.4);
let highlightColor = NETDATA.dataAttribute(state.element, 'sparkline-highlightcolor', undefined);
let tooltipContainer = NETDATA.dataAttribute(state.element, 'sparkline-tooltipcontainer', undefined);
let tooltipClassname = NETDATA.dataAttribute(state.element, 'sparkline-tooltipclassname', undefined);
let tooltipFormat = NETDATA.dataAttribute(state.element, 'sparkline-tooltipformat', undefined);
let tooltipPrefix = NETDATA.dataAttribute(state.element, 'sparkline-tooltipprefix', undefined);
let tooltipSuffix = NETDATA.dataAttribute(state.element, 'sparkline-tooltipsuffix', ' ' + state.units_current);
let tooltipSkipNull = NETDATA.dataAttributeBoolean(state.element, 'sparkline-tooltipskipnull', true);
let tooltipValueLookups = NETDATA.dataAttribute(state.element, 'sparkline-tooltipvaluelookups', undefined);
let tooltipFormatFieldlist = NETDATA.dataAttribute(state.element, 'sparkline-tooltipformatfieldlist', undefined);
let tooltipFormatFieldlistKey = NETDATA.dataAttribute(state.element, 'sparkline-tooltipformatfieldlistkey', undefined);
let numberFormatter = NETDATA.dataAttribute(state.element, 'sparkline-numberformatter', function (n) {
return n.toFixed(2);
});
let numberDigitGroupSep = NETDATA.dataAttribute(state.element, 'sparkline-numberdigitgroupsep', undefined);
let numberDecimalMark = NETDATA.dataAttribute(state.element, 'sparkline-numberdecimalmark', undefined);
let numberDigitGroupCount = NETDATA.dataAttribute(state.element, 'sparkline-numberdigitgroupcount', undefined);
let animatedZooms = NETDATA.dataAttributeBoolean(state.element, 'sparkline-animatedzooms', false);
if (spotColor === 'disable') {
spotColor = '';
}
if (minSpotColor === 'disable') {
minSpotColor = '';
}
if (maxSpotColor === 'disable') {
maxSpotColor = '';
}
// state.log('sparkline type ' + type + ', lineColor: ' + lineColor + ', fillColor: ' + fillColor);
state.sparkline_options = {
type: type,
lineColor: lineColor,
fillColor: fillColor,
chartRangeMin: chartRangeMin,
chartRangeMax: chartRangeMax,
composite: composite,
enableTagOptions: enableTagOptions,
tagOptionPrefix: tagOptionPrefix,
tagValuesAttribute: tagValuesAttribute,
disableHiddenCheck: disableHiddenCheck,
defaultPixelsPerValue: defaultPixelsPerValue,
spotColor: spotColor,
minSpotColor: minSpotColor,
maxSpotColor: maxSpotColor,
spotRadius: spotRadius,
valueSpots: valueSpots,
highlightSpotColor: highlightSpotColor,
highlightLineColor: highlightLineColor,
lineWidth: lineWidth,
normalRangeMin: normalRangeMin,
normalRangeMax: normalRangeMax,
drawNormalOnTop: drawNormalOnTop,
xvalues: xvalues,
chartRangeClip: chartRangeClip,
chartRangeMinX: chartRangeMinX,
chartRangeMaxX: chartRangeMaxX,
disableInteraction: disableInteraction,
disableTooltips: disableTooltips,
disableHighlight: disableHighlight,
highlightLighten: highlightLighten,
highlightColor: highlightColor,
tooltipContainer: tooltipContainer,
tooltipClassname: tooltipClassname,
tooltipChartTitle: state.title,
tooltipFormat: tooltipFormat,
tooltipPrefix: tooltipPrefix,
tooltipSuffix: tooltipSuffix,
tooltipSkipNull: tooltipSkipNull,
tooltipValueLookups: tooltipValueLookups,
tooltipFormatFieldlist: tooltipFormatFieldlist,
tooltipFormatFieldlistKey: tooltipFormatFieldlistKey,
numberFormatter: numberFormatter,
numberDigitGroupSep: numberDigitGroupSep,
numberDecimalMark: numberDecimalMark,
numberDigitGroupCount: numberDigitGroupCount,
animatedZooms: animatedZooms,
width: state.chartWidth(),
height: state.chartHeight()
};
$(state.element_chart).sparkline(data.result, state.sparkline_options);
return true;
};
|