How to set the origin while drag in d3.js in v4 [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 03:18:48

问题


This question already has an answer here:

  • d3 version 4 workaround for drag origin 1 answer

I am facing a jump issue when I drag a <rect>.

In this question they suggest to use drag.origin() but D3 v4 version doesn't have this method anymore.

Can some body suggest how to solve the jump issue?


回答1:


Instead of origin use subject.

So this

 .origin(function() { 
        var t = d3.select(this);
        return {x: t.attr("x"), y: t.attr("y")};
    })

will become

 .subject(function() { 
        var t = d3.select(this);
        return {x: t.attr("x"), y: t.attr("y")};
    })

Working fiddle using d3 v4 is here

API reference here



来源:https://stackoverflow.com/questions/38650637/how-to-set-the-origin-while-drag-in-d3-js-in-v4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!