@@ -21,18 +21,27 @@ class TraceAccordion extends Component {
2121 }
2222
2323 setLocals ( props , context ) {
24- // we don't want to include analysis transforms when we're in the create panel
2524 const base = props . canGroup ? context . fullData : context . data ;
2625 const traceFilterCondition = this . props . traceFilterCondition || ( ( ) => true ) ;
2726
28- this . filteredTracesIndexes = [ ] ;
29- this . filteredTraces = base . filter ( ( t , i ) => {
30- if ( traceFilterCondition ( t , context . fullData [ i ] ) ) {
31- this . filteredTracesIndexes . push ( i ) ;
32- return true ;
33- }
34- return false ;
35- } ) ;
27+ this . filteredTracesDataIndexes = [ ] ;
28+ this . filteredTraces = [ ] ;
29+
30+ if ( base && base . length && context . fullData . length ) {
31+ this . filteredTraces = base . filter ( ( t , i ) => {
32+ const fullTrace = props . canGroup ? t : context . fullData . filter ( tr => tr . index === i ) [ 0 ] ;
33+
34+ if ( fullTrace ) {
35+ const trace = context . data [ fullTrace . index ] ;
36+ if ( traceFilterCondition ( trace , fullTrace ) ) {
37+ this . filteredTracesDataIndexes . push ( fullTrace . index ) ;
38+ return true ;
39+ }
40+ }
41+
42+ return false ;
43+ } ) ;
44+ }
3645 }
3746
3847 renderGroupedTraceFolds ( ) {
@@ -44,7 +53,7 @@ class TraceAccordion extends Component {
4453 const dataArrayPositionsByTraceType = { } ;
4554 const fullDataArrayPositionsByTraceType = { } ;
4655
47- this . filteredTraces . forEach ( ( trace , index ) => {
56+ this . filteredTraces . forEach ( trace => {
4857 const traceType = plotlyTraceToCustomTrace ( trace ) ;
4958 if ( ! dataArrayPositionsByTraceType [ traceType ] ) {
5059 dataArrayPositionsByTraceType [ traceType ] = [ ] ;
@@ -55,7 +64,8 @@ class TraceAccordion extends Component {
5564 }
5665
5766 dataArrayPositionsByTraceType [ traceType ] . push ( trace . index ) ;
58- fullDataArrayPositionsByTraceType [ traceType ] . push ( this . filteredTracesIndexes [ index ] ) ;
67+ // _expandedIndex is the trace's index in the fullData array
68+ fullDataArrayPositionsByTraceType [ traceType ] . push ( trace . _expandedIndex ) ;
5969 } ) ;
6070
6171 return Object . keys ( fullDataArrayPositionsByTraceType ) . map ( ( type , index ) => (
@@ -71,28 +81,54 @@ class TraceAccordion extends Component {
7181 }
7282
7383 renderUngroupedTraceFolds ( ) {
74- return this . filteredTraces . map ( ( d , i ) => (
75- < TraceFold
76- key = { i }
77- traceIndexes = { [ d . index ] }
78- canDelete = { this . props . canAdd }
79- fullDataArrayPosition = { [ this . filteredTracesIndexes [ i ] ] }
80- >
81- { this . props . children }
82- </ TraceFold >
83- ) ) ;
84+ if ( this . filteredTraces . length ) {
85+ return this . filteredTraces . map ( ( d , i ) => (
86+ < TraceFold
87+ key = { i }
88+ traceIndexes = { [ d . index ] }
89+ canDelete = { this . props . canAdd }
90+ fullDataArrayPosition = { [ d . _expandedIndex ] }
91+ >
92+ { this . props . children }
93+ </ TraceFold >
94+ ) ) ;
95+ }
96+ return null ;
8497 }
8598
8699 renderTraceFolds ( ) {
87- return this . filteredTraces . map ( ( d , i ) => (
88- < TraceFold
89- key = { i }
90- traceIndexes = { [ this . filteredTracesIndexes [ i ] ] }
91- canDelete = { this . props . canAdd }
92- >
93- { this . props . children }
94- </ TraceFold >
95- ) ) ;
100+ if ( this . filteredTraces . length ) {
101+ return this . filteredTraces . map ( ( d , i ) => (
102+ < TraceFold
103+ key = { i }
104+ traceIndexes = { [ this . filteredTracesDataIndexes [ i ] ] }
105+ canDelete = { this . props . canAdd }
106+ >
107+ { this . props . children }
108+ </ TraceFold >
109+ ) ) ;
110+ }
111+ return null ;
112+ }
113+
114+ renderTracePanelHelp ( ) {
115+ const _ = this . context . localize ;
116+ return (
117+ < div className = "panel__empty__message" >
118+ < div className = "panel__empty__message__heading" > Trace your data.</ div >
119+ < div className = "panel__empty__message__content" >
120+ < p >
121+ { _ ( 'Traces of various types like bar and line are the building blocks of your figure.' ) }
122+ </ p >
123+ < p >
124+ { _ (
125+ 'You can add as many as you like, mixing and matching types and arranging them into subplots.'
126+ ) }
127+ </ p >
128+ < p > { _ ( 'Click on the + button above to add a trace.' ) } </ p >
129+ </ div >
130+ </ div >
131+ ) ;
96132 }
97133
98134 render ( ) {
@@ -110,29 +146,10 @@ class TraceAccordion extends Component {
110146 }
111147 } ,
112148 } ;
113- const content = this . renderTraceFolds ( ) ;
149+ const traceFolds = this . renderTraceFolds ( ) ;
114150 return (
115151 < PlotlyPanel addAction = { addAction } >
116- { content . length ? (
117- content
118- ) : (
119- < div className = "panel__empty__message" >
120- < div className = "panel__empty__message__heading" > Trace your data.</ div >
121- < div className = "panel__empty__message__content" >
122- < p >
123- { _ (
124- 'Traces of various types like bar and line are the building blocks of your figure.'
125- ) }
126- </ p >
127- < p >
128- { _ (
129- 'You can add as many as you like, mixing and matching types and arranging them into subplots.'
130- ) }
131- </ p >
132- < p > { _ ( 'Click on the + button above to add a trace.' ) } </ p >
133- </ div >
134- </ div >
135- ) }
152+ { traceFolds ? traceFolds : this . renderTracePanelHelp ( ) }
136153 </ PlotlyPanel >
137154 ) ;
138155 }
0 commit comments