Skip to content

ordinal opacity#2285

Merged
mbostock merged 14 commits intomainfrom
mbostock/ordinal-opacity
Apr 12, 2026
Merged

ordinal opacity#2285
mbostock merged 14 commits intomainfrom
mbostock/ordinal-opacity

Conversation

@mbostock
Copy link
Copy Markdown
Member

Fixes #2284.

@mbostock mbostock requested a review from Fil February 20, 2025 19:59
@mbostock mbostock enabled auto-merge (squash) February 20, 2025 20:02
@mbostock
Copy link
Copy Markdown
Member Author

Hmm, this still crashes if you try to have a threshold opacity scale, which is a separate but related bug:

Plot.cellX(d3.range(10), {fill: "red", opacity: Plot.identity}).plot({opacity: {type: "threshold", legend: true, domain: [1, 2, 3], range: [0.2, 0.4, 0.6, 0.8]}})

But also it crashes if you try to display an ordinal opacity scale with a ramp legend, which should be supported (because we can display ordinal color scales with a ramp legend, too):

Plot.cellX(d3.range(10), {fill: "red", opacity: Plot.identity}).plot({opacity: {type: "ordinal", legend: "ramp"}})

@mbostock mbostock disabled auto-merge February 20, 2025 20:12
@Fil Fil mentioned this pull request Feb 24, 2025
Copy link
Copy Markdown
Member Author

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has some merge conflicts with #2416

@mbostock
Copy link
Copy Markdown
Member Author

Unfortunately it looks like the color-mix(…) technique of #2419 doesn’t actually work (at least here) in part because the canvas element the ramp legend is using is detached, and hence currentColor isn’t available. (And more generally it won’t be reliable to have a color scale that references currentColor if we’re baking the colors into an image for the legend…)

@mbostock
Copy link
Copy Markdown
Member Author

Resurrected the SVG filter technique from #2416. 👍

@mbostock
Copy link
Copy Markdown
Member Author

I decided it’s easier for the ramp & swatches legends to understand opacity scales, rather than trying to have the opacity scale masquerade as a color scale.

@mbostock mbostock merged commit 92ea384 into main Apr 12, 2026
1 check passed
@mbostock mbostock deleted the mbostock/ordinal-opacity branch April 12, 2026 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ordinal opacity scales

2 participants