3 ms·
It's the same as react but with a chaining style dsl instead of JSX. Rather than mounting a component, you do a selection, then give it some data and define tra
by dsego 6y ago
It's the same as react but with a chaining style dsl instead of JSX. Rather than mounting a component, you do a selection, then give it some data and define transformations, ie how to render the data. D3 will look at the current DOM, do a diffing on data similar to React and see which changes need to be made to update the DOM.
A quick example (I haven't done d3 in a few months so maybe I got it wrong):
const drawBars = (plot, records) =>
plot.selectAll('rect.bar')
.data(records)
.join('rect')
.attr('class', 'bar')
.attr('height', d => d.value)
drawBars(d3.select('#plot'), records)
// same in React
const Bars = ({ records }) => {
return (
<>
{ records.map(d => (
<rect className="bar" height={d.value} />
)) }
</>
)
}
ReactDOM.render(
<Bars records={records} />,
document.getElementById('#plot')
)
- purplecats 6y agothanks i took a look at your code and it's making a lot more sense now. its kinda of like react with a different dsl. realizing that d3 stood for something something document, and that select/selectAll were basically querySelector functions made this much easier to consume. thanks for your input, i just finished all dozen of her in depth blogs (not linked) and it was really interesting. I can't wait to use this now.