2 archive_base="/meteo/archive";
4 var params = window.location.pathname.split('/').slice(-4);
5 var sensor_id = params[1];
6 var sensor = params[2];
9 var sensor_path = sensor_id + "." + sensor + "." + param;
13 function processDataset(dataset,sensorid,sensorname,paramname) {
14 var scale = properties["scale"][sensorid+"."+sensorname+"."+paramname]
17 for (idx in dataset) {
19 newRec.t = dataset[idx].t
20 newRec.y = dataset[idx].y * scale[0];
29 function drawGraph(graphData) {
31 document.getElementById("archive").href = archive_base+"////"+sensor_id + "/" + sensor + "/" + param;
33 var div = document.getElementById("chartdiv");
34 var canvas = document.getElementById("chart");
36 canvas.width = div.style.width;
37 canvas.height = div.style.height;
39 var ctx = canvas.getContext('2d');
40 var color = Chart.helpers.color;
57 responsiveAnimationDuration: 0,
60 fontColor: properties["fonts"]["legend"]["color"],
61 fontSize: properties["fonts"]["legend"]["size"],
62 fontStyle: properties["fonts"]["legend"]["style"],
68 distribution: 'series',
70 fontColor: properties["fonts"]["axes"]["color"],
71 fontSize: properties["fonts"]["axes"]["size"],
72 fontStyle: properties["fonts"]["axes"]["style"],
78 fontColor: properties["fonts"]["axes"]["color"],
79 fontSize: properties["fonts"]["axes"]["size"],
80 fontStyle: properties["fonts"]["axes"]["style"],
87 for (paramname in graphData) {
89 cfg.data.datasets.push(
91 label: properties["names"][sensor_id+"."+sensor+"."+paramname],
92 data: processDataset(graphData[paramname],sensor_id,sensor,paramname),
93 borderColor: properties["colors"][sensor_id+"."+sensor+"."+paramname],
105 var y_label = properties["names"][sensor_path];
106 if (properties["units"][sensor_path]) {
107 y_label = y_label + ", " + properties["units"][sensor_path];
115 label: properties["names"][sensor_path],
116 backgroundColor: color(properties["colors"][sensor_path]).alpha(0.5).rgbString(),
117 borderColor: properties["colors"][sensor_path],
118 data: processDataset(graphData,sensor_id,sensor,param),
131 animationDuration: 0,
133 responsiveAnimationDuration: 0,
136 fontColor: properties["fonts"]["legend"]["color"],
137 fontSize: properties["fonts"]["legend"]["size"],
138 fontStyle: properties["fonts"]["legend"]["style"],
144 distribution: 'series',
146 fontColor: properties["fonts"]["axes"]["color"],
147 fontSize: properties["fonts"]["axes"]["size"],
148 fontStyle: properties["fonts"]["axes"]["style"],
154 labelString: y_label,
155 fontColor: properties["fonts"]["axes"]["color"],
156 fontSize: properties["fonts"]["axes"]["size"],
157 fontStyle: properties["fonts"]["axes"]["style"],
165 var chart = new Chart(ctx, cfg);
168 function RefreshGraph() {
170 var req = new XMLHttpRequest();
172 req.onreadystatechange = function () {
173 if (this.readyState != 4) return;
174 if (this.status != 200) {
175 setTimeout(RefreshGraph,30000);
178 var graphData = JSON.parse(this.responseText);
179 drawGraph(graphData);
180 setTimeout(RefreshGraph,30000)
183 req.open("GET", urlbase+"get/"+sensor_id+"/"+sensor+"/"+param, true);
188 function GetProperties() {
189 var req = new XMLHttpRequest();
191 req.onreadystatechange = function () {
192 if (this.readyState != 4) return;
193 if (this.status != 200) {
194 setTimeout(GetProperties,30000);
197 properties = JSON.parse(this.responseText);
198 setTimeout(RefreshGraph,100)
201 req.open("GET", urlbase+"props", true);
206 setTimeout(GetProperties,100)