Skip to content

Commit

Permalink
feat(explore): support show annotation label [ID-8] (#17307)
Browse files Browse the repository at this point in the history
* feat(explore): support always show annotation label

* fix: lint

* fix: lint

* Hopefully appeasing the linter

* fix: lint

* Update superset-frontend/src/explore/components/controls/AnnotationLayerControl/AnnotationLayer.jsx

Co-authored-by: Geido <60598000+geido@users.noreply.github.com>

* change to allow none

* lint

Co-authored-by: Evan Rusackas <evan@preset.io>
Co-authored-by: Geido <60598000+geido@users.noreply.github.com>
  • Loading branch information
3 people committed Dec 2, 2021
1 parent 72f3215 commit a3cce57
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/src/resources/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@
"description": "Should the layer be shown",
"type": "boolean"
},
"showLabel": {
"description": "Should the label always be shown",
"type": "boolean"
},
"showMarkers": {
"description": "Should markers be shown. Only applies to line annotations.",
"type": "boolean"
Expand Down Expand Up @@ -201,6 +205,7 @@
"required": [
"name",
"show",
"showLabel",
"showMarkers",
"value"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ describe('Visualization > Line', () => {
value: 'y=140000',
overrides: { time_range: null },
show: false,
showLabel: false,
titleColumn: '',
descriptionColumns: [],
timeColumn: '',
Expand Down Expand Up @@ -263,6 +264,7 @@ describe('Visualization > Line', () => {
value,
overrides: { time_range: null },
show: true,
showLabel: false,
titleColumn: 'ds',
descriptionColumns: ['ds'],
timeColumn: 'ds',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const propTypes = {
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
overrides: PropTypes.object,
show: PropTypes.bool,
showLabel: PropTypes.bool,
titleColumn: PropTypes.string,
descriptionColumns: PropTypes.arrayOf(PropTypes.string),
timeColumn: PropTypes.string,
Expand Down Expand Up @@ -85,6 +86,7 @@ const defaultProps = {
overrides: {},
colorScheme: 'd3Category10',
show: true,
showLabel: false,
titleColumn: '',
descriptionColumns: [],
timeColumn: '',
Expand All @@ -111,6 +113,7 @@ export default class AnnotationLayer extends React.PureComponent {
value,
overrides,
show,
showLabel,
titleColumn,
descriptionColumns,
timeColumn,
Expand Down Expand Up @@ -142,6 +145,7 @@ export default class AnnotationLayer extends React.PureComponent {
value,
overrides,
show,
showLabel,
// slice
titleColumn,
descriptionColumns,
Expand Down Expand Up @@ -323,6 +327,7 @@ export default class AnnotationLayer extends React.PureComponent {
'value',
'overrides',
'show',
'showLabel',
'titleColumn',
'descriptionColumns',
'timeColumn',
Expand Down Expand Up @@ -689,7 +694,8 @@ export default class AnnotationLayer extends React.PureComponent {
}

render() {
const { isNew, name, annotationType, sourceType, show } = this.state;
const { isNew, name, annotationType, sourceType, show, showLabel } =
this.state;
const isValid = this.isValidForm();
const metadata = getChartMetadataRegistry().get(this.props.vizType);
const supportedAnnotationTypes = metadata
Expand Down Expand Up @@ -725,6 +731,14 @@ export default class AnnotationLayer extends React.PureComponent {
value={!show}
onChange={v => this.setState({ show: !v })}
/>
<CheckboxControl
name="annotation-label-show"
label={t('Show label')}
value={showLabel}
hovered
description={t('Whether to always show the annotation label')}
onChange={v => this.setState({ showLabel: v })}
/>
<SelectControl
ariaLabel={t('Annotation layer type')}
hovered
Expand Down
3 changes: 3 additions & 0 deletions superset/charts/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,9 @@ class AnnotationLayerSchema(Schema):
allow_none=True,
)
show = fields.Boolean(description="Should the layer be shown", required=True)
showLabel = fields.Boolean(
description="Should the label always be shown", allow_none=True,
)
showMarkers = fields.Boolean(
description="Should markers be shown. Only applies to line annotations.",
required=True,
Expand Down

0 comments on commit a3cce57

Please sign in to comment.