Commit 40eb84b5 authored by Michał Woźniak's avatar Michał Woźniak
Browse files

some bugfixes

parent 90d6f9b1
...@@ -689,6 +689,7 @@ let calculateDeltas = (data) => { ...@@ -689,6 +689,7 @@ let calculateDeltas = (data) => {
cur.active = 0; cur.active = 0;
cur.new_active = 0; cur.new_active = 0;
cur.cfr = 0 cur.cfr = 0
cur.new_cfr = 0
} else { } else {
cur.new_confirmed = cur.confirmed - d[i-1].confirmed cur.new_confirmed = cur.confirmed - d[i-1].confirmed
...@@ -705,6 +706,7 @@ let calculateDeltas = (data) => { ...@@ -705,6 +706,7 @@ let calculateDeltas = (data) => {
cur.new_cfr = cur.cfr - d[i-1].cfr cur.new_cfr = cur.cfr - d[i-1].cfr
} else { } else {
cur.cfr = 0 cur.cfr = 0
cur.new_cfr = 0
} }
} }
return cur; return cur;
...@@ -1445,58 +1447,55 @@ let updateChartSettings = () => { ...@@ -1445,58 +1447,55 @@ let updateChartSettings = () => {
// which dataset are we using? confirmed, recovered, deaths, active, cfr? // which dataset are we using? confirmed, recovered, deaths, active, cfr?
var chart_dataset = document.querySelector('input[type=radio][name=chart-data]:checked').value var chart_dataset = document.querySelector('input[type=radio][name=chart-data]:checked').value
// for cfr, this is easy: min=0, max=1, chart_type_factor=1 // for cfr, start with min=0, max=1
// also, no guidelines // also, no guidelines
if (chart_dataset === 'cfr') { if (chart_dataset === 'cfr') {
var max_cases = 1; var max_cases = 0.01;
var min_cases = 0; var min_cases = 0;
var max_data_points = 20; // make sure guidelines are hidden
theChart.data.datasets.slice(3).forEach((d)=>{
if (d.data.length > max_data_points) {
max_data_points = d.data.length
}
})
var chart_type_factor = 1
theChart.data.datasets[0].hidden = true theChart.data.datasets[0].hidden = true
theChart.data.datasets[1].hidden = true theChart.data.datasets[1].hidden = true
theChart.data.datasets[2].hidden = true theChart.data.datasets[2].hidden = true
// for everything else, a bit more involved // for everything else, a bit higher defaults
// also, guidelines // also, guidelines
} else { } else {
// calculate the max value and the x-axis length that make sense // calculate the max value and the x-axis length that make sense
// with reasonable minimums // with reasonable minimums
var max_cases = 100; var max_cases = 100;
var min_cases = 0; var min_cases = 0;
var max_data_points = 20;
theChart.data.datasets.slice(3).forEach((d)=>{
d_max = Math.max(...d.data)
d_min = Math.min(...d.data)
if (d_max > max_cases) {
max_cases = d_max
}
if (d_min < min_cases) {
min_cases = d_min
}
if (d.data.length > max_data_points) {
max_data_points = d.data.length
}
})
// set the chart factor:
// basically, we want a bit of headspace above the highest point on any graph
if (theChart.options.scales.yAxes[0].type == "logarithmic") {
var chart_type_factor = 2
} else {
var chart_type_factor = 1.1
}
// make sure guidelines are visible // make sure guidelines are visible
theChart.data.datasets[0].hidden = false theChart.data.datasets[0].hidden = false
theChart.data.datasets[1].hidden = false theChart.data.datasets[1].hidden = false
theChart.data.datasets[2].hidden = false theChart.data.datasets[2].hidden = false
} }
// find the maximums and minimums
var max_data_points = 20;
theChart.data.datasets.slice(3).forEach((d)=>{
d_max = Math.max(...d.data)
d_min = Math.min(...d.data)
if (d_max > max_cases) {
max_cases = d_max
}
if (d_min < min_cases) {
min_cases = d_min
}
if (d.data.length > max_data_points) {
max_data_points = d.data.length
}
})
// set the chart factor:
// basically, we want a bit of headspace above the highest point on any graph
if (theChart.options.scales.yAxes[0].type == "logarithmic") {
var chart_type_factor = 2
} else {
var chart_type_factor = 1.1
}
// set the max value // set the max value
theChart.options.scales.yAxes[0].ticks.max = Math.round(max_cases * chart_type_factor) theChart.options.scales.yAxes[0].ticks.max = Math.round((max_cases * chart_type_factor) * 1000) / 1000
var chart_start_setting = document.querySelector('input[type=radio][name=chart-start]:checked').value var chart_start_setting = document.querySelector('input[type=radio][name=chart-start]:checked').value
if (chart_start_setting === "date") { if (chart_start_setting === "date") {
...@@ -1521,7 +1520,7 @@ let updateChartSettings = () => { ...@@ -1521,7 +1520,7 @@ let updateChartSettings = () => {
// move the y-axis zero point depending on whether we're showing cumulative or new cases // move the y-axis zero point depending on whether we're showing cumulative or new cases
if (document.querySelector('input[type=radio][name=chart-cases]:checked').value === 'cumulative') { if (document.querySelector('input[type=radio][name=chart-cases]:checked').value === 'cumulative') {
if ( (chart_dataset !== "cfr" ) && (chart_dataset !== "active" ) && (document.querySelector('input[type=radio][name=chart-values]:checked').value === 'absolute') ) { if ( (chart_dataset !== "active" ) && (chart_dataset !== "cfr" ) && (document.querySelector('input[type=radio][name=chart-values]:checked').value === 'absolute') ) {
theChart.options.scales.yAxes[0].ticks.min = chart_start theChart.options.scales.yAxes[0].ticks.min = chart_start
} else { } else {
theChart.options.scales.yAxes[0].ticks.min = 0 theChart.options.scales.yAxes[0].ticks.min = 0
...@@ -1530,7 +1529,7 @@ let updateChartSettings = () => { ...@@ -1530,7 +1529,7 @@ let updateChartSettings = () => {
// showing new confirmed cases / recoveries / deaths / active cases // showing new confirmed cases / recoveries / deaths / active cases
// notice: *new active cases* can be *negative!* // notice: *new active cases* can be *negative!*
} else { } else {
theChart.options.scales.yAxes[0].ticks.min = Math.round(min_cases * chart_type_factor) theChart.options.scales.yAxes[0].ticks.min = Math.round((min_cases * chart_type_factor) * 1000) / 1000
theChart.options.scales.yAxes[0].scaleLabel.labelString += ", new" theChart.options.scales.yAxes[0].scaleLabel.labelString += ", new"
theChart.options.title.text[0] = `new ${theChart.options.title.text[0]}` theChart.options.title.text[0] = `new ${theChart.options.title.text[0]}`
} }
......
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