-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
DefaultEditor.js
108 lines (95 loc) · 3.26 KB
/
DefaultEditor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {PanelMenuWrapper} from './components';
import {
GraphCreatePanel,
GraphTransformsPanel,
GraphSubplotsPanel,
StyleLayoutPanel,
StyleAxesPanel,
StyleLegendPanel,
StyleNotesPanel,
StyleShapesPanel,
StyleSlidersPanel,
StyleImagesPanel,
StyleTracesPanel,
StyleColorbarsPanel,
StyleUpdateMenusPanel,
} from './default_panels';
import {traceHasColorbar} from './default_panels/StyleColorbarsPanel';
import Logo from './components/widgets/Logo';
import {TRANSFORMABLE_TRACES} from './lib/constants';
class DefaultEditor extends Component {
constructor(props, context) {
super(props, context);
this.hasTransforms = this.hasTransforms.bind(this);
this.hasAxes = this.hasAxes.bind(this);
this.hasMenus = this.hasMenus.bind(this);
this.hasSliders = this.hasSliders.bind(this);
this.hasColorbars = this.hasColorbars.bind(this);
}
hasTransforms() {
return this.context.fullData.some(d => TRANSFORMABLE_TRACES.includes(d.type));
}
hasAxes() {
return (
Object.keys(this.context.fullLayout._subplots).filter(
type =>
!['cartesian', 'mapbox'].includes(type) &&
this.context.fullLayout._subplots[type].length > 0
).length > 0
);
}
hasMenus() {
const {
fullLayout: {updatemenus = []},
} = this.context;
return updatemenus.length > 0;
}
hasSliders() {
const {
layout: {sliders = []},
} = this.context;
return sliders.length > 0;
}
hasColorbars() {
return this.context.fullData.some(d => traceHasColorbar({}, d));
}
render() {
const _ = this.context.localize;
const logo = this.props.logoSrc && <Logo src={this.props.logoSrc} />;
return (
<PanelMenuWrapper menuPanelOrder={this.props.menuPanelOrder}>
{logo ? logo : null}
<GraphCreatePanel group={_('Structure')} name={_('Traces')} />
<GraphSubplotsPanel group={_('Structure')} name={_('Subplots')} />
{this.hasTransforms() && (
<GraphTransformsPanel group={_('Structure')} name={_('Transforms')} />
)}
<StyleLayoutPanel group={_('Style')} name={_('General')} />
<StyleTracesPanel group={_('Style')} name={_('Traces')} />
{this.hasAxes() && <StyleAxesPanel group={_('Style')} name={_('Axes')} />}
<StyleLegendPanel group={_('Style')} name={_('Legend')} />
{this.hasColorbars() && <StyleColorbarsPanel group={_('Style')} name={_('Color Bars')} />}
<StyleNotesPanel group={_('Style')} name={_('Annotation')} />
<StyleShapesPanel group={_('Style')} name={_('Shapes')} />
<StyleImagesPanel group={_('Style')} name={_('Images')} />
{this.hasSliders() && <StyleSlidersPanel group={_('Style')} name={_('Sliders')} />}
{this.hasMenus() && <StyleUpdateMenusPanel group={_('Style')} name={_('Menus')} />}
{this.props.children ? this.props.children : null}
</PanelMenuWrapper>
);
}
}
DefaultEditor.propTypes = {
children: PropTypes.node,
logoSrc: PropTypes.string,
menuPanelOrder: PropTypes.array,
};
DefaultEditor.contextTypes = {
localize: PropTypes.func,
fullData: PropTypes.array,
fullLayout: PropTypes.object,
layout: PropTypes.object,
};
export default DefaultEditor;