-
Notifications
You must be signed in to change notification settings - Fork 377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow source, target and key accessors for linking by name. #1
Comments
Related Stack Overflow question. |
I’m currently doing this by hand: d3.queue()
.defer(d3.tsv, "nodes.tsv")
.defer(d3.tsv, "links.tsv")
.await(ready);
function ready(error, nodes, links) {
if (error) throw error;
var nodeByName = d3.map(nodes, function(d) { return d.name; });
links.forEach(function(d) {
d.source = nodeByName.get(d.source);
d.target = nodeByName.get(d.target);
});
// Initialize the force-layout here.
} |
Slightly different approach: var nodeById = d3.map();
d3.queue()
.defer(d3.tsv, "nodes.tsv", typeNode)
.defer(d3.tsv, "links.tsv", typeLink)
.await(ready);
function ready(error, nodes, links) {
if (error) throw error;
// Initialize the force-layout here.
}
function typeNode(d) {
nodeById.set(d.name, d);
return d;
}
function typeLink(d) {
d.source = nodeById.get(d.source);
d.target = nodeById.get(d.target);
return d;
} Maybe better would be to support a more natural file format for graphs, such as GML (see also this and this; there’s even a lesmis.gml already available) or GEXF. The latter might be good for use with d3-hierarchy, too (although JSON seems sufficient…). |
Actually, I don’t see a great reason to support GML given that it’s an arbitrary object serialization format that is similar but less popular and probably less expressive to JSON; yes, it enables the use of existing GML files and interoperability with other applications, but it’s not exactly hard to convert GML to JSON. GML would be nice to support as a parser plugin, but not preferable to the existing JSON format we’ve been using (see miserables.json). That’s especially true because GML’s graph conventions are limited to identifying nodes (and link sources and targets) by numeric identifier. I’ve added numeric linking in 541ef54, equivalent to what D3 3.x does. It’d still be nice to support linking by string identifier in d3.forceLink, though, I suppose. |
Passing functions to radial.x() and radial.y()
Related d3/d3-hierarchy#12.
Related bl.ocks.org/533daf20348023dfdd76.
The text was updated successfully, but these errors were encountered: