EDIT: This was a simple fix, I'd bound my link simulation up in a timer function, which meant I was trying to create an array before the links "existed" moving the graph.link.forEach function into the timer function has sorted it right out. Thanks to Gerardo for making me think properly about the problem!
So I'm working on a force chart and trying to use a modified version of the fade function and I've been trying to implement the fade function found here (and in many other examples).
The trouble is:
var linkedByIndex = {};
graph.links.forEach(function (d) {
linkedByIndex[d.source.index + "," + d.target.index] = 1;
});
returns an empty array. If I remove the .index, I get an array of source/target id's used to link the nodes.
Unfortunately, it seems to work fine with inline data in jsfiddle, but not when the data is from a get request. Also the source/target indexes show up in the links array in the console, so I'm not sure why the array's empty.
Any ideas?
Edit: An older version is here, linkedByIndex works in jsFiddle, but doesn't seem to after a PHP request.
The data structure is:
graph = "locations",
[
{"name": "a", "id": 1},
{"name": "b", "id": 2}
],
"nodes",
[
{"name": "A", "n_id": 1 "location": 1},
{"name": "B","n_id": 2, "location": 2}
],
"links",
[
{"source": "1", "target": "2"}
etc.
];