From 8d3c47d74deab3ea682c6ecf636a8907cc21b30d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 10 Apr 2024 07:32:32 +0000 Subject: [PATCH] Bump github.com/guptarohit/asciigraph from 0.5.5 to 0.7.1 Bumps [github.com/guptarohit/asciigraph](https://github.com/guptarohit/asciigraph) from 0.5.5 to 0.7.1. - [Release notes](https://github.com/guptarohit/asciigraph/releases) - [Changelog](https://github.com/guptarohit/asciigraph/blob/master/CHANGELOG.md) - [Commits](https://github.com/guptarohit/asciigraph/compare/v0.5.5...v0.7.1) --- updated-dependencies: - dependency-name: github.com/guptarohit/asciigraph dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../guptarohit/asciigraph/.goreleaser.yml | 15 +- .../guptarohit/asciigraph/CHANGELOG.md | 100 +++++++++++++ .../guptarohit/asciigraph/README.md | 136 +++++++++++++----- .../guptarohit/asciigraph/asciigraph.go | 10 ++ .../guptarohit/asciigraph/legend.go | 45 ++++++ .../guptarohit/asciigraph/options.go | 37 +++-- vendor/modules.txt | 2 +- 9 files changed, 297 insertions(+), 54 deletions(-) create mode 100644 vendor/github.com/guptarohit/asciigraph/CHANGELOG.md create mode 100644 vendor/github.com/guptarohit/asciigraph/legend.go diff --git a/go.mod b/go.mod index b2a5f3395..a5b009380 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/go-openapi/loads v0.22.0 github.com/go-openapi/spec v0.21.0 github.com/go-xmlfmt/xmlfmt v1.1.2 - github.com/guptarohit/asciigraph v0.5.5 + github.com/guptarohit/asciigraph v0.7.1 github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 github.com/opentracing/opentracing-go v1.2.0 github.com/peterbourgon/diskv v2.0.1+incompatible diff --git a/go.sum b/go.sum index cb75d3d3c..698a4cd0b 100644 --- a/go.sum +++ b/go.sum @@ -87,8 +87,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/guptarohit/asciigraph v0.5.5 h1:ccFnUF8xYIOUPPY3tmdvRyHqmn1MYI9iv1pLKX+/ZkQ= -github.com/guptarohit/asciigraph v0.5.5/go.mod h1:dYl5wwK4gNsnFf9Zp+l06rFiDZ5YtXM6x7SRWZ3KGag= +github.com/guptarohit/asciigraph v0.7.1 h1:K+JWbRc04XEfv8BSZgNuvhCmpbvX4+9NYd/UxXVnAuk= +github.com/guptarohit/asciigraph v0.7.1/go.mod h1:dYl5wwK4gNsnFf9Zp+l06rFiDZ5YtXM6x7SRWZ3KGag= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f h1:7LYC+Yfkj3CTRcShK0KOL/w6iTiKyqqBA9a41Wnggw8= diff --git a/vendor/github.com/guptarohit/asciigraph/.goreleaser.yml b/vendor/github.com/guptarohit/asciigraph/.goreleaser.yml index dc61ea8d0..23e7bc911 100644 --- a/vendor/github.com/guptarohit/asciigraph/.goreleaser.yml +++ b/vendor/github.com/guptarohit/asciigraph/.goreleaser.yml @@ -30,13 +30,14 @@ archives: files: - LICENSE - README.md - # Replacements for GOOS and GOARCH on the archive name. - replacements: - '386': i386 - darwin: Darwin - linux: Linux - windows: Windows - amd64: x86_64 + name_template: >- + {{- .ProjectName }}_ + {{- .Version }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end -}} format_overrides: - goos: windows format: zip diff --git a/vendor/github.com/guptarohit/asciigraph/CHANGELOG.md b/vendor/github.com/guptarohit/asciigraph/CHANGELOG.md new file mode 100644 index 000000000..9b538b929 --- /dev/null +++ b/vendor/github.com/guptarohit/asciigraph/CHANGELOG.md @@ -0,0 +1,100 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## [0.7.1] - 2024-03-30 + +### Added + +- CLI: Option to specify legends for series (`sl`) + +## [0.7.0] - 2024-03-30 + +### Added + +- CLI: Options to specify delimiter (`d`) and number of series (`sn`) + +### Changed + +- CLI: Option (`sc`) to specify series colors + +## [0.6.0] - 2024-03-25 + +### Added + +- Option to add legends for colored graphs + +## [0.5.6] - 2023-06-24 + +### Added + +- Options to set upper & lower bound of graph + +## [0.5.5] - 2022-05-03 + +### Added + +- Ansi colors support for graphs + +## [0.5.4] - 2022-05-03 + +### Added + +- Option to plot multiple series together (#34) +- Dockerfile file support (#33) + +## [0.5.3] - 2022-02-20 + +### Fixed + +- Handled NaN first value (#32) +- Fixed incorrect y-axis start value tick (#31) + +## [0.5.2] - 2021-03-28 + +### Added + +- added support to set custom precision of data point labels along the y-axis +- added go module support + +### Changed + +- updated README to markdown format + +## [0.5.1] - 2020-09-14 + +### Added + +- added support for NaN values in series +- added option to control fps of plot rendering via cli for real-time data + +### Changed + +- removed use of append() method +- make caption centered +- removed trailing spaces from plot + +## [0.5.0] - 2020-06-28 + +### Added + +- added support for the realtime plot of data points (from stdin) for CLI. + +## [0.4.2] - 2020-06-07 + +### Fixed + +- Prevent panics when data is flat. (#8) +- Prevent BADPREC issue when maximum and minimum values in a series are 0. (#10) + +[0.7.1]: https://github.com/guptarohit/asciigraph/releases/tag/v0.7.1 +[0.7.0]: https://github.com/guptarohit/asciigraph/releases/tag/v0.7.0 +[0.6.0]: https://github.com/guptarohit/asciigraph/releases/tag/v0.6.0 +[0.5.6]: https://github.com/guptarohit/asciigraph/releases/tag/v0.5.6 +[0.5.5]: https://github.com/guptarohit/asciigraph/releases/tag/v0.5.5 +[0.5.4]: https://github.com/guptarohit/asciigraph/releases/tag/v0.5.4 +[0.5.3]: https://github.com/guptarohit/asciigraph/releases/tag/v0.5.3 +[0.5.2]: https://github.com/guptarohit/asciigraph/releases/tag/v0.5.2 +[0.5.1]: https://github.com/guptarohit/asciigraph/releases/tag/v0.5.1 +[0.5.0]: https://github.com/guptarohit/asciigraph/releases/tag/v0.5.0 +[0.4.2]: https://github.com/guptarohit/asciigraph/releases/tag/v0.4.2 diff --git a/vendor/github.com/guptarohit/asciigraph/README.md b/vendor/github.com/guptarohit/asciigraph/README.md index dbcd45636..e984dd754 100644 --- a/vendor/github.com/guptarohit/asciigraph/README.md +++ b/vendor/github.com/guptarohit/asciigraph/README.md @@ -7,15 +7,15 @@ Go package to make lightweight ASCII line graphs ╭┈╯. ![image][] ## Installation -``` bash -go get github.com/guptarohit/asciigraph +```bash +go get -u github.com/guptarohit/asciigraph@latest ``` ## Usage ### Basic graph -``` go +```go package main import ( @@ -32,7 +32,7 @@ func main() { ``` Running this example would render the following graph: -``` bash +```bash 10.00 ┤ ╭╮ 9.00 ┤ ╭╮ ││ 8.00 ┤ ││ ╭╮││ @@ -46,7 +46,7 @@ Running this example would render the following graph: ### Multiple Series -``` go +```go package main import ( @@ -63,7 +63,7 @@ func main() { ``` Running this example would render the following graph: -``` bash +```bash 6.00 ┤ ╭─ 5.00 ┼╮ │ 4.00 ┤╰╮ ╭╯ @@ -75,7 +75,7 @@ Running this example would render the following graph: ### Colored graphs -``` go +```go package main import ( @@ -110,10 +110,63 @@ Running this example would render the following graph: ![colored_graph_image][] -## Command line interface +### Legends for colored graphs + +The graph can include legends for each series, making it easier to interpret. + +```go +package main + +import ( + "fmt" + "github.com/guptarohit/asciigraph" + "math" +) + +func main() { + data := make([][]float64, 3) + for i := 0; i < 3; i++ { + for x := -12; x <= 12; x++ { + v := math.NaN() + if r := 12 - i; x >= -r && x <= r { + v = math.Sqrt(math.Pow(float64(r), 2)-math.Pow(float64(x), 2)) / 2 + } + data[i] = append(data[i], v) + } + } + graph := asciigraph.PlotMany(data, + asciigraph.Precision(0), + asciigraph.SeriesColors(asciigraph.Red, asciigraph.Green, asciigraph.Blue), + asciigraph.SeriesLegends("Red", "Green", "Blue"), + asciigraph.Caption("Series with legends")) + fmt.Println(graph) +} +``` +Running this example would render the following graph: + +![graph_with_legends_image][] + + +## CLI Installation This package also brings a small utility for command line usage. -``` bash ✘ 0|125  16:19:23 + +Assuming `$GOPATH/bin` is in your `$PATH`, install CLI with following command: +```bash +go install github.com/guptarohit/asciigraph/cmd/asciigraph@latest +``` + +or pull Docker image: +```bash +docker pull ghcr.io/guptarohit/asciigraph:latest +``` + +or download binaries from the [releases][] page. + + +## CLI Usage + +```bash ✘ 0|125  16:19:23 > asciigraph --help Usage of asciigraph: asciigraph [options] @@ -126,10 +179,14 @@ Options: caption for the graph -cc caption color caption color of the plot + -d delimiter + data delimiter for splitting data points in the input stream (default ",") -f fps set fps to control how frequently graph to be rendered when realtime graph enabled (default 24) -h height height in text rows, 0 for auto-scaling + -lb lower bound + lower bound set the minimum value for the vertical axis (ignored if series contains lower values) (default +Inf) -lc label color y-axis label color of the plot -o offset @@ -138,43 +195,33 @@ Options: precision of data point labels along the y-axis (default 2) -r realtime enables realtime graph for data stream - -sc series color - series color of the plot + -sc series colors + comma-separated series colors corresponding to each series + -sl series legends + comma-separated series legends corresponding to each series + -sn number of series + number of series (columns) in the input data (default 1) + -ub upper bound + upper bound set the maximum value for the vertical axis (ignored if series contains larger values) (default -Inf) -w width width in columns, 0 for auto-scaling asciigraph expects data points from stdin. Invalid values are logged to stderr. ``` -### CLI Installation -Assuming `$GOPATH/bin` is in your `$PATH`, simply `go get` it then -install CLI with following command: -``` bash -go install github.com/guptarohit/asciigraph/cmd/asciigraph -``` - -or pull Docker image: -``` bash -docker pull ghcr.io/guptarohit/asciigraph:latest -``` - -or download binaries from the [releases][] page. - - -### CLI Usage Feed it data points via stdin: -``` bash +```bash seq 1 72 | asciigraph -h 10 -c "plot data from stdin" ``` or use Docker image: -``` bash +```bash seq 1 72 | docker run -i --rm ghcr.io/guptarohit/asciigraph -h 10 -c "plot data from stdin" ``` Output: -``` bash +```bash 72.00 ┤ ╭──── 64.90 ┤ ╭──────╯ 57.80 ┤ ╭──────╯ @@ -189,11 +236,31 @@ Output: plot data from stdin ``` -Example of real-time graph for data points stream via stdin: -``` bash + +Example of **real-time graph** for data points stream via stdin: + +Realtime graph for data points via stdin (google ping) using asciigraph + +
+command for above graph + +```sh ping -i.2 google.com | grep -oP '(?<=time=).*(?=ms)' --line-buffered | asciigraph -r -h 10 -w 40 -c "realtime plot data (google ping in ms) from stdin" ``` -[![asciinema][]][7] +
+ + +Example of **multi-series real-time graph** for data points stream via stdin: + +Ping latency comparison: Google (Blue) vs. DuckDuckGo (Red) with asciigraph + +
+command for above graph + +```sh +{unbuffer paste -d, <(ping -i 0.4 google.com | sed -u -n -E 's/.*time=(.*)ms.*/\1/p') <(ping -i 0.4 duckduckgo.com | sed -u -n -E 's/.*time=(.*)ms.*/\1/p') } | asciigraph -r -h 15 -w 60 -sn 2 -sc "blue,red" -c "Ping Latency Comparison" -sl "Google, DuckDuckGo" +``` +
## Acknowledgement @@ -222,5 +289,4 @@ Feel free to make a pull request! :octocat: [colored_graph_image]: https://user-images.githubusercontent.com/7895001/166443444-40ad8113-2c0f-46d7-9c75-1cf08435ce15.png [releases]: https://github.com/guptarohit/asciigraph/releases [asciichart]: https://github.com/kroitor/asciichart -[asciinema]: https://asciinema.org/a/382383.svg -[7]: https://asciinema.org/a/382383 +[graph_with_legends_image]: https://github.com/guptarohit/asciigraph/assets/7895001/4066ee95-55ca-42a4-8a03-e73ce20df5d3 diff --git a/vendor/github.com/guptarohit/asciigraph/asciigraph.go b/vendor/github.com/guptarohit/asciigraph/asciigraph.go index 394b66ddb..6200eb9f5 100644 --- a/vendor/github.com/guptarohit/asciigraph/asciigraph.go +++ b/vendor/github.com/guptarohit/asciigraph/asciigraph.go @@ -48,6 +48,12 @@ func PlotMany(data [][]float64, options ...Option) string { maximum = max } } + if config.LowerBound != nil && *config.LowerBound < minimum { + minimum = *config.LowerBound + } + if config.UpperBound != nil && *config.UpperBound > maximum { + maximum = *config.UpperBound + } interval := math.Abs(maximum - minimum) if config.Height <= 0 { @@ -247,5 +253,9 @@ func PlotMany(data [][]float64, options ...Option) string { } } + if len(config.SeriesLegends) > 0 { + addLegends(&lines, config, lenMax, config.Offset+maxWidth) + } + return lines.String() } diff --git a/vendor/github.com/guptarohit/asciigraph/legend.go b/vendor/github.com/guptarohit/asciigraph/legend.go new file mode 100644 index 000000000..42d98982e --- /dev/null +++ b/vendor/github.com/guptarohit/asciigraph/legend.go @@ -0,0 +1,45 @@ +package asciigraph + +import ( + "bytes" + "fmt" + "strings" + "unicode/utf8" +) + +// Create legend item as a colored box and text +func createLegendItem(text string, color AnsiColor) (string, int) { + return fmt.Sprintf( + "%s■%s %s", + color.String(), + Default.String(), + text, + ), + // Can't use len() because of AnsiColor, add 2 for box and space + utf8.RuneCountInString(text) + 2 +} + +// Add legend for each series added to the graph +func addLegends(lines *bytes.Buffer, config *config, lenMax int, leftPad int) { + lines.WriteString("\n\n") + lines.WriteString(strings.Repeat(" ", leftPad)) + + var legendsText string + var legendsTextLen int + rightPad := 3 + for i, text := range config.SeriesLegends { + item, itemLen := createLegendItem(text, config.SeriesColors[i]) + legendsText += item + legendsTextLen += itemLen + + if i < len(config.SeriesLegends)-1 { + legendsText += strings.Repeat(" ", rightPad) + legendsTextLen += rightPad + } + } + + if legendsTextLen < lenMax { + lines.WriteString(strings.Repeat(" ", (lenMax-legendsTextLen)/2)) + } + lines.WriteString(legendsText) +} diff --git a/vendor/github.com/guptarohit/asciigraph/options.go b/vendor/github.com/guptarohit/asciigraph/options.go index 0a2b16056..17dd4d006 100644 --- a/vendor/github.com/guptarohit/asciigraph/options.go +++ b/vendor/github.com/guptarohit/asciigraph/options.go @@ -11,14 +11,16 @@ type Option interface { // config holds various graph options type config struct { - Width, Height int - Offset int - Caption string - Precision uint - CaptionColor AnsiColor - AxisColor AnsiColor - LabelColor AnsiColor - SeriesColors []AnsiColor + Width, Height int + LowerBound, UpperBound *float64 + Offset int + Caption string + Precision uint + CaptionColor AnsiColor + AxisColor AnsiColor + LabelColor AnsiColor + SeriesColors []AnsiColor + SeriesLegends []string } // An optionFunc applies an option. @@ -59,6 +61,18 @@ func Height(h int) Option { }) } +// LowerBound sets the graph's minimum value for the vertical axis. It will be ignored +// if the series contains a lower value. +func LowerBound(min float64) Option { + return optionFunc(func(c *config) { c.LowerBound = &min }) +} + +// UpperBound sets the graph's maximum value for the vertical axis. It will be ignored +// if the series contains a bigger value. +func UpperBound(max float64) Option { + return optionFunc(func(c *config) { c.UpperBound = &max }) +} + // Offset sets the graphs offset. func Offset(o int) Option { return optionFunc(func(c *config) { c.Offset = o }) @@ -103,3 +117,10 @@ func SeriesColors(ac ...AnsiColor) Option { c.SeriesColors = ac }) } + +// SeriesLegends sets the legend text for the corresponding series. +func SeriesLegends(text ...string) Option { + return optionFunc(func(c *config) { + c.SeriesLegends = text + }) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 283018288..70a90f30f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -237,7 +237,7 @@ github.com/google/uuid # github.com/gorilla/mux v1.8.0 ## explicit; go 1.12 github.com/gorilla/mux -# github.com/guptarohit/asciigraph v0.5.5 +# github.com/guptarohit/asciigraph v0.7.1 ## explicit; go 1.11 github.com/guptarohit/asciigraph # github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542