Documentation ¶
Overview ¶
Package barchart is a helper to quickly create barchart from pairs of integers.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fprint ¶
Fprint plots p as a Unicode XY plot, using scale s. The results is something like:
0 █ 1 1 ██▉ 3 2 ███▉ 4 3 █████▊ 6 4 ███████▋ 8 5 nil 6 nil 7 ██████████████▎ 15 8 █████████▋ 10 9 ██████▋ 7 10 ████▊ 5 11 ██▉ 3 12 ██ 2 13 █ 1 14 ▏ 0 15 ███████████████████▏ 20
func Fprintf ¶
Fprintf plots p as a Unicode XY plot of width, scaling Y values with s and rendering axis labels with x and y format funcs. As in the example, you can render pretty things like:
12:06:00.098 █████▋ 12MB 12:06:00.213 ████▋ 8.0MB 12:06:00.329 ██████▋ 10MB 12:06:00.444 ▏ 3.0MB 12:06:00.559 nil 12:06:00.675 nil 12:06:00.790 ██████████████▉ 22MB 12:06:00.906 ████████████▏ 16MB 12:06:01.021 ████▋ 8.0MB 12:06:01.136 ▏ 3.0MB 12:06:01.252 █████▋ 9.0MB 12:06:01.367 ███▊ 7.0MB 12:06:01.483 ███████████▏ 15MB 12:06:01.598 ████▋ 8.0MB
Types ¶
type BarChart ¶
type BarChart struct {
MinX, MaxX, MinY, MaxY int
// contains filtered or unexported fields
}
BarChart of XY points.
func BarChartXYs ¶
BarChartXYs builds a BarChart using pairwise X and Y []float64.
Example ¶
data := [][2]int{ {0, 1}, {1, 3}, {2, 4}, {3, 6}, {4, 8}, // nil, // nil, {7, 15}, {8, 10}, {9, 7}, {10, 5}, {11, 3}, {12, 2}, {13, 1}, {14, 0}, {15, 20}, } plot := BarChartXYs(data) if err := Fprint(os.Stdout, plot, Linear(19)); err != nil { panic(err) }
Output: 0 █ 1 1 ██▉ 3 2 ███▉ 4 3 █████▊ 6 4 ███████▋ 8 5 nil 6 nil 7 ██████████████▎ 15 8 █████████▋ 10 9 ██████▋ 7 10 ████▊ 5 11 ██▉ 3 12 ██ 2 13 █ 1 14 ▏ 0 15 ███████████████████▏ 20
Example (Time) ¶
base := time.Date(1984, 01, 01, 00, 00, 00, 00, time.UTC) baseplus := func(i int) int { return int(base.Add(time.Duration(i) * time.Millisecond).UnixNano()) } mb := 1000000 r := rand.New(rand.NewSource(42)) data := [][2]int{ {baseplus(0), r.Intn(20) * mb}, {baseplus(100), r.Intn(20) * mb}, {baseplus(200), r.Intn(20) * mb}, {baseplus(300), r.Intn(20) * mb}, {baseplus(400), r.Intn(20) * mb}, // nil, // nil, {baseplus(700), r.Intn(20) * mb}, {baseplus(800), r.Intn(20) * mb}, {baseplus(900), r.Intn(20) * mb}, {baseplus(1000), r.Intn(20) * mb}, {baseplus(1100), r.Intn(20) * mb}, {baseplus(1200), r.Intn(20) * mb}, {baseplus(1300), r.Intn(20) * mb}, {baseplus(1400), r.Intn(20) * mb}, {baseplus(1500), r.Intn(20) * mb}, } xfmt := func(x float64) string { return time.Unix(base.Unix(), int64(x)).Format("15:04:05.000") } yfmt := func(y float64) string { return humanize.Bytes(uint64(y)) } plot := BarChartXYs(data) if err := Fprintf(os.Stdout, plot, len(data), Linear(13), xfmt, yfmt); err != nil { panic(err) } // 19:00:00.000 ██████▏ 12MB // 19:00:00.115 ███▌ 8.0MB // 19:00:00.230 ████▊ 10MB // 19:00:00.346 ▏ 3.0MB // 19:00:00.461 nil // 19:00:00.576 nil // 19:00:00.692 █████████████▏ 22MB // 19:00:00.807 ████████▉ 16MB // 19:00:00.923 ███▌ 8.0MB // 19:00:01.038 ▏ 3.0MB // 19:00:01.153 ████▏ 9.0MB // 19:00:01.269 ██▊ 7.0MB // 19:00:01.384 ████████▎ 15MB // 19:00:01.500 ███▌ 8.0MB
Output:
type FormatFunc ¶
FormatFunc formats a float into the proper string form. Used to print meaningful axe labels.
Click to show internal directories.
Click to hide internal directories.