Skip to content

Commit 3d8fb02

Browse files
committed
remove checkerboard
1 parent d8dd824 commit 3d8fb02

8 files changed

Lines changed: 25 additions & 60 deletions

src/legends.js

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,19 @@ function legendOpacity({type, interpolate, ...scale}, {legend = true, color = "c
6161
if (!interpolate) throw new Error(`${type} opacity scales are not supported`);
6262
if (legend === true) legend = "ramp";
6363
if (`${legend}`.toLowerCase() !== "ramp") throw new Error(`${legend} opacity legends are not supported`);
64-
const svg = legendColor({type, ...scale, interpolate: (t) => `rgba(0,0,0,${t})`}, {legend, ...options});
65-
if (!svg) return;
66-
const s = select(svg);
67-
const image = s.select("image");
68-
const x = +image.attr("x");
69-
const y = +image.attr("y");
70-
const w = +image.attr("width");
71-
const h = +image.attr("height");
72-
const pid = getFilterId();
64+
const node = legendColor({type, ...scale, interpolate: interpolateOpacity}, {legend, ...options});
65+
if (!node) return;
7366
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;
73+
}
7474

75-
// Checkerboard
76-
const pattern = s.append("pattern").attr("id", pid).attr("y", y).attr("width", h).attr("height", h).attr("patternUnits", "userSpaceOnUse"); // prettier-ignore
77-
pattern.append("path").attr("d", `M0,0h${h / 2}v${h / 2}H0ZM${h / 2},${h / 2}h${h / 2}v${h / 2}H${h / 2}Z`).attr("fill", "color-mix(in srgb, var(--plot-background), currentColor 20%)"); // prettier-ignore
78-
s.insert("rect", "image").attr("x", x).attr("y", y).attr("width", w).attr("height", h).attr("fill", `url(#${pid})`); // prettier-ignore
79-
80-
// Color
81-
image.attr("filter", `url(#${fid})`);
82-
s.append("filter").attr("id", fid).call((f) => { f.append("feFlood").attr("flood-color", color); f.append("feComposite").attr("in2", "SourceGraphic").attr("operator", "in"); }); // prettier-ignore
83-
return svg;
75+
function interpolateOpacity(t) {
76+
return `rgba(0,0,0,${t})`;
8477
}
8578

8679
export function createLegends(scales, context, options) {

test/output/opacityLegend.svg

Lines changed: 2 additions & 6 deletions
Loading

test/output/opacityLegendCSS4.svg

Lines changed: 2 additions & 6 deletions
Loading

test/output/opacityLegendColor.svg

Lines changed: 2 additions & 6 deletions
Loading

test/output/opacityLegendLinear.svg

Lines changed: 2 additions & 6 deletions
Loading

test/output/opacityLegendLog.svg

Lines changed: 2 additions & 6 deletions
Loading

test/output/opacityLegendRange.svg

Lines changed: 2 additions & 6 deletions
Loading

test/output/opacityLegendSqrt.svg

Lines changed: 2 additions & 6 deletions
Loading

0 commit comments

Comments
 (0)