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

svg #66

Closed
forresto opened this issue Jan 4, 2014 · 6 comments
Closed

svg #66

forresto opened this issue Jan 4, 2014 · 6 comments

Comments

@forresto
Copy link
Collaborator

forresto commented Jan 4, 2014

prototyping: http://forresto.github.io/prototyping/react/ ~ forresto/dataflow-prototyping#2

React's virtual dom will make it easy to render svg on the server, if we ever need that for previews, etc: https://github.com/facebook/react-page/

zuizui

@forresto
Copy link
Collaborator Author

forresto commented Jan 4, 2014

fontawesome + svg: http://stackoverflow.com/a/19892061/592125

g.append('text')
  .attr('text-anchor', 'middle')
  .attr('dominant-baseline', 'central')
  .attr('font-family', 'FontAwesome')
  .attr('font-size', '20px')
  .text(function(d) { return ICON_UNICODE[d.nodeType]; });

The attrs could be in css. The important part is the ICON_UNICODE object.

a = fontawesome yml -> to json -> this js:

var o = {}; 
a.icons.forEach(function (icon) {
  o[icon.id] = icon.unicode;
});
copy( JSON.stringify(o) );

output: https://gist.github.com/forresto/8254791

@forresto forresto mentioned this issue Jan 7, 2014
@forresto
Copy link
Collaborator Author

forresto commented Jan 8, 2014

Added icons and zoom breakpoints to change design: http://forresto.github.io/prototyping/react/

SVG certainly makes some things quite nice. Aligning the icon in the node, for example. Also, circles.

Unfortunately transform changes, which make zooming and infinite canvas really easy, always cause expensive layout / paint:

screen shot 2014-01-08 at 1 42 18 pm
70ms zoom, 40ms pan 👎 (but IE 9 does accelerated svg??? :trollface:)

Even though it makes the framerate slow, it is steady, so it doesn't feel super janky. But it doesn't feel like 60fps.

Could maybe work around by using transform3d on the parent div layer while the movement is happening, then swapping that to the transform on the SVG g at the end of the movement. Like what we have now. Would lose the vector feel while zooming though.

@forresto
Copy link
Collaborator Author

forresto commented Jan 9, 2014

Figured out that svg transform is much faster without css, as that's what's forcing the purple layout bars above. Here's a similar demo, fast without css. I don't think it is worth ditching CSS now, though (I went down that road a bit). If we did that (converting all styling to attributes, passing styles through) it would be almost as much work to go all-2d canvas.

Dragging a node works, is fast:
svg-drag-fast

Most of the frame budget is yellow, because React forces anything that affects stuff elsewhere in the tree (moving node changes its edges) to be rerendered by the common ancestor. In this case, it seems like it would be faster to have a listener on the edge (like we have in Polymer). OTOH, the pattern is clean.

@forresto
Copy link
Collaborator Author

Unexpected: Safari and Firefox feel way faster than Chrome with zooming and panning. There must be a bug causing all those purple layout invalidations.

@plievone
Copy link

Unexpected: Safari and Firefox feel way faster than Chrome with zooming and panning. There must be a bug causing all those purple layout invalidations.

Very interesting experiments! There might be an issue in Chrome where simply listening for wheel events disables some rendering optimizations. If you want to explore it further, one can build the current React master that doesn't listen for all events by default, but only the needed ones, and then compare performance if you declare an onWheel handler or not.

@forresto
Copy link
Collaborator Author

For the layout invalidations I made a reduced case and bug report to see what the Chromium folks say.

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

2 participants