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
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
canvasCanvasThe canvas to clean up from.
OnGraphChanged(Graph?)
Called when the graph changes to update cached calculations.
void OnGraphChanged(Graph? graph)
Parameters
graphGraphThe updated graph.
OnViewportChanged(BackgroundRenderContext)
Called when the viewport changes (pan/zoom).
void OnViewportChanged(BackgroundRenderContext context)
Parameters
contextBackgroundRenderContextThe updated context.
Render(Canvas, BackgroundRenderContext)
Renders background content onto the canvas.
void Render(Canvas canvas, BackgroundRenderContext context)
Parameters
canvasCanvasThe canvas to render to.
contextBackgroundRenderContextThe background rendering context.