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

feat(ui): add positioning option to line graphs #16077

Merged
merged 2 commits into from
Dec 4, 2019
Merged
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
2 changes: 2 additions & 0 deletions dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ type LinePlusSingleStatProperties struct {
XColumn string `json:"xColumn"`
YColumn string `json:"yColumn"`
ShadeBelow bool `json:"shadeBelow"`
Position string `json:"position"`
TCL735 marked this conversation as resolved.
Show resolved Hide resolved
}

// XYViewProperties represents options for line, bar, step, or stacked view in Chronograf
Expand All @@ -639,6 +640,7 @@ type XYViewProperties struct {
XColumn string `json:"xColumn"`
YColumn string `json:"yColumn"`
ShadeBelow bool `json:"shadeBelow"`
Position string `json:"position"`
}

// CheckViewProperties represents options for a view representing a check
Expand Down
3 changes: 2 additions & 1 deletion dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func TestView_MarshalJSON(t *testing.T) {
"showNoteWhenEmpty": false,
"xColumn": "",
"yColumn": "",
"shadeBelow": false
"shadeBelow": false,
"position": ""
}
}
`,
Expand Down
8 changes: 8 additions & 0 deletions http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7975,6 +7975,7 @@ components:
- legend
- note
- showNoteWhenEmpty
- position
properties:
type:
type: string
Expand Down Expand Up @@ -8006,6 +8007,9 @@ components:
type: string
shadeBelow:
type: boolean
position:
type: string
enum: [overlaid, stacked]
TCL735 marked this conversation as resolved.
Show resolved Hide resolved
geom:
$ref: '#/components/schemas/XYGeom'
XYGeom:
Expand All @@ -8025,6 +8029,7 @@ components:
- prefix
- suffix
- decimalPlaces
- position
properties:
type:
type: string
Expand Down Expand Up @@ -8056,6 +8061,9 @@ components:
type: string
shadeBelow:
type: boolean
position:
type: string
enum: [overlaid, stacked]
prefix:
type: string
suffix:
Expand Down
2 changes: 2 additions & 0 deletions pkger/clone_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func convertCellView(cv cellView) chart {
ch.Shade = p.ShadeBelow
ch.XCol = p.XColumn
ch.YCol = p.YColumn
ch.Position = p.Position
case influxdb.SingleStatViewProperties:
setCommon(chartKindSingleStat, p.ViewColors, p.DecimalPlaces, p.Queries)
setNoteFixes(p.Note, p.ShowNoteWhenEmpty, p.Prefix, p.Suffix)
Expand All @@ -165,6 +166,7 @@ func convertCellView(cv cellView) chart {
ch.Shade = p.ShadeBelow
ch.XCol = p.XColumn
ch.YCol = p.YColumn
ch.Position = p.Position
}

return ch
Expand Down
15 changes: 15 additions & 0 deletions pkger/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@ func (c chart) properties() influxdb.ViewProperties {
Queries: c.Queries.influxDashQueries(),
ViewColors: c.Colors.influxViewColors(),
Axes: c.Axes.influxAxes(),
Position: c.Position,
}
case chartKindXY:
return influxdb.XYViewProperties{
Expand All @@ -1020,6 +1021,7 @@ func (c chart) properties() influxdb.ViewProperties {
ViewColors: c.Colors.influxViewColors(),
Axes: c.Axes.influxAxes(),
Geom: c.Geom,
Position: c.Position,
}
default:
return nil
Expand Down Expand Up @@ -1058,14 +1060,27 @@ func (c chart) validProperties() []validationErr {
case chartKindSingleStatPlusLine:
fails = append(fails, c.Colors.hasTypes(colorTypeText)...)
fails = append(fails, c.Axes.hasAxes("x", "y")...)
fails = append(fails, validPosition(c.Position)...)
case chartKindXY:
fails = append(fails, validGeometry(c.Geom)...)
fails = append(fails, c.Axes.hasAxes("x", "y")...)
fails = append(fails, validPosition(c.Position)...)
}

return fails
}

func validPosition(pos string) []validationErr {
pos = strings.ToLower(pos)
if pos != "" && pos != "overlaid" && pos != "stacked" {
return []validationErr{{
Field: fieldChartPosition,
Msg: fmt.Sprintf("invalid position supplied %q; valid positions is one of [overlaid, stacked]", pos),
}}
}
return nil
}

var geometryTypes = map[string]bool{
"line": true,
"step": true,
Expand Down
8 changes: 5 additions & 3 deletions pkger/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ spec:
})
})

t.Run("single dashboard heatmap chart", func(t *testing.T) {
t.Run("single heatmap chart", func(t *testing.T) {
testfileRunner(t, "testdata/dashboard_heatmap", func(t *testing.T, pkg *Pkg) {
sum := pkg.Summary()
require.Len(t, sum.Dashboards, 1)
Expand Down Expand Up @@ -934,7 +934,7 @@ spec:
})
})

t.Run("single dashboard histogram chart", func(t *testing.T) {
t.Run("single histogram chart", func(t *testing.T) {
testfileRunner(t, "testdata/dashboard_histogram", func(t *testing.T, pkg *Pkg) {
sum := pkg.Summary()
require.Len(t, sum.Dashboards, 1)
Expand Down Expand Up @@ -1176,7 +1176,7 @@ spec:
})
})

t.Run("single dashboard markdown chart", func(t *testing.T) {
t.Run("single markdown chart", func(t *testing.T) {
testfileRunner(t, "testdata/dashboard_markdown", func(t *testing.T, pkg *Pkg) {
sum := pkg.Summary()
require.Len(t, sum.Dashboards, 1)
Expand Down Expand Up @@ -2029,6 +2029,7 @@ spec:
assert.Equal(t, int32(1), props.DecimalPlaces.Digits)
assert.Equal(t, "days", props.Suffix)
assert.Equal(t, "sumtin", props.Prefix)
assert.Equal(t, "overlaid", props.Position)
assert.Equal(t, "leg_type", props.Legend.Type)
assert.Equal(t, "horizontal", props.Legend.Orientation)

Expand Down Expand Up @@ -2400,6 +2401,7 @@ spec:
assert.Equal(t, true, props.ShadeBelow)
assert.Equal(t, "xy chart note", props.Note)
assert.True(t, props.ShowNoteWhenEmpty)
assert.Equal(t, "stacked", props.Position)

require.Len(t, props.Queries, 1)
q := props.Queries[0]
Expand Down
2 changes: 2 additions & 0 deletions pkger/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ func TestService(t *testing.T) {
ViewColors: []influxdb.ViewColor{{Type: "text", Hex: "red"}},
XColumn: "x",
YColumn: "y",
Position: "stacked",
},
},
},
Expand All @@ -975,6 +976,7 @@ func TestService(t *testing.T) {
ViewColors: []influxdb.ViewColor{{Type: "text", Hex: "red"}},
XColumn: "x",
YColumn: "y",
Position: "overlaid",
},
},
},
Expand Down
1 change: 1 addition & 0 deletions pkger/testdata/dashboard_single_stat_plus_line.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"shade": true,
"xColumn": "_time",
"yColumn": "_value",
"position": "overlaid",
"legend": {
"type": "leg_type",
"orientation": "horizontal"
Expand Down
1 change: 1 addition & 0 deletions pkger/testdata/dashboard_single_stat_plus_line.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ spec:
width: 6
height: 3
shade: true
position: overlaid
legend:
type: leg_type
orientation: horizontal
Expand Down
1 change: 1 addition & 0 deletions pkger/testdata/dashboard_xy.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"width": 6,
"height": 3,
"decimalPlaces": 1,
"position": "stacked",
"shade": true,
"xColumn": "_time",
"yColumn": "_value",
Expand Down
1 change: 1 addition & 0 deletions pkger/testdata/dashboard_xy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spec:
height: 3
shade: true
geom: line
position: stacked
legend:
queries:
- query: >
Expand Down
1 change: 1 addition & 0 deletions ui/mocks/dummyData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,7 @@ export const viewProperties: ViewProperties = {
xColumn: '_time',
yColumn: '_value',
shadeBelow: true,
position: 'overlaid',
}

export const numericColumnData: NumericColumnData = [
Expand Down
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"dependencies": {
"@influxdata/clockface": "1.0.6",
"@influxdata/flux-parser": "^0.3.0",
"@influxdata/giraffe": "0.16.5",
"@influxdata/giraffe": "0.16.8",
"@influxdata/influx": "0.5.5",
"@influxdata/influxdb-templates": "0.9.0",
"@influxdata/react-custom-scrollbars": "4.3.8",
Expand Down
1 change: 1 addition & 0 deletions ui/src/shared/components/ViewSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const ViewSwitcher: FunctionComponent<Props> = ({
colors: properties.colors.filter(c => c.type === 'scale'),
type: 'xy' as 'xy',
geom: 'line' as 'line',
position: 'overlaid' as 'overlaid',
} as XYViewProperties

const singleStatProperties = {
Expand Down
2 changes: 2 additions & 0 deletions ui/src/shared/components/XYPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const XYPlot: FunctionComponent<Props> = ({
base: yTickBase,
},
},
position,
},
}) => {
const storedXDomain = useMemo(() => parseBounds(xBounds), [xBounds])
Expand Down Expand Up @@ -149,6 +150,7 @@ const XYPlot: FunctionComponent<Props> = ({
y: yColumn,
fill: groupKey,
interpolation,
position,
colors: colorHexes,
shadeBelow: !!shadeBelow,
shadeBelowOpacity: 0.08,
Expand Down
1 change: 1 addition & 0 deletions ui/src/shared/utils/mocks/resourceToTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const myView: View = {
showNoteWhenEmpty: false,
xColumn: null,
yColumn: null,
position: 'overlaid',
},
}

Expand Down
1 change: 1 addition & 0 deletions ui/src/shared/utils/resourceToTemplate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ describe('resourceToTemplate', () => {
showNoteWhenEmpty: false,
xColumn: null,
yColumn: null,
position: 'overlaid',
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions ui/src/shared/utils/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const NEW_VIEW_CREATORS = {
geom: 'line',
xColumn: null,
yColumn: null,
position: 'overlaid',
},
}),
histogram: (): NewView<HistogramViewProperties> => ({
Expand Down Expand Up @@ -192,6 +193,7 @@ const NEW_VIEW_CREATORS = {
shape: 'chronograf-v2',
xColumn: null,
yColumn: null,
position: 'overlaid',
},
}),
table: (): NewView<TableViewProperties> => ({
Expand Down
8 changes: 7 additions & 1 deletion ui/src/timeMachine/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
GetState,
} from 'src/types'
import {Color} from 'src/types/colors'
import {HistogramPosition} from '@influxdata/giraffe'
import {HistogramPosition, LinePosition} from '@influxdata/giraffe'
import {RemoteDataState} from '@influxdata/clockface'
import {createView} from 'src/shared/utils/view'
import {setValues} from 'src/variables/actions'
Expand Down Expand Up @@ -83,6 +83,7 @@ export type Action =
| SetSymbolColumnsAction
| SetBinCountAction
| SetHistogramPositionAction
| ReturnType<typeof setLinePosition>
| SetXDomainAction
| SetYDomainAction
| SetXAxisLabelAction
Expand Down Expand Up @@ -603,6 +604,11 @@ export const setHistogramPosition = (
payload: {position},
})

export const setLinePosition = (position: LinePosition) => ({
type: 'SET_LINE_POSITION' as 'SET_LINE_POSITION',
payload: {position},
})

interface SetXDomainAction {
type: 'SET_VIEW_X_DOMAIN'
payload: {xDomain: [number, number]}
Expand Down
Loading