Skip to content

Commit

Permalink
Fix hidden legends handling on newer grafana versions
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Phoen committed Mar 21, 2023
1 parent 5dfb42c commit cc34bb1
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 56 deletions.
1 change: 1 addition & 0 deletions decoder/testdata/timeseries_panel.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"options": {
"legend": {
"calcs": [],
"showLegend": true,
"placement": "bottom",
"displayMode": "list"
},
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module github.com/K-Phoen/grabana
go 1.19

require (
github.com/K-Phoen/sdk v0.12.0
github.com/K-Phoen/sdk v0.12.2
github.com/blang/semver v3.5.1+incompatible
github.com/prometheus/common v0.39.0
github.com/rhysd/go-github-selfupdate v1.2.3
github.com/spf13/cobra v1.6.1
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.8.2
gopkg.in/yaml.v3 v3.0.1
)

Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/K-Phoen/sdk v0.12.0 h1:+0QqHoDZbO6zetFMggM3zKF48GKRu744Ycc9w4oyY0E=
github.com/K-Phoen/sdk v0.12.0/go.mod h1:wp7qXARaIhCYktmoOjRZ+TDMlek5nbayC+waN7vigxI=
github.com/K-Phoen/sdk v0.12.2 h1:0QofDlKE+lloyBOzhjEEMW21061zts/WIpfpQ5NLLAs=
github.com/K-Phoen/sdk v0.12.2/go.mod h1:qmM0wO23CtoDux528MXPpYvS4XkRWkWX6rvX9Za8EVU=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand All @@ -21,7 +21,6 @@ github.com/google/go-github/v30 v30.1.0/go.mod h1:n8jBpHl45a/rlBUtRJMOG4GhNADUQF
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/gosimple/slug v1.12.0/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ=
github.com/gosimple/slug v1.13.1 h1:bQ+kpX9Qa6tHRaK+fZR0A0M2Kd7Pa5eHPPsb1JpHD+Q=
github.com/gosimple/slug v1.13.1/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ=
github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o=
Expand Down Expand Up @@ -54,11 +53,10 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tcnksm/go-gitconfig v0.1.2 h1:iiDhRitByXAEyjgBqsKi9QU4o2TNtv9kPP3RgPgXBPw=
github.com/tcnksm/go-gitconfig v0.1.2/go.mod h1:/8EhP4H7oJZdIPyT+/UIsG87kTzrzM4UsLGSItWYCpE=
github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
Expand Down
4 changes: 4 additions & 0 deletions timeseries/timeseries.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ func ColorScheme(options ...scheme.Option) Option {
// Legend defines what should be shown in the legend.
func Legend(opts ...LegendOption) Option {
return func(timeseries *TimeSeries) error {
yup := true
legend := sdk.TimeseriesLegendOptions{
Show: &yup,
DisplayMode: "list",
Placement: "bottom",
Calcs: make([]string, 0),
Expand All @@ -319,7 +321,9 @@ func Legend(opts ...LegendOption) Option {
for _, opt := range opts {
switch opt {
case Hide:
nope := false
legend.DisplayMode = "hidden"
legend.Show = &nope
case AsList:
legend.DisplayMode = "list"
case AsTable:
Expand Down
3 changes: 3 additions & 0 deletions timeseries/timeseries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func TestLegendCanBeHidden(t *testing.T) {

req.NoError(err)
req.Equal("hidden", panel.Builder.TimeseriesPanel.Options.Legend.DisplayMode)
req.Equal(false, *panel.Builder.TimeseriesPanel.Options.Legend.Show)
}

func TestLegendCanBeDisplayedAsATable(t *testing.T) {
Expand All @@ -225,6 +226,7 @@ func TestLegendCanBeDisplayedAsATable(t *testing.T) {

req.NoError(err)
req.Equal("table", panel.Builder.TimeseriesPanel.Options.Legend.DisplayMode)
req.Equal(true, *panel.Builder.TimeseriesPanel.Options.Legend.Show)
}

func TestLegendCanBeDisplayedAsAList(t *testing.T) {
Expand All @@ -234,6 +236,7 @@ func TestLegendCanBeDisplayedAsAList(t *testing.T) {

req.NoError(err)
req.Equal("list", panel.Builder.TimeseriesPanel.Options.Legend.DisplayMode)
req.Equal(true, *panel.Builder.TimeseriesPanel.Options.Legend.Show)
}

func TestLegendCanBeShownToTheRight(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/K-Phoen/sdk/panel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 33 additions & 45 deletions vendor/github.com/stretchr/testify/assert/assertions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# github.com/K-Phoen/sdk v0.12.0
## explicit; go 1.16
# github.com/K-Phoen/sdk v0.12.2
## explicit; go 1.19
github.com/K-Phoen/sdk
# github.com/blang/semver v3.5.1+incompatible
## explicit
Expand Down Expand Up @@ -45,7 +45,7 @@ github.com/spf13/cobra
# github.com/spf13/pflag v1.0.5
## explicit; go 1.12
github.com/spf13/pflag
# github.com/stretchr/testify v1.8.1
# github.com/stretchr/testify v1.8.2
## explicit; go 1.13
github.com/stretchr/testify/assert
github.com/stretchr/testify/require
Expand Down

0 comments on commit cc34bb1

Please sign in to comment.