chart

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const FenceLanguage = "chart"

Fence language of a chart block.

View Source
const MinPlotWidth = 50

MinPlotWidth is the narrowest terminal that gets a drawn chart; narrower ones get the table only.

Variables

View Source
var ErrNotChart = errors.New("not a chart")

ErrNotChart is wrapped by every Parse failure.

Functions

func FormatValue

func FormatValue(c *Chart, v float64) string

FormatValue renders a value as the web app does (en-US): "$12,400", "12.5%", "340 ms".

func HeadingSuffix

func HeadingSuffix(c *Chart) string

HeadingSuffix is what follows the title: the currency code, or the plain unit.

func Render

func Render(c *Chart, o Options) []string

Render returns the chart as terminal lines: the title, the plot when Draw and the terminal is wide enough, the table, and the source line.

func Rows

func Rows(c *Chart) [][]string

Rows are the table's cells: a header (blank, then the series), then one row per x label. The columns match the Slack bot's table.

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).

func Parse

func Parse(src string) (*Chart, error)

Parse reads a chart block's body. It never panics; the error says why it isn't a chart.

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.

func Fences

func Fences(markdown string) []Fence

Fences finds every fenced code block in markdown (CommonMark's rules, enough for answers).

type Options

type Options struct {
	Style style.Style
	Width int  // terminal columns
	Draw  bool // draw the plot above the table
}

Options say how to render a chart.

type Series

type Series struct {
	Name   string    `json:"name"`
	Values []float64 `json:"values"`
}

Series is one named run of values.

Jump to

Keyboard shortcuts

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