D3.js Flashcards

1
Q

What’s the basic approach to add a bunch of divs based on an array of data?

A

d3.select(‘body’).selectAll(‘div’).data(someData).enter().append(‘div’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

If you’re adding elements to a selection with append or insert, how can you add a class?

A

.attr(‘class’, ‘my-class’) or else .attr(‘class’, d => d.className) // if data has className as a property.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

If you append an ‘svg’ and then append a ‘rect’, how can you now append a bunch of circles to ‘svg’ so they aren’t placed inside of ‘rect’?

A

Create a new selection. d3.select(‘svg’).selectAll(‘circle’).data(…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does d3.scaleLinear() work?

A

var xScale = d3.scaleLinear().domain( [ dataLow,dataHigh ] ).range( [ renderLow, renderHigh ] )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How could you fill up the horizontal space in a bar chart (assuming vertical space mapped to the data)?

A

Use d3.scaleBand() along with domain, range, and optional padding.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What ordinal scales does d3 provide?

A

scaleOrdinal, scaleBand, scalePoint, and category scales (that work with scaleOrdinal for colors)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly