Skip to content

Commit

Permalink
include new options in stat decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
aaguilartablada committed May 29, 2024
1 parent 996597a commit 8f374af
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions decoder/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions stat/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ func ValueField(field string) Option {
}
}

// ShowValues allows to enable or disable showing values
func ShowValues(show bool) Option {
// 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

Expand Down
2 changes: 1 addition & 1 deletion stat/stat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func TestValueFieldCanBeSet(t *testing.T) {
func TestShowValuesCanBeSet(t *testing.T) {
req := require.New(t)

panel, err := New("", ShowValues(true))
panel, err := New("", Values(true))

req.NoError(err)
req.Equal(true, panel.Builder.StatPanel.Options.ReduceOptions.Values)
Expand Down

0 comments on commit 8f374af

Please sign in to comment.