Skip to content

Commit

Permalink
Merge pull request #92 from K-Phoen/panel-description
Browse files Browse the repository at this point in the history
Panel description
  • Loading branch information
K-Phoen authored Mar 22, 2021
2 parents 9b0fcba + 2560cce commit b73c5fd
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 5 deletions.
10 changes: 10 additions & 0 deletions decoder/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ rows:
- name: Test row
panels:
- text:
description: Some description
height: 400px
span: 6
transparent: true
Expand Down Expand Up @@ -634,6 +635,7 @@ rows:
"height": "400px",
"styles": null,
"title": "Some markdown?",
"description": "Some description",
"transparent": true,
"options": {
"content": "",
Expand Down Expand Up @@ -709,6 +711,7 @@ rows:
panels:
- graph:
title: Heap allocations
description: Some description
height: 400px
span: 4
transparent: true
Expand Down Expand Up @@ -774,6 +777,7 @@ rows:
"span": 4,
"fill": 1,
"title": "Heap allocations",
"description": "Some description",
"aliasColors": {},
"alert": {
"conditions": [
Expand Down Expand Up @@ -1169,6 +1173,7 @@ rows:
panels:
- single_stat:
title: Heap Allocations
description: Some description
height: 400px
span: 4
transparent: true
Expand Down Expand Up @@ -1217,6 +1222,7 @@ rows:
"span": 4,
"height": "400px",
"title": "Heap Allocations",
"description": "Some description",
"transparent": true,
"type": "singlestat",
"colors": [
Expand Down Expand Up @@ -1297,6 +1303,7 @@ rows:
panels:
- table:
title: Threads
description: Threads here
height: 400px
span: 4
transparent: true
Expand Down Expand Up @@ -1345,6 +1352,7 @@ rows:
"renderer": "flot",
"span": 4,
"title": "Threads",
"description": "Threads here",
"transparent": true,
"type": "table",
"columns": [
Expand Down Expand Up @@ -1406,6 +1414,7 @@ rows:
panels:
- heatmap:
title: Reconciliation Performance
description: Does it perform?
span: 12
datasource: $datasource
data_format: time_series_buckets
Expand Down Expand Up @@ -1457,6 +1466,7 @@ rows:
"renderer": "flot",
"span": 12,
"title": "Reconciliation Performance",
"description": "Does it perform?",
"transparent": false,
"type": "heatmap",
"targets": [
Expand Down
4 changes: 4 additions & 0 deletions decoder/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var ErrInvalidLegendAttribute = fmt.Errorf("invalid legend attribute")

type DashboardGraph struct {
Title string
Description string `yaml:",omitempty"`
Span float32 `yaml:",omitempty"`
Height string `yaml:",omitempty"`
Transparent bool `yaml:",omitempty"`
Expand All @@ -29,6 +30,9 @@ type DashboardGraph struct {
func (graphPanel DashboardGraph) toOption() (row.Option, error) {
opts := []graph.Option{}

if graphPanel.Description != "" {
opts = append(opts, graph.Description(graphPanel.Description))
}
if graphPanel.Span != 0 {
opts = append(opts, graph.Span(graphPanel.Span))
}
Expand Down
4 changes: 4 additions & 0 deletions decoder/heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var ErrInvalidDataFormat = fmt.Errorf("invalid data format")

type DashboardHeatmap struct {
Title string
Description string `yaml:",omitempty"`
Span float32 `yaml:",omitempty"`
Height string `yaml:",omitempty"`
Transparent bool `yaml:",omitempty"`
Expand Down Expand Up @@ -53,6 +54,9 @@ func (tooltip *HeatmapTooltip) toOptions() []heatmap.Option {
func (heatmapPanel DashboardHeatmap) toOption() (row.Option, error) {
opts := []heatmap.Option{}

if heatmapPanel.Description != "" {
opts = append(opts, heatmap.Description(heatmapPanel.Description))
}
if heatmapPanel.Span != 0 {
opts = append(opts, heatmap.Span(heatmapPanel.Span))
}
Expand Down
1 change: 1 addition & 0 deletions decoder/heatmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func TestHeatmapCanBeDecoded(t *testing.T) {
req := require.New(t)

panel := DashboardHeatmap{
Description: "awesome description",
Span: 12,
Height: "300px",
Transparent: true,
Expand Down
2 changes: 1 addition & 1 deletion decoder/row.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

type DashboardRow struct {
Name string
Repeat string `yaml:"repeat_for"`
Repeat string `yaml:"repeat_for,omitempty"`
Panels []DashboardPanel
}

Expand Down
4 changes: 4 additions & 0 deletions decoder/singlestat.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var ErrInvalidSingleStatValueType = fmt.Errorf("invalid single stat value type")

type DashboardSingleStat struct {
Title string
Description string `yaml:",omitempty"`
Span float32 `yaml:",omitempty"`
Height string `yaml:",omitempty"`
Transparent bool `yaml:",omitempty"`
Expand All @@ -29,6 +30,9 @@ type DashboardSingleStat struct {
func (singleStatPanel DashboardSingleStat) toOption() (row.Option, error) {
opts := []singlestat.Option{}

if singleStatPanel.Description != "" {
opts = append(opts, singlestat.Description(singleStatPanel.Description))
}
if singleStatPanel.Span != 0 {
opts = append(opts, singlestat.Span(singleStatPanel.Span))
}
Expand Down
4 changes: 4 additions & 0 deletions decoder/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

type DashboardTable struct {
Title string
Description string `yaml:",omitempty"`
Span float32 `yaml:",omitempty"`
Height string `yaml:",omitempty"`
Transparent bool `yaml:",omitempty"`
Expand All @@ -19,6 +20,9 @@ type DashboardTable struct {
func (tablePanel DashboardTable) toOption() (row.Option, error) {
opts := []table.Option{}

if tablePanel.Description != "" {
opts = append(opts, table.Description(tablePanel.Description))
}
if tablePanel.Span != 0 {
opts = append(opts, table.Span(tablePanel.Span))
}
Expand Down
4 changes: 4 additions & 0 deletions decoder/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

type DashboardText struct {
Title string
Description string `yaml:",omitempty"`
Span float32 `yaml:",omitempty"`
Height string `yaml:",omitempty"`
Transparent bool `yaml:",omitempty"`
Expand All @@ -17,6 +18,9 @@ type DashboardText struct {
func (textPanel DashboardText) toOption() row.Option {
opts := []text.Option{}

if textPanel.Description != "" {
opts = append(opts, text.Description(textPanel.Description))
}
if textPanel.Span != 0 {
opts = append(opts, text.Span(textPanel.Span))
}
Expand Down
7 changes: 7 additions & 0 deletions graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ func Height(height string) Option {
}
}

// Description annotates the current visualization with a human-readable description.
func Description(content string) Option {
return func(graph *Graph) {
graph.Builder.Description = &content
}
}

// Transparent makes the background transparent.
func Transparent() Option {
return func(graph *Graph) {
Expand Down
11 changes: 10 additions & 1 deletion graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,23 @@ func TestGraphPanelHeightCanBeConfigured(t *testing.T) {
req.Equal("400px", *panel.Builder.Height)
}

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

panel := New("", Transparent())

req.True(panel.Builder.Transparent)
}

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

panel := New("", Description("lala"))

req.NotNil(panel.Builder.Description)
req.Equal("lala", *panel.Builder.Description)
}

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

Expand Down
7 changes: 7 additions & 0 deletions heatmap/heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ func Height(height string) Option {
}
}

// Description annotates the current visualization with a human-readable description.
func Description(content string) Option {
return func(heatmap *Heatmap) {
heatmap.Builder.Description = &content
}
}

// Transparent makes the background transparent.
func Transparent() Option {
return func(heatmap *Heatmap) {
Expand Down
11 changes: 10 additions & 1 deletion heatmap/heatmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,23 @@ func TestHeatmapPanelHeightCanBeConfigured(t *testing.T) {
req.Equal("400px", *panel.Builder.Height)
}

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

panel := New("", Transparent())

req.True(panel.Builder.Transparent)
}

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

panel := New("", Description("lala"))

req.NotNil(panel.Builder.Description)
req.Equal("lala", *panel.Builder.Description)
}

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

Expand Down
7 changes: 7 additions & 0 deletions singlestat/singlestat.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ func Height(height string) Option {
}
}

// Description annotates the current visualization with a human-readable description.
func Description(content string) Option {
return func(singleStat *SingleStat) {
singleStat.Builder.Description = &content
}
}

// Transparent makes the background transparent.
func Transparent() Option {
return func(singleStat *SingleStat) {
Expand Down
11 changes: 10 additions & 1 deletion singlestat/singlestat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,23 @@ func TestSingleStatPanelHeightCanBeConfigured(t *testing.T) {
req.Equal("400px", *panel.Builder.Height)
}

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

panel := New("", Transparent())

req.True(panel.Builder.Transparent)
}

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

panel := New("", Description("lala"))

req.NotNil(panel.Builder.Description)
req.Equal("lala", *panel.Builder.Description)
}

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

Expand Down
7 changes: 7 additions & 0 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ func Height(height string) Option {
}
}

// Description annotates the current visualization with a human-readable description.
func Description(content string) Option {
return func(table *Table) {
table.Builder.Description = &content
}
}

// Transparent makes the background transparent.
func Transparent() Option {
return func(table *Table) {
Expand Down
11 changes: 10 additions & 1 deletion table/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,19 @@ func TestDataCanBeTransformedAsTimeSeriesAggregations(t *testing.T) {
req.Equal(string(AVG), panel.Builder.TablePanel.Columns[0].Value)
}

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

panel := New("", Transparent())

req.True(panel.Builder.Transparent)
}

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

panel := New("", Description("lala"))

req.NotNil(panel.Builder.Description)
req.Equal("lala", *panel.Builder.Description)
}
7 changes: 7 additions & 0 deletions text/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ func Height(height string) Option {
}
}

// Description annotates the current visualization with a human-readable description.
func Description(content string) Option {
return func(text *Text) {
text.Builder.Description = &content
}
}

// Transparent makes the background transparent.
func Transparent() Option {
return func(text *Text) {
Expand Down
9 changes: 9 additions & 0 deletions text/text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,12 @@ func TestTextPanelBackgroundCanBeTransparent(t *testing.T) {

req.True(panel.Builder.Transparent)
}

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

panel := New("", Description("lala"))

req.NotNil(panel.Builder.Description)
req.Equal("lala", *panel.Builder.Description)
}

0 comments on commit b73c5fd

Please sign in to comment.