Skip to content

Commit

Permalink
Merge pull request #1181 from ploubser/fix_right_Side
Browse files Browse the repository at this point in the history
Fixes for actions with `graph` functionality
  • Loading branch information
ripienaar authored Nov 15, 2024
2 parents 6b8199e + 3b7084b commit 9acadb0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ABTaskFile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ commands:
script: |
set -e

go test ./...
go list ./... | grep -F -e asciigraph -v |xargs go test

- name: lint
type: exec
Expand Down
4 changes: 4 additions & 0 deletions cli/consumer_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ func (c *consumerCmd) graphAction(_ *fisk.ParseContext) error {
height -= 5
}

if width < 20 || height < 20 {
return fmt.Errorf("please increase terminal dimensions")
}

nfo, err := consumer.State()
if err != nil {
continue
Expand Down
13 changes: 9 additions & 4 deletions cli/server_graph_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ func (c *SrvGraphCmd) graphWrapper(graphs int, h func(width int, height int, vz
return fmt.Errorf("failed to get terminal dimensions: %w", err)
}

if width < 20 || height < graphs*5 {
minHeight := graphs*5 + 2 // 3 graph lines, the ruler, the heading and overall heading plus newline

if width < 20 || height < minHeight {
return fmt.Errorf("please increase terminal dimensions")
}

Expand Down Expand Up @@ -104,10 +106,14 @@ func (c *SrvGraphCmd) graphWrapper(graphs int, h func(width int, height int, vz
width = 80
}
if width > 15 {
width -= 10
width -= 11
}
if height > 10 {
height -= 6
height -= graphs + 1 // make space for the main heading and gaps in the graphs etc
}

if width < 20 || height < minHeight {
return fmt.Errorf("please increase terminal dimensions")
}

vz, err = c.getVz(nc, subj, body)
Expand Down Expand Up @@ -222,7 +228,6 @@ func (c *SrvGraphCmd) graphJetStream() error {

return []string{cpuPlot, assetsPlot, apiRatesPlot, pendingPlot, filePlot, memPlot}, nil
})

}

func (c *SrvGraphCmd) graphServer() error {
Expand Down
6 changes: 5 additions & 1 deletion cli/stream_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,16 @@ func (c *streamCmd) graphAction(_ *fisk.ParseContext) error {
width = 80
}
if width > 15 {
width -= 10
width -= 11
}
if height > 10 {
height -= 6
}

if width < 20 || height < 20 {
return fmt.Errorf("please increase terminal dimensions")
}

nfo, err := stream.State()
if err != nil {
continue
Expand Down
10 changes: 9 additions & 1 deletion internal/asciigraph/asciigraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func PlotMany(data [][]float64, options ...Option) string {
maxWidth = 0
}

maxLabelLength := 0
// axis and labels reusing the previously calculated magnitudes
for w, magnitude := range magnitudes {
var label string
Expand All @@ -181,12 +182,19 @@ func PlotMany(data [][]float64, options ...Option) string {

h := int(math.Max(float64(config.Offset)-float64(len(label)), 0))

labelLength := len(label)
if labelLength > maxLabelLength {
maxLabelLength = labelLength
}

plot[w][h].Text = label
plot[w][h].Color = config.LabelColor
plot[w][config.Offset-1].Text = "┤"
plot[w][config.Offset-1].Color = config.AxisColor
}

width -= maxLabelLength

for i := range data {
series := data[i]

Expand Down Expand Up @@ -289,7 +297,7 @@ func PlotMany(data [][]float64, options ...Option) string {
lines.WriteRune('\n')
lines.WriteString(strings.Repeat(" ", config.Offset+maxWidth))
if len(config.Caption) < lenMax {
lines.WriteString(strings.Repeat(" ", (lenMax-len(config.Caption))/2))
lines.WriteString(strings.Repeat(" ", (lenMax-len(config.Caption)-maxLabelLength)/2))
}
if config.CaptionColor != Default {
lines.WriteString(config.CaptionColor.String())
Expand Down

0 comments on commit 9acadb0

Please sign in to comment.