Skip to content
This is the alpha v4 version website. Looking for the v3 documentation?

Fill layers

Node appearance is built by compositing layers from back to front. These layers determine “how to colorize each pixel” within a node’s shape. Sigma ships with one built-in layer (layerFill), and three extension packages add specialized layers for borders, images, and piecharts.

How layers work

Layers are declared in primitives.nodes.layers. They are composited in order: earlier layers render behind later ones. Layers automatically disable themselves when they have no data for a given node (e.g., an image layer on a node without an image attribute renders as transparent).

All nodes share the same WebGL program, with the same shaders, regardless of which layers they use.

Available layers

LayerPackageDescription
layerFill()sigma/renderingSolid color fill using the node’s color
layerBorder()@sigma/node-borderConfigurable concentric borders
layerImage()@sigma/node-imageImage or pictogram rendered inside the shape
layerPiechart()@sigma/node-piechartPie chart slices

Borders

The @sigma/node-border package adds one or more concentric borders around nodes. Each border entry has a size (fraction of node radius), a color, and optional fill: true to fill the remaining space. Set mode: "pixels" for fixed pixel widths. Border sizes and colors can also be read from node attributes using { attribute: "..." }.

import { layerBorder } from "@sigma/node-border";
import Sigma from "sigma";
import { getSmallGraph } from "../_data/small-graph";
const container = document.getElementById("sigma-container") as HTMLElement;
const graph = getSmallGraph();
const BORDER_COLORS: Record<string, string> = {
a: "darkgrey",
b: "darkgrey",
c: "darkgrey",
d: "lightgrey",
e: "lightgrey",
f: "lightgrey",
};
graph.forEachNode((node) => {
graph.setNodeAttribute(node, "borderColor", BORDER_COLORS[node]);
});
new Sigma(graph, container, {
primitives: {
nodes: {
variables: {
borderColor: { type: "color", default: "red" },
},
layers: [
layerBorder({
borders: [
{ size: 0.3, color: { attribute: "borderColor" }, mode: "relative" },
{ size: 0, color: { attribute: "color" }, fill: true },
],
}),
],
},
},
});

Images and pictograms

The @sigma/node-image package renders photos or SVG icons inside nodes. The image is clipped to the node shape. For SVG pictograms, use drawingMode: "color" to tint the icon with the node’s color, and padding to add space around the icon.

import { layerImage } from "@sigma/node-image";
import Sigma from "sigma";
import { layerFill } from "sigma/rendering";
import { getSmallGraph } from "../_data/small-graph";
const container = document.getElementById("sigma-container") as HTMLElement;
const graph = getSmallGraph();
const IMAGES: Record<string, { label: string; image?: string }> = {
a: {
label: "Jim",
image: "https://upload.wikimedia.org/wikipedia/commons/7/7f/Jim_Morrison_1969.JPG",
},
b: {
label: "Johnny",
image: "https://upload.wikimedia.org/wikipedia/commons/a/a8/Johnny_Hallyday_%E2%80%94_Milan%2C_1973.jpg",
},
c: {
label: "Jimi",
image: "https://upload.wikimedia.org/wikipedia/commons/6/6c/Jimi-Hendrix-1967-Helsinki-d.jpg",
},
d: {
label: "Bob",
image:
"https://upload.wikimedia.org/wikipedia/commons/c/c5/Bob-Dylan-arrived-at-Arlanda-surrounded-by-twenty-bodyguards-and-assistants-391770740297_%28cropped%29.jpg",
},
e: {
label: "Eric",
image: "https://upload.wikimedia.org/wikipedia/commons/b/b1/Eric_Clapton_1.jpg",
},
f: {
label: "John Doe",
},
};
graph.forEachNode((node) => {
graph.mergeNodeAttributes(node, IMAGES[node]);
});
new Sigma(graph, container, {
primitives: {
nodes: {
variables: {
image: { type: "string", default: "/img/placeholder-node-image.png" },
},
layers: [layerFill(), layerImage()],
},
},
});

Piecharts

The @sigma/node-piechart package renders nodes as pie charts. Slice proportions are computed automatically. Set defaultColor to control the appearance when all values are zero. Use offset (radians) to rotate the starting angle.

import { layerPiechart } from "@sigma/node-piechart";
import Sigma from "sigma";
import { getSmallGraph } from "../_data/small-graph";
const container = document.getElementById("sigma-container") as HTMLElement;
const graph = getSmallGraph();
const SLICES: Record<string, { positive: number; neutral: number; negative: number }> = {
a: { positive: 10, neutral: 17, negative: 14 },
b: { positive: 2, neutral: 4, negative: 1 },
c: { positive: 0, neutral: 8, negative: 3 },
d: { positive: 0, neutral: 0, negative: 0 },
e: { positive: 17, neutral: 1, negative: 3 },
f: { positive: 0, neutral: 8, negative: 4 },
};
graph.forEachNode((node) => {
graph.mergeNodeAttributes(node, SLICES[node]);
});
new Sigma(graph, container, {
primitives: {
nodes: {
variables: {
negative: { type: "number", default: 0 },
neutral: { type: "number", default: 0 },
positive: { type: "number", default: 0 },
},
layers: [
layerPiechart({
defaultColor: "#BCB7C4",
slices: [
{ color: "#F05454", value: { attribute: "negative" } },
{ color: "#7798FA", value: { attribute: "neutral" } },
{ color: "#6DDB55", value: { attribute: "positive" } },
],
}),
],
},
},
});

Composing layers

Layers compose naturally. The example below combines a fill, a border and an image layer, composited in declaration order:

import { layerBorder } from "@sigma/node-border";
import { layerImage } from "@sigma/node-image";
import Sigma from "sigma";
import { layerFill } from "sigma/rendering";
import { getSmallGraph } from "../_data/small-graph";
const container = document.getElementById("sigma-container") as HTMLElement;
const graph = getSmallGraph();
const IMAGES: Record<string, { label: string; image?: string }> = {
a: {
label: "Jim",
image: "https://upload.wikimedia.org/wikipedia/commons/7/7f/Jim_Morrison_1969.JPG",
},
b: {
label: "Johnny",
image: "https://upload.wikimedia.org/wikipedia/commons/a/a8/Johnny_Hallyday_%E2%80%94_Milan%2C_1973.jpg",
},
c: {
label: "Jimi",
image: "https://upload.wikimedia.org/wikipedia/commons/6/6c/Jimi-Hendrix-1967-Helsinki-d.jpg",
},
d: {
label: "Bob",
image:
"https://upload.wikimedia.org/wikipedia/commons/c/c5/Bob-Dylan-arrived-at-Arlanda-surrounded-by-twenty-bodyguards-and-assistants-391770740297_%28cropped%29.jpg",
},
e: {
label: "Eric",
image: "https://upload.wikimedia.org/wikipedia/commons/b/b1/Eric_Clapton_1.jpg",
},
f: {
label: "John Doe",
},
};
graph.forEachNode((node) => {
graph.mergeNodeAttributes(node, IMAGES[node]);
});
new Sigma(graph, container, {
primitives: {
nodes: {
variables: {
image: { type: "string", default: "/img/placeholder-node-image.png" },
},
layers: [
layerFill({ color: "lightgrey" }),
layerImage(),
layerBorder({
borders: [
{ size: 0.2, color: "#333" },
{ size: 0.2, color: "#fff" },
{ color: "transparent", fill: true },
],
}),
],
},
},
});