leeoniya / uPlot

📈 A small, fast chart for time series, lines, areas, ohlc & bars
MIT License
8.51k stars 371 forks source link

Align two Y-axis scales #864

Open danielbachhuber opened 9 months ago

danielbachhuber commented 9 months ago

We'd love to have these two Y-axis scales match up:

CleanShot 2023-08-16 at 09 44 30@2x

e.g. the line for "30", or whatever the correct value is, runs directly across to "500"

Is this easily possible, or a huge lift?

Thanks in advance, and thanks for a great library!

leeoniya commented 9 months ago

it's a lift, but one i intend to do soon.

currently the scale range finding/snapping/padding is done in an axis-unaware matter, so does not take ticks into account. this causes other annoying issues like the data going above the top tick, or very crappy ticks at small plot heights :cry:

the aim in the near future is to guarantee ticks at top and bottom of the scale range and to have the number of ticks determined by plot height. this requires an inversion of flow and a scale-range<->pixels inter-dependency addition to the core logic, which requires re-evaluating all the invalidation conditions, etc. it has to be done, though :grimacing:. i have an ticks-axis-incrs branch that kinda attempts it and implements a ramping function i like, but i'm not happy with some of the other bits, which will need to change in more significant ways. doing this all in a backwards-compat manner adds extra trickiness.

you might be able to get something working by supplying your own scale.range and axis.splits functions in opts, which would give you full control over the scale ranging and tick gen for both axes.

danielbachhuber commented 9 months ago

Makes sense! Thanks for the detailed explanation 🙏