Skip to content

Commit 2bb410e

Browse files
committed
allow reordering of annotations
1 parent 888fca2 commit 2bb410e

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

src/EditorControls.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ class EditorControls extends Component {
312312
move(graphDiv.layout.shapes);
313313
}
314314

315+
if (payload.path === 'layout.annotations') {
316+
move(graphDiv.layout.annotations);
317+
}
318+
315319
const updatedData = payload.path.startsWith('data')
316320
? graphDiv.data.slice()
317321
: graphDiv.data;

src/components/containers/AnnotationAccordion.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AnnotationAccordion extends Component {
1313
layout: {annotations = [], meta = []},
1414
localize: _,
1515
} = this.context;
16-
const {canAdd, children} = this.props;
16+
const {canAdd, children, canReorder} = this.props;
1717

1818
const content =
1919
annotations.length &&
@@ -50,7 +50,7 @@ class AnnotationAccordion extends Component {
5050
};
5151

5252
return (
53-
<LayoutPanel addAction={canAdd ? addAction : null}>
53+
<LayoutPanel addAction={canAdd ? addAction : null} canReorder={canReorder}>
5454
{content ? (
5555
content
5656
) : (
@@ -76,6 +76,7 @@ AnnotationAccordion.contextTypes = {
7676
AnnotationAccordion.propTypes = {
7777
children: PropTypes.node,
7878
canAdd: PropTypes.bool,
79+
canReorder: PropTypes.bool,
7980
};
8081

8182
export default AnnotationAccordion;

src/default_panels/StyleNotesPanel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from '../components';
1818

1919
const StyleNotesPanel = (props, {localize: _}) => (
20-
<AnnotationAccordion canAdd>
20+
<AnnotationAccordion canAdd canReorder>
2121
<PlotlySection name={_('Note Text')} attr="text">
2222
<TextEditor attr="text" />
2323
<FontSelector label={_('Typeface')} attr="font.family" />

src/lib/connectAnnotationToLayout.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default function connectAnnotationToLayout(WrappedComponent) {
1010

1111
this.deleteAnnotation = this.deleteAnnotation.bind(this);
1212
this.updateAnnotation = this.updateAnnotation.bind(this);
13+
this.moveAnnotation = this.moveAnnotation.bind(this);
1314
this.setLocals(props, context);
1415
}
1516

@@ -35,6 +36,7 @@ export default function connectAnnotationToLayout(WrappedComponent) {
3536
deleteContainer: this.deleteAnnotation,
3637
container: this.container,
3738
fullContainer: this.fullContainer,
39+
moveContainer: this.moveAnnotation,
3840
};
3941
}
4042

@@ -57,6 +59,21 @@ export default function connectAnnotationToLayout(WrappedComponent) {
5759
}
5860
}
5961

62+
moveAnnotation(direction) {
63+
if (this.context.onUpdate) {
64+
const annotationIndex = this.props.annotationIndex;
65+
const desiredIndex = direction === 'up' ? annotationIndex - 1 : annotationIndex + 1;
66+
this.context.onUpdate({
67+
type: EDITOR_ACTIONS.MOVE_TO,
68+
payload: {
69+
fromIndex: annotationIndex,
70+
toIndex: desiredIndex,
71+
path: 'layout.annotations',
72+
},
73+
});
74+
}
75+
}
76+
6077
render() {
6178
return <WrappedComponent {...this.props} />;
6279
}
@@ -85,6 +102,7 @@ export default function connectAnnotationToLayout(WrappedComponent) {
85102
container: PropTypes.object,
86103
fullContainer: PropTypes.object,
87104
getValObject: PropTypes.func,
105+
moveContainer: PropTypes.func,
88106
};
89107

90108
const {plotly_editor_traits} = WrappedComponent;

0 commit comments

Comments
 (0)