Graphics Reference
In-Depth Information
(d.source / num)
+ pad;})
.attr("y1", function(d,i) { return scale *
(d.source % num)
+ pad; })
.attr("x2", function(d,i) { return scale *
(d.target / num)
+ pad;})
.attr("y2", function(d,i) { return scale *
(d.target % num)
+ pad; });
The function for
x1,y1
, and so on, is a bit different for the lines, too. For
the nodes, the iterator is used so that node
0
is placed based on a function of
the iterator. For the links, the
graph.links.source
attribute provides a
numerical index to the corresponding source node. In the
.data
step of this
chain, the links are connected to the list of links (that is,
graph.links)
.
Then, when each line is created for a link, the function provides the
parameters
d
and
i
, where
d
is a reference to that link's data, so
d.source
indicates the index to the source node, and
d.target
indicates the index to
the target node.
Figure 8-7
shows the result of this example code.