Skip to content

Commit

Permalink
feat(ui): add positioning option to line graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
TCL735 committed Dec 3, 2019
1 parent 2d46f42 commit 596a7a0
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 8 deletions.
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"`
}

// 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]
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
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
39 changes: 38 additions & 1 deletion ui/src/timeMachine/components/view_options/LineOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Libraries
import React, {PureComponent} from 'react'
import {connect} from 'react-redux'
import {capitalize} from 'lodash'

// Components
import {Grid} from '@influxdata/clockface'
import {Grid, Form, Dropdown} from '@influxdata/clockface'
import Geom from 'src/timeMachine/components/view_options/Geom'
import YAxisTitle from 'src/timeMachine/components/view_options/YAxisTitle'
import AxisAffixes from 'src/timeMachine/components/view_options/AxisAffixes'
Expand All @@ -25,6 +26,7 @@ import {
setXColumn,
setYColumn,
setShadeBelow,
setLinePosition,
} from 'src/timeMachine/actions'

// Utils
Expand All @@ -38,13 +40,15 @@ import {
// Types
import {ViewType} from 'src/types'
import {AppState, XYGeom, Axes, Color} from 'src/types'
import {LinePosition} from '@influxdata/giraffe'

interface OwnProps {
type: ViewType
axes: Axes
geom?: XYGeom
colors: Color[]
shadeBelow?: boolean
position: LinePosition
}

interface StateProps {
Expand All @@ -64,6 +68,7 @@ interface DispatchProps {
onSetXColumn: typeof setXColumn
onSetYColumn: typeof setYColumn
onSetGeom: typeof setGeom
onSetPosition: typeof setLinePosition
}

type Props = OwnProps & DispatchProps & StateProps
Expand All @@ -77,6 +82,8 @@ class LineOptions extends PureComponent<Props> {
colors,
geom,
shadeBelow,
position,
onSetPosition,
onUpdateColors,
onUpdateYAxisLabel,
onUpdateAxisPrefix,
Expand Down Expand Up @@ -140,6 +147,35 @@ class LineOptions extends PureComponent<Props> {
onSetDomain={this.handleSetYDomain}
label="Y Axis Domain"
/>
<Form.Element label="Positioning">
<Dropdown
button={(active, onClick) => (
<Dropdown.Button active={active} onClick={onClick}>
{capitalize(position)}
</Dropdown.Button>
)}
menu={onCollapse => (
<Dropdown.Menu onCollapse={onCollapse}>
<Dropdown.Item
id="overlaid"
value="overlaid"
onClick={onSetPosition}
selected={position === 'overlaid'}
>
Overlaid
</Dropdown.Item>
<Dropdown.Item
id="stacked"
value="stacked"
onClick={onSetPosition}
selected={position === 'stacked'}
>
Stacked
</Dropdown.Item>
</Dropdown.Menu>
)}
/>
</Form.Element>
</Grid.Column>
</>
)
Expand Down Expand Up @@ -181,6 +217,7 @@ const mdtp: DispatchProps = {
onSetShadeBelow: setShadeBelow,
onUpdateColors: setColors,
onSetGeom: setGeom,
onSetPosition: setLinePosition,
}

export default connect<StateProps, DispatchProps, OwnProps>(
Expand Down
6 changes: 6 additions & 0 deletions ui/src/timeMachine/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,12 @@ export const timeMachineReducer = (
return setViewProperties(state, {position})
}

case 'SET_LINE_POSITION': {
const {position} = action.payload

return setViewProperties(state, {position})
}

case 'SET_BIN_COUNT': {
const {binCount} = action.payload

Expand Down
8 changes: 4 additions & 4 deletions ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1014,10 +1014,10 @@
resolved "https://registry.yarnpkg.com/@influxdata/flux-parser/-/flux-parser-0.3.0.tgz#b63123ac814ad32c65e46a4097ba3d8b959416a5"
integrity sha512-nsm801l60kXFulcSWA2YH2YRz9oSsMlTK9Evn6Og9BoQnQMcwUsSUEug8mQRIUljnkNYV58JSs0W0mP8h7Y/ZQ==

"@influxdata/giraffe@0.16.5":
version "0.16.5"
resolved "https://registry.yarnpkg.com/@influxdata/giraffe/-/giraffe-0.16.5.tgz#31cb7732656420d69e4998332763b2234ddbcdac"
integrity sha512-LoPGngLpv2WAuc6y9hTBVrm7nxd+c6NiSlmuhCUtXRAlGrW1t3zdEF5CxX6OVEhnZqnpD55hLcFDjDw3Iw/b5w==
"@influxdata/giraffe@0.16.8":
version "0.16.8"
resolved "https://registry.yarnpkg.com/@influxdata/giraffe/-/giraffe-0.16.8.tgz#3bb07532fa09d252443f298aed651327f5b72853"
integrity sha512-/2osPn9o3Zo/Y9QrL012M6cOHouYEexs2pgZJn3EdGLY+1KkqJEgaJ5+xfCGus72IYO0XGKX24/BvW4WHwC3EA==

"@influxdata/influx@0.5.5":
version "0.5.5"
Expand Down

0 comments on commit 596a7a0

Please sign in to comment.