drag event not being fired

65 views
Skip to first unread message

cesar pachon

unread,
Oct 31, 2014, 10:31:15 AM10/31/14
to d3...@googlegroups.com
hi I am trying to enable dragging in my chart, but I only got dragstart and dragend events.

something strange is that if I use the .origin method as in the examples, it throws an exception (Uncaught TypeError: Cannot read property 'x' of undefined ):

    this._drag = d3.behavior.drag()
    //.origin(function(d) { return d;}) //if uncommented, throws error!
    .on("drag", function(d){console.log("drag!", d); self.on_drag(this);})
    .on("dragstart", function(){self.on_drag_start(this);})
    .on("dragend", function(){self.on_drag_end(this);})
    ;

any suggestions are highly appreciated!

Andy Thornton

unread,
Oct 31, 2014, 10:49:40 AM10/31/14
to d3...@googlegroups.com

Without seeing the rest of your code, I can't tell what source element the drag is being called on. Therefore, I can’t be sure of the data that is being passed to the drag origin function. But the error leads me to believe that you are calling the drag function on a source object with no data. From the API:

The origin accessor must return an object with x and y properties representing the starting coordinates of the element being dragged.

Frequently the origin accessor is specified as the identity function: function(d) { return d; }. This is suitable when the datum bound to the dragged element is already an object with x and y attributes representing its current position.

The key being the part of, "This is suitable when the datum bound to the dragged element is already an object with x and y attributes representing its current position." If you post where you are calling the drag function, we could steer you in the right direction.

Cheers,

Andy

--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

cesar pachon

unread,
Oct 31, 2014, 11:01:33 AM10/31/14
to d3...@googlegroups.com
thank you for your quick reply! your explanation help me to understand the issue with the origin method, even I yet have the problem of "drag" event not being fired.

as you pointed out, I am trying to move an arbitrary SVG path, to use it as a handler for a slider within the graph, so it does not have a datum element. I solved the origin issue by extracting the transform attribute of the shape, and returning a custom object with x and y attributes. but no clues about why it does not fire the drag event.

I will try to cleanup a bit the code to be able to post a clean example.

thank you

 

Cesar  Pachón
-------------------------------------------------------------
www.cesarpachon.com, just a digital hermit


--
You received this message because you are subscribed to a topic in the Google Groups "d3-js" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/d3-js/rDwMonSe7L4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to d3-js+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages