aatishb / covidtrends

Tracking the growth of COVID-19 Cases worldwide
https://aatishb.com/covidtrends/
MIT License
301 stars 107 forks source link

When there has been 0 new cases in the week, the line goes to negative infinity (visually). #114

Open brendanmeyer opened 4 years ago

brendanmeyer commented 4 years ago

Hi

When there has been 0 new cases in the week for a state (or possibly country), the line goes to negative infinity (probably only to 0), but due to the scaling of the logarithmic graph it looks like - infinity. This has a side effect of not being able to read the data in the hover mode.

Are you able to change the New Cases scale so that it ignores all the fractional cases?

To see this, go to: Confirmed Cases Australia Logarithmic Scale

and zoom out so you can see 0.1 (Weekly Cases)

The State: Australian National Territory looks to have gone to negative infinity.

I assume this will get worse, once there are more Countries that have 0 Weekly Cases.

Regards Brendan

waldyrious commented 4 years ago

I came across this the other day as well. For example, in the Australia region, the Australian Capital Territory line dips below the graph between 2020-04-16 and 2020-04-18:

Screenshot 2020-04-21 at 10 42 43

aatishb commented 4 years ago

Hi @brendanmeyer, thanks for filing this issue. We also see a similar issue if you select China in the Region selector.

It looks like we are running into a basic limitation of the log scale, which is that log(0) is not defined. The log scale devotes just as much visual space to numbers between 0 and 1, as to numbers between 1 and infinity. So when the number of cases hits zero, on the log scale it appears to plummet to negative infinity.

The simplest workaround would be to disable zoom in the log scale. Or, as I'm hearing you suggest, we could override the zoom out behavior so that the x and y range minimum don't drop below 1.

This would hide the problem of curves plummeting to -infinity when cases go to zero, but we'd still have the issue of labels & curves disappearing when the number of cases goes below 1.

Thinking aloud, I wonder if we could use some kind of a fake log scale where the ticks go 1000, 100, 10, 1, 0 as opposed to 100, 100, 10, 1, 0.1, 0.01, ... But perhaps this might inadvertently introduce other issues?

aatishb commented 4 years ago

Screenshot of China zoomed out showing some related behavior we definitely want to avoid.

Covid Trends(5)

brendanmeyer commented 4 years ago

Also, just thinking aloud.

I do like the idea of the fake log scale, as that still allows visually the representation of 0 cases, and as time goes on, we are going to see more and more of 0 weekly cases.

I feel as long as the hover information still shows 0 rather than a number under 1, then it could be visually pleasing, and not have the dramatic drops.

I hope that you are able to code this.

Thank you for looking into this issue.

Regards Brendan

joachimneumann commented 4 years ago

I second to introduce a hack here. This is justified, because we are dealing with integers (number of new people infected in a week) and no valid value between 0 and 1 can ever occur.

From a user experience point of view, I can see these options: 1) Set the number of weekly cases to max(cases, 1). 2) Set the number of weekly cases to max(cases, 0.1). or similar 3) Cut off the Logarithmic scale at 0.5 and set it to 0. or similar

In all cases, the tooltip should show the number in Weekly Confirmed Cases as 0.

From a programmer's point of view, I think only options 1 and 2 are viable, because option 3 would require to dive deeply into the plotly library.

P.S.: I am currently in Vietnam and we hope to hit 0 tomorrow Edit 1: It actually happened today, Vietnam now has 0 new cases in the last week Edit 2: After this hack is implemented, Vietnam could be added to the notableCountries, that have observed success so far (line 410 in vue-definitions.js)

joachimneumann commented 4 years ago

Here is a first and unsuccessful attempt to fix this problem: log_problem_diff.txt

Good: the red dot and the gray line are never below 1 Good: The minimal y-axis value is 0.5 Bad: The tooltip shows wrong data Bad: This also manipulates the minimum when a linear y axis is selected. The hack should only be active when the logarithmic y axis is selected.

I hope this can direct someone else in the right direction and make a proper pull request.

brendanmeyer commented 4 years ago

I have done some modifications based on @joachimneumann diff file

Here is a first and unsuccessful attempt to fix this problem: log_problem_diff.txt

Good: The tooltip shows the correct data (ie. 0) Good: the red dot and the gray line are never below 0.5 Not so good: The minimal y-axis value is 0.5 Bad: The y-axis shows "5" below 1, which is 0.5

So far, I am unable to change the 0.5 label But I think this is a bit closer :)

aatishb commented 4 years ago

Hi @brendanmeyer, could you share a link to your changes? Thanks.

brendanmeyer commented 4 years ago

hey sorry, I thought I attached the file version from last post https://github.com/brendanmeyer/covidtrends/commit/aaf0970a2cd74e854d761eac20ec46de7b6a5abb#diff-b0dafeb3555d8d2502c8e4ab17b7580

brendanmeyer commented 4 years ago

I now have a version that shows 0 on the y-axis graph

2020-05-01 23_47_11-Covid Trends

Good: The tooltip shows the correct data (ie. 0) Good: 0 is shown on the y-axis Good: the red dot and the gray line are never below 0.5 Bad: if zoomed in or scrolled down past the 0, the fractional numbers are show - this could be fixed, but it is late here

https://github.com/brendanmeyer/covidtrends/commit/1d450daecd9d11e028e63b0500923d45cc78e052#diff-b0dafeb3555d8d2502c8e4ab17b7580e

I am happy to work on this further to remove the side effects if it was to be merged in?

brendanmeyer commented 4 years ago

I've added a fix to limit the graphs lower bound and left bound - this removed the lines going below "0". see the preview here https://htmlpreview.github.io/?https://raw.githubusercontent.com/brendanmeyer/covidtrends/master/index.html

this should be up to date with your master commit currently

joachimneumann commented 4 years ago

I think that this is a near-perfect solution and I support merging this into the master branch.

When I set the scale to linear, I can see that the data points are not 0 any more, but 0.5. However, I think that this is a minor issue that can be ignored.

rpkoller commented 4 years ago

I've tested the latest build on https://htmlpreview.github.io/?https://raw.githubusercontent.com/brendanmeyer/covidtrends/master/index.html

when you zoom in the curves go only until 0.5 on the y axis

Bildschirmfoto 2020-05-23 um 15 49 41

is that intended cuz you wrote: "Good: the red dot and the gray line are never below 0.5" zoomed out it looks good

Bildschirmfoto 2020-05-23 um 15 52 22

but that never below 0.5 pattern zoomed in looks odd if the visitor takes a look at the tooltip showing 0 alongside. :/