Skip to content

Styling

Every node and edge has a style object controlling color, size, shape, borders, shadows, and labels. You can style objects individually, or theme the whole graph at once with a default-style callback.

Two ways to style

Per object

typescript
const node = orb.data.getNodeById(0);
node.patchStyle({ size: 10, color: '#FB6E00' }); // merge
node.setStyle({ size: 10 }); // replace

setDefaultStyle runs a callback for every node and edge - new ones included - so you theme the graph in one place instead of touching each object.

typescript
orb.data.setDefaultStyle({
  getNodeStyle(node) {
    return {
      size: 8,
      color: '#FB6E00',
      label: node.getData().label,
    };
  },
  getEdgeStyle(edge) {
    return {
      color: '#BAB8BB',
      width: 0.5,
      label: edge.getData().label,
    };
  },
});

orb.data.setup({ nodes, edges });

TIP

Orb doesn't guess which field is the label. Set the label style property (usually via a default-style callback) or nothing will render below the node.

WARNING

setDefaultStyle only styles objects that don't already have a style, so calling it again won't restyle the existing graph. To restyle live, set the style on each object and render:

typescript
orb.data.getNodes().forEach((node) => node.setStyle(nextStyle, { isNotifySkipped: true }));
orb.render();

Node style properties

Defined by INodeStyle. Base defaults are size: 5 and color: '#1d87c9'.

PropertyTypeDescription
colorColor | stringBackground color.
colorHover, colorSelectedColor | stringColor on hover / selection (falls back to color).
borderColorColor | stringBorder color.
borderColorHover, borderColorSelectedColor | stringBorder color on hover / selection.
borderWidth, borderWidthSelectednumberBorder width (and its selected variant).
sizenumberRadius.
shapeNodeShapeTypecircle, dot, square, diamond, triangle, triangleDown, star, hexagon.
labelstringText rendered below the node.
fontSize, fontColor, fontFamily, fontBackgroundColorLabel typography. Set fontSize: 0 to hide the label.
imageUrl, imageUrlSelectedstringImage background (overrides color).
shadowColor, shadowSize, shadowOffsetX, shadowOffsetYDrop shadow.
zIndexnumberStacking order during render.

Edge style properties

Defined by IEdgeStyle. Base defaults are color: '#ababab' and width: 0.3.

PropertyTypeDescription
colorColor | stringLine color.
colorHover, colorSelectedColor | stringLine color on hover / selection.
width, widthHover, widthSelectednumberLine width and its event variants.
arrowSizenumberArrowhead scale relative to width. 0 hides the arrow.
labelstringText rendered at the middle of the edge.
fontSize, fontColor, fontFamily, fontBackgroundColorLabel typography.
lineStyleIEdgeLineStyleLine dash pattern - see below.
shadowColor, shadowSize, shadowOffsetX, shadowOffsetYLine shadow.
zIndexnumberStacking order during render.

Line style

lineStyle sets the dash pattern via EdgeLineStyleType:

typescript
import { EdgeLineStyleType } from '@memgraph/orb';

edge.patchStyle({ lineStyle: { type: EdgeLineStyleType.DASHED } });
edge.patchStyle({ lineStyle: { type: EdgeLineStyleType.DOTTED } });

// A custom dash pattern (canvas dash array): 6px on, 3px off
edge.patchStyle({ lineStyle: { type: EdgeLineStyleType.CUSTOM, pattern: [6, 3] } });

Available types: SOLID (default), DASHED, DOTTED, and CUSTOM (requires pattern).

The Color utility

Color properties accept a hex string or a Color instance, which adds helpers:

typescript
import { Color } from '@memgraph/orb';

const base = new Color('#FB6E00');
base.getDarkerColor(); // darker tone (factor defaults to 0.3)
base.getLighterColor(); // lighter tone
base.getMixedColor(new Color('#ffffff'));
Color.getColorFromRGB({ r: 251, g: 110, b: 0 });
Color.getRandomColor();

A common pattern - derive hover/selected tones from a base color:

typescript
const c = new Color('#FB6E00');
node.patchStyle({
  color: c,
  colorHover: c.getLighterColor(),
  colorSelected: c.getDarkerColor(),
});

Global label and shadow toggles

Labels and shadows are the most expensive things to draw. For large graphs you can toggle them globally through render settings rather than per object. See Performance.

Next steps

Released under the Apache-2.0 License.