Class CanvasRenderModel
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
settingsFlowCanvasSettingsnodeRenderersNodeRendererRegistry
Fields
GroupBorderRadius
public const double GroupBorderRadius = 8
Field Value
GroupCollapseButtonSize
public const double GroupCollapseButtonSize = 18
Field Value
GroupDashedStrokeThickness
public const double GroupDashedStrokeThickness = 2
Field Value
GroupHeaderHeight
public const double GroupHeaderHeight = 28
Field Value
GroupHeaderMarginX
public const double GroupHeaderMarginX = 8
Field Value
GroupHeaderMarginY
public const double GroupHeaderMarginY = 6
Field Value
MinGroupHeight
public const double MinGroupHeight = 100
Field Value
MinGroupWidth
public const double MinGroupWidth = 200
Field Value
NodeCornerRadius
public const double NodeCornerRadius = 6
Field Value
PortHitPadding
public const double PortHitPadding = 4
Field Value
ResizeHandleSize
public const double ResizeHandleSize = 8
Field Value
Properties
NodeRenderers
Gets or sets the node renderer registry for custom node type dimensions.
public NodeRendererRegistry? NodeRenderers { get; set; }
Property Value
Settings
Gets the settings used by this model.
public FlowCanvasSettings Settings { get; }
Property Value
Methods
GetBezierControlPoints(Point, Point)
Calculates bezier control points for an edge.
public (Point cp1, Point cp2) GetBezierControlPoints(Point start, Point end)
Parameters
startPointendPoint
Returns
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
Returns
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
Returns
GetEdgeMidpoint(Point, Point)
Gets the midpoint of an edge (for label positioning).
public Point GetEdgeMidpoint(Point start, Point end)
Parameters
startPointendPoint
Returns
- Point
GetGroupCollapseButtonBounds(Node)
Gets the collapse button bounds for a group in canvas coordinates.
public Rect GetGroupCollapseButtonBounds(Node group)
Parameters
groupNode
Returns
- Rect
GetGroupLabelPosition(Node)
Gets the label position for a group in canvas coordinates.
public Point GetGroupLabelPosition(Node group)
Parameters
groupNode
Returns
- Point
GetNodeBounds(Node)
Gets the bounds of a node in canvas coordinates.
public Rect GetNodeBounds(Node node)
Parameters
nodeNode
Returns
- Rect
GetNodeCornerRadius(Node)
Gets the corner radius for a node.
public double GetNodeCornerRadius(Node node)
Parameters
nodeNode
Returns
GetNodeHeight(Node)
Gets the height of a node in canvas coordinates. Considers custom renderer dimensions when available.
public double GetNodeHeight(Node node)
Parameters
nodeNode
Returns
GetNodeWidth(Node)
Gets the width of a node in canvas coordinates. Considers custom renderer dimensions when available.
public double GetNodeWidth(Node node)
Parameters
nodeNode
Returns
GetPortHitRadius(double)
Gets the hit test radius for ports (includes padding for easier clicking).
public double GetPortHitRadius(double zoom)
Parameters
zoomdoubleCurrent zoom level for scaling screen-size hit radius to canvas coordinates.
Returns
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
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
Returns
- Point
GetResizeHandleBounds(Point)
Gets the bounds of a resize handle given its center position.
public Rect GetResizeHandleBounds(Point center)
Parameters
centerPoint
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
nodeNode
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
Returns
IsInVisibleBounds(Node, Rect)
Checks if a node is within visible bounds (for virtualization).
public bool IsInVisibleBounds(Node node, Rect visibleBounds)
Parameters
nodeNodevisibleBoundsRect
Returns
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
Returns
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
pointPointPoint in canvas coordinates.
portCenterPointPort center in canvas coordinates.
zoomdoubleCurrent zoom level for scaling screen-size hit area to canvas coordinates.
Returns
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
pointPointPoint in canvas coordinates.
handleCenterPointHandle center in canvas coordinates.
zoomdoubleCurrent zoom level for scaling screen-size hit area to canvas coordinates.
Returns
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
pointPointstartPointendPointthresholddouble
Returns
UpdateSettings(FlowCanvasSettings)
Updates the settings used by this model.
public void UpdateSettings(FlowCanvasSettings settings)
Parameters
settingsFlowCanvasSettingsThe new settings to use.