File tree Expand file tree Collapse file tree 5 files changed +90
-3
lines changed
styles/components/widgets Expand file tree Collapse file tree 5 files changed +90
-3
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import Inspector from 'react-inspector';
12
12
import tips from './tips' ;
13
13
import 'brace/mode/json' ;
14
14
import 'brace/theme/textmate' ;
15
+ import { categoryLayout , traceTypes , chartCategory } from 'lib/traceTypes' ;
15
16
16
17
// https://github.com/plotly/react-chart-editor#mapbox-access-tokens
17
18
import ACCESS_TOKENS from '../accessTokens' ;
@@ -41,6 +42,41 @@ const dataSourceOptions = Object.keys(dataSources).map(name => ({
41
42
42
43
const config = { mapboxAccessToken : ACCESS_TOKENS . MAPBOX , editable : true } ;
43
44
45
+ const traceTypesConfig = {
46
+ traces : _ => ( [
47
+ {
48
+ value : 'scattergl' ,
49
+ icon : 'scatter' ,
50
+ label : _ ( 'Scatter' ) ,
51
+ } ,
52
+ {
53
+ value : 'bar' ,
54
+ label : _ ( 'Bar' ) ,
55
+ } ,
56
+ {
57
+ value : 'histogram' ,
58
+ label : _ ( 'Histogram' ) ,
59
+ } ,
60
+ {
61
+ value : 'table' ,
62
+ label : _ ( 'Table' ) ,
63
+ } ,
64
+ {
65
+ value : 'pie' ,
66
+ label : _ ( 'Pie' ) ,
67
+ } ,
68
+ {
69
+ value : 'box' ,
70
+ label : _ ( 'Box' ) ,
71
+ } ,
72
+ {
73
+ value : 'histogram2d' ,
74
+ label : _ ( 'Histogram 2D' ) ,
75
+ } ,
76
+ ] ) ,
77
+ complex : true
78
+ } ;
79
+
44
80
class App extends Component {
45
81
constructor ( ) {
46
82
super ( ) ;
@@ -120,6 +156,8 @@ class App extends Component {
120
156
debug
121
157
advancedTraceTypeSelector
122
158
showFieldTooltips
159
+ traceTypesConfig = { traceTypesConfig }
160
+ useAsDefaultTrace = { { type : 'scattergl' } }
123
161
>
124
162
< DefaultEditor >
125
163
< GraphTransformsPanel group = "Dev" name = "Transforms" />
Original file line number Diff line number Diff line change @@ -118,7 +118,9 @@ class EditorControls extends Component {
118
118
if ( this . props . beforeAddTrace ) {
119
119
this . props . beforeAddTrace ( payload ) ;
120
120
}
121
- graphDiv . data . push ( { type : 'scatter' , mode : 'markers' } ) ;
121
+
122
+ graphDiv . data . push ( this . props . useAsDefaultTrace ) ;
123
+
122
124
if ( this . props . afterAddTrace ) {
123
125
this . props . afterAddTrace ( payload ) ;
124
126
}
@@ -298,6 +300,7 @@ EditorControls.propTypes = {
298
300
plotly : PropTypes . object ,
299
301
showFieldTooltips : PropTypes . bool ,
300
302
traceTypesConfig : PropTypes . object ,
303
+ useAsDefaultTrace : PropTypes . object ,
301
304
} ;
302
305
303
306
EditorControls . defaultProps = {
@@ -308,6 +311,7 @@ EditorControls.defaultProps = {
308
311
traces : _ => traceTypes ( _ ) ,
309
312
complex : true ,
310
313
} ,
314
+ useAsDefaultTrace : { type : 'scatter' , mode : 'markers' } ,
311
315
} ;
312
316
313
317
EditorControls . childContextTypes = {
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ class PlotlyEditor extends Component {
26
26
dictionaries = { this . props . dictionaries }
27
27
showFieldTooltips = { this . props . showFieldTooltips }
28
28
srcConverters = { this . props . srcConverters }
29
+ useAsDefaultTrace = { this . props . useAsDefaultTrace }
29
30
>
30
31
{ this . props . children }
31
32
</ EditorControls >
@@ -75,6 +76,7 @@ PlotlyEditor.propTypes = {
75
76
toSrc : PropTypes . func . isRequired ,
76
77
fromSrc : PropTypes . func . isRequired ,
77
78
} ) ,
79
+ useAsDefaultTrace : PropTypes . object ,
78
80
} ;
79
81
80
82
PlotlyEditor . defaultProps = {
Original file line number Diff line number Diff line change @@ -121,11 +121,53 @@ class TraceTypeSelector extends Component {
121
121
} ) ;
122
122
}
123
123
124
+ renderGrid ( ) {
125
+ return < div className = "trace-grid" > { this . renderCategories ( ) } </ div > ;
126
+ }
127
+
128
+ renderSingleBlock ( ) {
129
+ const { fullValue} = this . props ;
130
+ const {
131
+ traceTypesConfig : { traces, complex} ,
132
+ localize : _ ,
133
+ } = this . context ;
134
+
135
+ const items = traces ( _ ) . map ( item => (
136
+ < Item
137
+ key = { item . value }
138
+ complex = { complex }
139
+ active = { fullValue === item . value }
140
+ item = { item }
141
+ actions = { actions }
142
+ showActions = { false }
143
+ handleClick = { ( ) => this . selectAndClose ( item . value ) }
144
+ style = { { display : 'inline-block' } }
145
+ />
146
+ ) ) ;
147
+
148
+ return (
149
+ < div
150
+ style = { {
151
+ maxWidth : '460px' ,
152
+ display : 'flex' ,
153
+ flexFlow : 'wrap' ,
154
+ padding : '5px' ,
155
+ } }
156
+ >
157
+ { items }
158
+ </ div >
159
+ ) ;
160
+ }
161
+
124
162
render ( ) {
125
- const { localize : _ } = this . context ;
163
+ const {
164
+ traceTypesConfig : { categories} ,
165
+ localize : _ ,
166
+ } = this . context ;
167
+
126
168
return (
127
169
< Modal title = { _ ( 'Select Trace Type' ) } >
128
- < div className = "trace-grid" > { this . renderCategories ( ) } </ div >
170
+ { categories ? this . renderGrid ( ) : this . renderSingleBlock ( ) }
129
171
</ Modal >
130
172
) ;
131
173
}
Original file line number Diff line number Diff line change @@ -175,6 +175,7 @@ $item-size: 90px;
175
175
color : var (--color-text-base );
176
176
text-transform : capitalize ;
177
177
font-size : var (--font-size-small );
178
+ text-align : center ;
178
179
}
179
180
}
180
181
You can’t perform that action at this time.
0 commit comments