soxofaan / d3-plugin-captain-sankey

Friendly (subtree) fork of the "sankey" plugin from https://github.com/d3/d3-plugins
Other
42 stars 25 forks source link

added support for topology #12

Closed gchamon closed 4 years ago

gchamon commented 6 years ago

The plugin works fine when we assume all the paths are going to be linked to each layer, apart from the final layer. This PR includes support for a forced topology that will update each node position accordingly, if the correct position hasn't been achieved beforehand. That way the topology doesn't need to comprise all the nodes, only those that require a predetermined position. The topology has the following data structure:

declare var topology: [[string]];
const topology = [
  ['A', 'B', ...restLayer1],
  ['C', ...restLayer2],
  ['D', ...restLayer3],
  ...restLayers,
  ['N', ...restLayerN],
  ...rest
];

Suppose you have the following data structure:

const nodes = [
  {name: "A"},
  {name: "B"},
  {name: "C"},
  {name: "D"},
  {name: "E"}
];
const links = {
  {source: 'A', target: 'B', value: 1},
  {source: 'A', target: 'C', value: 1},
  {source: 'B', target: 'D', value: 1},
  {source: 'D', target: 'E', value: 1},
  {source: 'C', target: 'E', value: 1},
};
const topology = [
  ['A'],
  ['B'],
  ['C', 'D'],
  ['E'],
] ;

The plugin will now draw the sankey graph with the node C along with D.