observablehq / plot

A concise API for exploratory data visualization implementing a layered grammar of graphics
https://observablehq.com/plot/
ISC License
4.28k stars 174 forks source link

Tips are chaotic on compound marks #1835

Open tophtucker opened 1 year ago

tophtucker commented 1 year ago

When you pass tip: true to boxX, I think it passes it on to each of its constituent marks, which results in chaos (demo):

https://github.com/observablehq/plot/assets/841829/87ff4529-6a31-4850-b099-82f837494209

I noticed this when playing with adding box to Plot.auto (https://github.com/observablehq/plot/pull/1423), which automatically sets tip: true. But what would I expect? It's a little hard to say. I guess I'd want one tip that lands on a point for each quartile, and maybe for the outliers. Maybe this just means compound marks should ideally sometimes intercept the tip option and implement their own tip instead of passing the option through to each of their marks.

Fil commented 1 year ago

compound marks should ideally sometimes intercept the tip option and implement their own

100%

yurivish commented 1 year ago

Another place where I've run into this chaotic-tips phenomenon in the context of nested data, e.g. when data looks like this:

data = [{name: "Series A", points: [{ x, y }, ...] }, { name: "Series B", points: [{ x, y }, ...] }, ...]

One way to plot this data as a multiple-line time series is to transform the data into a single array of {name, x, y} objects. Another approach, which can sometimes be more convenient (and also potentially more efficient, since it requires less data transformation), is to map the data array to an array of line marks, plotting each series as its own mark:

data.map(series => Plot.line(series.points, { x: 'x', y: 'y', z: () => series.name })

Buti including tips with this second approach causes the same sort of chaotic occlusion as in the screen recording since the individual line marks each have their own tip.

I wonder if Plot.marks could be used to pass a top-level tip option for cases like that, to do something similar to the solution for built-in composite tips.

mbostock commented 1 year ago

I wonder if Plot.marks could be used to pass a top-level tip option for cases like that, to do something similar to the solution for built-in composite tips.

I don’t think that would work well, since Plot.marks would just pick one of the composite marks arbitrarily for the tip, and I don’t think that’s what you want. The only way to do it would be to combine the series into a single line mark.

mbostock commented 1 year ago

Reclassifying this as an enhancement since it’s the documented behavior (“options are passed through to these underlying marks”) but still think we should change it to only pass the tip mark through to one (or none) of the marks, or maybe add a new invisible mark just for the tip.

Fil commented 1 year ago

The tip on the linearRegression mark is also a bit chaotic, since it points at invisible dots. The cause of chaos is slightly different than for the box mark. (I don't see why someone would activate it on that mark, though.)