D3 v4.0.0 released
github.com
github.com
Definitely looking forward to try the new release.
D3 is good if your visualization benefits from interactivity, either with dynamic data adjustment or rich tooltips. But static visualizations are important too. (I recently restructured my workflow so I can output static images and interactive charts with the same code, which makes it the best of both worlds.)
To convert D3 to SVG, I believe all you need is a helper function but that is not my area of expertise.
Also there is ggvis https://github.com/rstudio/ggvis which is nice if you are already using ggplot2.
It's pretty easy to use. I don't do interactive so I just find it easier to export EPS files from R.
output.append('div').text(svg.node().outerHTML);
You can see it in action here:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="250" height="250"><rect x="25" y="25" width="200" height="200" fill="lime" stroke-width="4" stroke="pink"></rect><circle cx="125" cy="125" r="75" fill="orange"></circle><polyline points="50,125 50,200 200,200 200,125" stroke="red" stroke-width="4" fill="none"></polyline><path d="M50 125 c 25 -60 50 -60 75 0 c 25 60 50 60 75 0" fill="none" stroke-width="4" stroke="white"></path><text x="125" y="125" font-family="monospace" font-size="20" text-anchor="middle" fill="black">Hello world</text></svg>
A simple
d3.select('svg').node().outerHTML
would do the trick.
(You can use the same trick as in console-save to generate a download URL though.)
Currently, I am trying to make a dashboard for visualizing many different data sources with WebSockets and Chartjs but it's still not quite ideal-- there's a bit of lag, and sending too much data via JSON really slows things down. If anyone has solved that this problem I would appreciate it if they told me how they did it.
0. http://epochjs.github.io/epoch/
On ios, the performance wasnt the best though
it was replaced with straight d3 i think, or maybe something rendering on canvas
Keep in mind, D3 isn't a graphing library. It's a data binding library.
I know you probably know this, but for other people's sake - NVD3 requires the D3 library to work. It's therefore probably quite a good entry point into D3 - less complexity, but the same underlying code.
1) What's your opinion on the apparent case that the bulk of changes come from you, as society promotes teamwork so much? Is it a case of 'small team efficency'? (Btw. I know of others' contributions too, and reliance on Rollup, ColorBrewer, matplotlib/Viridis etc.)
2) What kept you going? It's probably at least a person-year of work just on your side that's not paid for by companies, not to mention some kind of startup bet. Have you alternatively toyed with the idea of starting a value-added layer, since so many for-profit organizations benefit from your work?
3) While it changes the API, and most everything is rewritten, it's IMO a conservative upgrade in that it doesn't steer away from familiar concepts and structure. It still does DOM binding, transitions, layout etc. fairly similarly. Have you considered much more disruptive departures? As an example, React's DOM diffing is more radically different from D3 selections than the change from D3 3.* to 4.* or the Grammar of Graphics as an API concept is more radically different from D3 than the 3.* -> 4.0 API changes. Or something like moving away from the 'functional objects' concept in favor of curried, fixed-argument pure functions, perhaps prefaced with the familiar chaining API would have been a large change (these are mostly examples rather than wishlist). What were YOUR ideas, had you wanted more disruptive changes, or 'D4'?
You might be interested in Vega and Vega lite if you want to go declarative.
Most external contributions to D3 tend to be either bug fixes or new features. Bug fixes are often merged quickly, but new features require careful assessment. Each addition to the API has a complexity cost: it makes the library bigger; it has to be documented; it may instigate support questions and issues; it may have ripple effects on the development of other features. I’ve long taken Josh Bloch’s advice to heart and try to maximize the “power-to-weight” ratio of my APIs, and to try to keep them as small as possible while still expressive. Part of the goal of 4.0’s modularity is to make it easier for others to release their new features as standalone libraries that they can use with D3, rather than it needing to be part of “core”. There isn’t a “core” D3 anymore; there’s just a default bundle. (And if we ship a web-based tool for rolling your own bundle, the barrier will be even lower for plugins.)
2. Yes, I’ve been working on D3 full-time for the last year, since leaving The New York Times. Partly I am playing catchup. D3 has been more popular than I could have imagined, and I want to make sure that it’s as good as I can make it. I loved working for the NYT (and I miss my colleagues dearly), but it was hard to think deeply about the design of D3 when you’re on deadline. I am interested in finding a way to make D3 development self-sustaining financially, as I cannot do this for free indefinitely. Prior to launch today, I have been focused on shipping 4.0; now that’s it’s released, I am thinking more about what’s next.
3. Yes, it’s not a huge departure despite the many changes and the new implementation. I hope that’s a testament to the strength of the original design… or perhaps it’s just my confidence in it. (There is more different between Protovis and D3 than between D3 3.x and 4.0.) There is not only one right tool for visualization; the right tool depends on the application, such as whether you’re designing bespoke custom news graphics, exploring a dataset of the first time, or doing realtime monitoring of your network. D3 is intended to be the lowest layer of visualization tools: the visualization “kernel”, or “standard library”. You can build higher-level abstractions on top of D3 that is more tailored to your application. One of the areas I am considering exploring is higher-level abstraction, perhaps more along the lines of Grammar of Graphics.
Really excited about this release. It seems like nothing has been left untouched with major changes to everything from selections to layout generations and the modularisation of the entire lib (think lodash).
There are major namespace changes with basically everything being flattened ( d3.geom.voronoi -> d3.voronoi) and many of the typical patterns will have to be relearned (major changes to selections), so I don't see upgrading any existing projects and I may have to hold off on using 4.0 in new projects until I actually understand what has happened.
Favourite thing so far has to be the changes to selections, which I think will make things a lot clearer to newer users: https://github.com/d3/d3/blob/master/CHANGES.md#selections-d...
The renames (like d3.voronoi instead of d3.geom.voronoi) are superficial changes, so although it might seem disruptive, it should be pretty easy to update your code and habits. At least, I haven’t found it difficult… The more design-y changes, like the new d3.stack and d3.treemap, require thought to migrate existing code. But the new designs are much better, so I hope you find the effort worthwhile.
Thank you for working so hard on this Mike!
My day job is building big data visualization applications with lots of D3 and React, so I have a lot of opinions about this.
If you can get away with using CSS transitions or react-motion in your app, and you don't need D3's enter-update-exit selections, I feel React's declarative syntax is a much simpler mental model and is consistent with how the rest of my app works. But anything complex you'll need to drop out of React and build your DOM in D3, which has a very different notion of element lifecycles than React and doesn't allow you to reuse any of your other React components.
The most interesting aspect, which applies to apps beyond React, is likely to be respecting the D3 selections API[1], if needed. If you're already familiar with the ins and outs of selections, then I wouldn't expect any particular problems.
[1] https://github.com/d3/d3/blob/master/API.md#selections-d3-se...
It mostly uses React to interface with DOM and d3 v4.0 for the math, etc.
Not being too familiar with D3, what would I get by adopting it? I would hope for higher level primitives, but the API seems imperative and stateful, which doesn't seem like a good fit with React. Would I end up duplicating and syncing my existing app model state into D3 state?
Example at http://flowgear.me/s/1Ae7Pso if you're interested.
One thing to watch out for is that there are some svg object attributes (and some objects) that aren't declared in react.
https://medium.com/@mbostock/introducing-d3-scale-61980c5154...
https://medium.com/@mbostock/introducing-d3-shape-73f8367e6d...
I tend to go in the other direction, I use d3 rather then react for the rest of the page, so I don't have any issues with integration.
http://bl.ocks.org/cpapazian/6228888157c39be85e9c (please excuse the coffeescript)
However, it looks like the work to modularize D3 will make it much, much easier to have the render function produce SVG markup directly.
Code samples in the book still use D3 v3, but my most recent experiments have been in v4. There's a lot of content in there on animation and transitions, which seems like the hard part.
Currently figuring out how to do mass 10k+ element animations. Adding it to the book when I figure it out.
1. use D3's low-level components to calculate layouts then render directly as React components, typically SVG elements, e.x. https://jsfiddle.net/g3o6t9xh/1/
2. use React's component lifecycle methods to grab the component's DOM element and render full D3 visualizations, e.x. https://jsfiddle.net/6xw2wvbc/2/
A simple example; the svg elements on this page https://ig.ft.com/sites/brexit-polling/
We do a lot of charts at work to visualize electricity consumption and are currently thinking about how to rewrite the js we've accumulated over the years. I've found some attempts at doing server-side rendering but nothing really compelling for now...
D3 is a well thought out library to do interactive visualizations in the browser and having an easy way to do svg exports (for things like automated emails) would be a big plus. Doing screenshots through selenium ain't always so pleasant ;)
Achieved this by (admittedly slightly clunky way) of sucking the SVG out of the chart and sending it to the server via ajax. Server intercepts SVG and passes it to inkscape which does pretty good command line svg -> pdf... then, sends back completed PDF.
One gotcha is that you won't get any CSS this way, so all styling has to be done via SVG props.
There actually is a way to bake stylesheets directly into the SVG in a way that at least Inkscape can read, but it's tricky. We're successfully doing this in a graphing library tuned for genetic data that's built on top of d3 called LocusZoom.
The first step is to get the content of the stylesheet into a string. We do that here with a CORS request in case the stylesheet is being loaded over a CDN, as javascript won't be able to access the content of CDN-loaded stylesheets from document.styleSheets:
https://github.com/statgen/locuszoom/blob/v0.4.0/assets/js/a...
Since the stylesheet doesn't change once the page is loaded this only needs to happen once. From there, in our case, we have a dynamic/interactive SVG plot so the download needs to bundle up the current state of the SVG on request. Here's the method that does that:
https://github.com/statgen/locuszoom/blob/v0.4.0/assets/js/a...
Other than what no doubt looks familiar for pulling the raw SVG markup into a string we also insert a tag right after the opening <svg> tag that looks like this:
"<style type=\"text/css\"><![CDATA[ " + this.css_string + " ]]></style>"
Where this.css_string is our stylesheet content. We then base64 encode the string and stick in the href of an <a> tag styled to look like a download button as seen here:
https://github.com/statgen/locuszoom/blob/v0.4.0/assets/js/a...
The end result is a download SVG link/button that is 100% client-side with our chosen stylesheet embedded.
Now, I have noticed that some styles defined in the stylesheet are valid in the browser but fail in InkScape and other SVG viewers. A prime example would be setting a stroke or fill to "transparent". InkScape doesn't interpret this properly and you can end up with solid black, just about the exact opposite of transparent. Keeping this in mind I stick to defining explicit "fill-opacity" and "stroke-opacity" values in the stylesheet for SVG elements and everything plays nice.
A working demo of this can be seen here: http://statgen.github.io/locuszoom/plot_builder.html
Another possibility is to use wkhtmlpdf to generate PDF: https://github.com/wkhtmltopdf/wkhtmltopdf
$29/month gets you up to 5,000 renders, so it's a very inexpensive option (compared to building and running your own server-side rendering tech).
https://www.npmjs.com/package/d3
One minor caution is to avoid using CSS to style the SVG, because won't convert to PNG properly.
Use ImageMagick or the svg2png (PhantomJS based) package to convert.
2. Would it be possible to add jsdoc comments for autocompletion?
3. Are the polyfills for Map and Set still necessary now that we have that in es2015?
4. Why is the lib so heavy on argument overloads?
5. Are there any code style restrictions? I often saw loops and conditions without curly brackets and alike.
6. Are there any fields you'd need support in for maintaining or reworking the library?
I really like D3.js although I haven't found an application for me yet. I find it hard to get/update the date from a none standard REST endpoint and display them, especially if they are kind of multichanneled, like working times of multiple users unordered.
And the detailed change list: https://github.com/d3/d3/blob/master/CHANGES.md
I will update my tutorials and examples (and probably write new tutorials) in the near future, and I expect others will, too. But as I now have thousands of examples, I didn’t want to hold the release on updating all of them. My newer examples use 4.0 already, and I’ll be going through the others in the coming weeks.
I know many tutorials reference your examples and it might create more confusion if they are updated in place.
I suppose it depends on how much you want to keep supporting v3, but I'd argue its worth keeping the old knowledge base intact for a while.
I've tried doing this with v4 beta, with strange behaviours :)
But it might be best to just migrate to 4.0. I know the changelist is long, but it might not be as hard as you think to migrate. And you can always send your questions to the d3-js Google group or d3.js on Stack Overflow and I’ll try to help.
We're probably at about 60% of the library upgraded/split-out but we've yet to tackle the more tricky changes like d3-selection.
It's harder to get interaction done with canvas compared to SVG, but for large graphs the performance gains are huge. Curious to dive into the other new features.
Thanks for this incredible piece of software mbostock!
* New pretty continuous color schemes (viridis, rainbow, ColorBrewer)
* New axes that are easier to use.
* Vastly improved circle-packing layout.
* More stable, extensible force layout.
* Cleaner implementation of immutable selections & transitions.
And a ton of other stuff. Taken overall, it feels like a big step forward in robustness and cleanliness. And I’m hopeful that it’ll be easier for folks to develop more D3 modules.
These are not tutorials, but working examples with some introductory texts. They are very helpful for diving into D3.