Skip to content

Adjacency matrix ​

A network as a grid: a coloured cell for each link. Good for dense networks, where lines would tangle.

The smallest code that works. change the code, then press Run

In your framework

import { Chart } from 'nervure/react';

const spec = {
  type: 'adjacency',
  nodes: [
    { id: 'n0', label: 'Tunis', group: 'North' },
    { id: 'n1', label: 'Sfax', group: 'South' },
    { id: 'n2', label: 'Sousse', group: 'East' },
    { id: 'n3', label: 'Bizerte', group: 'North' },
    { id: 'n4', label: 'Gabes', group: 'South' },
    { id: 'n5', label: 'Kairouan', group: 'East' },
    { id: 'n6', label: 'Tozeur', group: 'North' },
    { id: 'n7', label: 'Nabeul', group: 'South' },
    { id: 'n8', label: 'Mahdia', group: 'East' },
    { id: 'n9', label: 'Djerba', group: 'North' },
    { id: 'n10', label: 'Bread', group: 'South' },
    { id: 'n11', label: 'Fruit', group: 'East' },
    { id: 'n12', label: 'Cheese', group: 'North' },
    { id: 'n13', label: 'Coffee', group: 'South' },
  ],
  links: [
    { source: 'n1', target: 'n0', value: 4 },
    { source: 'n2', target: 'n0', value: 5 },
    { source: 'n2', target: 'n4', value: 2 },
    { source: 'n3', target: 'n0', value: 6 },
    { source: 'n4', target: 'n2', value: 3 },
    { source: 'n4', target: 'n6', value: 3 },
    { source: 'n4', target: 'n1', value: 3 },
    { source: 'n5', target: 'n1', value: 9 },
    { source: 'n5', target: 'n2', value: 1 },
    { source: 'n6', target: 'n3', value: 1 },
    { source: 'n6', target: 'n8', value: 4 },
    { source: 'n6', target: 'n3', value: 3 },
    { source: 'n7', target: 'n1', value: 7 },
    { source: 'n7', target: 'n4', value: 1 },
    { source: 'n8', target: 'n3', value: 6 },
    { source: 'n8', target: 'n10', value: 5 },
    { source: 'n8', target: 'n5', value: 8 },
    { source: 'n9', target: 'n1', value: 4 },
    { source: 'n9', target: 'n6', value: 5 },
    { source: 'n10', target: 'n8', value: 3 },
    { source: 'n10', target: 'n12', value: 5 },
    { source: 'n10', target: 'n7', value: 4 },
    { source: 'n11', target: 'n1', value: 7 },
    { source: 'n11', target: 'n8', value: 3 },
    { source: 'n12', target: 'n5', value: 9 },
    { source: 'n12', target: 'n0', value: 8 },
    { source: 'n12', target: 'n9', value: 4 },
    { source: 'n13', target: 'n2', value: 7 },
    { source: 'n13', target: 'n10', value: 4 },
  ],
};

export default function Example() {
  return <Chart spec={spec} style={{ height: 340 }} />;
}

Or import this chart alone: what each import weighs.

Options

Beside the fields shared by every chart (title, format, heading, export…), type adjacency takes:

/** A network as a grid: one row and one column per node, a cell per link. */
interface AdjacencySpec extends Base {
  type: 'adjacency';
  nodes: { id: string; label?: string; group?: string; color?: string }[];
  links: { source: string; target: string; value?: number }[];
  /** Nodes of a group side by side (default), by name, by number of links, or as given. */
  order?: 'group' | 'name' | 'links' | 'none';
  /** A link from A to B does not fill the cell of B to A. */
  directed?: boolean;
}

Style it

  • Colours: theme.palette, chart.setColor(name, colour), or --nervure-palette in your CSS. More
  • Marks: [data-series="name"], parts: [data-part="axes"], legend, series. What you change is kept in exports.
  • Movement: animation: false draws at once. More
  • Files: chart.download('png'), svg, csv. More

Close to it