table fill rewrite, no globalObject necessary
This commit is contained in:
+15
-10
@@ -1,5 +1,4 @@
|
|||||||
// All code in this file is licensed under the ISC license, provided in LICENSE.txt
|
// All code in this file is licensed under the ISC license, provided in LICENSE.txt
|
||||||
var globalObject;
|
|
||||||
$('#update').click(function () {
|
$('#update').click(function () {
|
||||||
updateData();
|
updateData();
|
||||||
});
|
});
|
||||||
@@ -9,12 +8,15 @@ function updateData () {
|
|||||||
const url = 'http://' + window.location.hostname + ':5000/data';
|
const url = 'http://' + window.location.hostname + ':5000/data';
|
||||||
$.ajax({ // spawn an AJAX request
|
$.ajax({ // spawn an AJAX request
|
||||||
url: url,
|
url: url,
|
||||||
success: function (data, status) { globalObject = data; console.log(data); graphSpectralData(globalObject[0], 0); },
|
success: function (data, status) {
|
||||||
|
console.log(data);
|
||||||
|
graphSpectralData(data[0], 0);
|
||||||
|
fillTableData(data);
|
||||||
|
},
|
||||||
timeout: 2500 // this should be a pretty sane timeout
|
timeout: 2500 // this should be a pretty sane timeout
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function graphSpectralData (obj, dom) {
|
function graphSpectralData (obj, dom) {
|
||||||
// graph spectral data in obj into dom
|
// graph spectral data in obj into dom
|
||||||
var graphPoints = [];
|
var graphPoints = [];
|
||||||
@@ -33,14 +35,17 @@ function graphSpectralData (obj, dom) {
|
|||||||
yaxis: {
|
yaxis: {
|
||||||
color: 'blue'
|
color: 'blue'
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
$.plot('#graph', [graphPoints], options);
|
$.plot('#graph', [graphPoints], options);
|
||||||
// flot expects an array of arrays (lines) of 2-element arrays (points)
|
// flot expects an array of arrays (lines) of 2-element arrays (points)
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillLuxUv (obj, dom) {
|
function fillTableData (obj) {
|
||||||
$(dom).find('#lx').text(obj[1]);
|
// fill the obj data into HTML tables
|
||||||
$(dom).find('#uva').text(obj[2][0]);
|
Object.keys(obj[0])
|
||||||
$(dom).find('#uvb').text(obj[2][1]);
|
.forEach((element) => { $('#' + element).text(obj[0][element]); });
|
||||||
$(dom).find('#uvi').text(obj[2][2]);
|
$('#lx').text(obj[1]);
|
||||||
|
$('#uva').text(obj[2][0]);
|
||||||
|
$('#uvb').text(obj[2][1]);
|
||||||
|
$('#uvi').text(obj[2][2]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user