Skip to content

Commit

Permalink
simpler clip geo (#2248)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil authored Nov 23, 2024
1 parent 9b53a85 commit b2b587a
Showing 1 changed file with 14 additions and 15 deletions.
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

0 comments on commit b2b587a

Please sign in to comment.