Skip to content

Commit

Permalink
feat(pkger): adds histogram chart support (influxdata#15943)
Browse files Browse the repository at this point in the history
  • Loading branch information
dearyhud authored Nov 16, 2019
1 parent 698200b commit 12846aa
Show file tree
Hide file tree
Showing 7 changed files with 420 additions and 18 deletions.
33 changes: 21 additions & 12 deletions pkger/clone_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ func convertCellView(cv cellView) chart {
ch.Note = p.Note
ch.NoteOnEmpty = p.ShowNoteWhenEmpty
ch.BinSize = int(p.BinSize)
case influxdb.HistogramViewProperties:
ch.Kind = chartKindHistogram
ch.Queries = convertQueries(p.Queries)
ch.Colors = convertColors(p.ViewColors)
ch.XCol = p.XColumn
ch.Axes = []axis{{Label: p.XAxisLabel, Name: "x", Domain: p.XDomain}}
ch.Note = p.Note
ch.NoteOnEmpty = p.ShowNoteWhenEmpty
ch.BinCount = p.BinCount
ch.Position = p.Position
case influxdb.MarkdownViewProperties:
ch.Kind = chartKindMarkdown
ch.Note = p.Note
Expand Down Expand Up @@ -151,10 +161,6 @@ func convertChartToResource(ch chart) Resource {
r[fieldChartLegend] = ch.Legend
}

if ch.BinSize != 0 {
r[fieldChartBinSize] = ch.BinSize
}

ignoreFalseBools := map[string]bool{
fieldChartNoteOnEmpty: ch.NoteOnEmpty,
fieldChartShade: ch.Shade,
Expand All @@ -166,12 +172,13 @@ func convertChartToResource(ch chart) Resource {
}

ignoreEmptyStrPairs := map[string]string{
fieldChartNote: ch.Note,
fieldPrefix: ch.Prefix,
fieldSuffix: ch.Suffix,
fieldChartGeom: ch.Geom,
fieldChartXCol: ch.XCol,
fieldChartYCol: ch.YCol,
fieldChartNote: ch.Note,
fieldPrefix: ch.Prefix,
fieldSuffix: ch.Suffix,
fieldChartGeom: ch.Geom,
fieldChartXCol: ch.XCol,
fieldChartYCol: ch.YCol,
fieldChartPosition: ch.Position,
}
for k, v := range ignoreEmptyStrPairs {
if v != "" {
Expand All @@ -180,8 +187,10 @@ func convertChartToResource(ch chart) Resource {
}

ignoreEmptyIntPairs := map[string]int{
fieldChartXPos: ch.XPos,
fieldChartYPos: ch.YPos,
fieldChartXPos: ch.XPos,
fieldChartYPos: ch.YPos,
fieldChartBinCount: ch.BinCount,
fieldChartBinSize: ch.BinSize,
}
for k, v := range ignoreEmptyIntPairs {
if v != 0 {
Expand Down
33 changes: 27 additions & 6 deletions pkger/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ const (
chartKindUnknown chartKind = ""
chartKindGauge chartKind = "gauge"
chartKindHeatMap chartKind = "heatmap"
chartKindHistogram chartKind = "histogram"
chartKindMarkdown chartKind = "markdown"
chartKindScatter chartKind = "scatter"
chartKindSingleStat chartKind = "single_stat"
Expand All @@ -267,8 +268,8 @@ const (

func (c chartKind) ok() bool {
switch c {
case chartKindGauge, chartKindHeatMap, chartKindMarkdown,
chartKindScatter, chartKindSingleStat,
case chartKindGauge, chartKindHeatMap, chartKindHistogram,
chartKindMarkdown, chartKindScatter, chartKindSingleStat,
chartKindSingleStatPlusLine, chartKindXY:
return true
default:
Expand Down Expand Up @@ -717,22 +718,24 @@ func (d *dashboard) summarize() SummaryDashboard {

const (
fieldChartAxes = "axes"
fieldChartBinCount = "binCount"
fieldChartBinSize = "binSize"
fieldChartColors = "colors"
fieldChartDecimalPlaces = "decimalPlaces"
fieldChartDomain = "domain"
fieldChartGeom = "geom"
fieldChartHeight = "height"
fieldChartLegend = "legend"
fieldChartNote = "note"
fieldChartNoteOnEmpty = "noteOnEmpty"
fieldChartPosition = "position"
fieldChartQueries = "queries"
fieldChartShade = "shade"
fieldChartWidth = "width"
fieldChartXCol = "xCol"
fieldChartXPos = "xPos"
fieldChartYCol = "yCol"
fieldChartYPos = "yPos"
fieldChartBinSize = "binSize"
fieldChartDomain = "domain"
)

type chart struct {
Expand All @@ -754,6 +757,8 @@ type chart struct {
XPos, YPos int
Height, Width int
BinSize int
BinCount int
Position string
}

func (c chart) properties() influxdb.ViewProperties {
Expand Down Expand Up @@ -791,6 +796,20 @@ func (c chart) properties() influxdb.ViewProperties {
Note: c.Note,
ShowNoteWhenEmpty: c.NoteOnEmpty,
}
case chartKindHistogram:
return influxdb.HistogramViewProperties{
Type: influxdb.ViewPropertyTypeHistogram,
Queries: c.Queries.influxDashQueries(),
ViewColors: c.Colors.influxViewColors(),
FillColumns: []string{},
XColumn: c.XCol,
XDomain: c.Axes.get("x").Domain,
XAxisLabel: c.Axes.get("x").Label,
Position: c.Position,
BinCount: c.BinCount,
Note: c.Note,
ShowNoteWhenEmpty: c.NoteOnEmpty,
}
case chartKindMarkdown:
return influxdb.MarkdownViewProperties{
Type: influxdb.ViewPropertyTypeMarkdown,
Expand Down Expand Up @@ -887,10 +906,12 @@ func (c chart) validProperties() []ValidationErr {
switch c.Kind {
case chartKindGauge:
fails = append(fails, c.Colors.hasTypes(colorTypeMin, colorTypeThreshold, colorTypeMax)...)
case chartKindScatter:
fails = append(fails, c.Axes.hasAxes("x", "y")...)
case chartKindHeatMap:
fails = append(fails, c.Axes.hasAxes("x", "y")...)
case chartKindHistogram:
fails = append(fails, c.Axes.hasAxes("x")...)
case chartKindScatter:
fails = append(fails, c.Axes.hasAxes("x", "y")...)
case chartKindSingleStat:
fails = append(fails, c.Colors.hasTypes(colorTypeText)...)
case chartKindSingleStatPlusLine:
Expand Down
2 changes: 2 additions & 0 deletions pkger/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,8 @@ func parseChart(r Resource) (chart, []ValidationErr) {
Width: r.intShort(fieldChartWidth),
Geom: r.stringShort(fieldChartGeom),
BinSize: r.intShort(fieldChartBinSize),
BinCount: r.intShort(fieldChartBinCount),
Position: r.stringShort(fieldChartPosition),
}

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

0 comments on commit 12846aa

Please sign in to comment.