Skip to content

Commit

Permalink
Allow configuring Stat reduceOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
aaguilartablada committed May 28, 2024
1 parent 234e2b7 commit 996597a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions stat/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

// ShowValues allows to enable or disable showing values
func ShowValues(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 {
Expand Down
18 changes: 18 additions & 0 deletions stat/stat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("", ShowValues(true))

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

func TestValueFontSizeCanBeSet(t *testing.T) {
req := require.New(t)

Expand Down

0 comments on commit 996597a

Please sign in to comment.