|
1 | | -import {select} from "d3"; |
2 | 1 | import {createContext} from "./context.js"; |
3 | 2 | import {legendRamp} from "./legends/ramp.js"; |
4 | 3 | import {isSymbolColorLegend, legendSwatches, legendSymbols} from "./legends/swatches.js"; |
5 | 4 | import {inherit, isScaleOptions} from "./options.js"; |
6 | | -import {getFilterId} from "./style.js"; |
7 | 5 | import {normalizeScale} from "./scales.js"; |
8 | 6 |
|
9 | 7 | const legendRegistry = new Map([ |
@@ -61,19 +59,11 @@ function legendOpacity({type, interpolate, ...scale}, {legend = true, color = "c |
61 | 59 | if (!interpolate) throw new Error(`${type} opacity scales are not supported`); |
62 | 60 | if (legend === true) legend = "ramp"; |
63 | 61 | if (`${legend}`.toLowerCase() !== "ramp") throw new Error(`${legend} opacity legends are not supported`); |
64 | | - const node = legendColor({type, ...scale, interpolate: interpolateOpacity}, {legend, ...options}); |
65 | | - if (!node) return; |
66 | | - const fid = getFilterId(); |
67 | | - const svg = select(node); |
68 | | - svg.select("image").attr("filter", `url(#${fid})`); |
69 | | - const filter = svg.append("filter").attr("id", fid); |
70 | | - filter.append("feFlood").attr("flood-color", color); |
71 | | - filter.append("feComposite").attr("in2", "SourceGraphic").attr("operator", "in"); |
72 | | - return node; |
| 62 | + return legendColor({type, ...scale, interpolate: interpolateOpacity(color)}, {legend, ...options}); |
73 | 63 | } |
74 | 64 |
|
75 | | -function interpolateOpacity(t) { |
76 | | - return `rgba(0,0,0,${t})`; |
| 65 | +function interpolateOpacity(color) { |
| 66 | + return (t) => `color-mix(in srgb, transparent, ${color} ${(t * 100).toFixed(1)}%)`; |
77 | 67 | } |
78 | 68 |
|
79 | 69 | export function createLegends(scales, context, options) { |
|
0 commit comments