diff --git a/decoder/stat.go b/decoder/stat.go index 799029b7..5f78db23 100644 --- a/decoder/stat.go +++ b/decoder/stat.go @@ -37,6 +37,8 @@ type DashboardStat struct { Orientation string `yaml:",omitempty"` Text string `yaml:",omitempty"` ValueType string `yaml:"value_type,omitempty"` + ValueField string `yaml:"value_field,omitempty"` + Values bool `yaml:"values,omitempty"` ColorMode string `yaml:"color_mode,omitempty"` TitleFontSize int `yaml:"title_font_size,omitempty"` ValueFontSize int `yaml:"value_font_size,omitempty"` @@ -114,6 +116,12 @@ func (statPanel DashboardStat) toOption() (row.Option, error) { opts = append(opts, opt) } + if statPanel.ValueField != "" { + opts = append(opts, stat.ValueField(statPanel.ValueField)) + } + if statPanel.Values { + opts = append(opts, stat.Values(statPanel.Values)) + } if statPanel.ColorMode != "" { opt, err := statPanel.colorMode() if err != nil { diff --git a/stat/stat.go b/stat/stat.go index 6c35b18e..a812204b 100644 --- a/stat/stat.go +++ b/stat/stat.go @@ -318,6 +318,24 @@ func ValueType(valueType ReductionType) Option { } } +// ValueField selects the fields that should be includedin the panel +func ValueField(field string) Option { + return func(stat *Stat) error { + stat.Builder.StatPanel.Options.ReduceOptions.Fields = field + + return nil + } +} + +// Values allows to enable or disable showing values +func Values(show bool) Option { + return func(stat *Stat) error { + stat.Builder.StatPanel.Options.ReduceOptions.Values = show + + return nil + } +} + // ValueFontSize sets the font size used to display the value. func ValueFontSize(size int) Option { return func(stat *Stat) error { diff --git a/stat/stat_test.go b/stat/stat_test.go index 03de680c..226334ed 100644 --- a/stat/stat_test.go +++ b/stat/stat_test.go @@ -342,6 +342,24 @@ func TestInvalidValueTypeIsRejected(t *testing.T) { req.ErrorIs(err, errors.ErrInvalidArgument) } +func TestValueFieldCanBeSet(t *testing.T) { + req := require.New(t) + + panel, err := New("", ValueField("somefield")) + + req.NoError(err) + req.Equal("somefield", panel.Builder.StatPanel.Options.ReduceOptions.Fields) +} + +func TestShowValuesCanBeSet(t *testing.T) { + req := require.New(t) + + panel, err := New("", Values(true)) + + req.NoError(err) + req.Equal(true, panel.Builder.StatPanel.Options.ReduceOptions.Values) +} + func TestValueFontSizeCanBeSet(t *testing.T) { req := require.New(t)