Fix two bugs of dashboard (#64)
1. Index out of range
1. Order of buttons
diff --git a/display/graph/dashboard/global.go b/display/graph/dashboard/global.go
index d28f3a7..c954ce0 100644
--- a/display/graph/dashboard/global.go
+++ b/display/graph/dashboard/global.go
@@ -106,7 +106,7 @@
// newLayoutButtons returns buttons that dynamically switch the layouts.
func newLayoutButtons(c *container.Container) ([]*button.Button, error) {
- var buttons []*button.Button
+ buttons := make([]*button.Button, len(strToLayoutType))
opts := []button.Option{
button.WidthFor(longestString(template.Buttons.Texts)),
@@ -127,7 +127,8 @@
if err != nil {
return nil, err
}
- buttons = append(buttons, b)
+
+ buttons[int(lt)] = b
}
return buttons, nil
diff --git a/display/graph/gauge/gauge.go b/display/graph/gauge/gauge.go
index c7571ee..a99234d 100644
--- a/display/graph/gauge/gauge.go
+++ b/display/graph/gauge/gauge.go
@@ -52,6 +52,11 @@
// Update updates the MetricColumn's `Absolute` and `BorderTitle`.
func (mc *MetricColumn) Update(data []*schema.SelectedRecord) error {
for i, item := range data {
+ // The number of `SelectedRecord` data may exceed the number of gauges in a `MetricColumn`.
+ if i >= len(mc.gauges) {
+ break
+ }
+
strValue := *(item.Value)
v, err := strconv.Atoi(strValue)
if err != nil {