Skip to content

Latest commit

 

History

History
 
 

graph

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

d3.graph

This plugin is not currently in active development.

For a more complete set of graph analysis tools, see the work of Elijah Meeks and Maya Krishnan.

A plugin for manipulating graph data structures.

Todo

Matrix

Create a matrix

  var matrix = d3.graph.matrix([
    [1,1,0],
    [0,0,0],
    [2,1,1]
  ]);

Get an edge value

matrix(i,j)

Check if edge exists (non-zero)

matrix.has(i,j)

Set an edge value

matrix.set(i,j,value)

Remove an edge

matrix.remove(i,j)

Get outgoing edge indices

matrix.outE(i)

Get incoming edge indices

matrix.inE(i)

todo

  • documentation
  • changing size

Basics

Convert matrix to list

d3.graph.matrixToList([
  [0,1,0],
  [1,0,0],
  [1,1,1]
])
/*
[
  {"source":0,"target":0,"value":0},{"source":0,"target":1,"value":1},{"source":0,"target":2,"value":0},
  {"source":1,"target":0,"value":1},{"source":1,"target":1,"value":0},{"source":1,"target":2,"value":0},
  {"source":2,"target":0,"value":1},{"source":2,"target":1,"value":1},{"source":2,"target":2,"value":1}
]
*/

Convert list to matrix

d3.graph.listToMatrix([
  {"source":0,"target":1,"value":1},
  {"source":1,"target":0,"value":1},
  {"source":2,"target":0,"value":1},
  {"source":2,"target":1,"value":1},
  {"source":2,"target":2,"value":1}
])
/*
  [0,1,0],
  [1,0,0],
  [1,1,1]
*/

Stateful Use

var graph = d3.graph();

Load a matrix

graph.matrix([
  [0,1,0],
  [1,0,0],
  [1,1,1]
]);

Get the graph as list of links

graph.links();

Get the graph as matrix

graph.matrix();

Nodes and links can be modified by passing in a value. This will overwrite existing data.

graph.nodes(['red', 'purple', 'orange']);
graph.links([{"source":0,"target":0,"value":0},{"source":0,"target":1,"value":1},{"source":0,"target":2,"value":0}]);

Get a description of the graph

graph.description();
// "d3.graph with 3 nodes and 9 links"