【发布时间】:2021-01-21 15:29:28
【问题描述】:
按照 D3v6 文档,我无法在使用 d3.symbol 工具绘制的路径 SVG 元素上实现简单的拖动行为。 typescript 类在此处显示为上下文。 事件在正确的元素上触发,但回调函数似乎没有接收到 (event, datum) 参数。 任何帮助将不胜感激。
import * as d3 from "d3";
export default class Sliders {
svg: SVGSVGElement;
constructor(svg: SVGSVGElement){
this.svg = svg;
}
draw(){
const g = d3.select(this.svg).append('g').attr('class', 'symbol');
const circle = g.append('circle').attr('r', 200);
const D = d3.drag() // `event` and `d` are always undefined in 3 lines below
.on("start", (event, d) => circle.attr("stroke", "lime"))
.on("drag", (event, d: any) => (d.x = event.x, d.y = event.y))
.on("end", (event, d) => circle.attr("stroke", "black")) as any; // Could not fathom the proper type
circle.call(D);
}
}
【问题讨论】:
标签: d3.js events parameters callback draggable