Table of Contents

Class CanvasElementManager

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

Coordinates rendering of all graph elements (nodes, ports, edges, handles). Acts as a facade over specialized visual managers for clean separation of concerns.

public class CanvasElementManager
Inheritance
CanvasElementManager
Inherited Members

Constructors

CanvasElementManager()

Creates a new graph renderer with default settings.

public CanvasElementManager()

CanvasElementManager(FlowCanvasSettings?)

Creates a new graph renderer with the specified settings.

public CanvasElementManager(FlowCanvasSettings? settings)

Parameters

settings FlowCanvasSettings

Canvas settings. If null, default settings are used.

CanvasElementManager(FlowCanvasSettings?, NodeRendererRegistry?)

Creates a new graph renderer with the specified settings and node renderer registry.

public CanvasElementManager(FlowCanvasSettings? settings, NodeRendererRegistry? nodeRendererRegistry)

Parameters

settings FlowCanvasSettings

Canvas settings. If null, default settings are used.

nodeRendererRegistry NodeRendererRegistry

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

Properties

BackgroundRenderers

Gets the background renderer registry for custom background rendering.

public BackgroundRendererRegistry BackgroundRenderers { get; }

Property Value

BackgroundRendererRegistry

EdgeRenderers

Gets the edge renderer registry for registering custom edge types.

public EdgeRendererRegistry EdgeRenderers { get; }

Property Value

EdgeRendererRegistry

Edges

Gets the edge visual manager.

public EdgeVisualManager Edges { get; }

Property Value

EdgeVisualManager

NodeRenderers

Gets the node renderer registry for registering custom node types.

public NodeRendererRegistry NodeRenderers { get; }

Property Value

NodeRendererRegistry

Nodes

Gets the node visual manager.

public NodeVisualManager Nodes { get; }

Property Value

NodeVisualManager

PortRenderers

Gets the port renderer registry for registering custom port types.

public PortRendererRegistry PortRenderers { get; }

Property Value

PortRendererRegistry

RenderContext

Gets the render context for coordinate transformations.

public RenderContext RenderContext { get; }

Property Value

RenderContext

ResizeHandles

Gets the resize handle manager.

public ResizeHandleManager ResizeHandles { get; }

Property Value

ResizeHandleManager

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 rendered visuals from tracking.

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.

GetEdgeEndpointHandles(string)

Gets the endpoint handles for an edge.

public (Ellipse? source, Ellipse? target) GetEdgeEndpointHandles(string edgeId)

Parameters

edgeId string

Returns

(Ellipse source, Ellipse target)

GetEdgeGlowPath(string)

Gets the glow path for an edge (background glow effect).

public Path? GetEdgeGlowPath(string edgeId)

Parameters

edgeId string

Returns

Path

GetEdgeLabel(string)

Gets the edge label for an edge.

public TextBlock? GetEdgeLabel(string edgeId)

Parameters

edgeId string

Returns

TextBlock

GetEdgeMarkers(string)

Gets the markers (arrows) for an edge.

public IReadOnlyList<Path>? GetEdgeMarkers(string edgeId)

Parameters

edgeId string

Returns

IReadOnlyList<Path>

GetEdgeVisiblePath(string)

Gets the visible path for an edge (the actual rendered stroke).

public Path? GetEdgeVisiblePath(string edgeId)

Parameters

edgeId string

Returns

Path

GetEdgeVisual(string)

Gets the visual element for an edge (hit area path).

public Path? GetEdgeVisual(string edgeId)

Parameters

edgeId string

Returns

Path

GetNodeDimensions(Node)

Gets the dimensions for a node, considering custom renderer sizes and node-specific overrides.

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

Parameters

node Node

Returns

(double width, double height)

GetNodeVisual(string)

Gets the visual element for a node.

public Control? GetNodeVisual(string nodeId)

Parameters

nodeId string

Returns

Control

GetPortCanvasPosition(Node, Port, bool)

Gets the port position in canvas coordinates. Use this for drawing visual elements on MainCanvas (which uses MatrixTransform).

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

Parameters

node Node
port Port
isOutput bool

Returns

Point

GetPortScreenPosition(Node, Port, bool)

Gets the port position in screen coordinates.

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

Parameters

node Node
port Port
isOutput bool

Returns

Point

GetPortViewportPosition(Node, Port, bool)

Gets the port position in viewport coordinates.

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

Parameters

node Node
port Port
isOutput bool

Returns

Point

Remarks

WARNING: For distance calculations with pointer events, prefer using GetPortCanvasPosition(Node, Port, bool) since pointer events give canvas coords via e.GetPosition(MainCanvas).

GetPortVisual(string, string)

Gets the visual element for a port.

public Control? GetPortVisual(string nodeId, string portId)

Parameters

nodeId string
portId string

Returns

Control

GetPortY(double, int, int)

Calculates the Y position for a port (legacy, returns canvas coordinates).

public double GetPortY(double nodeY, int portIndex, int totalPorts)

Parameters

nodeY double
portIndex int
totalPorts int

Returns

double

GetPortYCanvas(double, int, int, double?)

Calculates the Y position for a port in canvas coordinates.

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

Parameters

nodeY double
portIndex int
totalPorts int
nodeHeight double?

Returns

double

GetShapeVisual(string)

Gets the visual element for a shape.

public Control? GetShapeVisual(string shapeId)

Parameters

shapeId string

Returns

Control

HasEdgeVisual(string)

Checks if an edge visual exists.

public bool HasEdgeVisual(string edgeId)

Parameters

edgeId string

Returns

bool

HasNodeVisual(string)

Checks if a node visual exists.

public bool HasNodeVisual(string nodeId)

Parameters

nodeId string

Returns

bool

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).

public bool IsNodeVisible(Graph graph, Node node)

Parameters

graph Graph
node Node

Returns

bool

RemoveAllResizeHandles(Canvas)

Removes all resize handles from the canvas.

public void RemoveAllResizeHandles(Canvas canvas)

Parameters

canvas Canvas

RemoveEdgeVisual(Canvas, Edge)

Removes a single edge visual from the canvas.

public bool RemoveEdgeVisual(Canvas canvas, Edge edge)

Parameters

canvas Canvas

The canvas containing the visual.

edge Edge

The edge to remove.

Returns

bool

True if the visual was found and removed.

RemoveNodeVisual(Canvas, Node)

Removes a single node visual and its ports from the canvas.

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.

RemoveResizeHandles(Canvas, string)

Removes resize handles for a node.

public void RemoveResizeHandles(Canvas canvas, string nodeId)

Parameters

canvas Canvas
nodeId string

RenderEdge(Canvas, Edge, Graph, ThemeResources)

Renders a single edge with its markers and optional label.

public Path? RenderEdge(Canvas canvas, Edge edge, Graph graph, ThemeResources theme)

Parameters

canvas Canvas
edge Edge
graph Graph
theme ThemeResources

Returns

Path

RenderEdges(Canvas, Graph, ThemeResources, Path?)

Renders all edges in the graph. Edges with hidden endpoints (due to collapsed groups) are not rendered.

public void RenderEdges(Canvas canvas, Graph graph, ThemeResources theme, Path? excludePath = null)

Parameters

canvas Canvas
graph Graph
theme ThemeResources
excludePath Path

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

Renders a single node using the appropriate renderer for its type.

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

Parameters

canvas Canvas
node Node
theme ThemeResources
onNodeCreated Action<Control, Node>

Returns

Control

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

Renders all nodes in the graph. Groups are rendered first (behind), then regular nodes. Nodes hidden by collapsed groups are not rendered.

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

Parameters

canvas Canvas
graph Graph
theme ThemeResources
onNodeCreated Action<Control, Node>

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

Renders a single port.

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
node Node
port Port
index int
totalPorts int
isOutput bool
theme ThemeResources
onPortCreated Action<Control, Node, Port, bool>

Returns

Control

RenderResizeHandles(Canvas, Node, ThemeResources, Action<Rectangle, Node, ResizeHandlePosition>?)

Renders resize handles for a selected node.

public void RenderResizeHandles(Canvas canvas, Node node, ThemeResources theme, Action<Rectangle, Node, ResizeHandlePosition>? onHandleCreated = null)

Parameters

canvas Canvas
node Node
theme ThemeResources
onHandleCreated Action<Rectangle, Node, ResizeHandlePosition>

SetShapeVisualManager(ShapeVisualManager?)

Sets the shape visual manager for delegating shape operations.

public void SetShapeVisualManager(ShapeVisualManager? manager)

Parameters

manager ShapeVisualManager

SetViewport(ViewportState?)

Sets the viewport state to use for coordinate transformations.

public void SetViewport(ViewportState? viewport)

Parameters

viewport ViewportState

The viewport state.

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
port Port
theme ThemeResources

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
port Port
message string

TriggerPortSuccess(Node, Port)

Triggers a success animation on a specific port.

public void TriggerPortSuccess(Node node, Port port)

Parameters

node Node
port Port

UpdateAllNodePositions(Graph)

Updates all node positions for viewport changes (pan/zoom). This is an optimized path that avoids recreating the visual tree.

public void UpdateAllNodePositions(Graph graph)

Parameters

graph Graph

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.

public void UpdateAllPortStates(Graph graph, ThemeResources theme)

Parameters

graph Graph
theme ThemeResources

UpdateAllResizeHandles()

Updates size and position of all tracked resize handles. Called on zoom changes to recalculate InverseScale-based sizing.

public void UpdateAllResizeHandles()

UpdateEdgeSelection(Edge, ThemeResources)

Updates the selection visual of an edge.

public void UpdateEdgeSelection(Edge edge, ThemeResources theme)

Parameters

edge Edge
theme ThemeResources

UpdateNodePosition(Node)

Updates the position of a node visual.

public void UpdateNodePosition(Node node)

Parameters

node Node

UpdateNodeSelection(Node, ThemeResources)

Updates the selection visual of a node.

public void UpdateNodeSelection(Node node, ThemeResources theme)

Parameters

node Node
theme ThemeResources

UpdateNodeSize(Node, ThemeResources)

Updates the size of a node visual.

public void UpdateNodeSize(Node node, ThemeResources theme)

Parameters

node Node
theme ThemeResources

UpdateNodeStyle(Node, ThemeResources)

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

public void UpdateNodeStyle(Node node, ThemeResources theme)

Parameters

node Node
theme ThemeResources

UpdatePortPositions(Node)

Updates port positions for a node.

public void UpdatePortPositions(Node node)

Parameters

node Node

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
port Port
state PortVisualState
theme ThemeResources

UpdateResizeHandlePositions(Node)

Updates the position of resize handles for a node.

public void UpdateResizeHandlePositions(Node node)

Parameters

node Node

UpdateSettings(FlowCanvasSettings)

Updates the settings used by this renderer and all its sub-components. Call this when FlowCanvasSettings property changes to propagate the new values.

public void UpdateSettings(FlowCanvasSettings settings)

Parameters

settings FlowCanvasSettings

The new settings to use.

UpdateShapeSelection(string, bool)

Updates the selection visual for a shape.

public void UpdateShapeSelection(string shapeId, bool isSelected)

Parameters

shapeId string

The ID of the shape.

isSelected bool

Whether the shape is selected.

UpdateShapeVisual(ShapeElement)

Updates a shape visual after its properties have changed.

public void UpdateShapeVisual(ShapeElement shape)

Parameters

shape ShapeElement