dagrejs / dagre-d3

A D3-based renderer for Dagre
MIT License
2.84k stars 587 forks source link

Add data- attributes to SVGs for nodes? #258

Closed chihuahua closed 8 years ago

chihuahua commented 8 years ago

Is it possible to add data- attributes to the SVG elements of nodes when calling setNode?

chihuahua commented 8 years ago

Nvm, silly me. I could just bind the data directly to an SVG element via d3.

rienheuver commented 2 years ago

I'm running into this myself, could you please describe a bit more how you solved your problem? I'm having trouble with the D3-side of things in this library. This is my code currently:

.nodes.forEach((n) => {
  this.graph.setNode(n.id.toString(), {
    'data-id': n.id,
    label: n.label,
    class: this.companiesQuery.getActiveId() === n.id ? 'active' : '',
  });
});

data.edges.forEach((l) => {
  this.graph.setEdge(l.source.toString(), l.target.toString(), {
    arrowhead: 'undirected',
  });
});

The part of data-id on setNode of course doesn't work, how did you make that work?