Currently, I'm going through a tutorial that can be found at-
However, there's a particular section in the tutorial that has me puzzled.
"In conclusion, we link node ids to node objects and then substitute the source and target values in our links with the actual node objects themselves, rather than the ids from the raw data. This modification enables D3's force layout to function correctly, and streamlines the process of adding or removing nodes without concerns about maintaining the order within our nodes array and links array."
setupData = (data) ->
# initialize circle radius scale
countExtent = d3.extent(data.nodes, (d) -> d.playcount)
circleRadius = d3.scale.sqrt().range([3, 12]).domain(countExtent)
data.nodes.forEach (n) ->
# set initial x/y to values within the width/height
# of the visualization
n.x = randomnumber=Math.floor(Math.random()*width)
n.y = randomnumber=Math.floor(Math.random()*height)
# add radius to the node so we can use it later
n.radius = circleRadius(n.playcount)
# id's -> node objects
nodesMap = mapNodes(data.nodes)
# switch links to point to node objects instead of id's
data.links.forEach (l) ->
l.source = nodesMap.get(l.source)
l.target = nodesMap.get(l.target)
# linkedByIndex is used for link sorting
linkedByIndex["#{l.source.id},#{l.target.id}"] = 1
data
This excerpt follows the segment discussing the setupData() function. It talks about mapping node ids to node objects, which confuses me since it appears that the creation of node objects takes place later on via the update() method.
I am left wondering what these node objects are exactly? How does the mapNodes() function fit into all this?