Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,18 @@ export function maybeNamed(things) {
return isIterable(things) ? named(things) : things;
}

// A shared Sphere object coalesces all sphere clips.
const sphere = {type: "Sphere"};

export function maybeClip(clip) {
if (clip === true) clip = "frame";
else if (clip === false) clip = null;
else if (isGeoJSON(clip)) {
if (clip.type === "Sphere") clip = "sphere";
} else if (clip != null) clip = keyword(clip, "clip", ["frame", "sphere"]);
if (clip.type === "Sphere") clip = sphere;
} else if (clip != null) {
clip = keyword(clip, "clip", ["frame", "sphere"]);
if (clip === "sphere") clip = sphere;
}
return clip;
}

Expand Down
5 changes: 1 addition & 4 deletions src/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ function applyClip(selection, mark, dimensions, context) {
selection.node = () => this; // Note: mutation!
});
clipUrl = getFrameClip(context, dimensions);
} else if (clip === "sphere") clipUrl = getProjectionClip(context);
else if (clip?.type) clipUrl = getGeoClip(clip)(context);
} else if (clip?.type) clipUrl = getGeoClip(clip)(context);

// Here we’re careful to apply the ARIA attributes to the outer G element when
// clipping is applied, and to apply the ARIA attributes before any other
Expand Down Expand Up @@ -363,8 +362,6 @@ const getGeoClip = memoizeGeo((geo) =>
memoizeClip((clipPath, context) => clipPath.append("path").attr("d", context.path()(geo)))
);

const getProjectionClip = getGeoClip({type: "Sphere"});

// Note: may mutate selection.node!
export function applyIndirectStyles(selection, mark, dimensions, context) {
applyClip(selection, mark, dimensions, context);
Expand Down