Reputation: 21
I am starting with D3 and having the following problem:
I've created a directional force layout binding JSON data for links and nodes where data links are:
{
{ "source":"s1" , "target":"t1", "type_link"= "type1"},
{ "source":"s2" , "target":"t2", "type_link"= "type2"}
...
}
...where "source" and "target" identify nodes on both sides of each link.
I need to bind and visualize additional data to each node of previous force layout (no need to add or remove nodes to the layout). New data would be loaded for each existent node from another JSON file:
{
{ "node_id": "s1", value: {JSON object} //with additional data for node "s1"},
{ "node_id": "t1", value: {JSON object} //with additional data for node "t1"}
...
}
So, I would like to append 'value' field data (so, JSON object) to each 'node_id' node.
I thought that I could do it by binding to each node a dataset ( the JSON object), and then appending to each node (not circle) many SVG text as data in JSON object (maybe using . But I've read in https://github.com/mbostock/d3/wiki/Force-Layout that "a given force layout instance can only be used with a single dataset", so I'm confused.
Please, could you hep me with this issue?
Upvotes: 2
Views: 713
Reputation: 8264
The single dataset means that you can't use a given instance of the force layout with different pairs of nodes and links, because the force layout will store additional properties in the nodes and links. For instance, if you have nodes1
, links1
and nodes2
, links2
, you must create also a force layout for each (nodes, links) pair force1
and force2
.
An example of force layout can be found here: http://bl.ocks.org/mbostock/4062045
Upvotes: 1