Question and suggestion: get scale's data min/max and calculate average and sum of series data
Hi!
As I understand, currently I can get the whole scale's data min and max only in range function. After the options will be set, in uplot.series.min/max will appear visual min/max of scale but not a real min/max of data. Also I can get min and max of series after the options will be set.
For the last months of creating plugins for uPlot I faced (a lot of times) with necessity to access to data min/max per scale, also manually calculated average of series and so on. I suppose that it's a pretty common necessity for chart development.
So my question: am I right in my previous assumptions? Also I prepared an example in JSFiddle, and I've found that I can't modify series in init hook, to assign sum and avg so I need to precalc them outside of uPlot lifecycle somehow (look line 45). Why does it work in that way?
Suggestion:
- Store and expose real scale's data min/max in
scalesobject - Also calculate sum and average value of each series and per scale
Rationale:
- It could be useful for implementing plugins such as legend, tooltips, axes where there is a necessity to show average, sum and other values
- I think that it should be done in uPlot because of uPlot is already calculates series min and max and it would be very easy to add average and sum, and store scale's data average and sum
I suppose that it's a pretty common necessity for chart development.
might be, but uPlot only tries to do only what is necessary for the core; additional computation is pure overhead in all cases that do not need arithmetic mean (avg), median, geometric mean, and other summary stats.
scales are currently undergoing an internal refactor to address several open issues cause by how illogically auto and range interact. as part of this, i want to also make forward progress on improving vertical tick gen (https://github.com/leeoniya/uPlot/issues/620#issuecomment-970519182). the semantics will change a bit and will require a 2.0 bump, unfortunately. hopefully the end result is more logical. scales touch everything, so getting it all right is pretty tricky. i should have a working branch pushed in the next couple weeks. i can ping you to test it out if interested.