mopac-pdf v0: markdown to beautiful PDFs via digest-pinned typst
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
This commit is contained in:
+89
@@ -0,0 +1,89 @@
|
||||
package chart
|
||||
|
||||
// Interface Assertions.
|
||||
var (
|
||||
_ Series = (*PercentChangeSeries)(nil)
|
||||
_ FirstValuesProvider = (*PercentChangeSeries)(nil)
|
||||
_ LastValuesProvider = (*PercentChangeSeries)(nil)
|
||||
_ ValueFormatterProvider = (*PercentChangeSeries)(nil)
|
||||
)
|
||||
|
||||
// PercentChangeSeriesSource is a series that
|
||||
// can be used with a PercentChangeSeries
|
||||
type PercentChangeSeriesSource interface {
|
||||
Series
|
||||
FirstValuesProvider
|
||||
LastValuesProvider
|
||||
ValuesProvider
|
||||
ValueFormatterProvider
|
||||
}
|
||||
|
||||
// PercentChangeSeries applies a
|
||||
// percentage difference function to a given continuous series.
|
||||
type PercentChangeSeries struct {
|
||||
Name string
|
||||
Style Style
|
||||
YAxis YAxisType
|
||||
InnerSeries PercentChangeSeriesSource
|
||||
}
|
||||
|
||||
// GetName returns the name of the time series.
|
||||
func (pcs PercentChangeSeries) GetName() string {
|
||||
return pcs.Name
|
||||
}
|
||||
|
||||
// GetStyle returns the line style.
|
||||
func (pcs PercentChangeSeries) GetStyle() Style {
|
||||
return pcs.Style
|
||||
}
|
||||
|
||||
// Len implements part of Series.
|
||||
func (pcs PercentChangeSeries) Len() int {
|
||||
return pcs.InnerSeries.Len()
|
||||
}
|
||||
|
||||
// GetFirstValues implements FirstValuesProvider.
|
||||
func (pcs PercentChangeSeries) GetFirstValues() (x, y float64) {
|
||||
return pcs.InnerSeries.GetFirstValues()
|
||||
}
|
||||
|
||||
// GetValues gets x, y values at a given index.
|
||||
func (pcs PercentChangeSeries) GetValues(index int) (x, y float64) {
|
||||
_, fy := pcs.InnerSeries.GetFirstValues()
|
||||
x0, y0 := pcs.InnerSeries.GetValues(index)
|
||||
x = x0
|
||||
y = PercentDifference(fy, y0)
|
||||
return
|
||||
}
|
||||
|
||||
// GetValueFormatters returns value formatter defaults for the series.
|
||||
func (pcs PercentChangeSeries) GetValueFormatters() (x, y ValueFormatter) {
|
||||
x, _ = pcs.InnerSeries.GetValueFormatters()
|
||||
y = PercentValueFormatter
|
||||
return
|
||||
}
|
||||
|
||||
// GetYAxis returns which YAxis the series draws on.
|
||||
func (pcs PercentChangeSeries) GetYAxis() YAxisType {
|
||||
return pcs.YAxis
|
||||
}
|
||||
|
||||
// GetLastValues gets the last values.
|
||||
func (pcs PercentChangeSeries) GetLastValues() (x, y float64) {
|
||||
_, fy := pcs.InnerSeries.GetFirstValues()
|
||||
x0, y0 := pcs.InnerSeries.GetLastValues()
|
||||
x = x0
|
||||
y = PercentDifference(fy, y0)
|
||||
return
|
||||
}
|
||||
|
||||
// Render renders the series.
|
||||
func (pcs PercentChangeSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) {
|
||||
style := pcs.Style.InheritFrom(defaults)
|
||||
Draw.LineSeries(r, canvasBox, xrange, yrange, style, pcs)
|
||||
}
|
||||
|
||||
// Validate validates the series.
|
||||
func (pcs PercentChangeSeries) Validate() error {
|
||||
return pcs.InnerSeries.Validate()
|
||||
}
|
||||
Reference in New Issue
Block a user