I've been trying to use d3.geo.bounds() by calculating the bounds for
each state and then finding the extrema of these bounds, but this
returns latitudes and longitudes, which I can't seem to decipher in
terms of pixels. I thought maybe .pointRadius() would help, but that
returns me a function. I also tried invoking path() on e.g. { "type":
"Point", "coordinates": [gbounds.left, gbounds.bottom] }, but this
gives me some strange path results.
I've also tried just plotting the map first and then using
jQuery.width/.height to find the dimensions of each polygon, but for
some reason Alaska has a ginormous bounding box (which the default
projection - AlbersUSA? - doesn't even try to include in the visible
projected area).
For now I'm just eyeballing the dimensions of the drawn map at scale 1
and using these hardcoded values in my code, but I'm wondering if
there's a Better Way.
Thanks in advance.
--
Yang Zhang
http://yz.mit.edu/
Also, use the albers, azimuthal, mercator, etc. examples in the git
repository to play with the parameters interactively.
Mike
I agree. We've been discussing it:
https://github.com/mbostock/d3/issues/341
Probably there will be a change to the d3.behavior.zoom that is not
strictly-backwards compatible, and which will provide more flexibility
in terms of restricting the viewable range and manually adjusting the
viewport.
Mike
When plotting real-time data I move this canvas object above the SVG content and plot lines there until the data-collection
stops. When stopped I move the canvas object behind the D3 SVG graph and draw the completed data set once with D3.
real-time graphing now uses a canvas overlay
https://github.com/stepheneb/avalanche2d-js/commit/2f8ed4b52cba
I am using the D3 scales to generate the points to plot into the Canvas object:
https://github.com/stepheneb/avalanche2d-js/blob/master/src/grapher.js#L150
This is still a rough first hack ... but I think it works well for my purposes.
Compared to plotting 5000 points into SVG using D3 this is now between 5 and 15x faster.
Latest benchmarks:
browser model steps/s for 5000 model steps
--------------------------------------------------------------
Chrome 14.0.835.186 1400
Safari 5.1.1 (6534.51.22) 383
FireFox 7.0.1 191 **
I think this now represents well the performance capabilities of modern browsers.
To get higher performance would require re-coding the model and visualization to run on the GPU using webgl -- that's much
harder.
** There is a Canvas bug in FireFox I am looking for a work-around for
Executing the canvas stroke() command to render the line onto the canvas drawing surface causes the canvas drawing to
disappear.
gctx.stroke();
https://github.com/stepheneb/avalanche2d-js/blob/master/src/grapher.js#L159
The canvas itself is still layered above the SVG elements as show by the presence of the red border.
And the app itself is here: http://stepheneb.github.com/avalanche2d-js/avalanche2d.html
There is discussion about integrating canvas a little better into the
svg language, but there is talk about all sorts of things, and it
would be a ways off yet before browsers support the ideas and syntax
that were recently proposed, so keep up the good work.
Jon
A potential extents implementation for d3.behavior.zoom:
https://github.com/mbostock/d3/pull/345
I imagine we can make it more flexible, but hopefully that'll get things
started.
--
Jason Davies, http://www.jasondavies.com/
I just updated avalanche2d-js so that the graph drawn into the canvas overlay during real-time data collection re-scales properly when the axes are changed while graphing.
http://stepheneb.github.com/avalanche2d-js/avalanche2d.html
Because of how D3 is designed this was quite easy.
In my Canvas drawing benchmark on Chrome I can draw a Canvas line with 5000 segments (1 moveTo, the rest lineTo) in about 6ms -- so I always just draw the Canvas line even when not doing real-time graphing and the Canvas is layer under the SVG content.
Here's the 14 lines of code:
update real-time canvas graph when scales change
https://github.com/stepheneb/avalanche2d-js/commit/32c826955575
The speed up using Canvas when plotting large numbers of points is quite remarkable.
If you try avalanche2d-js in Chrome you'll need to change the Desk Array Size from 100x100 to 200x200 just to keep the graph plotting long enough to try and change a scale.
The graph supports panning/translation by dragging in the plot canvas proper ... but I haven't modified the canvas overlay feature to pass mouse events through yet so this feature won't work while graphing real-time data.
I made a large set of changes in the last week to make both the scheduling of the computational model and and canvas heat map and the rendering of the graph run faster. Using Canvas for the real-time graphing was both easy and a huge performance increase.
I created this graph showing the change in performance. The Canvas change occurred on Oct 19.
https://img.skitch.com/20111023-q8rkqfkhynifqhtj6yefm86aaw.jpg
Note: the Y-axis that measures performance is a log scale.
** it feels pretty silly sharing a jpg image of a graph on this list ;-)