This is a good start but it glosses over the hardest part of making React work with D3, which is animations. Most animations you want to do with D3 don't fall neatly into categories you can use with CSS animation (namely updating paths and entering / updating / exiting animations).<p>React as an ecosystem is pretty fantastic but the React animation story is still pretty terrible unfortunately. "Portals" / "reparenting" is a majorly hacky way of getting an element from one part of the DOM to another, and even React Motion, which solves a few of the animation gripes, is hard to use, slow, and brittle in my experience. There just isn't a good substitute for the enter-update-exit selections that make up the core of D3.<p>My usual workflow is to get as much DOM building done in React as I can, with D3 filling out the tricky bits. D3's lifecycles and direct DOM manipulation are much more complicated to reason about than React, on the whole.
Sorry, I don't get it. The code in any of the given example comparisons has no less obvious complexity and just removes the abstraction that writes the SVG nodes for you with having to explicitly write them in your JS which I similarly have never understood why we're intent on going back to.<p>Different for the sake of different is fine, but "preferable" is a bold statement that appears to have no evidence.
Hybrid approach:<p>> let React do all the migraine-inducing heavy lifting to figure out what to enter and exit, and have D3 take care of the updates.<p><a href="https://medium.com/@sxywu/on-d3-react-and-a-little-bit-of-flux-88a226f328f3#.h143joihp" rel="nofollow">https://medium.com/@sxywu/on-d3-react-and-a-little-bit-of-fl...</a>
Love this - awesome work.<p>Wrote an article on this concept last year: <a href="http://formidable.com/blog/2015/05/21/react-d3-layouts/" rel="nofollow">http://formidable.com/blog/2015/05/21/react-d3-layouts/</a><p>and spoke about it at Reactive2015: <a href="https://www.youtube.com/watch?v=n8TwLWsR40Y" rel="nofollow">https://www.youtube.com/watch?v=n8TwLWsR40Y</a><p>Have been doing data visualizations like this ever since, it works. Yes, the hardest part is animation, which we had to address, as well as the axis components and other higher order functionality that builds on d3 itself:<p><a href="https://github.com/FormidableLabs/victory-animation" rel="nofollow">https://github.com/FormidableLabs/victory-animation</a><p><a href="http://formidable.com/open-source/victory/docs/victory-axis/" rel="nofollow">http://formidable.com/open-source/victory/docs/victory-axis/</a>
My team and I have been using and finding success with such a pattern for a couple of years now.<p>As others are alluding to, transitions are not currently so easy to express with React alone. We wrote and recently open-sourced a React component that aims to encapsulate the power and simplicity of d3 transitions (feedback & contributions welcome): <a href="https://github.com/dechov/join-transition/" rel="nofollow">https://github.com/dechov/join-transition/</a>
>><i>There are some pieces of d3 that I would love to use but aren't easily portable. For example, d3-drag and d3-zoom smooth over a lot of the quirks you'd have to deal with when implementing dragging and zooming, but they're only designed to work with d3 selections [...] Ideally we could decouple these libraries from selections, but it might also be possible to mock the selection interface they expect while still using React.</i><p>According to the changelog for the recently released version 4.0.0 of D3.js by Mike Bostock[1], one of the big shifts is for D3 v4.0.0 to be "composed of many small libraries that"[2] can be used independently. So the author of D4.js can now more easily examine Bostock's refactored code for Zoom and Drag as they please.<p>[1] <a href="https://github.com/d3/d3/blob/master/CHANGES.md" rel="nofollow">https://github.com/d3/d3/blob/master/CHANGES.md</a><p>[2] <a href="https://github.com/d3/d3/releases/tag/v4.0.0" rel="nofollow">https://github.com/d3/d3/releases/tag/v4.0.0</a>
I find that D3 is great, but it needs an abstraction for the general update pattern (<a href="https://bl.ocks.org/mbostock/3808218" rel="nofollow">https://bl.ocks.org/mbostock/3808218</a>).<p>I did that! One function that receives actions for update, create, delete, etc. Now my code is easier to read. Check the function gupChildren (AKA: General update pattern for child nodes of a selection) in my code, and feel free to use it: <a href="https://bitbucket.org/aurelito/sandro-lib/src/83b81c4b55684866fbab50ff98088822b1d42410/src/sandro/nadaMas/d3.js?at=default&fileviewer=file-view-default" rel="nofollow">https://bitbucket.org/aurelito/sandro-lib/src/83b81c4b556848...</a><p>At last, unless you understand what you are doing, use selectAll and no select.<p>Cheers!
Shameless plug: I have been proposing this approach for long. I found that the missing piece is how to generate the actual geometric information starting from data, hence I wrote a library to this effect <a href="https://github.com/andreaferretti/paths-js" rel="nofollow">https://github.com/andreaferretti/paths-js</a><p>For the animations, it is often just a matter of continuosly updating the state of some component, something that I did in this mixin <a href="https://github.com/andreaferretti/paths-js-react-demo/blob/master/js/animate.jsx" rel="nofollow">https://github.com/andreaferretti/paths-js-react-demo/blob/m...</a>
I've done the opposite: use d3 to provide React-like semantics.<p>- Basically the data fetches get pushed to a lightweight queue/topic system in the browser (using publish.js).<p>- Each part of the page listens for messages it cares about and updates the page accordingly.<p>There is still some of the d3 plumbing (I must specify how updates differ from mere element creations, and handle the exits). But I still get a nice decoupling between the different parts of my app. Coupled with browserify, this ends up with semantics not unlike Erlang (I even named the listener method "receive" and it acts on patterns of messages).
Intelligently-optimized JS animations are generally more performant than CSS ones by an order of magnitude. See Greensock for relevant examples. Side note, your examples don't assign keys to your array-mapped paths, which will emit warnings.
@joelburget, btw the "demos" link leads to a 404.<p>( <a href="https://github.com/joelburget/d4/demo" rel="nofollow">https://github.com/joelburget/d4/demo</a> )
Very cool.. My only question is.. Is this "D4.js" a full feature replacement for D3.js? Could be a bit misleading. Might want to have a new name for it? Thoughts?