Documentation ¶
Index ¶
- func Bar(length int) string
- func Count(format string) string
- func CountIf(pos string, neg string) string
- func FloatFormat(length int) []string
- func Fprint[T histogram.Indexable](w io.Writer, h histogram.Histogram[T], formats ...string) error
- func IntFormat(length int) []string
- func Pct(format string) string
- func Range(format string) string
- func StringFormat(length int) []string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountIf ¶
Pct generates a .Pct value using the `pos` Printf format if the value is not zero, `pos` on a zero value. useful for hiding zero values
func FloatFormat ¶
FloatFormat generates a tabulated row with the bar length provided when the value is a float
func Fprint ¶
Fprint writes a histogram to an io.Writer using the format strings provided The format strings use the text/template syntax and write to a text/tabwriter multiple format strings are joined in order using \t to create aligned columns and each line automatically gets a \n, so no need to add an EOL. Values passed to the template:
.Total : the total number of records in the histogram (int) .Pct : percentage represesented by a bucket value relative to .Total (float64) .Min : lower bound of the bucket, inclusive .Max : higher bound of the bucket, exclusive except on the final bucket .Count : count of values in the bucket
[formatting.go](.formatting.go) contains some helper functions for common formats. If no formats are passed, it uses `IntFormat(5)` by default.
Example ¶
data := []float64{ 0.1, 0.2, 0.21, 0.22, 0.22, 0.4, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6, // 0.7 is empty // 0.8, 0.9, 1.0, 0.3, // intenionally out of order // 1000, } hist := histogram.Create(9, data) Fprint(os.Stdout, hist, FloatFormat(50)...)
Output: 0.1-0.2 5% █████ 1 0.2-0.3 25% █████████████████████████ 5 0.3-0.4 0% ▏ - 0.4-0.5 5% █████ 1 0.5-0.6 50% ██████████████████████████████████████████████████ 10 0.6-0.7 5% █████ 1 0.7-0.8 0% ▏ - 0.8-0.9 0% ▏ - 0.9-1 10% ██████████ 2
func IntFormat ¶
IntFormat generates a tabulated row with the bar length provided when the value is an int
func StringFormat ¶
StringFormat generates a tabulated row with the bar length provided when the value implements fmt.Stringer (time.Duration for example)
Types ¶
This section is empty.