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

fixing charts for negative values

parent 5cf31ce1
Pipeline #156 passed with stage
in 1 second
......@@ -1208,12 +1208,17 @@ let updateChartSettings = () => {
// calculate the max value and the x-axis length that make sense
// with reasonable minimums
var max_cases = 100;
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
}
......@@ -1221,12 +1226,14 @@ let updateChartSettings = () => {
// set the max value
if (theChart.options.scales.yAxes[0].type == "logarithmic") {
theChart.options.scales.yAxes[0].ticks.max = max_cases * 2
var chart_type_factor = 2
} else {
theChart.options.scales.yAxes[0].ticks.max = Math.round(max_cases * 1.1)
var chart_type_factor = 1.1
}
theChart.options.scales.yAxes[0].ticks.max = max_cases * chart_type_factor
var chart_start = (1 * document.querySelector('input[type=radio][name=chart-start]:checked').value)
//chart_start = min_cases * chart_type_factor
var chart_dataset = document.querySelector('input[type=radio][name=chart-data]:checked').value
......@@ -1241,11 +1248,13 @@ let updateChartSettings = () => {
if (document.querySelector('input[type=radio][name=chart-values]:checked').value === 'absolute') {
theChart.options.scales.yAxes[0].ticks.min = chart_start
} else {
theChart.options.scales.yAxes[0].ticks.min = 1
theChart.options.scales.yAxes[0].ticks.min = 0
}
theChart.options.scales.yAxes[0].scaleLabel.labelString += ", cumulative"
// showing new confirmed cases / recoveries / deaths / active cases
// notice: *new active cases* can be *negative!*
} else {
theChart.options.scales.yAxes[0].ticks.min = 1
theChart.options.scales.yAxes[0].ticks.min = min_cases * chart_type_factor
theChart.options.scales.yAxes[0].scaleLabel.labelString += ", new"
}
......@@ -1270,9 +1279,9 @@ let updateChartSettings = () => {
}
// set the x-asix length
theChart.data.datasets[0].data = genArr(theChart.options.scales.yAxes[0].ticks.min, max_data_points, (i, arr)=>{ return arr[i-1]*2 })
theChart.data.datasets[1].data = genArr(theChart.options.scales.yAxes[0].ticks.min, max_data_points, (i, arr)=>{ return arr[i-1]*Math.pow(2, 1/2) }),
theChart.data.datasets[2].data = genArr(theChart.options.scales.yAxes[0].ticks.min, max_data_points, (i, arr)=>{ return arr[i-1]*Math.pow(2, 1/7) }),
theChart.data.datasets[0].data = genArr(chart_start, max_data_points, (i, arr)=>{ return arr[i-1]*2 })
theChart.data.datasets[1].data = genArr(chart_start, max_data_points, (i, arr)=>{ return arr[i-1]*Math.pow(2, 1/2) }),
theChart.data.datasets[2].data = genArr(chart_start, max_data_points, (i, arr)=>{ return arr[i-1]*Math.pow(2, 1/7) }),
theChart.data.labels = genArr(1, max_data_points, 1)
// ignoring the potential error
......
Supports Markdown
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