mirror of
https://github.com/ConnectedHumber/Air-Quality-Web
synced 2024-12-22 10:25:01 +00:00
Bugfix: Don't crash if no data could be found for a specific reading type
This commit is contained in:
parent
902b17eed4
commit
659af6cf5d
2 changed files with 24 additions and 6 deletions
|
@ -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 {
|
|||
PM10, PM25,
|
||||
humidity,
|
||||
temperature,
|
||||
pressure
|
||||
pressure,
|
||||
unknown
|
||||
};
|
||||
|
|
|
@ -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…
Reference in a new issue