Skip to content
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

Closed
mbostock opened this issue Nov 3, 2015 · 4 comments
Closed

Allow source, target and key accessors for linking by name. #1

mbostock opened this issue Nov 3, 2015 · 4 comments
Assignees

Comments

@mbostock
Copy link
Member

mbostock commented Nov 3, 2015

Related d3/d3-hierarchy#12.
Related bl.ocks.org/533daf20348023dfdd76.

@mbostock
Copy link
Member Author

mbostock commented Dec 1, 2015

Related Stack Overflow question.

@mbostock mbostock self-assigned this Apr 6, 2016
@mbostock
Copy link
Member Author

mbostock commented Apr 6, 2016

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.
}

@mbostock
Copy link
Member Author

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…).

@mbostock
Copy link
Member Author

mbostock commented Apr 20, 2016

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.

fzyukio pushed a commit to fzyukio/d3-force that referenced this issue Aug 23, 2018
Passing functions to radial.x() and radial.y()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant