Table of Contents

Class NodeVisualManager

Namespace
FlowGraph.Avalonia.Rendering
Assembly
FlowGraph.Avalonia.dll

Manages rendering and tracking of node and port visuals. Responsible for creating, updating, and removing node/port UI elements. Uses GraphRenderModel for all geometry calculations to ensure visual parity with DirectCanvasRenderer.

public class NodeVisualManager
Inheritance
NodeVisualManager
Inherited Members

Remarks

This class is split across multiple files for organization:

  • NodeVisualManager - Core fields, constructor, basic accessors
  • NodeVisualManager.Ports.cs - Port state management and animations
  • NodeVisualManager.Rendering.cs - Node and port rendering methods
  • NodeVisualManager.Positioning.cs - Position updates and coordinate calculations
  • NodeVisualManager.Editing.cs - Inline label editing

Constructors

NodeVisualManager(RenderContext, NodeRendererRegistry?, PortRendererRegistry?)

Creates a new node visual manager.

public NodeVisualManager(RenderContext renderContext, NodeRendererRegistry? nodeRendererRegistry = null, PortRendererRegistry? portRendererRegistry = null)

Parameters

renderContext RenderContext

Shared render context.

nodeRendererRegistry NodeRendererRegistry

Registry for custom node renderers. If null, a default registry is created.

portRendererRegistry PortRendererRegistry

Registry for custom port renderers. If null, a default registry is created.

Properties

Model

Gets the render model used for geometry calculations.

public CanvasRenderModel Model { get; }

Property Value

CanvasRenderModel

NodeRenderers

Gets the node renderer registry for registering custom node types.

public NodeRendererRegistry NodeRenderers { get; }

Property Value

NodeRendererRegistry

PortRenderers

Gets the port renderer registry for registering custom port types.

public PortRendererRegistry PortRenderers { get; }

Property Value

PortRendererRegistry

Methods

BeginEditLabel(Node, ThemeResources, Action<string>, Action)

Begins inline editing for a node's label.

public bool BeginEditLabel(Node node, ThemeResources theme, Action<string> onCommit, Action onCancel)

Parameters

node Node

The node to edit.

theme ThemeResources

Theme resources for styling.

onCommit Action<string>

Callback when editing is committed with the new label value.

onCancel Action

Callback when editing is cancelled.

Returns

bool

True if edit mode was started successfully.

Clear()

Clears all tracked node and port visuals. Note: This does not remove them from the canvas.

public void Clear()

EndEditLabel(Node, ThemeResources)

Ends inline editing for a node's label.

public void EndEditLabel(Node node, ThemeResources theme)

Parameters

node Node

The node being edited.

theme ThemeResources

Theme resources for styling.

GetNodeDimensions(Node)

Gets the dimensions for a node using GraphRenderModel.

public (double width, double height) GetNodeDimensions(Node node)

Parameters

node Node

The node to get dimensions for.

Returns

(double width, double height)

The width and height of the node.

GetNodeVisual(string)

Gets the visual control for a node.

public Control? GetNodeVisual(string nodeId)

Parameters

nodeId string

The node ID.

Returns

Control

The node's visual control, or null if not found.

GetPortCanvasPosition(Node, Port, bool)

Gets the canvas position of a port using GraphRenderModel. Use this for drawing visual elements on MainCanvas (which uses MatrixTransform).

public Point GetPortCanvasPosition(Node node, Port port, bool isOutput)

Parameters

node Node

The parent node.

port Port

The port.

isOutput bool

True if this is an output port.

Returns

Point

The port position in canvas coordinates.

GetPortScreenPosition(Node, Port, bool)

Gets the screen position of a port using GraphRenderModel.

[Obsolete("Use GetPortViewportPosition or GetPortCanvasPosition instead. 'Screen' terminology was ambiguous.")]
public Point GetPortScreenPosition(Node node, Port port, bool isOutput)

Parameters

node Node
port Port
isOutput bool

Returns

Point

GetPortViewportPosition(Node, Port, bool)

Gets the viewport position of a port using GraphRenderModel.

public Point GetPortViewportPosition(Node node, Port port, bool isOutput)

Parameters

node Node

The parent node.

port Port

The port.

isOutput bool

True if this is an output port.

Returns

Point

The port position in viewport coordinates.

Remarks

WARNING: This returns viewport-relative coordinates, NOT screen/control coordinates. For distance calculations with pointer events, prefer using GetPortCanvasPosition(Node, Port, bool) and comparing in canvas space, since pointer events give canvas coords via e.GetPosition(MainCanvas).

GetPortVisual(string, string)

Gets the visual control for a port.

public Control? GetPortVisual(string nodeId, string portId)

Parameters

nodeId string

The parent node ID.

portId string

The port ID.

Returns

Control

The port's visual control, or null if not found.

GetPortYCanvas(double, int, int, double?)

Calculates the Y position for a port in canvas coordinates using GraphRenderModel.

public double GetPortYCanvas(double nodeY, int portIndex, int totalPorts, double? nodeHeight = null)

Parameters

nodeY double

Y position of the node.

portIndex int

Index of the port.

totalPorts int

Total number of ports.

nodeHeight double?

Optional node height override.

Returns

double

The Y position for the port.

HasNodeVisual(string)

Checks if a node visual exists in tracking.

public bool HasNodeVisual(string nodeId)

Parameters

nodeId string

The node ID to check.

Returns

bool

True if the node visual exists.

IsEditingLabel(Node)

Gets whether a node is currently in edit mode.

public bool IsEditingLabel(Node node)

Parameters

node Node

The node to check.

Returns

bool

True if the node is being edited.

IsNodeVisible(Graph, Node)

Checks if a node is visible (not hidden by a collapsed ancestor group). Delegates to GraphRenderModel.IsNodeVisible.

public static bool IsNodeVisible(Graph graph, Node node)

Parameters

graph Graph

The graph containing the node.

node Node

The node to check.

Returns

bool

True if the node is visible.

RemoveNodeVisual(Canvas, Node)

Removes a node visual and its port visuals from the canvas and tracking.

public bool RemoveNodeVisual(Canvas canvas, Node node)

Parameters

canvas Canvas

The canvas containing the visual.

node Node

The node to remove.

Returns

bool

True if the visual was found and removed.

RenderNode(Canvas, Node, ThemeResources, Action<Control, Node>?)

Renders a single node with its ports.

public Control RenderNode(Canvas canvas, Node node, ThemeResources theme, Action<Control, Node>? onNodeCreated = null)

Parameters

canvas Canvas

The canvas to render to.

node Node

The node to render.

theme ThemeResources

Theme resources for styling.

onNodeCreated Action<Control, Node>

Optional callback when the node visual is created.

Returns

Control

The created node visual control.

RenderNodes(Canvas, Graph, ThemeResources, Action<Control, Node>?)

Renders all nodes in the graph to the canvas. Groups are rendered first (behind), then regular nodes. Nodes hidden by collapsed groups are not rendered. When virtualization is enabled, only nodes in the visible viewport are rendered.

public void RenderNodes(Canvas canvas, Graph graph, ThemeResources theme, Action<Control, Node>? onNodeCreated = null)

Parameters

canvas Canvas

The canvas to render to.

graph Graph

The graph containing nodes.

theme ThemeResources

Theme resources for styling.

onNodeCreated Action<Control, Node>

Optional callback when a node visual is created.

RenderPort(Canvas, Node, Port, int, int, bool, ThemeResources, Action<Control, Node, Port, bool>?)

Renders a single port using GraphRenderModel for positioning.

public Control RenderPort(Canvas canvas, Node node, Port port, int index, int totalPorts, bool isOutput, ThemeResources theme, Action<Control, Node, Port, bool>? onPortCreated = null)

Parameters

canvas Canvas

The canvas to render to.

node Node

The parent node.

port Port

The port to render.

index int

Index of this port among siblings.

totalPorts int

Total number of sibling ports.

isOutput bool

True if this is an output port.

theme ThemeResources

Theme resources for styling.

onPortCreated Action<Control, Node, Port, bool>

Optional callback when the port visual is created.

Returns

Control

The created port visual control.

SupportsEditing(string?)

Checks if a node's renderer supports inline editing.

public bool SupportsEditing(string? nodeType)

Parameters

nodeType string

The node type to check.

Returns

bool

True if the renderer supports editing.

TriggerPortDataPulse(Node, Port, ThemeResources)

Triggers a data pulse animation on a specific port.

public void TriggerPortDataPulse(Node node, Port port, ThemeResources theme)

Parameters

node Node

The node containing the port.

port Port

The port to trigger the pulse on.

theme ThemeResources

The current theme.

TriggerPortError(Node, Port, string?)

Triggers an error animation on a specific port.

public void TriggerPortError(Node node, Port port, string? message = null)

Parameters

node Node

The node containing the port.

port Port

The port to show error on.

message string

Optional error message.

TriggerPortSuccess(Node, Port)

Triggers a success animation on a specific port.

public void TriggerPortSuccess(Node node, Port port)

Parameters

node Node

The node containing the port.

port Port

The port to show success on.

UpdateAllNodePositions(Graph)

Updates all existing node visuals to their current screen positions. This is an optimized path for viewport changes (pan/zoom) that avoids recreating the visual tree. Only updates positions, not visual properties. NOTE: With transform-based rendering, this method is no longer needed for viewport changes. It's kept for compatibility but should only be called when nodes actually move in canvas space.

public void UpdateAllNodePositions(Graph graph)

Parameters

graph Graph

The graph containing the nodes.

UpdateAllPortStates(Graph, ThemeResources)

Updates the visual state of all ports in the graph based on their connection status. This should be called after rendering to ensure animated ports start their animations. Detects state changes to trigger one-shot animations (e.g., ripple on connect).

public void UpdateAllPortStates(Graph graph, ThemeResources theme)

Parameters

graph Graph

The graph containing the nodes and edges.

theme ThemeResources

The current theme.

UpdateNodePosition(Node)

Updates the position of a node visual on the canvas.

public void UpdateNodePosition(Node node)

Parameters

node Node

The node whose position changed.

UpdateNodeSelection(Node, ThemeResources)

Updates the selection visual state of a node.

public void UpdateNodeSelection(Node node, ThemeResources theme)

Parameters

node Node

The node to update.

theme ThemeResources

Theme resources for styling.

UpdateNodeSize(Node, ThemeResources)

Updates the size of a node visual.

public void UpdateNodeSize(Node node, ThemeResources theme)

Parameters

node Node

The node to update.

theme ThemeResources

Theme resources for styling.

UpdateNodeStyle(Node, ThemeResources)

Updates the custom style of a node visual based on its Data property.

public void UpdateNodeStyle(Node node, ThemeResources theme)

Parameters

node Node

The node to update.

theme ThemeResources

Theme resources for styling.

UpdatePortPositions(Node)

Updates the positions of all ports for a node using GraphRenderModel.

public void UpdatePortPositions(Node node)

Parameters

node Node

The node whose ports need updating.

UpdatePortState(Node, Port, PortVisualState, ThemeResources)

Updates the visual state of a port using its renderer.

public void UpdatePortState(Node node, Port port, PortVisualState state, ThemeResources theme)

Parameters

node Node

The node containing the port.

port Port

The port to update.

state PortVisualState

The new visual state.

theme ThemeResources

The current theme.

UpdateSettings(FlowCanvasSettings)

Updates the settings used by this manager and its render model.

public void UpdateSettings(FlowCanvasSettings settings)

Parameters

settings FlowCanvasSettings

The new settings to use.