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

Add option to shade area below line graphs #14128

Merged
merged 1 commit into from
Jun 13, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Features

1. [14059](https://github.com/influxdata/influxdb/pull/14059): Enable formatting line graph y ticks with binary prefix
1. [14128](https://github.com/influxdata/influxdb/pull/14128): Add option to shade area below line graphs

### Bug Fixes

Expand Down
2 changes: 2 additions & 0 deletions dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ type LinePlusSingleStatProperties struct {
ShowNoteWhenEmpty bool `json:"showNoteWhenEmpty"`
XColumn string `json:"xColumn"`
YColumn string `json:"yColumn"`
ShadeBelow bool `json:"shadeBelow"`
}

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

// SingleStatViewProperties represents options for single stat view in Chronograf
Expand Down
9 changes: 5 additions & 4 deletions dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ func TestView_MarshalJSON(t *testing.T) {
"type": "xy",
"colors": null,
"legend": {},
"geom": "",
"geom": "",
"note": "",
"showNoteWhenEmpty": false,
"xColumn": "",
"yColumn": ""
"showNoteWhenEmpty": false,
"xColumn": "",
"yColumn": "",
"shadeBelow": false
}
}
`,
Expand Down
6 changes: 3 additions & 3 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
"@influxdata/influx": "github:influxdata/influxdb2-js#dev",
"@influxdata/influxdb-templates": "influxdata/influxdb-templates",
"@influxdata/react-custom-scrollbars": "4.3.8",
"@influxdata/giraffe": "0.11.1",
"@influxdata/giraffe": "0.12.0",
"axios": "^0.18.0",
"babel-polyfill": "^6.26.0",
"bignumber.js": "^4.0.2",
Expand Down
58 changes: 58 additions & 0 deletions ui/src/shared/components/Checkbox.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
$checkbox--size: 14px;
$checkbox--dot-size: 6px;
$checkbox--h-padding: $ix-marg-c;

.fancy-checkbox {
color: $g11-sidewalk;
font-size: 12px;
font-weight: 600;
position: relative;
padding-left: $checkbox--size + $ix-marg-b;
position: relative;
cursor: pointer;

input {
position: absolute;
left: -9999px;
}

&:before,
&:after {
content: '';
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
transition: background-color 0.25s ease;
}

&:before {
left: $checkbox--size / 2;
z-index: 2;
width: $checkbox--size;
height: $checkbox--size;
background-color: $g2-kevlar;
border-radius: 3px;
}

&:after {
left: $checkbox--size / 2;
z-index: 3;
width: $checkbox--dot-size;
height: $checkbox--dot-size;
background-color: $c-hydrogen;
transition: opacity 0.25s ease, transform 0.25s ease;
border-radius: 50%;
opacity: 0;
transform: translate(-50%, -50%) scale(1.8,1.8);
}

&.checked {
&:before {
background-color: $c-sapphire;
}
&:after {
opacity: 1;
transform: translate(-50%, -50%) scale(1,1);
}
}
}
26 changes: 26 additions & 0 deletions ui/src/shared/components/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Libraries
import React, {FunctionComponent} from 'react'

interface Props {
label: string
checked: boolean
onSetChecked: (checked: boolean) => void
}

// TODO: Replace this with the Clockface checkbox once available
//
// See https://github.com/influxdata/influxdb/issues/14125.
const Checkbox: FunctionComponent<Props> = ({label, checked, onSetChecked}) => {
return (
<label className={`fancy-checkbox ${checked ? 'checked' : ''}`}>
<input
type="checkbox"
checked={!!checked}
onChange={() => onSetChecked(!checked)}
/>
{label}
</label>
)
}

export default Checkbox
3 changes: 3 additions & 0 deletions ui/src/shared/components/XYContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const XYContainer: FunctionComponent<Props> = ({
colors,
xColumn: storedXColumn,
yColumn: storedYColumn,
shadeBelow,
axes: {
x: {label: xAxisLabel, bounds: xBounds},
y: {
Expand Down Expand Up @@ -125,6 +126,8 @@ const XYContainer: FunctionComponent<Props> = ({
fill: groupKey,
interpolation,
colors: colorHexes,
shadeBelow: !!shadeBelow,
shadeBelowOpacity: 0.08,
},
],
}
Expand Down
2 changes: 2 additions & 0 deletions ui/src/shared/utils/featureFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import {CLOUD} from 'src/shared/constants'
const OSS_FLAGS = {
heatmap: true,
scatter: true,
lineGraphShading: true,
}

const CLOUD_FLAGS = {
heatmap: false, // We need to ensure the API updates have been deployed before enabling
scatter: false, // ditto ^^
lineGraphShading: false, // ditto! ^^
}

export const isFlagEnabled = (flagName: string) => {
Expand Down
1 change: 1 addition & 0 deletions ui/src/style/chronograf.scss
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
@import 'src/dataLoaders/components/DataLoadersOverlay.scss';
@import 'src/shared/components/EmptyGraphError.scss';
@import 'src/shared/components/AutoDomainInput.scss';
@import 'src/shared/components/Checkbox.scss';
@import 'src/shared/components/dapperScrollbars/DapperScrollbars.scss';
@import 'src/dashboards/components/createFromTemplateOverlay/DashboardCreateFromTemplateOverlay.scss';
@import 'src/onboarding/components/SigninForm.scss';
Expand Down
11 changes: 11 additions & 0 deletions ui/src/timeMachine/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export type Action =
| SetXDomainAction
| SetYDomainAction
| SetXAxisLabelAction
| SetShadeBelowAction

interface SetActiveTimeMachineAction {
type: 'SET_ACTIVE_TIME_MACHINE'
Expand Down Expand Up @@ -486,6 +487,16 @@ export const setYColumn = (yColumn: string): SetYColumnAction => ({
payload: {yColumn},
})

interface SetShadeBelowAction {
type: 'SET_SHADE_BELOW'
payload: {shadeBelow}
}

export const setShadeBelow = (shadeBelow: boolean): SetShadeBelowAction => ({
type: 'SET_SHADE_BELOW',
payload: {shadeBelow},
})

interface SetBinSizeAction {
type: 'SET_BIN_SIZE'
payload: {binSize: number}
Expand Down
17 changes: 17 additions & 0 deletions ui/src/timeMachine/components/view_options/LineOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import ColorSelector from 'src/timeMachine/components/view_options/ColorSelector
import AutoDomainInput from 'src/shared/components/AutoDomainInput'
import YAxisBase from 'src/timeMachine/components/view_options/YAxisBase'
import ColumnSelector from 'src/shared/components/ColumnSelector'
import Checkbox from 'src/shared/components/Checkbox'
import {FeatureFlag} from 'src/shared/utils/featureFlag'

// Actions
import {
Expand All @@ -23,6 +25,7 @@ import {
setGeom,
setXColumn,
setYColumn,
setShadeBelow,
} from 'src/timeMachine/actions'

// Utils
Expand All @@ -45,6 +48,7 @@ interface OwnProps {
axes: Axes
geom?: XYViewGeom
colors: Color[]
shadeBelow?: boolean
}

interface StateProps {
Expand All @@ -60,6 +64,7 @@ interface DispatchProps {
onUpdateYAxisBounds: typeof setYAxisBounds
onUpdateYAxisBase: typeof setYAxisBase
onUpdateColors: typeof setColors
onSetShadeBelow: typeof setShadeBelow
onSetXColumn: typeof setXColumn
onSetYColumn: typeof setYColumn
onSetGeom: typeof setGeom
Expand All @@ -75,11 +80,13 @@ class LineOptions extends PureComponent<Props> {
},
colors,
geom,
shadeBelow,
onUpdateColors,
onUpdateYAxisLabel,
onUpdateAxisPrefix,
onUpdateAxisSuffix,
onUpdateYAxisBase,
onSetShadeBelow,
onSetGeom,
onSetYColumn,
yColumn,
Expand Down Expand Up @@ -114,6 +121,15 @@ class LineOptions extends PureComponent<Props> {
colors={colors.filter(c => c.type === 'scale')}
onUpdateColors={onUpdateColors}
/>
<Grid.Column>
<FeatureFlag name="lineGraphShading">
<Checkbox
label="Shade Area Below Lines"
checked={!!shadeBelow}
onSetChecked={onSetShadeBelow}
/>
</FeatureFlag>
</Grid.Column>
<Grid.Column>
<h5 className="view-options--header">Y Axis</h5>
</Grid.Column>
Expand Down Expand Up @@ -170,6 +186,7 @@ const mdtp: DispatchProps = {
onUpdateYAxisBase: setYAxisBase,
onSetXColumn: setXColumn,
onSetYColumn: setYColumn,
onSetShadeBelow: setShadeBelow,
onUpdateColors: setColors,
onSetGeom: setGeom,
}
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 @@ -438,6 +438,12 @@ export const timeMachineReducer = (
return setViewProperties(state, {decimalPlaces})
}

case 'SET_SHADE_BELOW': {
const {shadeBelow} = action.payload

return setViewProperties(state, {shadeBelow})
}

case 'SET_BACKGROUND_THRESHOLD_COLORING': {
const viewColors = state.view.properties.colors as Color[]

Expand Down
16 changes: 6 additions & 10 deletions ui/src/types/dashboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,6 @@ export type NewView<T extends ViewProperties = ViewProperties> = Omit<
'id' | 'links'
>

export interface ViewLinks {
self: string
}

export type DygraphViewProperties = XYView | LinePlusSingleStatView

export type ViewProperties =
| XYView
| LinePlusSingleStatView
Expand Down Expand Up @@ -173,8 +167,9 @@ export interface XYView {
queries: DashboardQuery[]
shape: ViewShape.ChronografV2
axes: Axes
xColumn: string
yColumn: string
xColumn?: string
yColumn?: string
shadeBelow?: boolean
colors: Color[]
legend: Legend
note: string
Expand All @@ -190,8 +185,9 @@ export interface LinePlusSingleStatView {
legend: Legend
prefix: string
suffix: string
xColumn: string
yColumn: string
xColumn?: string
yColumn?: string
shadeBelow?: boolean
decimalPlaces: DecimalPlaces
note: string
showNoteWhenEmpty: boolean
Expand Down