295 karma · joined August 1, 2014
But big picture, this write-up isn't tied to the current visualization! It's more focused on exploring _how_ a visual representation could help our understanding of codebases. There are tons of jumping off points, including different vizes!
There's also an interactive tool to check out your own repos and a GitHub Action if you want to integrate a diagram into a README.
https://twitter.com/misscrisp/status/1202792895448662016
It's really interesting how different authors play with the rhythm of their sentences - one of the best ones on here is The Raven, with very short sentences interspersed with longer ones.
https://wattenberger.com/blog/react-and-d3
I generally like to stick with React for DOM manipulation, and use D3 like a utility library.
https://wattenberger.com/blog/react-and-d3
I've done a lot of work that uses d3 within a JS framework (React, Vue, Svelte, & Angular), and the key is to understand 1. how to create shapes in plain SVG, and 2. how to use the parts of d3 that don't do DOM manipulation. I've found the least-hacky way is to handle DOM manipulation with the framework, and use d3 for things like data manipulation, creating SVG path strings, creating scales to map from the data domain to the visual properties, etc.
You can get pretty far before that happens - for example, here's a post representing every country in SVG. https://wattenberger.com/blog/d3#maps-and-globes
I added a 30ms debounce, just to help out a bit. I'm seeing some serious jank in Firefox, which smells like the beginning of a rabbit hole. Hopefully I'll find some time to dig in there.
This is due to the preserveAspectRatio property on the svg element. Its default value is `meet`, which scales the svg with three rules:
- aspect ratio is preserved - the entire viewBox is visible within the viewport - the viewBox is scaled up as much as possible, while still meeting the other criteria
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/p...
If you fiddle with the attribute value in the Dev Tools, try setting it to `xMinYMid` or `none` to see if that gives you a good sense of how it works. I'm worried that it might just confuse if not explained well :)
I also specifically didn't want to go into the data join patterns for two main reasons:
1. there are lots of other articles that talk about it in depth, and 2. these days, I largely don't use it at all.
This is partially why I wanted to write this up, because the DOM manipulation parts can seem like an integral part of D3, but there are really only 2 modules devoted to it. I mostly use D3 for its utility methods, and a JS framework like React to handle all of the rendering, and I really want other people to be able to discover those functions without first "learning d3".
If you're curious, the first chapter is free to download and gives a good sense of the flow:
all examples on Observable are up-to-date, so searching on here could be useful:
and if you find a bl.ock that you really want to port, this changelog could be helpful:
https://github.com/d3/d3/blob/master/CHANGES.md#changes-in-d...
most of the changes are simple name changes that put the methods directly on `d3`: eg. from `d3.scale.linear()` to `d3.scaleLinear()`
https://bost.ocks.org/mike/join/
I personally usually am working in a React app, so I would use that to render (and update) the chart.
However, that's a pretty complicated example to start with! You might be better off using one of the higher-level libraries, like this one:
https://apexcharts.com/javascript-chart-demos/candlestick-ch...
There are a ton to choose from (just google `js candlestick chart`), and they can be pretty customizeable.
To give you a bit of context, the _large_ majority of people buy the advanced package (which really surprised me). The advanced package really just tries to bring all of your new knowledge together, going over d3 + React and d3 + Angular. It also has detailed walkthroughs of 3 complex data vizes, which could be really helpful. But both versions give you a great foundation to build off of.
This is largely why I wanted to write a post like this - often "using d3.js" is what we think we need to do, but I wanted to show that most of the API is just utility functions. Here are the two modules devoted to manipulating the DOM:
https://wattenberger.com/blog/d3#manipulating-the-dom
I recommend (and follow) that you render elements like you normally would, and use things like d3 scales or d3.line() to convert your data into the physical aspects that are needed. I find it really hacky to do it any other way. I want to explore more, but I did a quick test to see which is more performant (letting React render a scatter plot, or letting d3 render a scatter plot), and pure React was 4x faster:
https://twitter.com/Wattenberger/status/1123413424678027265
Of course, this was just one example, but it agrees with my hypothesis.
I do have a whole chapter devoted to d3 + React (and one on d3 + Angular) that might be worth checking out. I think it largely comes down to understanding your tools and being able to pick the parts of d3 that will be most useful to you.