Differences between d3.event.clientX and d3.svg.mouse(this)

6,711 views
Skip to first unread message

Tsyren Ochirov

unread,
Mar 30, 2012, 11:39:06 AM3/30/12
to d3...@googlegroups.com

 I wonder to know in which cases d3.event.clientX and d3.svg.mouse(this) have differences

 Thanks

Tsyren Ochirov

unread,
Mar 30, 2012, 11:47:30 AM3/30/12
to d3...@googlegroups.com
Especially,

d3.svg.mouse(this) works not the same in Chrome vs Firefox

Chromium v17.0.963.79 (ubuntu)
Firefox 11 for ubuntu

This cause base on engine webkit vs gecko?

And how to fix this in Chrome?

Mike Bostock

unread,
Mar 30, 2012, 12:06:51 PM3/30/12
to d3...@googlegroups.com
d3.mouse returns local coordinates (relative to the origin of the
current SVG or HTML element):

https://github.com/mbostock/d3/wiki/Selections#wiki-d3_mouse

d3.event.clientX returns coordinates relative to the window. Beware of
scrolling.

http://www.quirksmode.org/dom/w3c_cssom.html

Mike

Tsyren Ochirov

unread,
Mar 30, 2012, 12:52:56 PM3/30/12
to d3...@googlegroups.com
Thanks, Mike!

Do you spot the bug in Chrome with mouse position?

Mike Bostock

unread,
Mar 30, 2012, 12:57:11 PM3/30/12
to d3...@googlegroups.com
> Do you spot the bug in Chrome with mouse position?

No, what bug?

Mike

Tsyren Ochirov

unread,
Apr 1, 2012, 12:58:11 AM4/1/12
to d3...@googlegroups.com

  in Chrome, d3.svg.mouse(this) gives me another offset then in Firefox, also, the same situation with d3.clientX

  Later, today, i will support it with code.

Tsyren Ochirov

unread,
Apr 2, 2012, 9:30:00 AM4/2/12
to d3...@googlegroups.com
I'm sorry for that poor explonation that i gave before.
Maybe this is not direct d3 issue, but anyway:

i was deep with debugger and here is

Breakpoint on line below

var coord = d3.mouse(this)[0];

fire

d3.mouse = function(container) {
  return d3_mousePoint(container, d3_eventSource());
};

than

function d3_eventSource() {
var e = d3.event, s;
while (s = e.sourceEvent) e = s;
return e;
}

and here


e has attr clientX=126 // in Firefox (Gecko)

and

e has attr clientX=98 // in Chrome (AppleWebkit)

I thought that diff btw this values are constant, but it wasn't, its changed while moving and grown.

Why it can be?

Tsyren Ochirov

unread,
Apr 2, 2012, 11:37:42 AM4/2/12
to d3...@googlegroups.com
Issue has fixed.

Its was zoom option in CSS.

kuan kuan

unread,
May 18, 2015, 4:38:11 PM5/18/15
to d3...@googlegroups.com
Hi, Tsyren:

Could you post the code about how you handle the scale?

Thanks
Reply all
Reply to author
Forward
0 new messages