Avoid skipping text SVG with text anchor while dragging

Here is the SVG text with anchor:

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" style="width:200px;height:200px;">
  <text x="50" y="30" fill="red" text-anchor="start">I love SVG</text>
</svg>

Now, if I write a drag and drop function:

var dragMove = function (d,i) {
    //d3.select(this).attr("text-anchor", "null"); Does not work
    d3.select(this).attr("x", d3.event.x)
                .attr("y", d3.event.y);
};

var dragEnd = function (d,i) {
    //d3.select(this).attr("text-anchor", "start"); Does not work
};

var drag = d3.behavior.drag()
                .on("drag", dragMove)
                .on("dragend", dragEnd);

d3.select("svg")
    .select("text")
    .call(drag);

It jumps after you drag it depending on its snap position. Is there a solution for this?

I tried to set the anchor-text to null and then set it again again, but this will not work. I don’t want the custom drag and drop mode to change at all. Even when the drag ends.

Any idea?

Here is the JSFiddle: http://jsfiddle.net/sewVr/

+2
source share
2 answers

, , x y , , text. : http://jsfiddle.net/twKD9/

0

d3.event.dx d3.event.dy, dragMove().

: http://jsfiddle.net/sewVr/1/

+3

All Articles