Skip to content
Open
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
17 changes: 16 additions & 1 deletion src/components/graph/Graph.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ import { merge, debounce, throwErr } from "../../utils";
* window.alert(`Graph is now zoomed at ${newZoom} from ${previousZoom}`);
* };
*
* const onDragChange = function(newZoom) {
* // newZoom is like {x: 1, y: 1, k: 1}
* window.alert(`Graph is now zoomed/dragged ending at ${newZoom}`);
* };
*
* <Graph
* id='graph-id' // id is mandatory, if no id is defined rd3g will throw an error
Expand All @@ -126,7 +130,8 @@ import { merge, debounce, throwErr } from "../../utils";
* onMouseOverLink={onMouseOverLink}
* onMouseOutLink={onMouseOutLink}
* onNodePositionChange={onNodePositionChange}
* onZoomChange={onZoomChange}/>
* onZoomChange={onZoomChange}
* onDragChange={onDragChange} />
*/
export default class Graph extends React.Component {
/**
Expand Down Expand Up @@ -300,6 +305,9 @@ export default class Graph extends React.Component {

if (!this.state.config.freezeAllDragEvents) {
zoomObject.on("zoom", this._zoomed);
if (this.onDragChange) {
zoomObject.on("end", this._zoomedEnd);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the use case for this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the use case is when we move the graph we need to handle the final position for save it in bdd and after reload we send an init position to the graph (i've not finish to code this part)

}
}

if (this.state.config.initialZoom !== null) {
Expand All @@ -311,6 +319,12 @@ export default class Graph extends React.Component {
selector.call(zoomObject).on("dblclick.zoom", null);
};

_zoomedEnd = () => {
const transform = d3Event.transform;

this.onDragChange && this.onDragChange(transform);
}

/**
* Handler for 'zoom' event within zoom config.
* @returns {Object} returns the transformed elements within the svg graph area.
Expand Down Expand Up @@ -545,6 +559,7 @@ export default class Graph extends React.Component {
this.isDraggingNode = false;
this.state = initializeGraphState(this.props, this.state);
this.debouncedOnZoomChange = this.props.onZoomChange ? debounce(this.props.onZoomChange, 100) : null;
this.onDragChange = this.props.onDragChange ? this.props.onDragChange : null;
}

/**
Expand Down