Skip to content

Commit

Permalink
CLI: Added option to specify legends for series (#52)
Browse files Browse the repository at this point in the history
CLI: Added option `-sl` to specify legends for series
  • Loading branch information
guptarohit authored Mar 30, 2024
2 parents 2c1dc11 + 3fa8a48 commit 403ab0f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ Options:
enables realtime graph for data stream
-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
Expand Down
10 changes: 10 additions & 0 deletions cmd/asciigraph/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
realTimeDataBuffer int
fps float64 = 24
seriesColors []asciigraph.AnsiColor
seriesLegends []string
captionColor asciigraph.AnsiColor
axisColor asciigraph.AnsiColor
labelColor asciigraph.AnsiColor
Expand Down Expand Up @@ -85,6 +86,13 @@ func main() {
return nil
}
})
flag.Func("sl", "comma-separated `series legends` corresponding to each series", func(str string) error {
for _, legend := range strings.Split(str, ",") {
seriesLegends = append(seriesLegends, strings.TrimSpace(legend))
}
return nil
})

flag.Float64Var(&lowerBound, "lb", lowerBound, "`lower bound` set the minimum value for the vertical axis (ignored if series contains lower values)")
flag.Float64Var(&upperBound, "ub", upperBound, "`upper bound` set the maximum value for the vertical axis (ignored if series contains larger values)")
flag.StringVar(&delimiter, "d", delimiter, "data `delimiter` for splitting data points in the input stream")
Expand Down Expand Up @@ -141,6 +149,7 @@ func main() {
asciigraph.Precision(precision),
asciigraph.Caption(caption),
asciigraph.SeriesColors(seriesColors...),
asciigraph.SeriesLegends(seriesLegends...),
asciigraph.CaptionColor(captionColor),
asciigraph.AxisColor(axisColor),
asciigraph.LabelColor(labelColor),
Expand Down Expand Up @@ -169,6 +178,7 @@ func main() {
asciigraph.Precision(precision),
asciigraph.Caption(caption),
asciigraph.SeriesColors(seriesColors...),
asciigraph.SeriesLegends(seriesLegends...),
asciigraph.CaptionColor(captionColor),
asciigraph.AxisColor(axisColor),
asciigraph.LabelColor(labelColor),
Expand Down

0 comments on commit 403ab0f

Please sign in to comment.