Cool!
> The problem I have when trying to plot 100s of svg paths, is however
> that I don't get the same kind of "mouseover sensitivity" as NYT's
> Flash version. (More so in Firefox 4 than Chrome.)
>
> To plot the lines I use this simple code:
>
> var line = d3.svg.line()
> .x(function(d) { return xScale(d.x); })
> .y(function(d) { return yScale(d.y); })
> .interpolate("linear");
>
> paths
> .enter().append("svg:path")
> .attr("class","path")
> .attr("d", function(d) {
> return line(d.data)
> })
> .attr("stroke",#666")
> .attr("fill","none")
> .attr("stroke-width", "1")
> .on("mouseover", mouseover);
>
>
> Perhaps I would get better results with some kind of "scale
> interaction technique"?
> http://mbostock.github.com/protovis/docs/invert.html
>
> Any ideas on how to improve the sensitivity of the mouseover trigger?
Instead of using "mouseover", you might want to listen for "mousemove"
on the whole chart instead, and compute the nearest path for each event.
This was called "pointing" in Protovis. This seems to be what the NYT
version is doing, because you can move the mouse in between paths (e.g.
at the top where they're further apart) and you can see it toggle
between whichever path is closest to the mouse at the time.
--
Jason Davies, http://www.jasondavies.com/
https://github.com/mbostock/d3/blob/master/src/geom/quadtree.js
You can even build a Voronoi diagram out of the points and then use
that, as described in this CHI '05 paper on "bubble cursors":
http://www.dgp.toronto.edu/papers/tgrossman_CHI2005.pdf
Mike
If you are on Safari, yes. I added a brief section about this to
https://github.com/mbostock/d3/wiki/FAQ just recently. Here it is in
case someone knows of a more elegant solution:
> You need to add a background <rect> element that fills the area of
> interest e.g. with fill="#fff". In Safari, mouse events will only fire
> on <svg> if the mouse is over a child element.
http://greenworld.org/chrome-test.svg
Sean
On Thu, Jul 21, 2011 at 10:32:27AM -0400, Sean Montague wrote:
> Thank you Jason, but I'm not sure this addresses the issue. I could
> be wrong. Here is a link to the svg may that lacks in performance on
> Chrome. It works well on FF, but still not as well as the old ASV
> plugin for IE. I can't run IE9 yet.
>
> http://greenworld.org/chrome-test.svg
Ah, this isn't quite the same issue as the one I was referring to, but
it's related. :) I was talking about mouseover not firing for <svg>.
In your case, mouseover is only firing for a filled or stroked part of
an element. Do you want it to fire for non-stroked parts of elements
i.e. the non-dashed parts of your paths?
I suppose you could add a layer of non-dashed transparent paths
underneath. This way you could also use a slightly thicker path to
increase the mouseover areas.
Thanks.
Sean
Which version of Chrome? Seems to work fine in 14 (dev) for me, unless
I'm not checking the right paths...
Thanks!
Sean
Thanks!
Sean
On 07/21/2011 11:35 AM, Jason Davies wrote: