Table of Contents

Interface IBackgroundRenderer

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

Interface for custom background renderers. Implement this to render custom backgrounds behind the main graph content.

public interface IBackgroundRenderer

Examples

// Register a background renderer
canvas.BackgroundRenderers.Add(new LifelineBackgroundRenderer());

// Or set as the single background
canvas.BackgroundRenderers.SetSingle(new SwimlaneBackgroundRenderer());

Remarks

Background renderers are called during the render cycle, after the grid but before edges and nodes. They can render static backgrounds (gradients, images) or graph-dependent visuals (swimlane lanes, sequence diagram lifelines).

Multiple background renderers can be registered and are rendered in order. Each renderer receives the full graph context and can access node positions.

Important: Set RenderTarget appropriately:

  • GridCanvas: For fixed backgrounds (default). Use CanvasToScreen() for coordinates.
  • MainCanvas: For diagram decorations that should zoom/pan with nodes. Use canvas coordinates directly.

Properties

RenderTarget

Gets the target canvas for this renderer. Default is GridCanvas (for backward compatibility). Override to return MainCanvas for diagram elements that should zoom/pan with nodes.

BackgroundRenderTarget RenderTarget { get; }

Property Value

BackgroundRenderTarget

Methods

Cleanup(Canvas)

Called when the renderer is being removed or replaced. Implementations should remove any visuals they added to the canvas.

void Cleanup(Canvas canvas)

Parameters

canvas Canvas

The canvas to clean up from.

OnGraphChanged(Graph?)

Called when the graph changes to update cached calculations.

void OnGraphChanged(Graph? graph)

Parameters

graph Graph

The updated graph.

OnViewportChanged(BackgroundRenderContext)

Called when the viewport changes (pan/zoom).

void OnViewportChanged(BackgroundRenderContext context)

Parameters

context BackgroundRenderContext

The updated context.

Render(Canvas, BackgroundRenderContext)

Renders background content onto the canvas.

void Render(Canvas canvas, BackgroundRenderContext context)

Parameters

canvas Canvas

The canvas to render to.

context BackgroundRenderContext

The background rendering context.