Class NodeVisualManager
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 animationsNodeVisualManager.Rendering.cs- Node and port rendering methodsNodeVisualManager.Positioning.cs- Position updates and coordinate calculationsNodeVisualManager.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
renderContextRenderContextShared render context.
nodeRendererRegistryNodeRendererRegistryRegistry for custom node renderers. If null, a default registry is created.
portRendererRegistryPortRendererRegistryRegistry 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
NodeRenderers
Gets the node renderer registry for registering custom node types.
public NodeRendererRegistry NodeRenderers { get; }
Property Value
PortRenderers
Gets the port renderer registry for registering custom port types.
public PortRendererRegistry PortRenderers { get; }
Property Value
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
nodeNodeThe node to edit.
themeThemeResourcesTheme resources for styling.
onCommitAction<string>Callback when editing is committed with the new label value.
onCancelActionCallback 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
nodeNodeThe node being edited.
themeThemeResourcesTheme resources for styling.
GetNodeDimensions(Node)
Gets the dimensions for a node using GraphRenderModel.
public (double width, double height) GetNodeDimensions(Node node)
Parameters
nodeNodeThe node to get dimensions for.
Returns
GetNodeVisual(string)
Gets the visual control for a node.
public Control? GetNodeVisual(string nodeId)
Parameters
nodeIdstringThe 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
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
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
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
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
nodeYdoubleY position of the node.
portIndexintIndex of the port.
totalPortsintTotal number of ports.
nodeHeightdouble?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
nodeIdstringThe 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
nodeNodeThe 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
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
canvasCanvasThe canvas containing the visual.
nodeNodeThe 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
canvasCanvasThe canvas to render to.
nodeNodeThe node to render.
themeThemeResourcesTheme resources for styling.
onNodeCreatedAction<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
canvasCanvasThe canvas to render to.
graphGraphThe graph containing nodes.
themeThemeResourcesTheme resources for styling.
onNodeCreatedAction<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
canvasCanvasThe canvas to render to.
nodeNodeThe parent node.
portPortThe port to render.
indexintIndex of this port among siblings.
totalPortsintTotal number of sibling ports.
isOutputboolTrue if this is an output port.
themeThemeResourcesTheme resources for styling.
onPortCreatedAction<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
nodeTypestringThe 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
nodeNodeThe node containing the port.
portPortThe port to trigger the pulse on.
themeThemeResourcesThe 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
nodeNodeThe node containing the port.
portPortThe port to show error on.
messagestringOptional error message.
TriggerPortSuccess(Node, Port)
Triggers a success animation on a specific port.
public void TriggerPortSuccess(Node node, Port port)
Parameters
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
graphGraphThe 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
graphGraphThe graph containing the nodes and edges.
themeThemeResourcesThe current theme.
UpdateNodePosition(Node)
Updates the position of a node visual on the canvas.
public void UpdateNodePosition(Node node)
Parameters
nodeNodeThe node whose position changed.
UpdateNodeSelection(Node, ThemeResources)
Updates the selection visual state of a node.
public void UpdateNodeSelection(Node node, ThemeResources theme)
Parameters
nodeNodeThe node to update.
themeThemeResourcesTheme resources for styling.
UpdateNodeSize(Node, ThemeResources)
Updates the size of a node visual.
public void UpdateNodeSize(Node node, ThemeResources theme)
Parameters
nodeNodeThe node to update.
themeThemeResourcesTheme 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
nodeNodeThe node to update.
themeThemeResourcesTheme resources for styling.
UpdatePortPositions(Node)
Updates the positions of all ports for a node using GraphRenderModel.
public void UpdatePortPositions(Node node)
Parameters
nodeNodeThe 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
nodeNodeThe node containing the port.
portPortThe port to update.
statePortVisualStateThe new visual state.
themeThemeResourcesThe current theme.
UpdateSettings(FlowCanvasSettings)
Updates the settings used by this manager and its render model.
public void UpdateSettings(FlowCanvasSettings settings)
Parameters
settingsFlowCanvasSettingsThe new settings to use.