Skip to content

Commit 760433f

Browse files
ebb-tideTCL735
authored andcommitted
feat(bandchart): Add pkger stuff
1 parent fecc4fd commit 760433f

File tree

6 files changed

+164
-1
lines changed

6 files changed

+164
-1
lines changed

pkger/clone_resource.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,17 @@ func convertCellView(cell influxdb.Cell) chart {
682682
Visible: fieldOpt.Visible,
683683
})
684684
}
685+
case influxdb.BandViewProperties:
686+
setCommon(chartKindBand, p.ViewColors, influxdb.DecimalPlaces{}, p.Queries)
687+
setNoteFixes(p.Note, p.ShowNoteWhenEmpty, "", "")
688+
setLegend(p.Legend)
689+
ch.Axes = convertAxes(p.Axes)
690+
ch.Geom = p.Geom
691+
ch.HoverDimension = p.HoverDimension
692+
ch.XCol = p.XColumn
693+
ch.YCol = p.YColumn
694+
ch.UpperColumn = p.UpperColumn
695+
ch.LowerColumn = p.LowerColumn
685696
case influxdb.XYViewProperties:
686697
setCommon(chartKindXY, p.ViewColors, influxdb.DecimalPlaces{}, p.Queries)
687698
setNoteFixes(p.Note, p.ShowNoteWhenEmpty, "", "")
@@ -726,6 +737,12 @@ func convertChartToResource(ch chart) Resource {
726737
if len(ch.YSeriesColumns) > 0 {
727738
r[fieldChartYSeriesColumns] = ch.YSeriesColumns
728739
}
740+
if len(ch.UpperColumn) > 0 {
741+
r[fieldChartUpperColumn] = ch.UpperColumn
742+
}
743+
if len(ch.LowerColumn) > 0 {
744+
r[fieldChartLowerColumn] = ch.LowerColumn
745+
}
729746
if ch.EnforceDecimals {
730747
r[fieldChartDecimalPlaces] = ch.DecimalPlaces
731748
}

pkger/parser.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,8 @@ func (p *Template) parseChart(dashMetaName string, chartIdx int, r Resource) (*c
14211421
YPos: r.intShort(fieldChartYPos),
14221422
FillColumns: r.slcStr(fieldChartFillColumns),
14231423
YSeriesColumns: r.slcStr(fieldChartYSeriesColumns),
1424+
UpperColumn: r.stringShort(fieldChartUpperColumn),
1425+
LowerColumn: r.stringShort(fieldChartLowerColumn),
14241426
}
14251427

14261428
if presLeg, ok := r[fieldChartLegend].(legend); ok {

pkger/parser_models.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,15 @@ const (
432432
chartKindSingleStatPlusLine chartKind = "single_stat_plus_line"
433433
chartKindTable chartKind = "table"
434434
chartKindXY chartKind = "xy"
435+
chartKindBand chartKind = "band"
435436
)
436437

437438
func (c chartKind) ok() bool {
438439
switch c {
439440
case chartKindGauge, chartKindHeatMap, chartKindHistogram,
440441
chartKindMarkdown, chartKindMosaic, chartKindScatter,
441442
chartKindSingleStat, chartKindSingleStatPlusLine, chartKindTable,
442-
chartKindXY:
443+
chartKindXY, chartKindBand:
443444
return true
444445
default:
445446
return false
@@ -552,6 +553,8 @@ const (
552553
fieldChartTickSuffix = "tickSuffix"
553554
fieldChartTimeFormat = "timeFormat"
554555
fieldChartYSeriesColumns = "ySeriesColumns"
556+
fieldChartUpperColumn = "upperColumn"
557+
fieldChartLowerColumn = "lowerColumn"
555558
fieldChartWidth = "width"
556559
fieldChartXCol = "xCol"
557560
fieldChartXPos = "xPos"
@@ -579,6 +582,8 @@ type chart struct {
579582
Geom string
580583
YSeriesColumns []string
581584
XCol, YCol string
585+
UpperColumn string
586+
LowerColumn string
582587
XPos, YPos int
583588
Height, Width int
584589
BinSize int
@@ -666,6 +671,23 @@ func (c *chart) properties() influxdb.ViewProperties {
666671
ShowNoteWhenEmpty: c.NoteOnEmpty,
667672
TimeFormat: c.TimeFormat,
668673
}
674+
case chartKindBand:
675+
return influxdb.BandViewProperties{
676+
Type: influxdb.ViewPropertyTypeBand,
677+
Queries: c.Queries.influxDashQueries(),
678+
ViewColors: c.Colors.influxViewColors(),
679+
Legend: c.Legend.influxLegend(),
680+
HoverDimension: c.HoverDimension,
681+
XColumn: c.XCol,
682+
YColumn: c.YCol,
683+
UpperColumn: c.UpperColumn,
684+
LowerColumn: c.LowerColumn,
685+
Axes: c.Axes.influxAxes(),
686+
Geom: c.Geom,
687+
Note: c.Note,
688+
ShowNoteWhenEmpty: c.NoteOnEmpty,
689+
TimeFormat: c.TimeFormat,
690+
}
669691
case chartKindScatter:
670692
return influxdb.ScatterViewProperties{
671693
Type: influxdb.ViewPropertyTypeScatter,

pkger/parser_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,57 @@ spec:
12911291
})
12921292
})
12931293

1294+
t.Run("band chart", func(t *testing.T) {
1295+
t.Run("happy path", func(t *testing.T) {
1296+
testfileRunner(t, "testdata/dashboard_band.yml", func(t *testing.T, template *Template) {
1297+
sum := template.Summary()
1298+
require.Len(t, sum.Dashboards, 1)
1299+
1300+
actual := sum.Dashboards[0]
1301+
assert.Equal(t, KindDashboard, actual.Kind)
1302+
assert.Equal(t, "dash-1", actual.Name)
1303+
assert.Equal(t, "a dashboard w/ single band chart", actual.Description)
1304+
1305+
require.Len(t, actual.Charts, 1)
1306+
actualChart := actual.Charts[0]
1307+
assert.Equal(t, 3, actualChart.Height)
1308+
assert.Equal(t, 6, actualChart.Width)
1309+
assert.Equal(t, 1, actualChart.XPosition)
1310+
assert.Equal(t, 2, actualChart.YPosition)
1311+
1312+
props, ok := actualChart.Properties.(influxdb.BandViewProperties)
1313+
require.True(t, ok)
1314+
assert.Equal(t, "band note", props.Note)
1315+
assert.True(t, props.ShowNoteWhenEmpty)
1316+
assert.Equal(t, "y", props.HoverDimension)
1317+
assert.Equal(t, "foo", props.UpperColumn)
1318+
assert.Equal(t, "bar", props.LowerColumn)
1319+
1320+
require.Len(t, props.ViewColors, 1)
1321+
c := props.ViewColors[0]
1322+
assert.Equal(t, "laser", c.Name)
1323+
assert.Equal(t, "scale", c.Type)
1324+
assert.Equal(t, "#8F8AF4", c.Hex)
1325+
assert.Equal(t, 3.0, c.Value)
1326+
1327+
require.Len(t, props.Queries, 1)
1328+
q := props.Queries[0]
1329+
expectedQuery := `from(bucket: v.bucket) |> range(start: v.timeRangeStart) |> filter(fn: (r) => r._measurement == "mem") |> filter(fn: (r) => r._field == "used_percent") |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false) |> yield(name: "mean")`
1330+
assert.Equal(t, expectedQuery, q.Text)
1331+
assert.Equal(t, "advanced", q.EditMode)
1332+
1333+
for _, key := range []string{"x", "y"} {
1334+
xAxis, ok := props.Axes[key]
1335+
require.True(t, ok, "key="+key)
1336+
assert.Equal(t, key+"_label", xAxis.Label, "key="+key)
1337+
assert.Equal(t, key+"_prefix", xAxis.Prefix, "key="+key)
1338+
assert.Equal(t, key+"_suffix", xAxis.Suffix, "key="+key)
1339+
}
1340+
1341+
})
1342+
})
1343+
})
1344+
12941345
t.Run("scatter chart", func(t *testing.T) {
12951346
t.Run("happy path", func(t *testing.T) {
12961347
testfileRunner(t, "testdata/dashboard_scatter", func(t *testing.T, template *Template) {

pkger/service_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,6 +2224,31 @@ func TestService(t *testing.T) {
22242224
},
22252225
},
22262226
},
2227+
{
2228+
name: "band",
2229+
newName: "new name",
2230+
expectedView: influxdb.View{
2231+
ViewContents: influxdb.ViewContents{
2232+
Name: "view name",
2233+
},
2234+
Properties: influxdb.BandViewProperties{
2235+
Type: influxdb.ViewPropertyTypeBand,
2236+
Axes: newAxes(),
2237+
Geom: "step",
2238+
Legend: influxdb.Legend{Type: "type", Orientation: "horizontal"},
2239+
Note: "a note",
2240+
Queries: []influxdb.DashboardQuery{newQuery()},
2241+
HoverDimension: "y",
2242+
ShowNoteWhenEmpty: true,
2243+
ViewColors: []influxdb.ViewColor{{Type: "text", Hex: "red"}},
2244+
XColumn: "x",
2245+
YColumn: "y",
2246+
UpperColumn: "upper",
2247+
LowerColumn: "lower",
2248+
TimeFormat: "",
2249+
},
2250+
},
2251+
},
22272252
{
22282253
name: "markdown",
22292254
newName: "new name",

pkger/testdata/dashboard_band.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
apiVersion: influxdata.com/v2alpha1
2+
kind: Dashboard
3+
metadata:
4+
name: dash-1
5+
spec:
6+
description: a dashboard w/ single band chart
7+
charts:
8+
- kind: Band
9+
name: band chart
10+
note: band note
11+
noteOnEmpty: true
12+
prefix: sumtin
13+
suffix: days
14+
xPos: 1
15+
yPos: 2
16+
xCol: _time
17+
yCol: _value
18+
upperColumn: foo
19+
lowerColumn: bar
20+
hoverDimension: "y"
21+
geom: line
22+
width: 6
23+
height: 3
24+
queries:
25+
- query: >
26+
from(bucket: v.bucket) |> range(start: v.timeRangeStart) |> filter(fn: (r) => r._measurement == "mem") |> filter(fn: (r) => r._field == "used_percent") |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false) |> yield(name: "mean")
27+
colors:
28+
- name: laser
29+
type: scale
30+
hex: "#8F8AF4"
31+
value: 3
32+
axes:
33+
- name: "x"
34+
label: x_label
35+
prefix: x_prefix
36+
suffix: x_suffix
37+
domain:
38+
- 0
39+
- 10
40+
- name: "y"
41+
label: y_label
42+
prefix: y_prefix
43+
suffix: y_suffix
44+
domain:
45+
- 0
46+
- 100

0 commit comments

Comments
 (0)