Skip to content

Labeling algorithms (e.g., occlusion)? #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mbostock opened this issue Nov 3, 2020 · 12 comments
Open

Labeling algorithms (e.g., occlusion)? #27

mbostock opened this issue Nov 3, 2020 · 12 comments
Labels
enhancement New feature or request

Comments

@mbostock
Copy link
Member

mbostock commented Nov 3, 2020

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 mbostock added the enhancement New feature or request label Nov 3, 2020
@mbostock mbostock changed the title Automatic labeling? Labeling algorithms (e.g., occlusion)? Feb 24, 2021
@mbostock
Copy link
Member Author

mbostock commented Feb 24, 2021

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

@Fil
Copy link
Contributor

Fil commented Mar 5, 2021

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

@mbostock
Copy link
Member Author

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.

@Fil
Copy link
Contributor

Fil commented Sep 27, 2021

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:

@Fil
Copy link
Contributor

Fil commented Mar 29, 2022

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.

@mbostock
Copy link
Member Author

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

@Fil
Copy link
Contributor

Fil commented Mar 29, 2022

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
Copy link
Contributor

Fil commented Dec 8, 2022

@Fil
Copy link
Contributor

Fil commented Mar 23, 2023

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
Copy link
Contributor

Fil commented Apr 4, 2023

@Fil
Copy link
Contributor

Fil commented Jun 29, 2023

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

@huw
Copy link

huw commented Oct 7, 2024

Here's a hack for occluding axis ticks by combining dodge with a filter initializer: https://observablehq.com/@huw/occlude-axis (FWIW it would be good if any occlusion transform also supported axes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants