Simple task (SVG vs. Canvas) [closed]

此生再无相见时 提交于 2019-12-19 04:58:09

问题


I just want to make 200 clickable nodes (capture mouse events) which are connected by lines. Each node has some data associated with them in form of live data streams ( for simplicity assume CSVs) and clicking on node shows up the values plotted in a graph.

  • The area in which all these nodes and lines are there, should be zoom-able.

Even after googling a lot, I confused for something as simple as this SVG is more suited or Canvas. Moreover what libraries will be best for the purpose. Like for Canvas we have KineticJS (with HTML5) and for SVGs we have d3 and all.

Experts, Please suggest. Thanks a lot in advance.


回答1:


SVG is way better for that. Canvas has no mouse events, you would have use a picking technic.




回答2:


It depends. If you have complex visuals associated with each node, it would work much faster if you rasterize a node once, then clone and draw on canvas rather than use SVG. It can be done using Paper.js for example (and it has some support for mouse events). If your nodes are simple, say, simple rectangles or something, you can use SVG. Some browsers are more efficient with SVG than others. For example, IE9 has very efficient SVG support, so if you target particular browser, check out it's SVG drawing speed first.
BTW, Paper.js is particularly useful if you want to rotate, zoom, move objects and groups of objects etc. It has a pretty good support for that.



来源:https://stackoverflow.com/questions/12464788/simple-task-svg-vs-canvas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!