Commit 85a50d83 authored by Michał Woźniak's avatar Michał Woźniak

bugfix

parent 2198ea05
Pipeline #214 passed with stage
in 1 second
......@@ -1285,6 +1285,9 @@ let chart = () => {
theChart.newLegend = legend;
Chart.layoutService.addBox(theChart, legend);
theChart.update()
// prepare the new_datasets object
theChart.data.new_datasets = []
// set the update timeout thingy
theChart.updateTimeout = false
......@@ -1422,18 +1425,18 @@ let updateChartData = (siteSelect) => {
}
// assign the data to the chart
theChart.data.datasets[siteSelect.siteNo + 3] = to_chart
theChart.data.new_datasets[siteSelect.siteNo] = to_chart
// if we have some undefined elements in the chart's data array
// that means that not all data is in yet -- bail!
if (theChart.data.datasets.includes(undefined)) {
if (theChart.data.new_datasets.includes(undefined)) {
return;
}
// update the chart settings
clearTimeout(theChart.updateTimeout)
theChart.updateTimeout = setTimeout(updateChartSettings, 100)
}
// update the chart settings
clearTimeout(theChart.updateTimeout)
theChart.updateTimeout = setTimeout(updateChartSettings, 250)
}
......@@ -1442,6 +1445,10 @@ let updateChartData = (siteSelect) => {
* based on datasets we have
*/
let updateChartSettings = () => {
// make sure to cancel any other updates to the chart
clearTimeout(theChart.updateTimeout)
theChart.updateTimeout = false
// if *any* of the sitesSelects are still fetching data, bail out
for (let sselect of sitesSelects) {
......@@ -1488,7 +1495,7 @@ let updateChartSettings = () => {
// find the maximums and minimums
var max_data_points = 20;
theChart.data.datasets.slice(3).forEach((d)=>{
theChart.data.new_datasets.forEach((d)=>{
d_max = Math.max(...d.data)
d_min = Math.min(...d.data)
if (d_max > max_cases) {
......@@ -1587,7 +1594,7 @@ let updateChartSettings = () => {
// set the x-axis length
if (chart_start_setting === "date") {
theChart.data.labels = siteData['Global'].data.slice(-1 * theChart.data.datasets[3].data.length).map(d=>d.date)
theChart.data.labels = siteData['Global'].data.slice(-1 * theChart.data.new_datasets[0].data.length).map(d=>d.date)
} else {
theChart.data.labels = genArr(1, max_data_points, 1)
}
......@@ -1605,6 +1612,11 @@ let updateChartSettings = () => {
// while data for (n-1)th is still undefined
// in which case theChart.update() will fail
try {
// set the new datasets as datasets
theChart.data.new_datasets.forEach((el, idx)=>{
theChart.data.datasets[idx + 3] = theChart.data.new_datasets[idx]
})
// update the chart
theChart.update();
} catch (e) {}
}
......@@ -2072,8 +2084,8 @@ document.addEventListener('DOMContentLoaded', (e)=>{
removeSite.addEventListener('click', (ev)=>{
ev.preventDefault()
// update the chart
if (theChart.data.datasets[theChart.data.datasets.length - 1].label === sitesSelects[sitesSelects.length - 1].value) {
theChart.data.datasets.pop()
if ( (theChart.data.new_datasets.length > 0) && (theChart.data.new_datasets[theChart.data.new_datasets.length - 1].label === sitesSelects[sitesSelects.length - 1].value) ) {
theChart.data.new_datasets.pop()
}
// if we have more than one site available
if (sitesSelects.length > 1) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment