Skip to content

Commit e243e64

Browse files
committed
d3 v6 support
1 parent c6f56bb commit e243e64

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
]
3838
},
3939
"peerDependencies": {
40-
"d3": "^5.5.0",
40+
"d3": "^6.2.0",
4141
"react": "^16.4.1"
4242
},
4343
"devDependencies": {
@@ -52,7 +52,7 @@
5252
"cross-env": "5.2.1",
5353
"css-loader": "2.0.2",
5454
"cypress": "3.8.3",
55-
"d3": "^5.5.0",
55+
"d3": "^6.2.0",
5656
"documentation": "12.1.2",
5757
"eslint": "6.3.0",
5858
"eslint-config-recommended": "4.0.0",

Diff for: src/components/graph/Graph.jsx

+13-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22

33
import { drag as d3Drag } from "d3-drag";
44
import { forceLink as d3ForceLink } from "d3-force";
5-
import { select as d3Select, selectAll as d3SelectAll, event as d3Event } from "d3-selection";
5+
import { select as d3Select, selectAll as d3SelectAll } from "d3-selection";
66
import { zoom as d3Zoom } from "d3-zoom";
77

88
import CONST from "./graph.const";
@@ -181,7 +181,10 @@ export default class Graph extends React.Component {
181181
.on("end", this._onDragEnd);
182182

183183
d3Select(`#${this.state.id}-${CONST.GRAPH_WRAPPER_ID}`)
184-
.selectAll(".node")
184+
.selectAll("g.node[id]")
185+
.datum(function() {
186+
return this.id; // The variable `this` will be equal to each of the selected `HTMLElement`s!
187+
})
185188
.call(customNodeDrag);
186189
}
187190

@@ -218,22 +221,19 @@ export default class Graph extends React.Component {
218221
/**
219222
* Handles d3 'drag' event.
220223
* {@link https://github.com/d3/d3-drag/blob/master/README.md#drag_subject|more about d3 drag}
221-
* @param {Object} ev - if not undefined it will contain event data.
222-
* @param {number} index - index of the node that is being dragged.
223-
* @param {Array.<Object>} nodeList - array of d3 nodes. This list of nodes is provided by d3, each
224-
* node contains all information that was previously fed by rd3g.
224+
* @param {Object} d3Event - `DragEvent` contains d3 event data.
225+
* @param {string} datum - The datum we configured inside, our d3Select call,
226+
* currently happening inside _graphNodeDragConfig function.
227+
* in our case the datum, will be equal to the nodeId.
225228
* @returns {undefined}
226229
*/
227-
_onDragMove = (ev, index, nodeList) => {
228-
const id = nodeList[index].id;
229-
230+
_onDragMove = (d3Event, datum) => {
230231
if (!this.state.config.staticGraph) {
231232
// this is where d3 and react bind
232-
let draggedNode = this.state.nodes[id];
233+
let draggedNode = this.state.nodes[datum];
233234

234235
draggedNode.oldX = draggedNode.x;
235236
draggedNode.oldY = draggedNode.y;
236-
237237
draggedNode.x += d3Event.dx;
238238
draggedNode.y += d3Event.dy;
239239

@@ -302,9 +302,10 @@ export default class Graph extends React.Component {
302302

303303
/**
304304
* Handler for 'zoom' event within zoom config.
305+
* @param {Object} d3Event - `ZoomEvent` contains d3 event data
305306
* @returns {Object} returns the transformed elements within the svg graph area.
306307
*/
307-
_zoomed = () => {
308+
_zoomed = d3Event => {
308309
const transform = d3Event.transform;
309310

310311
d3SelectAll(`#${this.state.id}-${CONST.GRAPH_CONTAINER_ID}`).attr("transform", transform);

0 commit comments

Comments
 (0)