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 onZoomChange prop to Graph #354

Merged
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion src/components/graph/Graph.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ import { merge, throwErr } from "../../utils";
* window.alert(`Node ${nodeId} moved to new position x= ${x} y= ${y}`);
* };
*
* const onZoomChange = function(newZoom) {
danielcaldas marked this conversation as resolved.
Show resolved Hide resolved
* window.alert(`Graph is now zoomed at ${newZoom}`);
* };
*
*
* <Graph
* id='graph-id' // id is mandatory, if no id is defined rd3g will throw an error
Expand All @@ -115,7 +119,8 @@ import { merge, throwErr } from "../../utils";
* onMouseOverNode={onMouseOverNode}
* onMouseOutNode={onMouseOutNode}
* onMouseOverLink={onMouseOverLink}
* onMouseOutLink={onMouseOutLink}/>
* onMouseOutLink={onMouseOutLink}
* onZoomChange={onZoomChange}/>
*/
export default class Graph extends React.Component {
/**
Expand Down Expand Up @@ -302,6 +307,12 @@ export default class Graph extends React.Component {
d3SelectAll(`#${this.state.id}-${CONST.GRAPH_CONTAINER_ID}`).attr("transform", transform);

this.state.config.panAndZoom && this.setState({ transform: transform.k });

// only send zoom change events if the zoom has changed (_zoomed() also gets called when panning)
if (this.props.onZoomChange && this.state.previousZoom !== transform.k) {
this.setState({ previousZoom: transform.k });
danielcaldas marked this conversation as resolved.
Show resolved Hide resolved
this.props.onZoomChange(transform.k);
}
};

/**
Expand Down