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

yet more improvements in the graph

parent f7da3600
Pipeline #106 passed with stage
in 0 seconds
......@@ -334,6 +334,7 @@ let niceChartColors = [
* updating le charte
*/
let updateChart = (site, data, siteno) => {
// add the data to the chart
var to_chart = {
label: site,
......@@ -343,14 +344,34 @@ let updateChart = (site, data, siteno) => {
borderWidth: 1
}
theChart.data.datasets[siteno + 3] = to_chart
// calculate the max value that makes sense
var max_cases = 0;
theChart.data.datasets.slice(2).map((d)=>{
// calculate the max value and the x-axis length that make sense
// with reasonable minimums
var max_cases = 100;
var max_data_points = 20;
theChart.data.datasets.slice(3).map((d)=>{
if (d.data[d.data.length-1] > max_cases) {
max_cases = d.data[d.data.length-1]
}
if (d.data.length > max_data_points) {
max_data_points = d.data.length
console.log('max-data-points:', max_data_points)
}
})
theChart.options.scales.yAxes[0].ticks.max = max_cases * 2
// set the max value
if (theChart.options.scales.yAxes[0].type == "logarithmic") {
theChart.options.scales.yAxes[0].ticks.max = max_cases * 2
} else {
theChart.options.scales.yAxes[0].ticks.max = max_cases * 1.1
}
// set the x-asix length
theChart.data.datasets[0].data = genArr(max_data_points, (i, arr)=>{ return arr[i-1]*2 })
theChart.data.datasets[1].data = genArr(max_data_points, (i, arr)=>{ return arr[i-1]*Math.pow(2, 1/2) }),
theChart.data.datasets[2].data = genArr(max_data_points, (i, arr)=>{ return arr[i-1]*Math.pow(2, 1/7) }),
theChart.data.labels = genArr(max_data_points, 1)
// ignoring the potential error
// because we might have filled out data for an nth site
// while data for (n-1)th is still undefined
......
<html>
<head>
<meta charset="utf-8"/>
<title>Scary COVID-19 Data</title>
<script src="./wtf_wikipedia-client.min.js"></script>
<script src="./Chart.bundle.min.js"></script>
<script src="./covid.js"></script>
......@@ -205,6 +206,8 @@
</div>
<div id="the-chart-container">
<canvas id="the-chart"></canvas>
<!--input type="radio" id="chart-tipe-logarithmic" name="chart-type"/>
<input type="radio" id="chart-tipe-linear" name="chart-type"/-->
</div>
<p><strong>Disclaimer:</strong> this is all back-of-the-napkin math using data from Wikipedia. Take with a grain (or preferably, a spoonfull) of salt. Check your own sources; some great resources: <a href="http://covid.hi.is/">University of Iceland's COVID data model</a> (and its <a href="https://github.com/bgautijonsson/covid19/">sources</a>).</p>
<footer>
......
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