Documentation
¶
Overview ¶
Package chart reads the ```chart blocks that Waniis writes into its answers (DEC-156) and draws them for a terminal: always a table, and, on a wide enough terminal, a bar or line plot.
The schema and the validation rules mirror the server's answer-chart module: a block that doesn't satisfy them is not a chart and stays the code block the model wrote.
Index ¶
Constants ¶
const ( MaxJSONChars = 6000 MaxPoints = 24 MaxSeries = 4 MaxTitle = 120 MaxLabel = 32 MaxSeriesNme = 40 MaxUnit = 16 MaxSource = 200 MaxMagnitude = 1e15 )
Limits are the server's limits for a chart block.
const FenceLanguage = "chart"
Fence language of a chart block.
const MinPlotWidth = 50
MinPlotWidth is the narrowest terminal that gets a drawn chart; narrower ones get the table only.
Variables ¶
var ErrNotChart = errors.New("not a chart")
ErrNotChart is wrapped by every Parse failure.
Functions ¶
func FormatValue ¶
FormatValue renders a value as the web app does (en-US): "$12,400", "12.5%", "340 ms".
func HeadingSuffix ¶
HeadingSuffix is what follows the title: the currency code, or the plain unit.
Types ¶
type Chart ¶
type Chart struct {
Kind string `json:"kind"`
Title string `json:"title"`
X []string `json:"x"`
Series []Series `json:"series"`
Format string `json:"format"`
Currency string `json:"currency,omitempty"`
Unit string `json:"unit,omitempty"`
Source string `json:"source,omitempty"`
}
Chart is a parsed chart block. The JSON tags are the block's own, so a Chart marshals back to the shape the model wrote (--json emits it as is).
type Fence ¶
type Fence struct {
Language string // lower case first word of the info string, or ""
Start int // byte offsets of the whole block, fences included
End int
Code string
Closed bool
}
Fence is a fenced code block in Markdown.