Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simpler clip geo #2248

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Changes from all commits
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
29 changes: 14 additions & 15 deletions src/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,21 +352,20 @@ const getFrameClip = memoizeClip((clipPath, context, dimensions) => {
.attr("height", height - marginTop - marginBottom);
});

const getGeoClip = (function () {
const cache = new WeakMap();
const sphere = {type: "Sphere"};
return (geo, context) => {
let c, url;
if (!(c = cache.get(context))) cache.set(context, (c = new WeakMap()));
if (geo.type === "Sphere") geo = sphere; // coalesce all spheres.
if (!(url = c.get(geo))) {
const id = getClipId();
select(context.ownerSVGElement).append("clipPath").attr("id", id).append("path").attr("d", context.path()(geo));
c.set(geo, (url = `url(#${id})`));
}
return url;
};
})();
const geoClipCache = new WeakMap();
const sphere = {type: "Sphere"};

function getGeoClip(geo, context) {
let cache, url;
if (!(cache = geoClipCache.get(context))) geoClipCache.set(context, (cache = new WeakMap()));
if (geo.type === "Sphere") geo = sphere; // coalesce all spheres
if (!(url = cache.get(geo))) {
const id = getClipId();
select(context.ownerSVGElement).append("clipPath").attr("id", id).append("path").attr("d", context.path()(geo));
cache.set(geo, (url = `url(#${id})`));
}
return url;
}

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