leeoniya / uPlot

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

What is needed to rotate box plots? #783

Open smarr opened 1 year ago

smarr commented 1 year ago

Based on

I assumed that I could possibly try to flip the x and y axis for box plots (https://leeoniya.github.io/uPlot/demos/box-whisker.html). Though, a quick hack doesn't seem to do the trick.

Looking a bit more at the code of the demo, it seems like I would also need to flip the logic in the drawing routines.

Though, the interactive bits of the plots seem all very "column"-oriented. Should I be aware of any implicit assumptions that box plots are "columns"? Or should rotating/flipping axis "just work"?

At the end, I'd like reach a point where I have box plots like this:

I'd like to flip the axis mostly to make long performance reports more compact horizontally, to get loads of benchmarks on a relatively compact page. Full example: https://rebench.stefan-marr.de/TruffleSOM/compare/b953d3244f41878a1730350618a22afd595d5ba2..65141f9d66669a21cce28a5141f01b07b0f8a93f (this is currently generated with R+ggplot)

The other bit that I'd still need to figure out is how to draw the data points on top of the box, which is quite useful to me. But that's for another time.

Thanks!

smarr commented 1 year ago

After some fiddling, I got almost where I want to be:

Screen Shot of box plot with flipped axis

I did:

To me it looks now like it's mostly correct. Except for the axis size of the x axis, which isn't correctly taken into account.

smarr commented 1 year ago

Hm, I think I fixed it for me. I set the y scale to { ori: 0, dir: 0 } which seems to give the desired result.

leeoniya commented 1 year ago

nice, glad you got it working.

flipped the x and y coordinates in the drawing code

you should be able to avoid this by wrapping the drawing code in uPlot.orient(). i should probably add this to the demo. the demo code was derived from candlesticks which are always vertical, so i never bothered :)

e.g.:

https://github.com/leeoniya/uPlot/blob/9fc7bb4881c43eef11677661ad92b4320d7f8a13/demos/latency-heatmap.html#L440