Dae Il Kim
unread,Aug 13, 2011, 3:07:43 PM8/13/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to d3-js
Hi guys,
A newbie at this so please bear with me, but I'm having some trouble
modifying each link color based off of some information in my data
associated with each link using the force directed layout. If there is
some kind of example where each link has some color assigned to it
given a dataset, that would work for me as well to save folks some
trouble. Here is the relevant data that I'm using as test:
"links":
[{"source":0, "target":1, "forward":98, "backward":100, "topic":1},
{"source":0, "target":2, "forward":19, "backward":100, "topic":1},
{"source":1, "target":3, "forward":38, "backward":100, "topic":2},
{"source":2, "target":4, "forward":19, "backward":100, "topic":2},
{"source":3, "target":2, "forward":15, "backward":100, "topic":2},
{"source":0, "target":6, "forward":19, "backward":100, "topic":3},
{"source":5, "target":4, "forward":29, "backward":100, "topic":3},
{"source":5, "target":8, "forward":49, "backward":100, "topic":4},
{"source":6, "target":7, "forward":19, "backward":100, "topic":1}]}
I can see the links and nodes when I specify a manual color, but I
want the links between nodes to change given the topic value:
Here is the relevant code. I'm wondering if accessing is d.topic is
not possible since assigning link data only evaluates the source and
target variables associated with links.:
d3.json("../data/dataFD-test.json", function(json) {
var force = self.force = d3.layout.force()
.nodes(json.nodes)
.links(json.links)
.gravity(.05)
.distance(function(d) {return d.forward;})
.charge(-150)
.size([w, h])
.start();
var linkpath = linkenter.append("svg:path")
.attr("class","link")
.attr("id", function(d) {return "path"+d.source.index
+"_"+d.target.index;})
---> .attr("stroke", function(d) {return "#"+ d.topic +"00";})
.attr("marker-end", function(d) {return
"url(#marker"+d.source.index+"_"+d.target.index+")"});
Thanks so much.