From bb32762d62e38705ed18aedbaa7110b7c1a526a5 Mon Sep 17 00:00:00 2001 From: nakabonne Date: Sun, 1 Nov 2020 10:22:31 +0900 Subject: [PATCH] Include legend text in column --- diagnoser/gui/gui.go | 17 +++++++++++++++-- diagnoser/gui/widgets.go | 8 ++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/diagnoser/gui/gui.go b/diagnoser/gui/gui.go index e729cd8..841ac98 100644 --- a/diagnoser/gui/gui.go +++ b/diagnoser/gui/gui.go @@ -108,8 +108,13 @@ func gridLayout(w *widgets) ([]container.Option, error) { grid.ColWidthPerc(50, grid.Widget(w.CPUChart, container.Border(linestyle.Light), container.BorderTitle("CPU Usage (%)"))), grid.ColWidthPerc(50, grid.Widget(w.GoroutineChart, container.Border(linestyle.Light), container.BorderTitle("Goroutines"))), ) - raw3 := grid.RowHeightPerc(45, - grid.Widget(w.HeapChart, container.Border(linestyle.Light), container.BorderTitle("Heap (MB)")), + raw3 := grid.RowHeightPercWithOpts(45, + []container.Option{container.Border(linestyle.Light), container.BorderTitle("Heap (MB)")}, + grid.RowHeightPerc(97, grid.ColWidthPerc(99, grid.Widget(w.HeapChart))), + grid.RowHeightPercWithOpts(3, + []container.Option{container.MarginLeftPercent(w.HeapChart.Options().MinimumSize.X)}, + textsInColumn(w.HeapAllocLegend.text, w.HeapIdelLegend.text, w.HeapInuseLegend.text)..., + ), ) builder := grid.New() builder.Add( @@ -121,6 +126,14 @@ func gridLayout(w *widgets) ([]container.Option, error) { return builder.Build() } +func textsInColumn(texts ...Text) []grid.Element { + els := make([]grid.Element, 0, len(texts)) + for _, text := range texts { + els = append(els, grid.ColWidthPerc(3, grid.Widget(text))) + } + return els +} + // appendStats appends entities as soon as a stats arrives. // Note that it doesn't redraw the moment stats are appended. func (g *GUI) appendStats(ctx context.Context) { diff --git a/diagnoser/gui/widgets.go b/diagnoser/gui/widgets.go index 3119a8a..746c83e 100644 --- a/diagnoser/gui/widgets.go +++ b/diagnoser/gui/widgets.go @@ -55,18 +55,18 @@ func newWidgets(meta *stats.Meta) (*widgets, error) { return nil, err } - allocColor := cell.FgColor(cell.ColorMagenta) + allocColor := cell.FgColor(cell.ColorYellow) allocText, err := newText("alloc", text.WriteCellOpts(allocColor)) if err != nil { return nil, err } - idleColor := cell.FgColor(cell.ColorGreen) + idleColor := cell.FgColor(cell.ColorNumber(87)) idleText, err := newText("idle", text.WriteCellOpts(idleColor)) if err != nil { return nil, err } - inuseColor := cell.FgColor(cell.ColorYellow) - inuseText, err := newText("idle", text.WriteCellOpts(inuseColor)) + inuseColor := cell.FgColor(cell.ColorGreen) + inuseText, err := newText("inuse", text.WriteCellOpts(inuseColor)) if err != nil { return nil, err }