Table of Contents

Class CanvasRenderModel

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

Central model that calculates all rendering geometry for a graph. This is the single source of truth for node bounds, port positions, edge paths, etc. Both VisualTree rendering and DirectDraw rendering use this model to ensure 100% visual parity.

public class CanvasRenderModel
Inheritance
CanvasRenderModel
Inherited Members

Examples

var model = new GraphRenderModel(settings);

// Get node bounds in canvas coordinates
var bounds = model.GetNodeBounds(node);

// Get port position
var portPos = model.GetPortPosition(node, port, isOutput: true);

// Calculate edge endpoints
var (start, end) = model.GetEdgeEndpoints(edge, graph);

Remarks

The GraphRenderModel provides geometry calculations for:

  • Node bounds and dimensions
  • Port positions (supporting all 4 sides: Left, Right, Top, Bottom)
  • Edge endpoints and bezier control points
  • Group header and collapse button positions
  • Resize handle positions
  • Hit testing utilities

By centralizing all geometry calculations here, both the visual tree renderer (NodeVisualManager) and the direct renderer (DirectCanvasRenderer) produce identical visual output.

Constructors

CanvasRenderModel(FlowCanvasSettings, NodeRendererRegistry?)

public CanvasRenderModel(FlowCanvasSettings settings, NodeRendererRegistry? nodeRenderers = null)

Parameters

settings FlowCanvasSettings
nodeRenderers NodeRendererRegistry

Fields

GroupBorderRadius

public const double GroupBorderRadius = 8

Field Value

double

GroupCollapseButtonSize

public const double GroupCollapseButtonSize = 18

Field Value

double

GroupDashedStrokeThickness

public const double GroupDashedStrokeThickness = 2

Field Value

double

GroupHeaderHeight

public const double GroupHeaderHeight = 28

Field Value

double

GroupHeaderMarginX

public const double GroupHeaderMarginX = 8

Field Value

double

GroupHeaderMarginY

public const double GroupHeaderMarginY = 6

Field Value

double

MinGroupHeight

public const double MinGroupHeight = 100

Field Value

double

MinGroupWidth

public const double MinGroupWidth = 200

Field Value

double

NodeCornerRadius

public const double NodeCornerRadius = 6

Field Value

double

PortHitPadding

public const double PortHitPadding = 4

Field Value

double

ResizeHandleSize

public const double ResizeHandleSize = 8

Field Value

double

Properties

NodeRenderers

Gets or sets the node renderer registry for custom node type dimensions.

public NodeRendererRegistry? NodeRenderers { get; set; }

Property Value

NodeRendererRegistry

Settings

Gets the settings used by this model.

public FlowCanvasSettings Settings { get; }

Property Value

FlowCanvasSettings

Methods

GetBezierControlPoints(Point, Point)

Calculates bezier control points for an edge.

public (Point cp1, Point cp2) GetBezierControlPoints(Point start, Point end)

Parameters

start Point
end Point

Returns

(Point p1, Point p2)

GetEdgeEndpoints(Edge, Graph)

Calculates the start and end points for an edge in canvas coordinates.

public (Point start, Point end) GetEdgeEndpoints(Edge edge, Graph graph)

Parameters

edge Edge
graph Graph

Returns

(Point p1, Point p2)

GetEdgeEndpoints(Edge, Node, Node)

Calculates the start and end points for an edge in canvas coordinates. OPTIMIZED: Use this overload when you already have the source/target nodes looked up.

public (Point start, Point end) GetEdgeEndpoints(Edge edge, Node sourceNode, Node targetNode)

Parameters

edge Edge
sourceNode Node
targetNode Node

Returns

(Point p1, Point p2)

GetEdgeMidpoint(Point, Point)

Gets the midpoint of an edge (for label positioning).

public Point GetEdgeMidpoint(Point start, Point end)

Parameters

start Point
end Point

Returns

Point

GetGroupCollapseButtonBounds(Node)

Gets the collapse button bounds for a group in canvas coordinates.

public Rect GetGroupCollapseButtonBounds(Node group)

Parameters

group Node

Returns

Rect

GetGroupLabelPosition(Node)

Gets the label position for a group in canvas coordinates.

public Point GetGroupLabelPosition(Node group)

Parameters

group Node

Returns

Point

GetNodeBounds(Node)

Gets the bounds of a node in canvas coordinates.

public Rect GetNodeBounds(Node node)

Parameters

node Node

Returns

Rect

GetNodeCornerRadius(Node)

Gets the corner radius for a node.

public double GetNodeCornerRadius(Node node)

Parameters

node Node

Returns

double

GetNodeHeight(Node)

Gets the height of a node in canvas coordinates. Considers custom renderer dimensions when available.

public double GetNodeHeight(Node node)

Parameters

node Node

Returns

double

GetNodeWidth(Node)

Gets the width of a node in canvas coordinates. Considers custom renderer dimensions when available.

public double GetNodeWidth(Node node)

Parameters

node Node

Returns

double

GetPortHitRadius(double)

Gets the hit test radius for ports (includes padding for easier clicking).

public double GetPortHitRadius(double zoom)

Parameters

zoom double

Current zoom level for scaling screen-size hit radius to canvas coordinates.

Returns

double

GetPortPosition(Node, Port, bool)

Gets the position of a port in canvas coordinates. Supports all four port positions (Left, Right, Top, Bottom).

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

Parameters

node Node
port Port
isOutput bool

Returns

Point

GetPortPositionByIndex(Node, int, int, bool)

Gets the position of a port by index in canvas coordinates.

public Point GetPortPositionByIndex(Node node, int portIndex, int totalPorts, bool isOutput)

Parameters

node Node
portIndex int
totalPorts int
isOutput bool

Returns

Point

GetResizeHandleBounds(Point)

Gets the bounds of a resize handle given its center position.

public Rect GetResizeHandleBounds(Point center)

Parameters

center Point

Returns

Rect

GetResizeHandlePositions(Node)

Gets all resize handle positions for a node in canvas coordinates. Respects the node's AllowedResizeHandles setting.

public IEnumerable<(ResizeHandlePosition position, Point center)> GetResizeHandlePositions(Node node)

Parameters

node Node

Returns

IEnumerable<(ResizeHandlePosition position, Point center)>

IsEdgeInVisibleBounds(Edge, Graph, Rect)

Checks if an edge is within visible bounds (either endpoint visible).

public bool IsEdgeInVisibleBounds(Edge edge, Graph graph, Rect visibleBounds)

Parameters

edge Edge
graph Graph
visibleBounds Rect

Returns

bool

IsInVisibleBounds(Node, Rect)

Checks if a node is within visible bounds (for virtualization).

public bool IsInVisibleBounds(Node node, Rect visibleBounds)

Parameters

node Node
visibleBounds Rect

Returns

bool

IsNodeVisible(Graph, Node)

Checks if a node is visible (not hidden by a collapsed ancestor group).

public static bool IsNodeVisible(Graph graph, Node node)

Parameters

graph Graph
node Node

Returns

bool

IsPointInPort(Point, Point, double)

Checks if a point (in canvas coords) is within a port's hit area.

public bool IsPointInPort(Point point, Point portCenter, double zoom)

Parameters

point Point

Point in canvas coordinates.

portCenter Point

Port center in canvas coordinates.

zoom double

Current zoom level for scaling screen-size hit area to canvas coordinates.

Returns

bool

IsPointInResizeHandle(Point, Point, double)

Checks if a point is within a resize handle's hit area.

public bool IsPointInResizeHandle(Point point, Point handleCenter, double zoom)

Parameters

point Point

Point in canvas coordinates.

handleCenter Point

Handle center in canvas coordinates.

zoom double

Current zoom level for scaling screen-size hit area to canvas coordinates.

Returns

bool

IsPointNearEdge(Point, Point, Point, double)

Checks if a point (in canvas coords) is near a bezier edge.

public bool IsPointNearEdge(Point point, Point start, Point end, double threshold)

Parameters

point Point
start Point
end Point
threshold double

Returns

bool

UpdateSettings(FlowCanvasSettings)

Updates the settings used by this model.

public void UpdateSettings(FlowCanvasSettings settings)

Parameters

settings FlowCanvasSettings

The new settings to use.