Skip to content

Commit

Permalink
a Map is enough (and more reliable), because there is only one projec…
Browse files Browse the repository at this point in the history
…tion for a given plot
  • Loading branch information
Fil committed Aug 22, 2023
1 parent 5658113 commit 3c1176a
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,16 @@ function clipDefs({ownerSVGElement}) {
}

// Note: may mutate selection.node!
const frame = Symbol("frame");
function applyClip(selection, mark, dimensions, context) {
let clipUrl;
const {clip = context.clip} = mark;
switch (clip) {
case "frame": {
const clips = context.clips ?? (context.clips = new WeakMap());
if (!clips.has(frame)) {
const clips = context.clips ?? (context.clips = new Map());
if (!clips.has("frame")) {
const {width, height, marginLeft, marginRight, marginTop, marginBottom} = dimensions;
const id = getClipId();
clips.set(frame, id);
clips.set("frame", id);
clipDefs(context)
.append("clipPath")
.attr("id", id)
Expand All @@ -337,23 +336,23 @@ function applyClip(selection, mark, dimensions, context) {
this.appendChild(selection.node());
selection.node = () => this; // Note: mutation!
});
clipUrl = `url(#${clips.get(frame)})`;
clipUrl = `url(#${clips.get("frame")})`;
break;
}
case "sphere": {
const clips = context.clips ?? (context.clips = new WeakMap());
const clips = context.clips ?? (context.clips = new Map());
const {projection} = context;
if (!projection) throw new Error(`the "sphere" clip option requires a projection`);
if (!clips.has(projection)) {
if (!clips.has("projection")) {
const id = getClipId();
clips.set(projection, id);
clips.set("projection", id);
clipDefs(context)
.append("clipPath")
.attr("id", id)
.append("path")
.attr("d", geoPath(projection)({type: "Sphere"}));
}
clipUrl = `url(#${clips.get(projection)})`;
clipUrl = `url(#${clips.get("projection")})`;
break;
}
}
Expand Down

0 comments on commit 3c1176a

Please sign in to comment.