4.3 Task 7 Review
4.3.1 From Day 18
7-1. You cannot use the function of
max
by calling itself. You have to calld3
first, just like when you are usingscaleLinear()
. This is because bothscaleLinear()
andmax()
ared3
functions or methods.7-5.
My original understanding of margin convention is wrong. There isn’t magic involved here. What
var margin = ({ })
does here is simply assign numbers to names, so that those numbers can be referred to by callingmargin.top
,margin.left
….If the range of
yScale
was initially[h, 0]
, do pay attention when you use margin convention. If you can do it right, you have clearly understood margin convention. Hint : It should be.range([h - margin.bottom, margin.top])
.Why is that we should use
.range([h - margin.bottom, margin.top])
here? The domain here is ([0, the maximum of d[1]), and we want circles with smaller d[1] values appear at bottom, so the range should start fromh
something. Now, supposemargin.top = 20
, andmargin.bottom = 40
. If we use.range([h - margin.top, margin.bottom])
, then0
in the input domain will becomeh - margin.top
, and that will be the lowest point in our chart. Is this what we want? Not really. I want the lowest point to be ath - margin.bottom
.
4.3.2 From Day 19
- 7-1. The order of codes does matter in D3.js. If I put
xScale
andyScale
beforevar dataset = ...
, then D3 would not be able to generate any results. This because I need to calldataset
inxScale
andyScale
.
4.3.3 From Day 22
7-1-5. In var margin = ({top: 20, right: 30, bottom: 30, left: 40});
, you should not, and in fact cannot, put ;
right after left:40
.