render

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package render carries the cross-renderer surface: the Renderer interface every output backend satisfies, the RenderOpts shape, and the RenderPrecision constant that pins float formatting across the SVG (P05), PNG (P12), PDF (P15), and canvas-JSON (P12) backends.

Concrete renderers live in subpackages (render/svg/, render/pdf/, render/canvas/). All three consume the same scene.SceneDoc shape.

Index

Constants

View Source
const RenderPrecision = 3

RenderPrecision pins float-to-string precision across every renderer for cross-impl + cross-Go-version stability. SVG goldens and the JS port's Canvas output both anchor on this constant. 3 decimals = sub-millimetre at typical chart sizes; no perceivable visual difference vs higher precision. JS port matches via the scene-JSON having pre-rounded floats (the encoder snaps before emitting).

Variables

This section is empty.

Functions

func FormatFloat

func FormatFloat(v float64) string

FormatFloat renders v with RenderPrecision decimal places, trimming trailing zeros after the decimal point and dropping the decimal point itself when no fractional part remains (so "1.000" → "1", "1.230" → "1.23"). Matches D3's default formatting and keeps goldens diff-friendly.

NaN and +/-Inf coordinates are rendered as "0" defensively — the encoder is responsible for catching non-finite values upstream and raising PRISM_RENDER_001; the renderer's job is to never emit broken SVG even when handed garbage.

Types

type RenderOpts

type RenderOpts struct {
	// Format is the requested output format ("svg" | "png" | "pdf" |
	// "canvas-json"). The CLI rejects formats the runtime cannot
	// produce with PRISM_RENDER_FORMAT_UNAVAILABLE.
	Format string
	// Width overrides the scene's natural width. 0 = use the scene's.
	Width float64
	// Height overrides the scene's natural height. 0 = use the scene's.
	Height float64
	// Theme overrides SceneDoc.Theme. nil = use the doc's.
	Theme *scene.Theme
	// Background overrides the theme's background ("transparent",
	// "#fff", "rgba(0,0,0,0.5)", etc.). "" = use the theme's.
	Background string
	// Paginate is PDF-only (P15). One chart per page.
	Paginate bool
	// DPI is PNG-only (P12).
	DPI float64
}

RenderOpts carries the runtime knobs every renderer accepts. Zero values are sensible: 0 dimensions = use the scene's natural width/height; nil Theme = use the scene's Theme.

type Renderer

type Renderer interface {
	// Render produces output bytes for the SceneDoc + opts. The
	// returned bytes are renderer-format-specific; callers route them
	// through MimeType() for HTTP / display contexts.
	Render(doc *scene.SceneDoc, opts RenderOpts) ([]byte, error)
	// MimeType returns the canonical MIME type for the renderer's
	// output (image/svg+xml, image/png, application/pdf, etc.).
	MimeType() string
}

Renderer is the contract every output-format backend satisfies. The SVG impl ships in P05; PNG (via resvg-go) lands in P12, PDF in P15, canvas-json in P12.

Directories

Path Synopsis
Package pdf is the Prism PDF renderer.
Package pdf is the Prism PDF renderer.
Package svg implements render.Renderer for SVG output.
Package svg implements render.Renderer for SVG output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL