@@ -17,8 +17,58 @@ import {
1717 StyleUpdateMenusPanel ,
1818} from './default_panels' ;
1919import Logo from './components/widgets/Logo' ;
20+ import { TRANSFORMABLE_TRACES } from './lib/constants' ;
2021
2122class 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+
2272 render ( ) {
2373 const _ = this . context . localize ;
2474 const logo = this . props . logoSrc && < Logo src = { this . props . logoSrc } /> ;
@@ -28,17 +78,27 @@ class DefaultEditor extends Component {
2878 { logo ? logo : null }
2979 < GraphCreatePanel group = { _ ( 'Graph' ) } name = { _ ( 'Create' ) } />
3080 < GraphSubplotsPanel group = { _ ( 'Graph' ) } name = { _ ( 'Subplots' ) } />
31- < GraphTransformsPanel group = { _ ( 'Graph' ) } name = { _ ( 'Transforms' ) } />
81+ { this . hasTransforms ( ) && (
82+ < GraphTransformsPanel group = { _ ( 'Graph' ) } name = { _ ( 'Transforms' ) } />
83+ ) }
3284 < StyleTracesPanel group = { _ ( 'Style' ) } name = { _ ( 'Traces' ) } />
3385 < StyleLayoutPanel group = { _ ( 'Style' ) } name = { _ ( 'Layout' ) } />
34- < StyleAxesPanel group = { _ ( 'Style' ) } name = { _ ( 'Axes' ) } />
86+ { this . hasAxes ( ) && (
87+ < StyleAxesPanel group = { _ ( 'Style' ) } name = { _ ( 'Axes' ) } />
88+ ) }
3589 < StyleLegendPanel group = { _ ( 'Style' ) } name = { _ ( 'Legend' ) } />
36- < StyleColorbarsPanel group = { _ ( 'Style' ) } name = { _ ( 'Color Bars' ) } />
90+ { this . hasColorbars ( ) && (
91+ < StyleColorbarsPanel group = { _ ( 'Style' ) } name = { _ ( 'Color Bars' ) } />
92+ ) }
3793 < StyleNotesPanel group = { _ ( 'Style' ) } name = { _ ( 'Annotations' ) } />
3894 < StyleShapesPanel group = { _ ( 'Style' ) } name = { _ ( 'Shapes' ) } />
3995 < 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+ ) }
42102 { this . props . children ? this . props . children : null }
43103 </ PanelMenuWrapper >
44104 ) ;
@@ -52,6 +112,9 @@ DefaultEditor.propTypes = {
52112
53113DefaultEditor . contextTypes = {
54114 localize : PropTypes . func ,
115+ fullData : PropTypes . array ,
116+ fullLayout : PropTypes . object ,
117+ layout : PropTypes . object ,
55118} ;
56119
57120export default DefaultEditor ;
0 commit comments