plot icon indicating copy to clipboard operation
plot copied to clipboard

Labeling algorithms (e.g., occlusion)?

Open mbostock opened this issue 5 years ago • 12 comments

In some line plots, if the cardinality of z is relatively low, it would be nice to label the lines say at the start or end. Similarly for dot plots, it would be lovely to have an automatic labeling strategy. Related vega-label.

mbostock avatar Nov 03 '20 15:11 mbostock

Related #139 for a transform that is useful for labeling lines.

mbostock avatar Feb 24 '21 21:02 mbostock

we have a nice solution for stacked series and bars thanks to stackXMid

Fil avatar Mar 05 '21 14:03 Fil

I really want an automatic algorithm for labeling scatterplots. And possibly stacked areas and other things. Something that considers only occlusion, like @fil/occlusion, would be a great place to start.

mbostock avatar Mar 18 '21 02:03 mbostock

I also like the "halo" (white stroke clone) strategy from https://observablehq.com/@mbostock/inequality-in-american-cities and think it should be available from Plot.text (and maybe occlusion as well!).

Other refs:

  • clipping the text to another mark https://github.com/observablehq/plot/issues/181
  • dodge, as in https://observablehq.com/@d3/slope-chart

Fil avatar Sep 27 '21 22:09 Fil

Here's a prototype for a labelling strategy based on @fil/occlusion https://observablehq.com/@observablehq/plot-occlusion-27

On this scatterplot, the occludeText function is able to avoid putting text on top of symbols. It's still not capable of finding a correct position to put the texts. It also needs to wait for the chart to be appended to the DOM before it can kick in, as it needs to measure the actual bounding boxes.

Fil avatar Mar 29 '22 09:03 Fil

Can we avoid getBoundingClientRect by using the same metrics approach that Plot.text uses?

mbostock avatar Mar 29 '22 17:03 mbostock

Yes it's one of the todos. Some challenges (probably not too hard):

  • we'll have to compute intersections not only for text but for symbols, rects, lines, paths… (this might also be useful for interactions);
  • this is yet another case where it will be useful to know in which facet we are, because the same position in two facets is not creating an occlusion.

Fil avatar Mar 29 '22 19:03 Fil

Voronoi centroid initializer https://observablehq.com/@fil/plot-voronoi-labels

Fil avatar Dec 08 '22 15:12 Fil

A typical request is to limit occlusion of end-of-line labels, like in https://observablehq.com/@d3/cancer-survival-rates (unfinished Plot version: https://observablehq.com/@observablehq/plot-cancer-survival-rates). The dodgeY transform doesn't address this concern since by construction it disregards an initial y channel.

I wonder if it would be fair for the dodgeY transform to switch to a different algorithm if y is already there?

Fil avatar Mar 23 '23 09:03 Fil

See also mapbox’s text-variable-anchor property https://docs.mapbox.com/mapbox-gl-js/example/variable-label-placement/

Fil avatar Apr 04 '23 06:04 Fil

Another example, in which the temptation was to use dodgeY (but that's not how it works) to avoid label occlusion https://observablehq.com/d/1eb96ffa035f4676

Fil avatar Jun 29 '23 05:06 Fil