Generates a D3 compatible node-link structure from a data frame (array of objects).
data
Array array of objects containing the data.keys
(Object | Array) object of {key: column/accessor} pairs or an array of [key, column/accessor] pairsvalues
Object object of accessor functions for link values. (optional, default{}
)
const data = [
{ Country: "USA", Religion: "Christian" },
{ Country: "UK", Religion: "Christian" },
{ Country: "Iran", Religion: "Muslim" },
];
// List nodes to extract from each row
const keys = {
Country: "Country", // Create node from "Country" field
Religion: (d) => d.Religion, // Create node from "Religion" field
};
// Define attributes to add to each node / link
const values = {
count: 1, // Sum "1" to count the number of rows matching each node / link
Population: "Population", // Sum the "Population" field from rows matching each node / link
};
const { nodes, links } = kpartite(data, keys, values);
Returns NodeLink { nodes, links }
arrays with the node-link structure.
Type: Object
-
nodes
Array unique nodes for each key in each data element -
links
Array unique links for each PAIR of keys in each data element
Creates a network visualization.
-
el
(string | HTMLElement) The selector or HTML element for the SVG. -
params
Object Parameters for the visualization.params.nodes
Array list of node objects.params.links
Array list of {source, target} link objects.params.width
number? width of the SVG.params.height
number? height of the SVG.params.linkCurvature
number curvature of the links. 0 = straight, 1 = half-circle. (optional, default0
)params.nodeTag
string SVG tag to use for nodes. (optional, default"circle"
)params.forces
Object? forces to apply to the simulation.params.brush
Function? callback function to handle brush events.params.id
string? unique identifier for the simulation. Usesel.id
if not specified.params.d3
Object D3 instance to use. (optional, defaultwindow.d3
)
Returns Graph Object containing D3.js selections for nodes and links.
Define the returned graph
Type: Object