Visucodize Visualization API Documentation
Overview π
Welcome to the Visucodize Visualization API! This API allows you to create animated visualizations of data structures and algorithms by using special visualization classes that behave like their standard JavaScript counterparts but automatically generate visual representations.
Core Concept π
Instead of using standard JavaScript data structures, you use Vis (Visualization) classes that maintain the same behavior but add visualization capabilities:
let arr = [1, 2, 3];
let arr = new VisArray(1, 2, 3);
The visualization classes expose a visManager property that allows you to control the visualization appearance and behavior.
Quick Start π
function visMainFunction(index, backgroundColor) {
let arr = new VisArray(5, 2, 8, 1, 9)
.options({
label: 'My Array',
renderingStyle: RenderingStyle.BAR_CHART
});
arr.makeVisManagerForIndex(0).addClass('highlighted');
arr.makeVisManagerForIndex(index).setProp('backgroundColor', backgroundColor);
arr.push(3);
arr.sort((a, b) => a - b);
return arr;
}
Visualization Lifecycle π
Automatic Visualization π
By default, visualization objects are automatically visualized when assigned to a variable:
const arr = new VisArray();
let nums = new VisArray(1, 2, 3);
Scope-Based Destruction π
Visualizations are automatically destroyed based on the declaration location of the variable, not assignment location:
let arr;
{
arr = new VisArray();
}
let arr2 = new VisArray();
{
let a = arr2;
}
Controlling Visualization Creation π
Use .createVis(visPref) to control whether a visualization object should be visualized:
new VisArray();
new VisArray().createVis();
new VisArray().createVis(true);
new VisArray().createVis(false);
const arr = new VisArray().createVis(false);
Important: The visualization preference can only be set once and it will be assumed to set to true if not set to false directly during the assignment:
const arr = new VisArray().createVis(false);
arr.createVis(true);
const arr = [new VisArray()];
arr[0].createVis(true);
const arr = new VisArray();
arr.createVis(false);
Manual Destruction π
Use .destroyVis() to destroy a visualization early:
const arr = new VisArray();
arr.destroyVis();
arr[0] = 1;
Reassignment Behavior π
Reassigning a variable destroys the previous visualization and may create a new one:
const arr = new VisArray();
arr = new VisArray(1, 2);
const nums = new VisArray();
nums = null;
The display label used for visualized elements in Visucodize.
How the label is determined for datagroups π
-
If .options({ label: '...' }) is provided
β This explicitly becomes the datagroupβs label.
-
If no explicit label is set but the datagroup is assigned to a variable
β The variable name becomes the label (e.g., let arr = new VisArray() gives the label "arr").
-
If neither condition applies
β No label is rendered.
let myArray = new VisArray(1, 2, 3);
let arr = new VisArray(4, 5, 6).options({ label: 'Custom' });
How the label is determined for datagroup elements π
Element labels follow this priority order:
-
labelExtractionPolicy output (if NOT undefined)
β Returned value becomes the elementβs label.
-
If labelExtractionPolicy returns undefined
β Visucodize falls back to the UIβs built-in extraction logic:
- If data is an
ElementReference
β Recursively use the referenced elementβs label.
- If data is a plain object
β Label becomes an empty string ("").
- Otherwise
β Label becomes "" + data (string conversion).
- If no meaningful label exists
β The label becomes null and nothing is rendered.
The value associated with a visualized element in Visucodize.
This value may influence visualization behavior (e.g., bar heights in bar-chart arrays, ordering in heaps, etc.).
How the value is determined for datagroups π
Datagroups themselves do not have a single βvalue.β
Each element inside the datagroup is assigned its own extracted value (see below).
How the value is determined for datagroup elements π
Element values follow this priority order:
-
valueExtractionPolicy output (if NOT undefined)
β The returned value becomes the elementβs value.
-
If valueExtractionPolicy returns undefined)
β Visucodize falls back to its built-in client-side extraction logic:
-
If the data is an ElementReference
β Recursively use the referenced elementβs value.
-
Otherwise
β The elementβs value becomes the underlying data itself.
-
If no meaningful value exists
β The value becomes null.
Available Visualization Classes π
| Class | Description | Standard Equivalent |
|---|
VisArray | Visualized array | Array |
VisSet | Visualized set | Set |
VisMap | Visualized map | Map |
VisObject | Visualized object | Object |
VisBinaryTree | Binary tree structure | Custom |
VisTree | General tree structure | Custom |
VisDictionaryTree | Dictionary/trie structure | Custom |
VisGraph | Graph structure | Custom |
VisNetworkGraph | Network graph | Custom |
VisLinkedList | Linked list | Custom |
VisQueue | Queue structure (uses @datastructures-js/queue v4.2.3) | Custom |
VisPriorityQueue | Priority queue (uses @datastructures-js/priority-queue v5.4.0) | Custom |
VisMinPriorityQueue | Min priority queue (uses @datastructures-js/priority-queue v5.4.0) | Custom |
VisMaxPriorityQueue | Max priority queue (uses @datastructures-js/priority-queue v5.4.0) | Custom |
VisArray2D | 2D array/matrix | 2D Array |
VisVariable | Single visualized variable | Variable |
Documentation Structure π
- Classes - Detailed documentation for all visualization classes
- Vis Manager API - Methods for controlling visualization appearance
- Global Functions - Utility functions available in the visualization context
- Options - Configuration options for data structures
Key Features π
1. Automatic Visualization π
Operations on Vis classes are automatically visualized:
let list = new VisArray(1, 2, 3);
list.push(4);
list.pop();
2. Element-Level Control π
Access and style individual elements:
let arr = new VisArray(10, 20, 30);
arr.makeVisManagerForIndex(1).addClass('current');
arr.makeVisManagerForIndex(1).setProp('label', 'Checking');
3. Custom Styling π
Apply visual properties:
arr.visManager.setProp('borderColor', 'red');
arr.visManager.setProp('backgroundColor', 'lightblue');
arr.visManager.addClass('highlighted');
Entry Point π
Your visualization code must be wrapped in a function named visMainFunction:
function visMainFunction(num1, num2) {
let arr = new VisArray(num1, num2);
arr.push(4);
return arr;
}
The provided inputs are retrieved by the entry method in order.
For example, in the sample above, num1 corresponds to the first input and num2 to the second.
How It Works π
- Write Code: Use Vis classes in your
visMainFunction function
- Run: The code executes in a sandboxed environment
- Visualize: Operations are captured and converted to visualization steps
- Animate: Steps are played back to create the animation
Next Steps π
Visualization Classes
This document describes all available visualization classes in the Visucodize API. Each class is an animatable (visucodizable) version of a standard JavaScript data structure or a custom visualization structure.
VisArray π
An animatable version of the standard JavaScript Array class. VisArray supports all standard JavaScript Array methods and operations - you can use it exactly like a regular array, and all operations will be automatically visualized.
Constructor
let arr = new VisArray(...elements);
let arr2 = new VisArray(5, 10, 15);
let arr3 = new VisArray(1, 2, 3, { label: 'My Array' });
Visualization-Specific Features
Properties:
visManager - Manager for styling the entire array
Methods:
makeVisManagerForIndex(index) - Returns a visualization manager for the element at the given index
All standard Array methods (push, pop, shift, unshift, splice, slice, concat, reverse, sort, etc.) work as normal and are automatically visualized.
Example
let arr = new VisArray(3, 1, 4, 1, 5)
.options({ label: 'Numbers' });
arr.makeVisManagerForIndex(0)
.addClass('highlighted')
.setProp('backgroundColor', 'yellow');
arr.push(9);
VisArray2D π
An animatable 2D array (matrix) visualization. Use this for algorithms that work with 2D grids, matrices, or tables.
Constructor
let matrix = new VisArray2D([new VisArray(1, 2, 3), new VisArray(4, 5, 6)]);
let grid = new VisArray2D([
new VisArray(1, 2),
new VisArray(3, 4)
]).options({ label: 'Grid' });
Note β VisArray2D has special rendering behavior:
VisArray2D accepts any value as a row entry β including plain JavaScript arrays, numbers, strings, or other types.
These entries are valid, but only VisArray instances are rendered as actual visual rows.
Any non-VisArray row (including plain arrays like [4, 5, 6] or values like 'test') is displayed as a placeholder cell, indicating that the item is part of the data but does not have a row structure that VisArray2D can visualize.
To produce proper row-based 2D visualizations, wrap each row in a VisArray:
const matrix = new VisArray2D(
new VisArray(1, 2, 3),
[4, 5, 6],
"test",
new VisArray(7, 8, 9)
);
If you want all rows to render visually, ensure each one is a VisArray:
const matrix = new VisArray2D(
new VisArray(1, 2, 3),
new VisArray(4, 5, 6),
new VisArray(7, 8, 9)
);
Visualization-Specific Features
Properties:
visManager - Manager for styling the entire 2D array
Methods:
makeVisManagerForIndexPair(row, col) - Returns a visualization manager for the cell at position (row, col)
You can access and modify cells using standard array syntax: matrix[row][col].
If matrix[row] is also a visualized VisArray, then modifying matrix[row][col] triggers
animation in both the parent VisArray2D and the rowβs own VisArray instance.
Example
let board = new VisArray2D([[0, 0, 0], [0, 0, 0], [0, 0, 0]])
.options({ label: 'Tic Tac Toe' });
board.makeVisManagerForIndexPair(1, 1).addClass('center');
board[0][0] = 1;
An animatable version of the standard JavaScript Set class. VisSet supports all standard JavaScript Set methods - you can use it exactly like a regular Set.
Constructor
let set = new VisSet();
let set2 = new VisSet([1, 2, 3]);
let visited = new VisSet([1, 2, 3]).options({ label: 'Visited' });
Visualization-Specific Features
Properties:
visManager - Manager for styling the entire set
Methods:
makeVisManagerForMember(member) β Returns a visualization manager for the given member
All standard Set methods (add, delete, has, clear, forEach, etc.) work as normal and are automatically visualized.
Example
let seen = new VisSet()
.options({ label: 'Seen' });
seen.add(5);
seen.add(10);
seen.makeVisManagerForMember(5).addClass('first-visit');
An animatable version of the standard JavaScript Map class. VisMap supports all standard JavaScript Map methods - you can use it exactly like a regular Map.
Constructor
let map = new VisMap();
let map2 = new VisMap([[key1, val1], [key2, val2]]);
let freqMap = new VisMap([], { label: 'Frequency Map' });
Visualization-Specific Features
Properties:
visManager - Manager for styling the entire map
Methods:
makeVisManagerForKey(key) β Returns a visualization manager for the given key element
makeVisManagerForValue(key) β Returns a visualization manager for the value corresponding to that key
All standard Map methods (set, get, delete, has, clear, forEach, etc.) work as normal and are automatically visualized.
Example
let freq = new VisMap()
.options({ label: 'Character Frequency' });
freq.set('a', 1);
freq.set('b', 2);
freq.makeVisManagerForKey('a').addClass('key-highlight');
freq.makeVisManagerForValue('a').setProp('color', 'blue');
VisObject π
An animatable version of a standard JavaScript object. You can set properties and access them like a regular object.
Constructor
let obj = new VisObject();
let obj2 = new VisObject({ name: 'John', age: 30 });
let obj3 = new VisObject({}, { label: 'Person Data' });
Visualization-Specific Features
Properties:
visManager - Manager for styling the entire object
Methods:
makeVisManagerForPropertyKey(key) β Returns a visualization manager for the given property key
makeVisManagerForValue(key) β Returns a visualization manager for the value corresponding to that key
Notes and Limitations
Important: VisObject has some known limitations due to implementation constraints:
- Symbols are not supported as keys in
VisObject, which differs from standard JavaScript objects.
- Besides symbols, you should avoid using the following strings as keys to ensure that
VisObject behaves as expected:
visManager, visType, visCategory, keyExtractionPolicyManager, extractionPolicyManager,
includeOldDataInStepScratch, contentObj, steps, idGenerator,
options, getSpecificOptionsToSkip, handleSpecificOptions,
wrapKeyData, wrapValueData, getVisContent, handleDataUpdate,
makeNewVisItemManager, toPropertyKey,
makeVisManagerForMember, makeVisManagerForPropertyKey, makeVisManagerForValue,
createVis, destroyVis
Example
let person = new VisObject()
.options({ label: 'Person' });
person.name = 'Alice';
person.age = 25;
person.makeVisManagerForPropertyKey('name').addClass('highlighted');
person.makeVisManagerForValue('age').setProp('color', 'green');
VisBinaryTree π
A binary tree visualization structure. Each node can have left and right children. VisBinaryTree extends VisGraph, so it inherits node and edge visualization methods.
Constructor
let tree = new VisBinaryTree(rootNode);
let tree2 = new VisBinaryTree(rootNode, {
dataPropName: 'value',
leftPropName: 'left',
rightPropName: 'right'
}).options({ label: 'Binary Search Tree' });
Constructor parameters:
rootNode - Root node for the tree (children inferred recursively).
options (optional):
dataPropName - Property name for node data (default: 'data')
leftPropName - Property name for left child (default: 'left')
rightPropName - Property name for right child (default: 'right')
Node Structure
Each node should have:
data (or custom property via dataPropName) - The node value
left (or custom property via leftPropName) - Left child node or null
right (or custom property via rightPropName) - Right child node or null
Visualization-Specific Features
Properties:
visManager - Manager for styling the entire tree
Inherited Methods:
VisBinaryTree extends VisGraph, inheriting all methods documented in the VisGraph section (makeVisManagerForNode, makeVisManagerForEdge, preserveNode, undoPreserveNode).
Each node also has its own visManager property for node-level styling.
Example
Updating the root or any descendant (value changes or child edits) is automatically visualized.
const root = {
data: 10,
left: {
data: 5,
left: { data: 3 },
right: { data: 7 }
},
right: {
data: 15,
right: { data: 20 }
}
};
let bst = new VisBinaryTree(root).options({ label: 'Binary Search Tree' });
A general tree visualization for trees with arbitrary numbers of children. Unlike VisBinaryTree, children are stored in an array.
Constructor
Updating the root or any descendant (value changes or child edits) is automatically visualized.
const root = {
data: 'root',
children: new VisChildrenArray([
{ data: 'child1', children: new VisChildrenArray([]) },
{ data: 'child2', children: new VisChildrenArray([]) }
])
};
let tree = new VisTree(root, {
childrenPropName: 'children',
dataPropName: 'data'
}).options({ label: 'File System' });
Constructor parameters:
rootNode - Root node for the tree (children inferred recursively).
options (optional):
childrenPropName - Property name for children array (default: 'children')
dataPropName - Property name for node data (default: 'data')
Node Structure
Each node should have:
data (or custom property via dataPropName) - The node value
children (or custom property via childrenPropName) - Array of child nodes (must be VisChildrenArray for animation tracking)
Important: For proper animation, the children array must be a VisChildrenArray, not a regular array. Updating the root or any descendant (value changes or child edits) is automatically visualized.
Visualization-Specific Features
Properties:
visManager - Manager for styling the entire tree
Inherited Methods:
VisTree extends VisGraph, inheriting all methods documented in the VisGraph section (makeVisManagerForNode, makeVisManagerForEdge, preserveNode, undoPreserveNode).
VisDictionaryTree π
A tree structure where children are stored in a Map or Object (dictionary-like), useful for tries and prefix trees.
Constructor
let trie = new VisDictionaryTree(rootNode, {
childrenPropName: 'children',
dataPropName: 'data'
}).options({ label: 'Trie' });
Constructor parameters:
rootNode - Root node for the dictionary tree (children inferred recursively).
options (optional):
childrenPropName - Property name for children dictionary (default: 'children')
dataPropName - Property name for node data (default: 'data')
childrenType - Whether children are represented as a map or object; accepts 'map' or 'object' (default: 'object'). This determines whether nodes should use VisChildrenMap or VisChildrenObject.
Node Structure
Each node should have:
data (or custom property via dataPropName) - The node value
children (or custom property via childrenPropName) - Map or Object of child nodes (must be VisChildrenMap or VisChildrenObject for animation tracking)
Important: For proper animation, the children must be a VisChildrenMap (when childrenType: 'map') or VisChildrenObject (when childrenType: 'object'). Updating the root or any descendant (value changes or child edits) is automatically visualized.
const root = {
data: '',
children: new VisChildrenMap([
['a', { data: 'a', children: new VisChildrenMap() }],
['b', { data: 'b', children: new VisChildrenMap() }]
])
};
const trieMap = new VisDictionaryTree(root, {
childrenPropName: 'children',
dataPropName: 'data',
childrenType: 'map'
}).options({ label: 'Trie (Map)' });
const root2 = {
data: '',
children: new VisChildrenObject({
'a': { data: 'a', children: new VisChildrenObject({}) },
'b': { data: 'b', children: new VisChildrenObject({}) }
})
};
const trieObj = new VisDictionaryTree(root2, {
childrenPropName: 'children',
dataPropName: 'data'
}).options({ label: 'Trie (Object)' });
Visualization-Specific Features
Properties:
visManager - Manager for styling the entire tree
Inherited Methods:
VisDictionaryTree extends VisGraph, inheriting all methods documented in the VisGraph section (makeVisManagerForNode, makeVisManagerForEdge, preserveNode, undoPreserveNode).
VisGraph π
An abstract base class for graph-based visualizations. This class provides the foundation for graph structures like VisBinaryTree, VisNetworkGraph, and VisLinkedList. Note: You typically don't instantiate VisGraph directly - use its subclasses instead.
Visualization-Specific Features
Properties:
visManager - Manager for styling the entire graph structure
Methods:
makeVisManagerForNode(nodeId) - Returns a visualization manager for a specific node
makeVisManagerForEdge(fromId, toId) - Returns a visualization manager for an edge between two nodes
preserveNode(nodeId) - Prevents a node from being automatically removed during graph operations
undoPreserveNode(nodeId) - Removes the preservation status from a node, allowing it to be removed normally
Example
let tree = new VisBinaryTree(root, { dataPropName: 'value' });
tree.makeVisManagerForNode('nodeId').addClass('visited');
tree.makeVisManagerForEdge('node1', 'node2').setProp('color', 'red');
tree.preserveNode('importantNode');
tree.undoPreserveNode('importantNode');
VisNetworkGraph π
An animatable network/social graph visualization. Extends VisGraph and provides methods for building and manipulating general graph structures with nodes and edges.
Constructor
let network = new VisNetworkGraph(
{ nodes, edges },
{ dataPropName: 'data' }
).options({
label: 'Social Network',
layoutOptions: {
rankdir: 'LR',
directed: false
}
});
Constructor parameters:
graphData - Graph data containing nodes and edges.
options (optional):
dataPropName - Property name for node data (default: 'data')
Visualization-Specific Features
Properties:
visManager - Manager for styling the entire graph (inherited from VisGraph)
Methods:
addNode(id, data) - Add a node to the graph
addEdge(from, to, weight) - Add an edge between nodes
removeNode(id) - Remove a node from the graph
removeEdge(from, to) - Remove an edge between nodes
getNeighbors(id) - Get all nodes adjacent to the given node
Inherited Methods (from VisGraph):
makeVisManagerForNode(nodeId) - Returns a visualization manager for a specific node
makeVisManagerForEdge(fromId, toId) - Returns a visualization manager for an edge
preserveNode(nodeId) - Prevents a node from being removed
undoPreserveNode(nodeId) - Allows a preserved node to be removed
Example
let network = new VisNetworkGraph({ nodes, edges }, { dataPropName: 'value' })
.options({
label: 'Social Graph',
layoutOptions: { directed: true }
});
network.addNode('Alice', { value: 'User 1' });
network.addNode('Bob', { value: 'User 2' });
network.addNode('Charlie', { value: 'User 3' });
network.addEdge('Alice', 'Bob');
network.addEdge('Bob', 'Charlie');
let neighbors = network.getNeighbors('Bob');
network.makeVisManagerForNode('Alice').addClass('start-node');
network.makeVisManagerForEdge('Alice', 'Bob').setProp('color', 'blue');
VisLinkedList π
A linked list visualization. Each node has a next pointer.
Constructor
let list = new VisLinkedList(headNode);
let list2 = new VisLinkedList(headNode, { label: 'Linked List' });
Constructor parameters:
headNode - Head node of the list (subsequent nodes are linked via next by default).
options (optional):
nextPropName - Property name for the next pointer (default: 'next')
Node Structure
Each node should have:
data - The node value
next (or custom property via nextPropName) - Reference to the next node or null
Visualization-Specific Features
Properties:
visManager - Manager for styling the entire linked list
Inherited Methods:
VisLinkedList extends VisGraph, inheriting all methods documented in the VisGraph section (makeVisManagerForNode, makeVisManagerForEdge, preserveNode, undoPreserveNode).
Example
let head = { data: 1, next: { data: 2, next: { data: 3, next: null } } };
let list = new VisLinkedList(head)
.options({ label: 'My List' });
VisQueue π
A queue visualization (FIFO - First In, First Out).
Implementation note: Backed by @datastructures-js/queue from the datastructures.js library (v4.2.3 in the runner).
Constructor
let queue = new VisQueue();
let queue2 = new VisQueue({ label: 'Task Queue' });
Visualization-Specific Features
Properties:
visManager - Manager for styling the entire queue
Methods:
enqueue(item) - Add item to the back of the queue
dequeue() - Remove and return item from the front
peek() - View the front item without removing
isEmpty() - Check if queue is empty
makeVisManagerForIndex(index) - Returns a visualization manager for element at index
Example
let q = new VisQueue()
.options({ label: 'Processing Queue' });
q.enqueue(1);
q.enqueue(2);
q.enqueue(3);
let front = q.dequeue();
q.makeVisManagerForIndex(0).addClass('next-to-process');
VisPriorityQueue π
A priority queue visualization (min-heap or max-heap based).
Implementation note: Uses @datastructures-js/priority-queue from the datastructures.js library (v5.4.0 in the runner).
Constructor
let pq = new VisPriorityQueue(compareFunction);
let pq2 = new VisPriorityQueue((a, b) => a - b, { label: 'Min Heap' });
The compare function determines priority: (a, b) => a - b for min-heap, (a, b) => b - a for max-heap.
Visualization-Specific Features
Properties:
visManager - Manager for styling the entire priority queue
Methods:
enqueue(item) - Add item with automatic priority ordering
dequeue() - Remove and return highest priority item
peek() - View the highest priority item
isEmpty() - Check if queue is empty
makeVisManagerForIndex(index) - Returns a visualization manager for element at index
VisMinPriorityQueue π
A min-priority queue (smallest element has highest priority). Extends VisPriorityQueue.
Implementation note: Shares the same @datastructures-js/priority-queue backing (v5.4.0) as VisPriorityQueue.
Constructor
let minPQ = new VisMinPriorityQueue();
let minPQ2 = new VisMinPriorityQueue({ label: 'Min Heap' });
Automatically uses min-heap comparison (a, b) => a - b.
VisMaxPriorityQueue π
A max-priority queue (largest element has highest priority). Extends VisPriorityQueue.
Implementation note: Shares the same @datastructures-js/priority-queue backing (v5.4.0) as VisPriorityQueue.
Constructor
let maxPQ = new VisMaxPriorityQueue();
let maxPQ2 = new VisMaxPriorityQueue({ label: 'Max Heap' });
Automatically uses max-heap comparison (a, b) => b - a.
VisVariable π
A visualized variable that can be obtained by wrapping any variable with makeVisVariable.
Constructor
let counter = 1;
makeVisVariable(counter).options({ label: 'counter' }).createVis();
counter = 2;
let value = 'test';
const valueVis = makeVisVariable(value).options({ label: 'value' });
Visualization-Specific Features
Properties:
visManager - Manager controlling visualization of this VisVariable
Methods:
registerAsIndexPointer(arr, indexClass, valueToIndex) β Registers this variable as an index pointer for a VisArray.
arr β The VisArray to point to
indexClass β The class name applied to the index matching the variableβs value
valueToIndex (optional) β A function that maps the variableβs value to the index that receives indexClass. Defaults to using the value directly.
Example
let arr = new VisArray(1,2,3);
let index = 0;
makeVisVariable(index).registerAsIndexPointer(arr, INDEX_CLASS);
index = 1;
Common Properties
All Vis classes share these features:
visManager - Manager for the entire structure (see Vis Manager API)
- Methods to create visualization managers for sub-elements (varies by class - see individual class documentation above)
- Support for method chaining on all manager methods
Observable Children Types π
Some visclasses require specialized child containers so that changes to children (add/remove/update) are observed and animated. These types mirror their base counterparts but are tuned for child observation:
-
VisChildrenArray π
A child-aware array. Nearly the same as VisArray, but required by classes like VisTree to ensure child updates are tracked.
-
VisChildrenMap π
A child-aware map. Nearly the same as VisMap, and used where children are keyed maps (see VisDictionaryTree).
-
VisChildrenObject π
A child-aware plain object. Nearly the same as VisObject, and used when children are stored as objects (also in VisDictionaryTree).
Related classes already call out when to use these containers in their own docs; use the linked sections above for the required child type.
See Vis Manager API for styling and control details.
Vis Manager API
The visManager is available on all visualization objects and provides methods to control their visual appearance.
Overview π
Every Vis class instance has a visManager property:
let arr = new VisArray(1, 2, 3);
arr.visManager.setProp('borderColor', 'blue');
All visualization manager methods support method chaining, allowing you to call multiple methods in sequence:
arr.makeVisManagerForIndex(0)
.setProp('backgroundColor', 'blue')
.addClass('highlighted')
.addClass('current');
setProp(property, value) π
Set a visual property. Properties set with setProp are prioritized over CSS classes - if you set a property directly with setProp and then add a class that affects the same property, the setProp value will take precedence.
arr.visManager.setProp('borderColor', 'red');
arr.visManager.setProp('backgroundColor', '#f0f0f0');
arr.visManager
.setProp('borderColor', 'green')
.setProp('backgroundColor', 'lightblue');
Common Properties (by element type):
borderColor (shapes) β Outline color for nodes/shapes.
backgroundColor (shapes) β Fill color for nodes/shapes.
backgroundOpacity (shapes) β Fill opacity for nodes/shapes.
borderDasharray (shapes) β Dashed outline pattern for nodes/shapes.
lineColor (lines) β Stroke color for edges/lines.
lineWidth (lines) β Stroke width for edges/lines.
lineDirection (lines) β Arrow placement: 'straight' puts arrowhead at target, 'reverse' at source.
addClass(className) π
Add a CSS class for styling. Returns the manager for chaining.
arr.makeVisManagerForIndex(0).addClass('highlighted');
arr.makeVisManagerForIndex(1).addClass('current');
arr.makeVisManagerForIndex(2)
.addClass('visited')
.addClass('checked');
Note: The actual CSS class names are user-defined. Use setClassProperties() to define visual properties for your custom classes.
removeClass(className) π
Remove a CSS class. Returns the manager for chaining.
arr.makeVisManagerForIndex(0).removeClass('highlighted');
arr.makeVisManagerForIndex(1)
.removeClass('current')
.addClass('visited');
removeAllClasses() π
Remove all CSS classes from the element. Returns the manager for chaining.
arr.makeVisManagerForIndex(0).removeAllClasses();
arr.makeVisManagerForIndex(1)
.removeAllClasses()
.addClass('fresh-start');
setRenderingStyle(style) π
Change how the structure is rendered. Use RenderingStyle enum (recommended) or string values.
arr.visManager.setRenderingStyle(RenderingStyle.BAR_CHART);
arr.visManager.setRenderingStyle(RenderingStyle.USE_DEFAULT);
arr.visManager.setRenderingStyle('bar_chart');
arr.visManager.setRenderingStyle('use_default');
RenderingStyle Enum Values:
RenderingStyle.UNIFORM_GRID - Grid/matrix view
RenderingStyle.BAR_CHART - Bar chart view (for arrays)
RenderingStyle.BINARY_TREE - Binary tree view
RenderingStyle.NETWORK_GRAPH - Network/graph view
RenderingStyle.USE_DEFAULT - Use default style
String Values (alternative):
'uniform_grid' - Grid/matrix view
'bar_chart' - Bar chart view (for arrays)
'binary_tree' - Binary tree view
'network_graph' - Network/graph view
'use_default' - Use default style
Property Priority π
Important: Properties set directly with setProp() take precedence over properties applied via CSS classes with addClass().
setClassProperties('highlighted', { backgroundColor: 'yellow' });
arr.makeVisManagerForIndex(0).addClass('highlighted');
arr.makeVisManagerForIndex(0).setProp('backgroundColor', 'red');
Element-Specific Managers π
Each visualization class provides methods to get managers for specific elements within the structure. See the individual class documentation for specific methods.
General Pattern:
- Each class has its own way of accessing element-specific managers
- All element manager methods return a visualization manager that supports chaining
- Refer to the specific class documentation (see Classes) for exact method names
Examples:
- VisArray:
makeVisManagerForIndex(index)
- VisMap:
makeVisManagerForKey(key), makeVisManagerForValue(key)
- VisSet:
makeVisManagerForMember(member)
- VisBinaryTree:
makeVisManagerForNode(nodeId), makeVisManagerForEdge(fromId, toId) (inherited from VisGraph)
- VisObject:
makeVisManagerForPropertyKey(key), makeVisManagerForValue(key)
- VisArray2D:
makeVisManagerFor(row, col)
Global Functions
Global utility functions available in the visualization environment.
Visualization Functions
makeVisVariable(variableToObserve) π
Creates a VisVariable instance.
Note: See the VisVariable section in the Classes documentation for more details about VisVariable.
setClassProperties(className, properties) π
Set CSS properties for a class that will be applied when addClass() is called.
setClassProperties('highlighted', {
backgroundColor: 'yellow',
borderColor: 'red',
fontWeight: 'bold'
});
arr.makeVisManagerForIndex(0).addClass('highlighted');
Note: Remember that properties set directly with setProp() take precedence over class properties.
Control Flow
breakpoint() π
Pause execution for debugging.
breakpoint();
startBatch() π
Begins a batch operation. While a batch is active, all visualization substeps are collected into a single final step, and rendering is temporarily disabled until endBatch() is called.
Intermediate states are not shown β the visualizer will only render the final state after the batch finishes.
Use this when multiple updates should appear as one atomic change in the visualization.
startBatch();
arr.push(1);
arr.push(2);
arr.push(3);
endBatch();
startPartialBatch() π
Start a partial batch of operations.
Just like startBatch(), all substeps are collected into a single final step, but unlike startBatch(), the substeps are rendered while the batch is open.
Use this when you want to group operations but still show the intermediate visualizations during execution.
startPartialBatch();
arr.push(1);
arr.push(2);
arr.push(3);
endBatch();
Key Difference:
startBatch(): Disables rendering until batch ends (fast, no intermediate visuals)
startPartialBatch(): Renders substeps during the batch (slower, shows intermediate states)
endBatch() π
End a batch of operations started with either startBatch() or startPartialBatch(). This closes the batch.
startBatch();
endBatch();
Logging and Notifications
log(message) π
Log a message (visible in console).
log('Starting algorithm...');
log('Current value: ' + value);
notification(message) π
Show a notification in the visualization.
notification('Found target!');
notification('Sorting complete');
explanationNotification() π
Show an explanation notification in the visualization. This function takes no parameters - it automatically retrieves its content from the explanation section defined in the client-side UI.
Usage:
explanationNotification();
Note: The content displayed is controlled by the explanation section in the visualization interface, not by parameters passed to this function.
Utility Functions
generateIntervalsSvgContent(intervals) π
Generate SVG content for visualizing intervals.
let svg = generateIntervalsSvgContent([[1, 3], [5, 7], [9, 12]]);
makeColoredSpan(text, color) π
Create a colored span element.
let span = makeColoredSpan('important text', 'red');
Example
function visMainFunction(nums) {
log('Starting visualization');
let arr = makeVisVariable(nums)
.options({ label: 'Input Array' });
setClassProperties('found', {
backgroundColor: 'green',
color: 'white'
});
startBatch();
notification(`Processing ${arr.value.length} elements`);
endBatch();
explanationNotification('Algorithm completed successfully');
return arr;
}
Configuration Options
Options for customizing visualization behavior and appearance.
These options cover the common .options() settings shared across most vis classes. Some of these options would be class specific (for example, layoutOptions on VisNetworkGraph), and those are called out here as class-specific. Additionally, some custom vis classes (e.g., certain VisTree variants) may have constructor-only options that are documented in the individual class docs.
Note: The .options() method must be called during creation via method chaining. You cannot call .options() after the object has been created.
RenderingStyle Enum π
The RenderingStyle enum provides type-safe values for the renderingStyle option:
enum RenderingStyle {
NETWORK_GRAPH = 'network_graph',
UNIFORM_GRID = 'uniform_grid',
BAR_CHART = 'bar_chart',
BINARY_TREE = 'binary_tree',
USE_DEFAULT = 'use_default'
}
Usage:
let arr = new VisArray(1, 2, 3).options({
label: 'My Array',
renderingStyle: RenderingStyle.BAR_CHART
});
Data Structure Options π
Common Options π
All vis classes can be configured using the .options() method, which must be chained immediately after construction:
let arr = new VisArray(1, 2, 3).options({
label: 'My Array',
renderingStyle: RenderingStyle.BAR_CHART
});
Option Properties π
Display label for the structure.
{ label: 'Sorted Array' }
renderingStyle π
How to render the structure. Use the RenderingStyle enum (recommended) or string values.
RenderingStyle Enum Values:
RenderingStyle.UNIFORM_GRID - Grid/matrix view (for 2D arrays)
RenderingStyle.BAR_CHART - Bar chart view (for arrays)
RenderingStyle.BINARY_TREE - Binary tree view (for trees)
RenderingStyle.NETWORK_GRAPH - Network/graph view (for graphs)
RenderingStyle.USE_DEFAULT - Use the default rendering style for the data structure
{ renderingStyle: RenderingStyle.BAR_CHART }
A callback function that extracts the label for each element of a datagroup using that elementβs data.
Type: (data) => string
Default behavior (when not provided):
- Falls back to a function that returns
"Inf" when the data is Infinity, "-Inf" when the data is -Infinity, and undefined otherwise. Returning undefined tells the Visucodize UI to use its own default label-extraction logic (see the label semantics docs).
Key/value structures: For structures that have both keys and values (e.g., VisMap, VisObject, VisDictionaryTree), this callback runs on the value side. Use keyLabelExtractionPolicy to customize labels for keys.
let tree = new VisBinaryTree(root, {
labelExtractionPolicy: (data) => data.name || '-'
});
A callback function that extracts element values from their data for each element of a datagroup.
Type: (node) => any
Default behavior (when not provided):
- Falls back to a function that returns
undefined. Returning undefined tells the Visucodize UI to use its own default value-extraction logic (see the value semantics docs).
Key/value structures: For structures that have both keys and values (e.g., VisMap, VisObject, VisDictionaryTree), this callback runs on the value side.
let tree = new VisBinaryTree(root, {
valueExtractionPolicy: (data) => data.value || 0
});
Optional callback to extract labels for keys in data structures that have separate keys and values (such as VisMap, VisObject, and VisDictionaryTree). The regular labelExtractionPolicy and valueExtractionPolicy still apply to the value data; use this callback to customize how keys are labeled.
Type: (key) => string
Default behavior (when not provided):
- Falls back to
undefined, which lets the Visucodize UI use its default key label extraction (similar to the default labelExtractionPolicy behavior).
Layout options (class-specific) π
Some datagroups expose layout settings through .options({ layoutOptions: { ... } }). Currently available:
- VisNetworkGraph
layoutOptions.rankdir β Layout direction passed to Dagre; one of 'LR' (default, leftβright), 'RL' (rightβleft), 'TB' (topβbottom), 'BT' (bottomβtop).
layoutOptions.directed β Whether edges are treated as directed for layout purposes (default: true).
Example Configurations π
Array as Bar Chart
let arr = new VisArray(3, 7, 1, 9, 2)
.options({
label: 'Heights',
renderingStyle: RenderingStyle.BAR_CHART
});