Documentation
¶
Overview ¶
Package cumul provides a cumulative multi-value graph implementation for the Charta system. It displays multiple numeric values as stacked horizontal bars with configurable colors, labels, and scaling. Each value is represented as a colored segment in a single cumulative bar, making it ideal for visualizing parts of a whole or comparing multiple components that sum to a total.
Index ¶
- Variables
- type FileGraphStruct
- type FileLineStruct
- type FileStruct
- type Graph
- func (g *Graph) AddToParse(parser *argparse.Parser) *argparse.Parser
- func (g *Graph) AddValue(value float64) (printed bool)
- func (g *Graph) GetName() string
- func (g *Graph) InitValues()
- func (g *Graph) New(common *common.Graph) common.Grapher
- func (g *Graph) ParseLine(line string) (printed bool)
- func (g *Graph) Print(newline bool)
- func (g *Graph) PrintHelpFile(t string)
- func (g *Graph) PrintLegend()
- func (g *Graph) ProcessStructuredFile(f, ext string) error
Constants ¶
This section is empty.
Variables ¶
var HelpFiles embed.FS
PrintHelpFile displays embedded help content for a specific file type. Exits the program after displaying help or error.
Parameters:
- t: File type to display help for (e.g., "txt", "json", "yaml")
Functions ¶
This section is empty.
Types ¶
type FileGraphStruct ¶
type FileGraphStruct struct {
Args map[string]string `json:"args"`
Colors []string `json:"colors"`
Labels []string `json:"labels"`
Lines []FileLineStruct `json:"lines"`
}
FileGraphStruct represents a single graph configuration within a file. It includes graph-level arguments and multiple data lines.
type FileLineStruct ¶
type FileLineStruct struct {
// Args map[string]string `json:"args"`
Values []float64 `json:"values"`
}
FileLineStruct represents a single line of data within a graph. It includes line-specific arguments and a map of labeled values.
type FileStruct ¶
type FileStruct struct {
Graphs []FileGraphStruct `json:"graphs"`
}
FileStruct represents the structure of JSON/YAML input files for cumul graphs. It contains an array of graph configurations, each with arguments and data lines.
type Graph ¶ added in v0.5.0
type Graph struct {
Name string
Values []float64
Colors []string
Labels []string
NoLegend bool
*common.Graph // Shared configuration and state
}
Cumul represents a cumulative multi-value graph that displays multiple numeric values as stacked horizontal bars. Each value is rendered as a colored segment, creating a visual representation of how different components contribute to a total.
Fields:
- Name: Graph type identifier ("cumul")
- Values: Slice of numeric values to display as stacked segments
- Colors: Slice of color names for each value segment
- Labels: Slice of text labels for each value (shown in legend)
- NoLegend: If true, suppresses the legend display
- Graph: Embedded shared configuration (width, title, etg.)
func (*Graph) AddToParse ¶ added in v0.5.0
AddToParse adds the "cumul" subcommand to the argument parser. This registers all cumul-specific command-line options including colors, labels, and the nolegend flag.
Parameters:
- parser: The main argument parser to add the subcommand to
func (*Graph) AddValue ¶ added in v0.5.0
AddValue adds a numeric value to the cumul graph's value list. Unlike simple graphs, cumul graphs accumulate multiple values to display as stacked segments. Values are not automatically printed; call Print() explicitly or use "new" command to render the accumulated values.
Parameters:
- value: The numeric value to add
Returns:
- printed: true if the graph was rendereL labd as a result of adding this value
func (*Graph) GetName ¶ added in v0.5.0
GetName returns the name identifier for this graph type.
Returns:
- string: The graph type name ("cumul")
func (*Graph) InitValues ¶ added in v0.5.0
func (g *Graph) InitValues()
func (*Graph) New ¶ added in v0.5.0
New creates a new Cumul graph instance with the provided common configuration.
Parameters:
- common: Pointer to the shared Graph configuration containing width, title, colors, and other display settings
Returns:
- common.Grapher: New Cumul graph instance implementing the Grapher interface
func (*Graph) ParseLine ¶ added in v0.5.0
ParseLine processes a single line of input data for the cumul graph. Handles key=value pairs for configuration, numeric values to add to the cumulative total, and special commands like "new" and "new=graph".
Parameters:
- line: Input line to process
Returns:
- printed: true if the graph was rendered as a result of this line
func (*Graph) Print ¶ added in v0.5.0
Print renders the cumulative graph to the terminal. Displays a horizontal stacked bar graph where each value is shown as a colored segment. The graph includes:
- Scale indicators showing 0 and maximum values
- Color-coded segments for each value
- Total value displayed within or after the bar
- Automatic scale calculation based on the sum of all values
The bar is composed of adjacent colored segments, each proportional to its value relative to the total. If there's insufficient space, the total value is omitted.
Parameters:
- newline: If true, ends with newline; if false, ends with carriage return
func (*Graph) PrintHelpFile ¶ added in v0.5.0
func (*Graph) PrintLegend ¶ added in v0.5.0
func (g *Graph) PrintLegend()
PrintLegend prints the legend showing color-coded labels for each value segment. The legend displays colored boxes with corresponding labels, wrapping to multiple lines if necessary to fit within the graph width. It is only printed once per graph, even if Print is called multiple times.
This optimized version reduces string allocations by pre-calculating line lengths.
func (*Graph) ProcessStructuredFile ¶ added in v0.5.0
ProcessStructuredFile reads and processes JSON or YAML files containing cumul graph data. Supports multiple graphs with individual configurations and multiple lines per graph. Each line can have its own arguments and multiple labeled values.
Parameters:
- f: Path to the file
- ext: File extension (.json, .yaml, or .yml)
Returns:
- error: Any error encountered during file processing