Overview
Kuva follows a four-stage rendering pipeline that transforms high-level plot definitions into backend-specific output. This architecture separates concerns and allows the same plot definition to be rendered to SVG, PNG, PDF, or terminal output.Rendering Pipeline
The core pipeline follows this flow:Stage 1: Plot Definition
Plots are defined using builder APIs for specific plot types:Stage 2: Layout
TheLayout defines the coordinate system, axes configuration, and visual properties:
Layout::auto_from_plots() method automatically computes:
- Axis ranges by examining plot bounds
- Tick count and positions
- Legend and colorbar requirements
- Categorical axis labels (for bar, box, violin plots)
Stage 3: Scene Generation
Therender_multiple() function transforms plots + layout into a Scene containing rendering primitives:
Scene struct contains:
- Width and height
- Background color
- Font family and text color
- Vector of
Primitiveelements:Circle- for scatter pointsLine- for axes, grid lines, connectionsPath- for complex shapes (lines, bands, contours)Rect- for bars, heatmap cells, filled regionsText- for labels, titles, tick marksGroupStart/GroupEnd- for transforms and layering
Stage 4: Backend Rendering
Backends convert theScene into final output format:
Convenience Functions
For simple cases, Kuva provides one-shot rendering functions that collapse the pipeline:render_multiple() and the appropriate backend.
Source Code References
- Pipeline definition:
src/lib.rs:3-13 - Scene struct:
src/render/render.rs:92-102 - Primitive enum:
src/render/render.rs:35-83 - Layout computation:
src/render/layout.rs:213-544
Design Principles
Separation of Concerns
Each stage has a single responsibility:- Plots define what data to show
- Layout defines where and how to show it
- Scene defines the abstract geometry
- Backends define the output format
Type Safety
Plot types are strongly typed. ThePlot enum (src/render/plots.rs:30-56) wraps all plot types:
Into<Plot> for ergonomic collection into Vec<Plot>.
Backend Agnostic
TheScene contains only abstract primitives. Backends independently interpret these primitives:
- SVG: Direct mapping to SVG elements
- PNG: SVG → resvg → rasterization
- PDF: SVG → svg2pdf → PDF primitives
- Terminal: Primitives → braille dots + box-drawing characters
Automatic Configuration
Layout::auto_from_plots() inspects plot types and data to automatically configure:
- Axis ranges with smart padding
- Log scale handling
- Categorical vs continuous axes
- Legend and colorbar presence
- Grid visibility
- Tick formatting
Next Steps
- Plot System - Creating and configuring plots
- Layout System - Customizing axes and appearance
- Theme System - Visual styling
- Backend System - Output formats