Go CLI that turns the markdown currency of this stack (Redmine notes, Discourse posts, briefing output) into typeset PDFs: two embedded typst templates (report with title page/TOC/headers, dense brief), front-matter (title/subtitle/author/date/classification/template), GFM tables, and bar charts rendered in pure Go (go-chart) from fenced chart data blocks. Engine is a prebuilt typst 0.15.1 container pinned by digest and run --network none; PDF bytes to stdout or -o. Exit codes 0/1/2. All dev in docker (dev.sh/Makefile); unit tests + golden typst fixtures plus a host-side smoke against the real engine container. Generated with Crush Assisted-by: Crush:glm-5.2
54 lines
957 B
Go
54 lines
957 B
Go
package chart
|
|
|
|
// Value is a chart value.
|
|
type Value struct {
|
|
Style Style
|
|
Label string
|
|
Value float64
|
|
}
|
|
|
|
// Values is an array of Value.
|
|
type Values []Value
|
|
|
|
// Values returns the values.
|
|
func (vs Values) Values() []float64 {
|
|
values := make([]float64, len(vs))
|
|
for index, v := range vs {
|
|
values[index] = v.Value
|
|
}
|
|
return values
|
|
}
|
|
|
|
// ValuesNormalized returns normalized values.
|
|
func (vs Values) ValuesNormalized() []float64 {
|
|
return Normalize(vs.Values()...)
|
|
}
|
|
|
|
// Normalize returns the values normalized.
|
|
func (vs Values) Normalize() []Value {
|
|
var output []Value
|
|
var total float64
|
|
|
|
for _, v := range vs {
|
|
total += v.Value
|
|
}
|
|
|
|
for _, v := range vs {
|
|
if v.Value > 0 {
|
|
output = append(output, Value{
|
|
Style: v.Style,
|
|
Label: v.Label,
|
|
Value: RoundDown(v.Value/total, 0.0001),
|
|
})
|
|
}
|
|
}
|
|
return output
|
|
}
|
|
|
|
// Value2 is a two axis value.
|
|
type Value2 struct {
|
|
Style Style
|
|
Label string
|
|
XValue, YValue float64
|
|
}
|