Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d3.mouse return incorrect position when browser zoomed. #668

Closed
frogcherry opened this issue Jun 6, 2012 · 6 comments
Closed

d3.mouse return incorrect position when browser zoomed. #668

frogcherry opened this issue Jun 6, 2012 · 6 comments
Labels
bug Something isn’t working
Milestone

Comments

@frogcherry
Copy link

d3.mouse performs a little strange in mouse events. When the svg did not on the left of screen, if I use the zoom tool of browser, it can’t recognize the location of mouse correctly. It happens in IE9, chrome, safari, opera, only in firefox it works well.

I made a simple demo of that: http://walkpie.cnodejs.net/
You can review the demo and download the code in the demo page.

The core part of the demo:

<table>
<tr>
<td width="35%" style="background-color: steelblue;">This is Left.</td>
<td><div id="container"></div></td>
</tr>
</table>
var vis = d3.select("#container")
    .append("svg")
    .attr("width",600)
    .attr("height",400);

vis.append("rect")
    .attr("width",600)
    .attr("height", 400)
    .attr("style", "fill:none;stroke:red;");

var cl = vis.append("circle")
    .attr("cx", 50)
    .attr("cy", 50)
    .attr("r", 5);

vis.on("mousemove", function(){
    var cp = d3.mouse(this);
    cl.attr("cx", cp[0])
      .attr("cy", cp[1]);
});
@mbostock
Copy link
Member

mbostock commented Jun 6, 2012

Last time I looked, the bug is in browsers' implementation of getScreenCTM, and I'm not sure this is fixable in JavaScript.

@frogcherry
Copy link
Author

Thanks a lot for your reply so fast! I've tried many times, but failed. I'm such a freshman in JavaScript. ><~
Btw, it works well in Firefox.

@vogievetsky
Copy link

See #766

@lyuata
Copy link

lyuata commented Apr 22, 2014

Is the issue supposed to be fixed in d3.v3 ? I am still experiencing the same problem under Chrome.

@mbostock
Copy link
Member

No, this is a browser bug, and there is no explicit workaround in D3.

@mbostock
Copy link
Member

As far as I can tell, this has been fixed in current browsers. However, it is related to d3/d3-selection#67.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn’t working
Development

No branches or pull requests

4 participants