Expand description
Chart rendering for query results.
Converts a list of JSON rows (typically from crate::engine::Engine::execute_query_to_json)
into a PNG or SVG image via the plotters crate. The output is raw bytes plus a
MIME type ready to drop into an MCP ImageContent.
§Supported Chart Types
- Bar — categorical x-axis by default; multi-series supported via
seriescolumn. - Line — auto-detects categorical x (DATE/TIMESTAMP/TEXT); override with
x_as_category. - Scatter — same auto-detection as line.
- Histogram — single numeric column binned into N buckets (default 20).
§Rendering Pipeline
- The MCP
charttool runs a read-only SQL query viacrate::engine::Engine. - Rows are grouped into series via
group_series(categorical x values get synthetic sequential indices; numeric x values pass through directly). - The chart is drawn on either a
BitMapBackend(PNG, written to a temp file) or anSVGBackend(SVG, rendered to an in-memory string). - The result is returned as base64-encoded
ImageContentplus a JSON stats block.
§Color Palette
Multi-series charts cycle through an 8-color palette designed for white backgrounds.
The palette is defined in series_color.
Structs§
- Chart
Options - User-facing chart configuration, parsed from MCP tool parameters.
- Chart
Result - Result of rendering a chart.
Enums§
- Chart
Disposition - How the
charttool should deliver the rendered image: write it to disk, return it inline in the MCP tool result, or both. This is a pure decision based on the caller’sinline/output_pathflags — no I/O happens here;write_chart_to_diskdoes the actual write. - Chart
Format - Output format for the rendered chart.
- Chart
Type - Supported chart types.
Functions§
- auto_
generated_ chart_ path - Synthesize a unique path under
std::env::temp_dir()/hyperdb-charts/for a default-disposition chart write. The filename encodes a monotonic counter + PID + unix-nanos so two calls in the same nanosecond (or on two hosts with sync’d clocks) don’t collide. - parse_
hex_ color - Parse a
"#rrggbb"hex string into anRGBColor. ReturnsNonewhen the string is not in the expected format so callers can log and skip rather than hard-failing. - render_
chart - Render a chart from a list of JSON row objects.
- resolve_
chart_ disposition - Decide what the chart tool should do with the rendered bytes based on
the caller’s
inlineandoutput_pathflags plus the already-resolvedformat. - resolve_
chart_ format - Resolve the effective output format from an explicit
formatparameter and/or anoutput_path’s extension. - write_
chart_ to_ disk - Write chart bytes to
path, creating the parent directory if needed and honoring theoverwriteflag.