javascript - Using d3 drag, why doesn't dragstart have d3.event.x set? -


i can access d3.event.x inside on("drag"...) x doesn't exist inside on("dragstart"...); why? , how can way, preferably not hackish?

check console output example:

d3.select("body").append("svg").append("rect")     .attr("width", 100)     .attr("height", 100)     .style("color", "black")     .call(         d3.behavior.drag()             .on("dragstart", function(){                 console.log(d3.event);             })             .on("drag", function(){                 console.log(d3.event);             })             .on("dragend", function(){                 console.log(d3.event);             })         ); 

jsfiddle

@lars explains why, how do it? d3.mouse pretty slick:

    d3.behavior.drag()         .on("dragstart", function(){             console.log('relative rect: ' + d3.mouse(this));             console.log('relative body: ' + d3.mouse(d3.select("body").node()));         }) 

updated example.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -