Let's say I have svg with circles in there.
let svg = d3.select("body").append("svg").attr("width", 600).attr("height", 100)
let dataset = [5, 10, 20]
let circles = svg.selectAll("circle").data(dataset).enter().append("circle")
and I want to make circle's location dynamic by the index of the dataset and radius with dataset's values
circles.attr("cx", (d,i)=>(i*50)+25)
.attr("cy", 50)
.attr("r", (d)=>d)
I technically could pass in i for the "r"'s function. But I do not have to. That makes this optional parameter. I get that.
But I want to learn how this is possible in javascript language. So I digged deeper by looking at the implementation of d3.js trying to understand how they allow such an optional paremter. But I am struggling to understand what is passing the dataset's current item as well as index of it.