Documentation
¶
Overview ¶
Package minmax provides a min/max/average graph implementation for the Charta system. It displays multiple numeric values showing the minimum, maximum, and average as a horizontal bar graph with visual indicators for each statistic.
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) PrintNegPosGraph(c, textBeforeMin, textBeforeAvg, textAfterAvg, textAfterMax string)
- func (g *Graph) PrintNegativeGraph(c, textBeforeMin, textBeforeAvg, textAfterAvg, textAfterMax string)
- func (g *Graph) PrintPositiveGraph(c, textBeforeMin, textBeforeAvg, textAfterAvg, textAfterMax string)
- func (g *Graph) PrintStringGraph(min, avg, max float64)
- 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 ¶ added in v0.2.0
type FileGraphStruct struct {
Args map[string]string `json:"args"` // Graph-level configuration (label, colors, etc.)
Lines []FileLineStruct `json:"lines"` // Array of data lines with values
}
FileGraphStruct represents a single MinMax graph configuration within a file. It includes graph-level configuration and multiple data lines.
type FileLineStruct ¶ added in v0.2.0
type FileLineStruct struct {
Args map[string]string `json:"args"` // Line-specific configuration overrides
Values []float64 `json:"values"` // Array of numeric values to analyze
}
FileLineStruct represents a single data line in a structured file. It contains line-specific configuration and the values to analyze.
type FileStruct ¶ added in v0.2.0
type FileStruct struct {
Graphs []FileGraphStruct `json:"graphs"` // Array of graph definitions
}
FileStruct represents the structure of JSON/YAML input files for MinMax graphs. It contains an array of graph configurations, each with arguments and data lines. This structure allows multiple MinMax graphs to be defined in a single file.
type Graph ¶ added in v0.5.0
type Graph struct {
Name string // Graph type identifier ("MinMax")
Values []float64 // Collection of values to analyze
*common.Graph // Shared configuration and state
}
Graph represents a min/max/average graph that displays statistical information about a collection of numeric values as a horizontal bar with markers for minimum, average (with a special symbol ⧗), and maximum values.
The MinMax graph analyzes multiple values and displays:
- Minimum value (leftmost position with 🮐 characters)
- Average value (marked with ⧗ symbol)
- Maximum value (rightmost position)
This visualization is ideal for showing data distribution and central tendency.
func (*Graph) AddToParse ¶ added in v0.5.0
AddToParse adds the "minmax" subcommand to the argument parser. This allows users to specify minmax graph mode and provide multiple values.
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 minmax graph's dataset. Handles both single values and grouped values based on the GroupBy setting. When grouping is enabled, values are accumulated until the group is complete, then the graph is rendered and the dataset is cleared for the next group.
Parameters:
- value: The numeric value to add
Returns:
- printed: true if the graph was rendered 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 ("MinMax")
func (*Graph) InitValues ¶ added in v0.5.0
func (g *Graph) InitValues()
func (*Graph) New ¶ added in v0.5.0
New creates a new MinMax graph instance and registers it with the common graph system.
Parameters:
- common: Pointer to the shared Graph configuration containing width, min/max values, labels, colors, and other display settings
Returns:
- common.Grapher: New MinMax graph instance implementing the Grapher interface
func (*Graph) ParseLine ¶ added in v0.5.0
ParseLine processes a single line of input data for the minmax graph. Handles both key=value pairs for configuration and plain numeric values.
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 min/max/average graph to the terminal. Displays a horizontal bar graph with minimum, average (⧗), and maximum values, including color coding based on thresholds and overflow indicators.
Parameters:
- newline: If true, ends with newline; if false, ends with carriage return
func (*Graph) PrintHelpFile ¶ added in v0.5.0
func (*Graph) PrintNegPosGraph ¶ added in v0.12.0
func (g *Graph) PrintNegPosGraph(c, textBeforeMin, textBeforeAvg, textAfterAvg, textAfterMax string)
getNegPosGraph renders a graph for positive values with colored segments. The graph shows minimum, average (⧗), and maximum positions with appropriate coloring.
Parameters:
- c: Primary color for the graph bar
- textBeforeMin, textBeforeAvg, textAfterAvg, textAfterMax: Text of parts)
Returns:
- text: Formatted graph string
func (*Graph) PrintNegativeGraph ¶ added in v0.12.0
func (g *Graph) PrintNegativeGraph(c, textBeforeMin, textBeforeAvg, textAfterAvg, textAfterMax string)
getNegativeGraph renders a graph for positive values with colored segments. The graph shows minimum, average (⧗), and maximum positions with appropriate coloring.
Parameters:
- c: Primary color for the graph bar
- textBeforeMin, textBeforeAvg, textAfterAvg, textAfterMax: Text of parts)
Returns:
- text: Formatted graph string
func (*Graph) PrintPositiveGraph ¶ added in v0.12.0
func (g *Graph) PrintPositiveGraph(c, textBeforeMin, textBeforeAvg, textAfterAvg, textAfterMax string)
getPositiveGraph renders a graph for positive values with colored segments. The graph shows minimum, average (⧗), and maximum positions with appropriate coloring.
Parameters:
- c: Primary color for the graph bar
- textBeforeMin, textBeforeAvg, textAfterAvg, textAfterMax: Text of parts)
Returns:
- text: Formatted graph string
func (*Graph) PrintStringGraph ¶ added in v0.12.0
getStringGraph generates the complete graph string with all elements. Determines appropriate colors based on thresholds and delegates to specific rendering functions based on value signs.
This optimized version reduces string allocations and improves performance by pre-calculating values and using more efficient string operations.
Parameters:
- min: Minimum value from the dataset
- avg: Average value from the dataset
- max: Maximum value from the dataset
Returns:
- string: Complete formatted graph with brackets and overflow indicators
func (*Graph) ProcessStructuredFile ¶ added in v0.5.0
ProcessStructuredFile reads and processes JSON or YAML files containing graph data. Supports multiple graphs and lines with individual configurations.
Parameters:
- f: Path to the file
- ext: File extension (.json, .yaml, or .yml)
Returns:
- error: Any error encountered during file processing