@@ -17,8 +17,58 @@ import {
17
17
StyleUpdateMenusPanel ,
18
18
} from './default_panels' ;
19
19
import Logo from './components/widgets/Logo' ;
20
+ import { TRANSFORMABLE_TRACES } from './lib/constants' ;
20
21
21
22
class DefaultEditor extends Component {
23
+ constructor ( props , context ) {
24
+ super ( props , context ) ;
25
+ this . hasTransforms = this . hasTransforms . bind ( this ) ;
26
+ this . hasAxes = this . hasAxes . bind ( this ) ;
27
+ this . hasMenus = this . hasMenus . bind ( this ) ;
28
+ this . hasSliders = this . hasSliders . bind ( this ) ;
29
+ this . hasColorbars = this . hasColorbars . bind ( this ) ;
30
+ }
31
+
32
+ hasTransforms ( ) {
33
+ return this . context . fullData . some ( d =>
34
+ TRANSFORMABLE_TRACES . includes ( d . type )
35
+ ) ;
36
+ }
37
+
38
+ hasAxes ( ) {
39
+ return (
40
+ Object . keys ( this . context . fullLayout . _subplots ) . filter (
41
+ type =>
42
+ ! [ 'cartesian' , 'mapbox' ] . includes ( type ) &&
43
+ this . context . fullLayout . _subplots [ type ] . length > 0
44
+ ) . length > 0
45
+ ) ;
46
+ }
47
+
48
+ hasMenus ( ) {
49
+ const {
50
+ fullLayout : { updatemenus = [ ] } ,
51
+ } = this . context ;
52
+
53
+ return updatemenus . length > 0 ;
54
+ }
55
+
56
+ hasSliders ( ) {
57
+ const {
58
+ layout : { sliders = [ ] } ,
59
+ } = this . context ;
60
+
61
+ return sliders . length > 0 ;
62
+ }
63
+
64
+ hasColorbars ( ) {
65
+ return this . context . fullData . some (
66
+ d =>
67
+ ( d . marker && d . marker . showscale !== undefined ) || // eslint-disable-line no-undefined
68
+ d . showscale !== undefined // eslint-disable-line no-undefined
69
+ ) ;
70
+ }
71
+
22
72
render ( ) {
23
73
const _ = this . context . localize ;
24
74
const logo = this . props . logoSrc && < Logo src = { this . props . logoSrc } /> ;
@@ -28,17 +78,27 @@ class DefaultEditor extends Component {
28
78
{ logo ? logo : null }
29
79
< GraphCreatePanel group = { _ ( 'Graph' ) } name = { _ ( 'Create' ) } />
30
80
< GraphSubplotsPanel group = { _ ( 'Graph' ) } name = { _ ( 'Subplots' ) } />
31
- < GraphTransformsPanel group = { _ ( 'Graph' ) } name = { _ ( 'Transforms' ) } />
81
+ { this . hasTransforms ( ) && (
82
+ < GraphTransformsPanel group = { _ ( 'Graph' ) } name = { _ ( 'Transforms' ) } />
83
+ ) }
32
84
< StyleTracesPanel group = { _ ( 'Style' ) } name = { _ ( 'Traces' ) } />
33
85
< StyleLayoutPanel group = { _ ( 'Style' ) } name = { _ ( 'Layout' ) } />
34
- < StyleAxesPanel group = { _ ( 'Style' ) } name = { _ ( 'Axes' ) } />
86
+ { this . hasAxes ( ) && (
87
+ < StyleAxesPanel group = { _ ( 'Style' ) } name = { _ ( 'Axes' ) } />
88
+ ) }
35
89
< StyleLegendPanel group = { _ ( 'Style' ) } name = { _ ( 'Legend' ) } />
36
- < StyleColorbarsPanel group = { _ ( 'Style' ) } name = { _ ( 'Color Bars' ) } />
90
+ { this . hasColorbars ( ) && (
91
+ < StyleColorbarsPanel group = { _ ( 'Style' ) } name = { _ ( 'Color Bars' ) } />
92
+ ) }
37
93
< StyleNotesPanel group = { _ ( 'Style' ) } name = { _ ( 'Annotations' ) } />
38
94
< StyleShapesPanel group = { _ ( 'Style' ) } name = { _ ( 'Shapes' ) } />
39
95
< StyleImagesPanel group = { _ ( 'Style' ) } name = { _ ( 'Images' ) } />
40
- < StyleSlidersPanel group = { _ ( 'Style' ) } name = { _ ( 'Sliders' ) } />
41
- < StyleUpdateMenusPanel group = { _ ( 'Style' ) } name = { _ ( 'Menus' ) } />
96
+ { this . hasSliders ( ) && (
97
+ < StyleSlidersPanel group = { _ ( 'Style' ) } name = { _ ( 'Sliders' ) } />
98
+ ) }
99
+ { this . hasMenus ( ) && (
100
+ < StyleUpdateMenusPanel group = { _ ( 'Style' ) } name = { _ ( 'Menus' ) } />
101
+ ) }
42
102
{ this . props . children ? this . props . children : null }
43
103
</ PanelMenuWrapper >
44
104
) ;
@@ -52,6 +112,9 @@ DefaultEditor.propTypes = {
52
112
53
113
DefaultEditor . contextTypes = {
54
114
localize : PropTypes . func ,
115
+ fullData : PropTypes . array ,
116
+ fullLayout : PropTypes . object ,
117
+ layout : PropTypes . object ,
55
118
} ;
56
119
57
120
export default DefaultEditor ;
0 commit comments