compare

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package compare provides a dual-value comparison graph implementation for the Charta system. It displays two numeric values side-by-side as horizontal bars with independent colors, allowing direct visual comparison between two metrics or data sources.

Index

Constants

This section is empty.

Variables

View Source
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"`  // Graph-level configuration (label, colors, etg.)
	Lines []FileLineStruct  `json:"lines"` // Array of data lines with values
}

FileGraphStruct represents a single graph definition in a structured file. It contains graph-level configuration and multiple data lines.

type FileLineStruct

type FileLineStruct struct {
	Args   map[string]string `json:"args"`   // Line-specific configuration overrides
	Value  float64           `json:"value"`  // First value (left bar)
	Value2 float64           `json:"value2"` // Second value (right bar)
}

FileLineStruct represents a single data line in a structured file. It contains line-specific configuration and the two values to compare.

type FileStruct

type FileStruct struct {
	Graphs []FileGraphStruct `json:"graphs"` // Array of graph definitions
}

FileStruct represents the structure of JSON/YAML input files for compare graphs. It contains multiple graphs, each with configuration arguments and data lines.

type Graph added in v0.5.0

type Graph struct {
	Name          string    // Graph type name ("Compare")
	Values        []float64 // The first value to display (left bar)
	Values2       []float64 // The second value to display (right bar)
	Legend2       string    // Legend text for the second value
	Color2        string    // Color for the second value's bar
	*common.Graph           // Shared configuration and state
}

Compare represents a dual-value comparison graph that displays two numeric values side-by-side as horizontal bars with independent colors and legends. This allows for direct visual comparison between two metrics, such as comparing performance between two servers, before/after measurements, or any two related values.

func (*Graph) AddToParse added in v0.5.0

func (g *Graph) AddToParse(parser *argparse.Parser) *argparse.Parser

AddToParse adds the "compare" subcommand to the argument parser. This allows users to specify compare graph mode and provide two values for comparison. The method registers command-line arguments for both values and their visual properties.

Parameters:

  • parser: The main argument parser to add the subcommand to

Returns:

  • *argparse.Parser: The subparser for the compare command, or nil if parser is nil

func (*Graph) AddValues added in v0.5.0

func (g *Graph) AddValues(value, value2 float64) (printed bool)

AddValues sets both comparison values and immediately renders the graph. Unlike simple or minmax graphs, compare graphs don't support grouping since they are designed for direct one-to-one comparison of two values.

Parameters:

  • value: The first value (left bar)
  • value2: The second value (right bar)

Returns:

  • printed: Always returns true since the graph is always rendered

func (*Graph) GetName added in v0.5.0

func (g *Graph) GetName() string

func (*Graph) InitValues added in v0.5.0

func (g *Graph) InitValues()

func (*Graph) New added in v0.5.0

func (g *Graph) New(cg *common.Graph) common.Grapher

New creates a new Compare graph instance and registers it with the common graph system.

Parameters:

  • cg: Pointer to the shared Graph configuration

Returns:

  • common.Grapher: New Compare graph instance implementing the Grapher interface

func (*Graph) ParseLine added in v0.5.0

func (g *Graph) ParseLine(line string) (printed bool)

ParseLine processes a single line of input data for the compare graph. Handles both key=value pairs for configuration and space-separated numeric value pairs.

Input formats:

  • "value1 value2" - Two space-separated numbers to compare
  • "key=value" - Configuration setting
  • "new" - Print current graph and prepare for new data
  • "new graph" - Print and reset all configuration

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

func (g *Graph) Print(newline bool)

Print renders the compare graph to the terminal. Displays two horizontal bars side-by-side with a centered label between them. The graph includes: - Two independent colored bars for visual comparison - Centered label between the bars - Automatic scale calculation based on the maximum of both values - Overflow indicators (🯝 and 🯟) for values outside the scale range - Support for custom colors and legends for each value

The layout is: [left_bar] LABEL [right_bar]

Parameters:

  • newline: If true, ends with newline; if false, ends with carriage return (for updates)

func (*Graph) PrintCondensed added in v0.7.0

func (g *Graph) PrintCondensed()

func (*Graph) PrintHelpFile added in v0.5.0

func (g *Graph) PrintHelpFile(t string)

func (*Graph) PrintLegend added in v0.5.0

func (g *Graph) PrintLegend()

PrintLegend prints the legend for both values if configured. The legend shows the scale and labels for both the left and right bars. It is only printed once per graph, even if Print is called multiple times. PrintLegend prints the legend for both values if configured. The legend shows the scale and labels for both the left and right bars. It is only printed once per graph, even if Print is called multiple times.

func (*Graph) PrintNormal added in v0.7.0

func (g *Graph) PrintNormal()

func (*Graph) ProcessStructuredFile added in v0.5.0

func (g *Graph) ProcessStructuredFile(f, ext string) error

ProcessStructuredFile reads and processes JSON or YAML files containing graph data. Supports multiple graphs with individual configurations and multiple data lines per graph. Command-line arguments take precedence over file-based configuration.

File structure:

  • graphs: Array of graph definitions
  • Each graph has: args (configuration) and lines (data)
  • Each line has: args (overrides) and value/value2 (data)

Parameters:

  • f: Path to the file (relative or absolute)
  • ext: File extension (.json, .yaml, or .yml)

Returns:

  • error: Any error encountered during file reading, parsing, or processing

Jump to

Keyboard shortcuts

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