metric

package
v0.0.0-...-8f0b1ba Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package metric draws metric graphs using SVG lines. it is primarily taken from zserge/metric.

Index

Constants

This section is empty.

Variables

View Source
var AutoValue = NaN

AutoValue is used in min/max sample numbers to make path find the threshold dynamically.

View Source
var NaN = math.NaN()

NaN is a float64 not-a-number constant.

Functions

func FormatBytes

func FormatBytes(b float64) string

FormatBytes plugs into PtString to format bytes as strings.

func FormatDecimalPlaces

func FormatDecimalPlaces(dec int) func(float64) string

FormatDecimalPlaces returns a new PtString formatter that formats a floating point number to the given decimal places.

func FormatPercentage

func FormatPercentage(dec int, typ byte) func(float64) string

FormatPercentage plugs into PtString to format the float as a percentage. typ should be either 'g' or 'f'.

func FormatSigFigs

func FormatSigFigs(sf int) func(float64) string

FormatSigFigs returns a new PtString formatter that formats a floating point number to the given significant figures with trailing zeros trimmed out.

Types

type GraphData

type GraphData struct {
	// Names contains a list of names that correspond to each Samples sets.
	Names []string
	// Colors contains a list of colors that correspond to Names. If there are
	// more names than colors, then those names will be colored black.
	Colors []uint32
	// Samplesets contains a sampleset list of samples. Sample points can be
	// NaN, in which it will not be drawn out. If samplesets don't have equal
	// lengths, then an error will be returned and the graph will not be drawn.
	Samplesets [][]float64
	// PtString formats each sample point into a human-readable string.
	PtString func(float64) string
	// Range describes the time range of this graph.
	Range sysmet.BucketRange
	// MaxSample is the maximum sample point. If NaN, then it will be manually
	// found.
	MaxSample float64 // NaN values are changed
	// MinSample is similar to MaxSample but for miminum.
	MinSample float64
	// Width describes the number of points that the graph should have; if it's
	// 0, then the number of samples will be used instead. It is only relative:
	// SVGs can be scaled arbitrarily.
	Width float64
	// Height is the height of the graph. It determines the aspect ratio of the
	// graph.
	Height float64
}

GraphData contains the data for graphing. Width and Height are optional.

func NewGraphData

func NewGraphData(b sysmet.SnapshotBuckets, height int, names ...string) GraphData

NewGraphData creates a new graph data with reasonable defaults.

func (*GraphData) AddSamples

func (data *GraphData) AddSamples(name string, n int) int

AddSamples adds a new set of samples with the given n length. If n mismatches existing samplesets sizes, then it'll panic.

func (*GraphData) ColorHex

func (data *GraphData) ColorHex(nameIx int) template.HTMLAttr

ColorHex returns the name's color in CSS hexadecimal format. It returns an empty string if the name isn't in the colors list.

func (*GraphData) IsLaterHalf

func (data *GraphData) IsLaterHalf(i int) bool

IsLaterHalf returns true if the current width index is beyond half.

func (*GraphData) IsNullAt

func (data *GraphData) IsNullAt(i int) bool

IsNullAt returns true if all samplesets at the given index contain NaN values.

func (*GraphData) MidSample

func (data *GraphData) MidSample() float64

MidSample returns the middle sample between min and max.

func (*GraphData) PointInString

func (data *GraphData) PointInString(pt float64) string

PointInString calls data.PtString if pt is a number. If pt is NaN, then "null" is returned.

func (*GraphData) RangeTime

func (data *GraphData) RangeTime(i int) time.Time

RangeTime returns the time of the sample from the given index.

Jump to

Keyboard shortcuts

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