Documentation ¶
Overview ¶
Package metric draws metric graphs using SVG lines. it is primarily taken from zserge/metric.
Index ¶
- Variables
- func FormatBytes(b float64) string
- func FormatDecimalPlaces(dec int) func(float64) string
- func FormatPercentage(dec int, typ byte) func(float64) string
- func FormatSigFigs(sf int) func(float64) string
- type GraphData
- func (data *GraphData) AddSamples(name string, n int) int
- func (data *GraphData) ColorHex(nameIx int) template.HTMLAttr
- func (data *GraphData) IsLaterHalf(i int) bool
- func (data *GraphData) IsNullAt(i int) bool
- func (data *GraphData) MidSample() float64
- func (data *GraphData) PointInString(pt float64) string
- func (data *GraphData) RangeTime(i int) time.Time
Constants ¶
This section is empty.
Variables ¶
var AutoValue = NaN
AutoValue is used in min/max sample numbers to make path find the threshold dynamically.
var NaN = math.NaN()
NaN is a float64 not-a-number constant.
Functions ¶
func FormatBytes ¶
FormatBytes plugs into PtString to format bytes as strings.
func FormatDecimalPlaces ¶
FormatDecimalPlaces returns a new PtString formatter that formats a floating point number to the given decimal places.
func FormatPercentage ¶
FormatPercentage plugs into PtString to format the float as a percentage. typ should be either 'g' or 'f'.
func FormatSigFigs ¶
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 ¶
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 ¶
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 ¶
IsLaterHalf returns true if the current width index is beyond half.
func (*GraphData) IsNullAt ¶
IsNullAt returns true if all samplesets at the given index contain NaN values.
func (*GraphData) PointInString ¶
PointInString calls data.PtString if pt is a number. If pt is NaN, then "null" is returned.