Documentation
¶
Overview ¶
Package rtisvg renders rows returned by an SQL query into an SVG template and optionally rasterizes the result to PNG.
The package accepts an already-open *sql.DB. It does not choose a database driver, open a database, or manage application credentials.
Project: https://github.com/x07-it/rtisvg
Made with ❤️ by Xenon007 for X07.IT.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNilDatabase = errors.New("rtisvg: nil database") ErrEmptyQuery = errors.New("rtisvg: empty SQL query") ErrInvalidTemplate = errors.New("rtisvg: invalid template") ErrInvalidColumns = errors.New("rtisvg: invalid columns") ErrInvalidLayout = errors.New("rtisvg: invalid layout") ErrUnsafeSVG = errors.New("rtisvg: unsafe SVG") ErrLimitExceeded = errors.New("rtisvg: limit exceeded") ErrNilRasterizer = errors.New("rtisvg: nil rasterizer") )
Functions ¶
This section is empty.
Types ¶
type CellData ¶
type CellData struct {
RowIndex int
ColumnIndex int
ColumnName string
Text string
Raw any
Align Align
Anchor string
X float64
Y float64
Width float64
Height float64
TextX float64
TextY float64
}
CellData describes one query value and its computed cell geometry.
type Column ¶
type Column struct {
// Name optionally asserts the expected SQL column name.
Name string
// Header is displayed in the table header. An empty value uses the SQL name.
Header string
// Align defaults to AlignLeft.
Align Align
// Width is the logical SVG width. Zero shares the remaining width equally.
Width float64
// Formatter overrides the default SQL value formatter.
Formatter FormatFunc
}
Column customizes one query column. Columns are positional and must match the order returned by the SELECT statement.
type ColumnData ¶
type ColumnData struct {
Index int
Name string
Header string
Align Align
Anchor string
X float64
Width float64
CenterX float64
Right float64
}
ColumnData contains computed geometry for a query column.
type FormatFunc ¶
FormatFunc converts a scanned SQL value into text for the SVG template.
func TimeFormat ¶
func TimeFormat(layout string) FormatFunc
TimeFormat returns a formatter for time.Time values. Nil values remain empty.
type HeaderData ¶
type HeaderData struct {
Index int
Name string
Text string
Align Align
Anchor string
X float64
Y float64
Width float64
Height float64
TextX float64
TextY float64
}
HeaderData describes one rendered header cell.
type Layout ¶
type Layout struct {
Width float64
PaddingX float64
Top float64
HeaderHeight float64
RowHeight float64
Bottom float64
CellPadding float64
}
Layout controls generated table geometry in logical SVG pixels.
type Limits ¶
type Limits struct {
MaxRows int
MaxTemplateBytes int64
MaxSVGBytes int
MaxPNGBytes int
// MaxPixels limits Width*Height after PNG scaling.
MaxPixels int64
}
Limits protects a process from unexpectedly large reports. Zero uses the package default. A negative MaxRows disables only the row-count limit.
type PNGOptions ¶
type PNGOptions struct {
// Scale multiplies PNG pixel dimensions. Zero means 1.
Scale float64
// Background is an optional SVG/CSS color. Empty means transparent.
Background string
}
PNGOptions controls raster output.
type RasterizeOptions ¶
RasterizeOptions are supplied to a Rasterizer after the SVG has been rendered.
type Rasterizer ¶
type Rasterizer interface {
Rasterize(ctx context.Context, svg []byte, options RasterizeOptions) ([]byte, error)
}
Rasterizer converts a completed SVG document to PNG.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer renders reports with a configurable PNG rasterizer.
func New ¶
func New() *Renderer
New creates a renderer using the package's pure-Go PNG implementation.
func NewWithRasterizer ¶
func NewWithRasterizer(rasterizer Rasterizer) *Renderer
NewWithRasterizer creates a renderer with a caller-supplied rasterizer.
type Request ¶
type Request struct {
Query string
Args []any
// Headers is the compact positional form. It is mutually exclusive with Columns.
Headers []string
// Columns is the extended positional form. It is mutually exclusive with Headers.
Columns []Column
Template Template
Data map[string]any
Layout Layout
PNG PNGOptions
Limits Limits
// DisableQueryOnly skips the SQLite PRAGMA query_only guard. It should be used
// only for drivers that do not implement that SQLite pragma.
DisableQueryOnly bool
}
Request describes one report render.
type Result ¶
type Result struct {
PNG []byte
SVG []byte
// Width and Height are logical SVG dimensions.
Width int
Height int
// PNGWidth and PNGHeight are raster pixel dimensions. They are zero for RenderSVG.
PNGWidth int
PNGHeight int
Rows int
Columns int
ColumnNames []string
}
Result contains both reusable vector output and Telegram-friendly PNG output.
func RenderWith ¶
func RenderWith(ctx context.Context, db *sql.DB, req Request, rasterizer Rasterizer) (Result, error)
RenderWith creates SVG and PNG output using a caller-supplied rasterizer.
type RowData ¶
type RowData struct {
Index int
Number int
Y float64
Height float64
CenterY float64
Cells []CellData
}
RowData describes one query row.
type Template ¶
Template identifies an SVG Go template in an fs.FS.
func FileTemplate ¶
FileTemplate creates a Template for one file on the local filesystem.
type TemplateData ¶
type TemplateData struct {
Width float64
Height float64
RowCount int
ColCount int
Headers []HeaderData
Columns []ColumnData
Rows []RowData
Data map[string]any
Layout Layout
}
TemplateData is the root object available inside an SVG Go template.