Principle:777genius Agent teams ai Canvas Rendering
| Knowledge Sources | |
|---|---|
| Domains | Visualization, Rendering |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Pattern for rendering graph nodes, edges, and effects to an HTML canvas with semantic zoom levels, focus-based opacity, and render caching.
Description
Canvas Rendering is the process of drawing graph elements (agent nodes, task nodes, edges, particles) to a 2D canvas context. The rendering uses semantic zoom to simplify visual detail at low zoom levels, focus-based opacity to dim non-focused nodes, and render caches to avoid redundant computation.
Key aspects:
- Semantic zoom: At zoom < 0.19, rendering simplifies (less detail, no labels). At higher zoom, full detail is rendered.
- Focus opacity: When `focusNodeIds` is set, nodes outside the focus set have reduced opacity.
- Node kinds: `drawAgents` renders only 'member' and 'lead' nodes (hexagonal shapes with glow effects); task nodes are rendered separately.
- State-based coloring: Node color is derived from the node's visual state (spawning, running, idle, error) via `getStateColor()`.
- Card hierarchy: Nodes with `cardSize` (hierarchy cards) use different opacity and visibility rules.
Usage
Use this principle when rendering an interactive graph to canvas with performance-sensitive zoom and focus behavior. Applicable to any canvas-based visualization where detail level should adapt to zoom and user focus.
Theoretical Basis
# Abstract algorithm (NOT real implementation)
def draw_agents(ctx, nodes, time, selected_id, hovered_id, focus_ids, zoom):
simplify = zoom < 0.19
for node in nodes:
if node.kind not in ('member', 'lead'):
continue
opacity = compute_opacity(node) * compute_focus_opacity(node.id, focus_ids)
if opacity < MIN_VISIBLE:
continue
color = node.color or get_state_color(node.state)
is_selected = node.id == selected_id
is_hovered = node.id == hovered_id
ctx.save()
ctx.global_alpha = opacity
draw_hexagon(ctx, node.x, node.y, radius, color)
if is_selected or is_hovered:
draw_glow(ctx, node.x, node.y, color)
if not simplify:
draw_label(ctx, node.label, node.x, node.y)
ctx.restore()