style

The style namespace controls how the graph looks: colors, sizes, icons, images, captions, dashes, arrow visibility, badges, tags, and per-category defaults. Every mutating method routes through CommandExecutor and is recorded in the undo/redo history.

Style operations live in four layers, in order of precedence:

  1. Per-element overrides — setNodeColor(id, color), setEdgeWidth(id, w), etc. Win over everything else.
  2. Property-driven mappings — colorNodesByProperty(...), sizeNodesByProperty(...) derive style from data automatically.
  3. Category / relationship defaults — setCategoryColor("Person", color), setRelationshipShape("KNOWS", "curve"). Apply to every element of that type that has no override.
  4. Engine defaults — setDefaultNodeSize(8) etc. The fallback when nothing else specifies.
// Engine default
api.style.setDefaultNodeSize(6);

// Category default
api.style.setCategoryColor("Person", [0.2, 0.6, 1.0]);

// Property mapping (overrides category default for matching nodes)
api.style.sizeNodesByProperty("score", { min: 4, max: 24 });

// Per-node override (wins over everything above)
api.style.setNodeSize("alice", 32);

Nodes

setNodeColor / setNodeColors / setNodeSize / setNodeSizes are the per-node primitives. Use the plural form when batching — it commits a single undo step instead of one per id.

setNodeIcon and setNodeImage replace the default disc with a glyph or texture. getAvailableIcons() returns the icon ids the engine currently has loaded.

Edges

setEdgeColor / setEdgeWidth / setEdgeDashed / setEdgeArrowVisible / setEdgeShape cover the per-edge case. setEdgeShapes is the batched variant.

setEdgeBlend controls whether edge colors additively brighten where they overlap (useful for dense fan-out hubs).

Visual mappings

The *ByProperty family derives style from data and keeps the mapping live as new nodes arrive:

api.style.colorNodesByProperty("category", {
  scheme: "category10",
});

api.style.sizeNodesByProperty("revenue", {
  min: 4, max: 32, scale: "log",
});

api.style.imageByProperty("avatarUrl");

clearStyles() tears down all per-element overrides AND mappings, restoring category defaults.

Captions

setCaptions(nodes?, edges?) chooses which property is shown as the floating label on each element. setCaptionScale(n) scales caption size globally; getCaptionScale() reads the current value.

Visibility (category-level)

setCategoryVisibility("Person", false) hides every node in a category at once — different from api.nodes.hide(ids) which works per element. setRelationshipVisibility("KNOWS", false) is the edge equivalent.

For one-off ad-hoc filters, prefer api.filter.*; for permanent type-level toggles use these.

Badges, tags, collections

Three independent decoration channels that compose:

The three channels render at different positions on the node and never visually conflict.

Stylesheets

applyStylesheet(rules) accepts an array of declarative rules so you can ship one configuration object instead of dozens of imperative calls. Useful for theming and for round-tripping style state via the io namespace.

Methods