Skip to content

Commit bdff657

Browse files
authored
New freezeAllDragEvents configuration property to prevent node drag-and-drop (#388)
* Add new freezeAllDragEvents config to prevent node drag-and-drop * Update freezeAllDragEvents behavior to also disable panning and zooming * Addressing comments from PR * Restoring some auto-updated files to their previous state
1 parent 30304b7 commit bdff657

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/components/graph/Graph.jsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ export default class Graph extends React.Component {
196196
this.state.simulation.nodes(this.state.d3Nodes).on("tick", this._tick);
197197
this._graphLinkForceConfig();
198198
}
199-
this._graphNodeDragConfig();
199+
if (!this.state.config.freezeAllDragEvents) {
200+
this._graphNodeDragConfig();
201+
}
200202
}
201203

202204
/**
@@ -288,9 +290,11 @@ export default class Graph extends React.Component {
288290
_zoomConfig = () => {
289291
const selector = d3Select(`#${this.state.id}-${CONST.GRAPH_WRAPPER_ID}`);
290292

291-
const zoomObject = d3Zoom()
292-
.scaleExtent([this.state.config.minZoom, this.state.config.maxZoom])
293-
.on("zoom", this._zoomed);
293+
const zoomObject = d3Zoom().scaleExtent([this.state.config.minZoom, this.state.config.maxZoom]);
294+
295+
if (!this.state.config.freezeAllDragEvents) {
296+
zoomObject.on("zoom", this._zoomed);
297+
}
294298

295299
if (this.state.config.initialZoom !== null) {
296300
zoomObject.scaleTo(selector, this.state.config.initialZoom);

src/components/graph/graph.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
*
6767
* <img src="https://github.com/danielcaldas/react-d3-graph/blob/master/docs/rd3g-zoom-animation.gif?raw=true" width="820" height="480"/>
6868
*
69+
* @param {boolean} [freezeAllDragEvents=false] - <a id="freeze-all-drag-events" href="#freeze-all-drag-events">🔗</a> Disables manipulation of graph through drag
70+
* and drop. This includes dragging graph elements, panning and zooming. *Note: this property can only be set in the first mount, it does not update dynamically.*
6971
* @param {number} [focusAnimationDuration=0.75] - <a id="focus-animation-duration" href="#focus-animation-duration">🔗</a> duration (in seconds) for the animation that takes place when focusing the graph on a node.
7072
* @param {number} [height=400] - <a id="height" href="#height">🔗</a> the height of the (svg) area where the graph will be rendered.
7173
* @param {boolean} [nodeHighlightBehavior=false] - <a id="node-highlight-behavior" href="#node-highlight-behavior">🔗</a> 🚅🚅🚅 when user mouse hovers a node that node and adjacent common
@@ -245,6 +247,7 @@ export default {
245247
directed: false,
246248
focusAnimationDuration: 0.75,
247249
focusZoom: 1,
250+
freezeAllDragEvents: false,
248251
height: 400,
249252
highlightDegree: 1,
250253
highlightOpacity: 1,

0 commit comments

Comments
 (0)