Browse Source

Bugfix: Don't crash if no data could be found for a specific reading type

pull/51/head
Starbeamrainbowlabs 3 years ago
parent
commit
659af6cf5d
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
  1. 13
      client_src/js/Overlay/OverlaySpecs.mjs
  2. 17
      client_src/js/Overlay/VoronoiManager.mjs

13
client_src/js/Overlay/OverlaySpecs.mjs

@ -87,12 +87,20 @@ var pressure = { @@ -87,12 +87,20 @@ var pressure = {
"1100": "#BFED91"
}
};
var unknown = {
max: 100,
gradient: {
"0": "green",
"100": "red"
}
}
var specs = {
PM10, PM25,
humidity,
temperature,
pressure
pressure,
unknown
};
export default specs;
@ -100,5 +108,6 @@ export { @@ -100,5 +108,6 @@ export {
PM10, PM25,
humidity,
temperature,
pressure
pressure,
unknown
};

17
client_src/js/Overlay/VoronoiManager.mjs

@ -52,16 +52,25 @@ class VoronoiManager { @@ -52,16 +52,25 @@ class VoronoiManager {
this.last_datetime = datetime;
this.last_reading_type = reading_type;
this.spec = Specs[reading_type];
this.spec = Specs[reading_type] || Specs["unknown"];
if(typeof this.spec.chroma == "undefined")
this.spec.chroma = chroma.scale(Object.values(this.spec.gradient))
.domain(Object.keys(this.spec.gradient));
this.guage.set_spec(this.spec);
this.guage.render();
let dataset = JSON.parse(await GetFromUrl(
`${Config.api_root}?action=fetch-data&datetime=${encodeURIComponent(datetime.toISOString())}&reading_type=${encodeURIComponent(reading_type)}`
));
let dataset = null;
try {
dataset = JSON.parse(await GetFromUrl(
`${Config.api_root}?action=fetch-data&datetime=${encodeURIComponent(datetime.toISOString())}&reading_type=${encodeURIComponent(reading_type)}`
));
}
catch(error) { // string
document.querySelector("main").classList.remove("working-visual");
alert(error);
throw new Error(error);
}
let result = [];
for(let row of dataset) {

Loading…
Cancel
Save