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

Question: Create Alternate C3 Rendering Pipeline Using Raster Canvas #1318

Closed
cnatale opened this issue Aug 14, 2015 · 6 comments
Closed

Question: Create Alternate C3 Rendering Pipeline Using Raster Canvas #1318

cnatale opened this issue Aug 14, 2015 · 6 comments

Comments

@cnatale
Copy link

cnatale commented Aug 14, 2015

I'm working on a project that requires generating a lot of data points (100k+). Our current implementation uses C3. SVG is clearly the bottleneck, so we are exploring how best to replace the SVG rendering with canvas.

After looking through C3's source, it seems like the generation of data points in SVG format using generateDraw[name of graph type], and the actual rendering with redraw[name of graph type] methods are modular in a way that would lend itself to adding an alternate raster Canvas methods. Mouse events would need to be handled differently, but this doesn't seem insurmountable.

My question is, can anyone with more experience in the code base advise if this is a foolhardy approach for reasons I'm not considering? If I make these additions, would this be something people would be interested for me to refactor to the point where it's clean enough to offer as a pull request? Thanks.

@aendra-rininsland
Copy link
Member

Wow, interesting. C3 uses D3 for everything, which is entirely SVG. So you'd likely need a library to abstract the rendering in a way similar to D3 (does such a thing exist?).

I admittedly have zero experience in Canvas, so I'm not very helpful, but that's a crazy-cool idea. I wonder if you could render SVG in a virtual DOM à la React and then use Canvg to convert to Canvas like SVG Crowbar does, and whether this would be any better for performance?

@aendra-rininsland
Copy link
Member

Actually, D3 can apparently be used with Canvas. Who'd've thunk? https://bocoup.com/weblog/d3js-and-canvas/

@cnatale
Copy link
Author

cnatale commented Aug 14, 2015

Yeah, D3 doesn't inherently require using SVG. It's a misconception. It does have SVG helper methods, but the actual generation of SVG elements always occurs within the enter() handlers and whatnot instead of the core library.

EDIT: Actually it looks like I'm wrong here about how enter() works. I assumed it was building its own model, but all the info I can find suggests it is just using a list of html elements as its model. The first method mentioned in the bocoup article would work, but it's a pretty big divergence since all of the current methods are using the enter() approach to update the model/elements.

@cnatale
Copy link
Author

cnatale commented Oct 19, 2015

FYI, I've implemented a subset of C3's functionality using Canvas rendering, and created a pull request: https://github.com/cnatale/c3

More info is available here: #1436

Performance improvements have been very impressive. My company's QA is still running tests, but we're seeing an increase in the number of data points a graph can display of anywhere from a factor of 10-100. Raster rendering also greatly cuts down on memory footprint, since the graph doesn't need to keep around all the SVG elements representing graph segments, or the vertical strips used for mouseover detection.

Note that animations are not currently implemented (although hover highlighting is), so if you need animated transitions definitely stick with the SVG version for now. Also this pull request is for version 0.4.8, which is a few versions back from head as of the time of writing. The only file in the fork with the canvas update is the actual c3.js, not the other compressed c3 files in the directory.

@buremba
Copy link

buremba commented Oct 25, 2015

💯

@michaelrodov
Copy link

looks like the issue is closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants