Skip to content

Commit 77d8c39

Browse files
committed
patch graph,js for d3v7 (danielcaldas#380)
1 parent c9f9f2e commit 77d8c39

File tree

2 files changed

+11877
-14
lines changed

2 files changed

+11877
-14
lines changed

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

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import React from "react";
22

3-
import { drag as d3Drag } from "d3-drag";
4-
import { forceLink as d3ForceLink } from "d3-force";
5-
import { select as d3Select, selectAll as d3SelectAll, event as d3Event } from "d3-selection";
6-
import { zoom as d3Zoom } from "d3-zoom";
3+
import {
4+
forceLink as d3ForceLink,
5+
drag as d3Drag,
6+
select as d3Select,
7+
selectAll as d3SelectAll,
8+
zoom as d3Zoom,
9+
} from "d3";
710

811
import CONST from "./graph.const";
912
import DEFAULT_CONFIG from "./graph.config";
@@ -182,7 +185,10 @@ export default class Graph extends React.Component {
182185
.on("end", this._onDragEnd);
183186

184187
d3Select(`#${this.state.id}-${CONST.GRAPH_WRAPPER_ID}`)
185-
.selectAll(".node")
188+
.selectAll("g.node[id]")
189+
.datum(function() {
190+
return this.id; // The variable `this` will be equal to each of the selected `HTMLElement`s!
191+
})
186192
.call(customNodeDrag);
187193
}
188194

@@ -228,18 +234,16 @@ export default class Graph extends React.Component {
228234
/**
229235
* Handles d3 'drag' event.
230236
* {@link https://github.com/d3/d3-drag/blob/master/README.md#drag_subject|more about d3 drag}
231-
* @param {Object} ev - if not undefined it will contain event data.
232-
* @param {number} index - index of the node that is being dragged.
233-
* @param {Array.<Object>} nodeList - array of d3 nodes. This list of nodes is provided by d3, each
234-
* node contains all information that was previously fed by rd3g.
237+
* @param {Object} d3Event - `DragEvent` contains d3 event data.
238+
* @param {string} datum - The datum we configured inside, our d3Select call,
239+
* currently happening inside _graphNodeDragConfig function.
240+
* in our case the datum, will be equal to the nodeId.
235241
* @returns {undefined}
236242
*/
237-
_onDragMove = (ev, index, nodeList) => {
238-
const id = nodeList[index].id;
239-
243+
_onDragMove = (d3Event, datum) => {
240244
if (!this.state.config.staticGraph) {
241245
// this is where d3 and react bind
242-
let draggedNode = this.state.nodes[id];
246+
let draggedNode = this.state.nodes[datum];
243247

244248
draggedNode.oldX = draggedNode.x;
245249
draggedNode.oldY = draggedNode.y;
@@ -320,9 +324,10 @@ export default class Graph extends React.Component {
320324

321325
/**
322326
* Handler for 'zoom' event within zoom config.
327+
* @param {Object} d3Event - `ZoomEvent` contains d3 event data
323328
* @returns {Object} returns the transformed elements within the svg graph area.
324329
*/
325-
_zoomed = () => {
330+
_zoomed = d3Event => {
326331
const transform = d3Event.transform;
327332

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

0 commit comments

Comments
 (0)