0
我正在尝试使用D3的拖动功能“拖动圆点”(一个svg圆圈)。为了保持模块化,我有多个文件。在“App.js”文件中实例化一个来自“Dot类”文件的点是可行的!然而,拖动行为是平稳的。在模块化ES6中使用D3
我一直在这一段时间,修补和“谷歌搜索”。现在拉头发。我需要第二套眼睛。我错了什么?
谢谢!
Dot.js:
import * as d3 from "d3";
export class Dot {
constructor(cx, cy, rad){
this.cx = cx;
this.cy = cy;
this.radius = rad;
this.svg = null;
this.dot = null;
this.width = 199;
this.height = 533;
}
buildDot(){
this.dot =
d3.select("body").append("svg").attr("width",this.width).attr("height",this.height).append("circle").attr("cx",this.cx).attr("cy",this.cy).attr("r",this.radius);
return this.dot;
}
onDrag(){
console.log("dragging");
}
}
App.js:
import {Dot} from './js/Dot';
import * as d3 from "d3";
(function(){
var dot = new Dot(200, 200, 99).buildDot();
console.log(dot);
dot.call(d3.drag().on("drag", dot.onDrag));
})();