You can use d3 utilities just for data transformation. Here's an
example that uses d3.layout.stack() and renders with Underscore.js:
exposedata.com/canvas/stacked.html
Perhaps someone will create a chart class which renders to canvas.
http://bost.ocks.org/mike/chart/
D3 would never work this way; it doesn't abstract the rendering layer.
When you say append("element"), you are creating an element and adding
that to the DOM. That's it. It goes against the design to have an
operation that purports to create or modify DOM elements implicitly do
something else, like render to canvas. If you want that, you could try
a shim (see also [1]), but that's no guaranteed performance
improvement.
Since D3 does not hide the underlying representation, you are free to
do whatever you like, mixing and matching elements and rendering
systems. I frequently combine SVG, HTML and Canvas depending on what
I'm trying to visualize. Canvas is great if you need to render
hundreds of thousands elements, and you're willing to sacrifice the
data-join and transition abstractions. But in that case, you're
dropping down a layer of abstraction and making canvas calls (perhaps
in conjunction with scales and layouts, and in the future path
generators).
Mike
https://github.com/stepheneb/avalanche2d-js/blob/master/src/grapher.js
The performance is much faster than using SVG.
This is the specific commit where I switched to using a canvas overlay and when graphing 5000 points it sped up the graphing by
a factor of 4:
https://github.com/stepheneb/avalanche2d-js/commit/2f8ed4b52cba
You can run the demo here:
One caveat -- the code is somewhat messy and written very quickly before I understood more about D3. So use it as inspiration, but don't necessarily follow the exact patterns.
I am re-writing it now for another project so it can graph data from multiple streams at the same time and plan to fix the UI issues. I also need to make the whole grapher performant with 50,000 or more data points. The Canvas graphing is definitely fast enough but I need to more intelligently prune the amount of data rendered into SVG Path objects becasue they slow down a great deal when rendering a Path with large numbers of points.
>From a quick look I understand that the
>D3 flow is being intercepted and directed to a Canvas, which sits on
>top of the SVG graph. The questions I have next is how much is D3
>still doing in this layered scenario?
Checkout the demo and repository and play with it.
For example the graph has the axis re-scaling UI I implemented here:
If you are quick start the model running and then mousedown on a numeric label on the Y-axis and drag down while the model is running. The axis will re-scale (but you'll see some display bugs). You can slow the whole thing down by increasing the size ofthe "Desk Array" from 100x100 to 200x200. The UI for axis re-scaling is all D3.
I am using the same D3 scale objects for converting from data to screen coordinates.
Zooming and panning are NOT yet working while the real-time data are being plotted -- but this could be fixed by letting eventspass through the canvas to the underlying D3 SVG document.
When the plotting of real-time data is done the canvas is dropped under the SVG and the what you see is the D3 managed SVG document.