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

Add a missing d3 property clickDistance #466

Open
wants to merge 1 commit into
base: master
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
12 changes: 11 additions & 1 deletion src/Tree/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Tree extends React.Component<TreeProps, TreeState> {
draggable: true,
zoom: 1,
scaleExtent: { min: 0.1, max: 1 },
clickDistance: 0,
nodeSize: { x: 140, y: 140 },
separation: { siblings: 1, nonSiblings: 2 },
shouldCollapseNeighborNodes: false,
Expand Down Expand Up @@ -149,7 +150,15 @@ class Tree extends React.Component<TreeProps, TreeState> {
* specified in `props.scaleExtent`.
*/
bindZoomListener(props: TreeProps) {
const { zoomable, scaleExtent, translate, zoom, onUpdate, hasInteractiveNodes } = props;
const {
zoomable,
scaleExtent,
translate,
zoom,
clickDistance,
onUpdate,
hasInteractiveNodes,
} = props;
const svg = select(`.${this.svgInstanceRef}`);
const g = select(`.${this.gInstanceRef}`);

Expand All @@ -158,6 +167,7 @@ class Tree extends React.Component<TreeProps, TreeState> {
svg.call(d3zoom().transform, zoomIdentity.translate(translate.x, translate.y).scale(zoom));
svg.call(
d3zoom()
.clickDistance(clickDistance)
.scaleExtent(zoomable ? [scaleExtent.min, scaleExtent.max] : [zoom, zoom])
// TODO: break this out into a separate zoom handler fn, rather than inlining it.
.filter((event: any) => {
Expand Down
13 changes: 11 additions & 2 deletions src/Tree/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ export interface TreeProps {
*/
zoomable?: boolean;

/**
/**
* Toggles ability to drag the Tree.
*
* {@link Tree.defaultProps.draggable | Default value}
*/
draggable?: boolean;
draggable?: boolean;

/**
* A floating point number to set the initial zoom level. It is constrained by `scaleExtent`.
Expand All @@ -224,6 +224,15 @@ export interface TreeProps {
max?: number;
};

/**
* Set the maximum distance that the mouse can move between mousedown and mouseup that will trigger
* a subsequent click event. If at any point between mousedown and mouseup the mouse is greater than or equal to
* distance from its position on mousedown, the click event following mouseup will be suppressed.
*
* {@link Tree.defaultProps.clickDistance | Default value}
*/
clickDistance?: number;

/**
* The amount of space each node element occupies.
*
Expand Down