-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.js
118 lines (102 loc) · 3.7 KB
/
index.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
116
117
118
(function () {
var jqPlotWidget = function (settings) {
var self = this;
var currentSettings = settings;
var htmlElement;
var data;
var options;
var chartHeight = currentSettings.chartHeight;
var chartWidth = currentSettings.chartWidth;
//seems to be called once (or after settings change)
this.render = function (element) {
console.log('render');
//add external css
$(element).append('<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jqPlot/1.0.9/jquery.jqplot.min.css" />');
//add the chart div to the dom
var chartDiv = '<div id="' + currentSettings.id + '" style="height:' + currentSettings.chartHeight + 'px;width:' + currentSettings.chartWidth + 'px;"></div>';
console.log(chartDiv);
htmlElement = $(chartDiv);
$(element).append(htmlElement);
}
this.onSettingsChanged = function (newSettings) {
currentSettings = newSettings;
}
//seems to be called after render whenever a calculated value changes
this.onCalculatedValueChanged = function (settingName, newValue) {
console.log('onCalculatedValueChanged for ' + settingName);
console.log(newValue);
if (settingName == 'data')
data = newValue;
if (settingName == 'options')
options = newValue;
chartHeight = currentSettings.chartHeight;
chartWidth = currentSettings.chartWidth;
//render the chart
htmlElement.empty();
$.jqplot(currentSettings.id, data, options);
}
this.onDispose = function () {
}
this.getHeight = function () {
return Number(currentSettings.height);
}
this.onSettingsChanged(settings);
};
freeboard.loadWidgetPlugin({
"type_name": "jqPlotWidget",
"display_name": "jqPlot",
"fill_size": true,
"external_scripts": [
"//cdnjs.cloudflare.com/ajax/libs/jqPlot/1.0.9/jquery.jqplot.min.js",
"//cdnjs.cloudflare.com/ajax/libs/jqPlot/1.0.9/plugins/jqplot.pieRenderer.min.js",
"//cdnjs.cloudflare.com/ajax/libs/jqPlot/1.0.9/plugins/jqplot.donutRenderer.min.js",
"//cdnjs.cloudflare.com/ajax/libs/jqPlot/1.0.9/plugins/jqplot.barRenderer.min.js",
"//cdnjs.cloudflare.com/ajax/libs/jqPlot/1.0.9/plugins/jqplot.categoryAxisRenderer.min.js",
"//cdnjs.cloudflare.com/ajax/libs/jqPlot/1.0.9/plugins/jqplot.pointLabels.min.js"
],
"settings": [
{
"name": "id",
"display_name": "id",
"default_value": "chart1",
"description": "dom element id of the chart (must be unique for multiple charts)"
},
{
"name": "data",
"display_name": "Chart Data",
"type": "calculated",
"description": "The data to plot"
},
{
"name": "options",
"display_name": "Chart Options",
"type": "calculated",
"description": "js object containing jqPlot options for chart"
},
{
"name": "chartHeight",
"display_name": "Chart Height (px)",
"type": "number",
"default_value": 300,
"description": "chart height in pixels (require freeboard config reload/refresh)"
},
{
"name": "chartWidth",
"display_name": "Chart Width (px)",
"type": "number",
"default_value": 300,
"description": "chart width in pixels (require freeboard config reload/refresh)"
},
{
"name": "height",
"display_name": "Height Blocks",
"type": "number",
"default_value": 5,
"description": "A height block is around 60 pixels"
}
],
newInstance: function (settings, newInstanceCallback) {
newInstanceCallback(new jqPlotWidget(settings));
}
});
}());