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:
- Per-element overrides —
setNodeColor(id, color),setEdgeWidth(id, w), etc. Win over everything else. - Property-driven mappings —
colorNodesByProperty(...),sizeNodesByProperty(...)derive style from data automatically. - Category / relationship defaults —
setCategoryColor("Person", color),setRelationshipShape("KNOWS", "curve"). Apply to every element of that type that has no override. - 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:
- Badge — a small disc in the top-right of a node showing up to 4 chars or an icon.
setNodeBadge,getNodeBadge,clearAllBadges. - Tag — a longer free-text label attached to a node.
createTag,assignTag,unassignTag,listTags,updateTag,deleteTag,clearAllTags,getNodeTag. - Collect marker — five small dots indicating this node has been "collected" into a parent.
setNodeCollect,getNodeCollect.
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
- applyStylesheet
- assignTag
- clearAllBadges
- clearAllTags
- clearEdgeTubeGlow
- clearNodeHalo
- clearStyles
- colorEdgesByProperty
- colorNodesByProperty
- createTag
- deleteTag
- getAvailableIcons
- getCaptionConfig
- getCaptionScale
- getCategoryColor
- getEdgeArrowVisible
- getEdgeBlend
- getNodeBadge
- getNodeCollect
- getNodeTag
- getRelationshipColor
- imageByProperty
- listTags
- setCaptions
- setCaptionScale
- setCategoryColor
- setCategoryIcon
- setCategoryVisibility
- setDefaultNodeSize
- setEdgeArrowVisible
- setEdgeBlend
- setEdgeColor
- setEdgeDashed
- setEdgeScale
- setEdgeShape
- setEdgeShapes
- setEdgeTubeGlow
- setEdgeWidth
- setNodeBadge
- setNodeCollect
- setNodeColor
- setNodeColors
- setNodeHalo
- setNodeIcon
- setNodeImage
- setNodeSize
- setNodeSizes
- setNodeTag
- setRelationshipColor
- setRelationshipShape
- setRelationshipVisibility
- setRelationshipWidth
- sizeNodesByProperty
- unassignTag
- updateTag