forked from Freeboard/freeboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaltGuage.js
109 lines (94 loc) · 3.32 KB
/
altGuage.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
window.dyngaugeID = 0;
(function() {
var dynamicGaugeWidget = function (settings) {
var self = this;
thisDynGaugeID = "dyngauge-" + window.dyngaugeID++;
var titleElement = $('<h2 class="section-title"></h2>');
var gaugeElement = $('<div id="' + thisDynGaugeID + '"></div>');
var gaugeObject;
var rendered = false;
var currentSettings = settings;
function createGauge() {
if (!rendered) {
return;
}
gaugeElement.empty();
gaugeObject = new JustGage({
id: thisDynGaugeID,
value: (_.isUndefined(currentSettings.min_value) ? 0 : currentSettings.min_value),
min: (_.isUndefined(currentSettings.min_value) ? 0 : currentSettings.min_value),
max: (_.isUndefined(currentSettings.max_value) ? 0 : currentSettings.max_value),
label: currentSettings.units,
showInnerShadow: false,
valueFontColor: "#d3d4d4",
levelColors: ['#ff0000', '#ffa500','#ffa500','#ffff00', '#00ff00']
});
}
this.render = function (element) {
rendered = true;
$(element).append(titleElement).append($('<div class="gauge-widget-wrapper"></div>').append(gaugeElement));
createGauge();
}
this.onSettingsChanged = function (newSettings) {
if (newSettings.min_value != currentSettings.min_value || newSettings.max_value != currentSettings.max_value || newSettings.units != currentSettings.units) {
currentSettings = newSettings;
createGauge();
}
else {
currentSettings = newSettings;
}
titleElement.html(newSettings.title);
}
this.onCalculatedValueChanged = function (settingName, newValue) {
if (!_.isUndefined(gaugeObject)) {
gaugeObject.refresh(Number(newValue));
}
}
this.onDispose = function () {
}
this.getHeight = function () {
return 3;
}
this.onSettingsChanged(settings);
};
freeboard.loadWidgetPlugin({
type_name: "dyngauge",
display_name: "DynamicGauge",
"external_scripts" : [
"plugins/thirdparty/raphael.2.1.0.min.js",
"plugins/thirdparty/justgage.1.0.1.js"
],
settings: [
{
name: "title",
display_name: "Title",
type: "text"
},
{
name: "value",
display_name: "Value",
type: "calculated"
},
{
name: "units",
display_name: "Units",
type: "text"
},
{
name: "min_value",
display_name: "Minimum",
type: "text",
default_value: 0
},
{
name: "max_value",
display_name: "Maximum",
type: "text",
default_value: 100
}
],
newInstance: function (settings, newInstanceCallback) {
newInstanceCallback(new dynamicGaugeWidget(settings));
}
});
}());