graph

package
v0.2.14 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorForIndex

func ColorForIndex(idx int) lipgloss.Color

ColorForIndex returns the color for a given series index, cycling through the Grafana chart palette.

func ComplianceColor

func ComplianceColor(value, target float64) lipgloss.Color

ComplianceColor returns a color reflecting how close value is to target. Both value and target are percentages (0–100).

func RenderBarChart

func RenderBarChart(w io.Writer, data *ChartData, opts ChartOptions) error

RenderBarChart renders instant query data as a horizontal bar chart.

func RenderChart

func RenderChart(w io.Writer, data *ChartData, opts ChartOptions) error

RenderChart auto-selects chart type based on data characteristics. For instant queries (single point per series at same timestamp), uses bar chart. For range queries (multiple points over time), uses line chart.

func RenderLineChart

func RenderLineChart(w io.Writer, data *ChartData, opts ChartOptions) error

RenderLineChart renders a line chart to the writer.

func RenderPercentageBars

func RenderPercentageBars(w io.Writer, title string, items []PercentageBarItem, opts ChartOptions) error

RenderPercentageBars renders labeled horizontal bars scaled 0–100%. Each item gets a line: name, filled/unfilled bar, value, and optional target.

Types

type ChartData

type ChartData struct {
	Title  string
	Series []Series
}

ChartData represents data ready to be rendered as a chart.

func FromLokiMetricResponse added in v0.2.2

func FromLokiMetricResponse(resp *loki.MetricQueryResponse) (*ChartData, error)

FromLokiMetricResponse converts a Loki metric query response (time-series) to ChartData.

func FromLokiResponse

func FromLokiResponse(resp *loki.QueryResponse) (*ChartData, error)

FromLokiResponse converts a Loki query response to ChartData.

func FromPrometheusResponse

func FromPrometheusResponse(resp *prometheus.QueryResponse) (*ChartData, error)

FromPrometheusResponse converts a Prometheus query response to ChartData.

func FromPyroscopeResponse

func FromPyroscopeResponse(resp *pyroscope.QueryResponse) (*ChartData, error)

FromPyroscopeResponse converts a Pyroscope query response to ChartData for visualization. It extracts the top functions by self-time and renders them as a horizontal bar chart.

func FromPyroscopeSeriesResponse added in v0.2.0

func FromPyroscopeSeriesResponse(resp *pyroscope.SelectSeriesResponse) (*ChartData, error)

FromPyroscopeSeriesResponse converts a SelectSeries response to ChartData for time-series visualization.

func FromTempoMetricsResponse added in v0.2.2

func FromTempoMetricsResponse(resp *tempo.MetricsResponse) (*ChartData, error)

FromTempoMetricsResponse converts a Tempo metrics query response to ChartData.

func FromTopSeriesResponse added in v0.2.0

func FromTopSeriesResponse(resp *pyroscope.TopSeriesResponse) *ChartData

FromTopSeriesResponse converts a TopSeriesResponse to ChartData for bar chart visualization.

func (*ChartData) IsInstantQuery

func (d *ChartData) IsInstantQuery() bool

IsInstantQuery returns true if all series have exactly one data point at the same timestamp (typical of Prometheus instant/vector queries).

type ChartOptions

type ChartOptions struct {
	Width    int
	Height   int
	Title    string
	TextOnly bool
	MaxValue *float64 // Optional max value for bar charts (e.g., 100 for percentages)
}

ChartOptions configures chart rendering.

func DefaultChartOptions

func DefaultChartOptions() ChartOptions

DefaultChartOptions returns default chart options.

type PercentageBarItem

type PercentageBarItem struct {
	Name   string  // Label shown to the left of the bar
	Value  float64 // Current value as percentage (0–100)
	Target float64 // Target/objective as percentage (0–100); 0 means no target
}

PercentageBarItem represents a single item in a percentage bar chart.

type Point

type Point struct {
	Time  time.Time
	Value float64
}

Point represents a single data point.

type Series

type Series struct {
	Name   string
	Labels map[string]string
	Points []Point
	Color  lipgloss.Color // Optional: if set, overrides ColorForIndex for this series
}

Series represents a single time series in the chart.

Jump to

Keyboard shortcuts

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