Skip to content

Commit e785986

Browse files
mbostockFil
andauthored
pointer-events: none when not sticky (#1697)
* pointer-events: none when not sticky * add missing context in call to applyIndirectStyles * regenerate snapshots * greedy context copy --------- Co-authored-by: Philippe Rivière <fil@rezo.net>
1 parent dbb7d59 commit e785986

File tree

82 files changed

+136
-132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+136
-132
lines changed

src/interactions/pointer.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, render, ...op
2121
// outermost render function because it will re-render dynamically in
2222
// response to pointer events.
2323
render: composeRender(function (index, scales, values, dimensions, context, next) {
24+
context = {...context, pointerSticky: false};
2425
const svg = context.ownerSVGElement;
2526
const {data} = context.getMarkState(this);
2627

@@ -68,6 +69,7 @@ function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, render, ...op
6869

6970
let i; // currently focused index
7071
let g; // currently rendered mark
72+
let s; // currently rendered stickiness
7173
let f; // current animation frame
7274

7375
// When faceting, if more than one pointer would be visible, only show
@@ -97,8 +99,9 @@ function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, render, ...op
9799
}
98100

99101
function render(ii) {
100-
if (i === ii) return; // the tooltip hasn’t moved
102+
if (i === ii && s === state.sticky) return; // the tooltip hasn’t moved
101103
i = ii;
104+
s = context.pointerSticky = state.sticky;
102105
const I = i == null ? [] : [i];
103106
if (faceted) (I.fx = index.fx), (I.fy = index.fy), (I.fi = index.fi);
104107
const r = next(I, scales, values, dimensions, context);
@@ -144,7 +147,7 @@ function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, render, ...op
144147
if (i == null) return; // not pointing
145148
if (state.sticky && state.roots.some((r) => r?.contains(event.target))) return; // stay sticky
146149
if (state.sticky) (state.sticky = false), state.renders.forEach((r) => r(null)); // clear all pointers
147-
else state.sticky = true;
150+
else (state.sticky = true), render(i);
148151
event.stopImmediatePropagation(); // suppress other pointers
149152
}
150153

src/marks/rule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class RuleX extends Mark {
3535
const {width, height, marginTop, marginRight, marginLeft, marginBottom} = dimensions;
3636
const {insetTop, insetBottom} = this;
3737
return create("svg:g", context)
38-
.call(applyIndirectStyles, this, dimensions)
38+
.call(applyIndirectStyles, this, dimensions, context)
3939
.call(applyTransform, this, {x: X && x}, offset, 0)
4040
.call((g) =>
4141
g

src/style.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ export function applyIndirectStyles(selection, mark, dimensions, context) {
377377
applyAttr(selection, "shape-rendering", mark.shapeRendering);
378378
applyAttr(selection, "filter", mark.imageFilter);
379379
applyAttr(selection, "paint-order", mark.paintOrder);
380-
applyAttr(selection, "pointer-events", mark.pointerEvents);
380+
const {pointerEvents = context.pointerSticky === false ? "none" : undefined} = mark;
381+
applyAttr(selection, "pointer-events", pointerEvents);
381382
}
382383

383384
export function applyDirectStyles(selection, mark) {

test/output/autoArea.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoAreaColor.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoAreaColorColor.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoAreaColorName.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoAreaColorValue.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoAreaStackColor.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoAutoHistogram.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoBar.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoBarColorReducer.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoBarMode.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoBarNoReducer.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoBarNonZeroReducer.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoBarStackColor.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoBarStackColorConstant.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoBarStackColorField.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoChannels.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoConnectedScatterplot.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoDot.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoDotBin.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoDotColor.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoDotFacet.svg

Lines changed: 3 additions & 3 deletions
Loading

test/output/autoDotFacet2.svg

Lines changed: 5 additions & 5 deletions
Loading

test/output/autoDotGroup.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoDotOrdCont.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoDotOrdinal.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoDotSize.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoDotSize2.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoDotUnsortedDate.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoDotZero.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoHeatmap.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoHeatmapOrdCont.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoHeatmapOrdinal.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoHistogram.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/autoHistogramDate.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)