From fb78a6e351b93bedb0cbccb58a59fb9b6dbc442a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Sat, 23 Nov 2024 06:17:01 +0100 Subject: [PATCH 1/2] simpler clip geo --- src/style.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/style.js b/src/style.js index f123ef3b6a..e1ec3dd26d 100644 --- a/src/style.js +++ b/src/style.js @@ -352,21 +352,19 @@ 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 cache = new WeakMap(); +const sphere = {type: "Sphere"}; +function getGeoClip(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; +} // Note: may mutate selection.node! export function applyIndirectStyles(selection, mark, dimensions, context) { From 1d64cab8990043b8c9f5e383554c7d00ca4e07d9 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Sat, 23 Nov 2024 07:55:13 -0800 Subject: [PATCH 2/2] more descriptive variable names --- src/style.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/style.js b/src/style.js index e1ec3dd26d..4fc1c9828a 100644 --- a/src/style.js +++ b/src/style.js @@ -352,16 +352,17 @@ const getFrameClip = memoizeClip((clipPath, context, dimensions) => { .attr("height", height - marginTop - marginBottom); }); -const cache = new WeakMap(); +const geoClipCache = new WeakMap(); const sphere = {type: "Sphere"}; + function getGeoClip(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))) { + 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)); - c.set(geo, (url = `url(#${id})`)); + cache.set(geo, (url = `url(#${id})`)); } return url; }