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

Experiment: add support for distinguishing hover & click events #1979

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/interactions/pointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, render, ...op

// Dispatch the value. When simultaneously exiting this facet and
// entering a new one, prioritize the entering facet.
if (!(i == null && facetState?.size > 1)) context.dispatchValue(i == null ? null : data[i]);
if (!(i == null && facetState?.size > 1)) context.dispatchValue(i == null ? null : data[i], s);
return r;
}

Expand Down
39 changes: 31 additions & 8 deletions src/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@ import {creator, select} from "d3";
import {createChannel, inferChannelScale} from "./channel.js";
import {createContext} from "./context.js";
import {createDimensions} from "./dimensions.js";
import {createFacets, recreateFacets, facetExclude, facetGroups, facetTranslator, facetFilter} from "./facet.js";
import {createFacets, facetExclude, facetFilter, facetGroups, facetTranslator, recreateFacets} from "./facet.js";
import {pointer, pointerX, pointerY} from "./interactions/pointer.js";
import {createLegends, exposeLegends} from "./legends.js";
import {Mark} from "./mark.js";
import {axisFx, axisFy, axisX, axisY, gridFx, gridFy, gridX, gridY} from "./marks/axis.js";
import {frame} from "./marks/frame.js";
import {tip} from "./marks/tip.js";
import {isColor, isIterable, isNone, isScaleOptions} from "./options.js";
import {arrayify, map, yes, maybeIntervalTransform, subarray} from "./options.js";
import {
arrayify,
isColor,
isIterable,
isNone,
isScaleOptions,
map,
maybeIntervalTransform,
subarray,
yes
} from "./options.js";
import {createProjection, getGeometryChannels, hasProjection} from "./projection.js";
import {createScales, createScaleFunctions, autoScaleRange, exposeScales} from "./scales.js";
import {innerDimensions, outerDimensions} from "./scales.js";
import {
autoScaleRange,
createScaleFunctions,
createScales,
exposeScales,
innerDimensions,
outerDimensions
} from "./scales.js";
import {isPosition, registry as scaleRegistry} from "./scales/index.js";
import {applyInlineStyles, maybeClassName} from "./style.js";
import {initializer} from "./transforms/basic.js";
Expand Down Expand Up @@ -172,10 +187,11 @@ export function plot(options = {}) {
};

// Allows e.g. the pointer transform to support viewof.
context.dispatchValue = (value) => {
if (figure.value === value) return;
context.dispatchValue = (value, sticky) => {
if (figure.value === value && context.stickyState === sticky) return;
figure.value = value;
figure.dispatchEvent(new Event("input", {bubbles: true}));
context.stickyState = sticky;
figure.dispatchEvent(new StickyEvent("input", {bubbles: true, sticky}));
};

// Reinitialize; for deriving channels dependent on other channels.
Expand Down Expand Up @@ -743,3 +759,10 @@ function outerRange(scale) {
if (x2 < x1) [x1, x2] = [x2, x1];
return [x1, x2 + scale.bandwidth()];
}

class StickyEvent extends Event {
constructor(type, options) {
super(type, options);
this.sticky = options.sticky;
}
}
Loading
Loading