Javascript 迁移到d3 v4会导致拖动时出现重复
我正在将这个项目迁移到D3V4 JSFIDDLE 画布正在渲染,但拖动时存在某种问题。 我必须改变这个密码Javascript 迁移到d3 v4会导致拖动时出现重复,javascript,jquery,d3.js,Javascript,Jquery,D3.js,我正在将这个项目迁移到D3V4 JSFIDDLE 画布正在渲染,但拖动时存在某种问题。 我必须改变这个密码 GraphCreator.prototype.dragmove = function(d) { var thisGraph = this; if (thisGraph.state.shiftNodeDrag){ thisGraph.dragLine.attr('d', 'M' + d.x + ',' + d.y + 'L' + d3.mouse(thisGr
GraphCreator.prototype.dragmove = function(d) {
var thisGraph = this;
if (thisGraph.state.shiftNodeDrag){
thisGraph.dragLine.attr('d', 'M' + d.x + ',' + d.y + 'L' + d3.mouse(thisGraph.svgG.node())[0] + ',' + d3.mouse(this.svgG.node())[1]);
} else{
d.x += d3.event.dx;
d.y += d3.event.dy;
thisGraph.updateGraph();
}
});
不知怎的,这个graph.updateGraph();拖动时导致无限节点移动,但我只能找到这些
这是一个updateGraph函数
//调用以将更改传播到图形GraphCreator.prototype.updateGraph=函数(){ 在
updateGraph()中
替换行
newGs.append("circle")
.attr("r", String(consts.nodeRadius));
newGs.each(function(d){
thisGraph.insertTitleLinebreaks(d3.select(this), d.title);
});
用这些
newGs.each(function(d) {
if (this.childNodes.length === 0) {
d3.select(this)
.append("circle")
.attr("r", String(consts.nodeRadius));
thisGraph.insertTitleLinebreaks(d3.select(this), d.title);
}
});
使用d3到5.7版进行测试您是否检查了thisGraph.updateGrapth();的功能?我想这就是问题所在,但我找不到d3 v4对该部分的更改。添加了有问题的thisGraph.updateGrapth
newGs.each(function(d) {
if (this.childNodes.length === 0) {
d3.select(this)
.append("circle")
.attr("r", String(consts.nodeRadius));
thisGraph.insertTitleLinebreaks(d3.select(this), d.title);
}
});