简体   繁体   中英

d3 drag path does not work

I have this code for configuring a path that surrounds some elements, the path is named cluster:

 cluster
            .data(getData()).enter()
            .append("path")  // notice SVG path elements
            //...
            .call(d3.behavior.drag()
            .on("drag", function (d, i) {
                d.x += d3.event.dx
                d.y += d3.event.dy
                console.log("d3.event.dx", d3.event.dx)  //prints a number
                cluster.attr("transform", function (d, i) {
                    return "translate(" + d3.event.dx +", "+ d3.event.dy + ")"
                })
            }));

Everything is working except the dragging functionality for cluster path.

This is what I get if I console.log 在此输入图像描述

Shouldn't it be dx instead of d3.event.dx (likewise for y )?

cluster.attr("transform", function (d, i) {
  return "translate(" + d.x + ", "+ d.y + ")"
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM