Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring Stat reduceOptions #263

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
}
}

// 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 {
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("", Values(true))

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

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

Expand Down
Loading