d3.js - Updating graph as I drag a point around -
i making line of best fit app using d3 in want line of best fit update drag points around. got work when drag ends, line updates itself. however, when comes updating point being dragged, unable so.
here drag function:
var move = d3.behavior.drag() .on("drag",drag) .on("dragend",function(){ dict.length = 0; var dragpoint = d3.select(this); var newx = x_scale2(parseint(dragpoint.attr("cx"))); var newy = y_scale2(parseint(dragpoint.attr("cy"))); model.replace_point(dragpoint.attr("id"),newx,newy); updatedisplay(); }); function drag(){ var dragpoint = d3.select(this); dragpoint .attr("cx",function(){return d3.event.dx + parseint(dragpoint.attr("cx"));}) .attr("cy",function(){return d3.event.dy +parseint(dragpoint.attr("cy"));}) }
** on how accomplish goal appreciated **
you can include 'update-code' in drag function.
line update every time drag event fired. means every time position of point changes.
var move = d3.behavior.drag() .on("drag", drag); function drag() { var dragpoint = d3.select(this); dragpoint .attr("cx", d3.event.dx + parseint(dragpoint.attr("cx"))) .attr("cy", d3.event.dy + parseint(dragpoint.attr("cy"))); var newx = x_scale2(parseint(dragpoint.attr("cx"))); var newy = y_scale2(parseint(dragpoint.attr("cy"))); model.replace_point(dragpoint.attr("id"), newx, newy); updatedisplay(); }
Comments
Post a Comment