Islandora-Labs / islandora_usage_stats_charts

Module that provides charts showing usage statistics for Islandora objects.
GNU General Public License v3.0
1 stars 0 forks source link

Make step size adapt to large numbers #20

Closed mjordan closed 6 years ago

mjordan commented 6 years ago

We probably need to change the Y axis step size to adapt to values. Currently, this is happening:

charts

We already do this for very small numbers, e.g. https://github.com/mjordan/islandora_usage_stats_charts/blob/7.x/js/usageStatsChart.js#L34.

mjordan commented 6 years ago

Worse example (maximum month is 3100 views):

charts This effect is likely what @bondjimbond is seeing in #18.

bondjimbond commented 6 years ago

@mjordan yes, if you look at https://arcabc.ca/islandora/object/kora%3Apublications# (source of screenshot in #18), you'll see that the highest number of views is 1295, while smallest is 67. Adaptive scale is needed... Is it possible to set a maximum number of steps? Or if not, we can set a maximum number of steps and do some simple math to get the stepSizeValue... How is it set currently?

mjordan commented 6 years ago

It's set in the Javascript that integrates Chart.js into the Drupal module, at https://github.com/mjordan/islandora_usage_stats_charts/blob/7.x/js/usageStatsChart.js#L34. We need some algorithm that will allow very high usage numbers to render as meaningfully as very small numbers. I like the idea of a maximum number of steps, e.g. 20.

mjordan commented 6 years ago

@bondjimbond can you test the issue-20 branch? I've set the step size to be 1/10 of the total, so we always have at most 10 steps. Here's the same usage chart as above running issue-20:

cartoons_usage

Be sure to test objects/collections with a lot of usage, plus objects with very little usage to ensure that the step size adjustments work on both the low and high end. Also test with high numbers of downloads if possible.

The logic is now:

bondjimbond commented 6 years ago

Seems to work. Here are some screenshots: screen shot 2018-08-01 at 3 32 33 pm screen shot 2018-08-01 at 3 33 39 pm screen shot 2018-08-01 at 3 34 55 pm

bondjimbond commented 6 years ago

Note, though, the weird increments. Typically you'd want to see round number increments on charts -- 1, 2, 5, 10, 50, etc. 373 is a weird number to appear on the Y-axis.

Would it be possible to do a little math and round the increments appropriately?

mjordan commented 6 years ago

Thanks for confirming that we've hit the problem with the scrunched Y axis.

Currently the increments are the result of straight division by 10. If my math sense is correct, the maximum value will determine whether we should round up to the 10s, 100s, or 1000s (or with very large numbers, maybe the 10,000s?). Straight /10 may not look good but its simple..... can we live without the rounding?

mjordan commented 6 years ago

But am open to algorithms for rounding to match different maximum values.

bondjimbond commented 6 years ago

Apparently this is a pretty common problem, and somewhat complex. Easy for humans to do, harder for machines.

Possible helpful solution: http://austinclemens.com/blog/2016/01/09/an-algorithm-for-creating-a-graphs-axes/

mjordan commented 6 years ago

Good find but seems to verge on AI to me.... mind if I merge issue-20 and we open a new issue for this problem? That at least gets rid of the munged Y axis.

bondjimbond commented 6 years ago

Sounds good!

mjordan commented 6 years ago

Cool, thanks for testing, will merge in a bit. Feel free to open a new issue or let me know if you want me to.

mjordan commented 6 years ago

Closed with 6479c5a60f302eef58ee8b837d4fbe1048ef6c72.