Skip to content

Commit 1935414

Browse files
authored
Merge pull request #502 from plotly/dev-custom-traces
Try customTraces in Dev
2 parents 33e2f7a + ea2d775 commit 1935414

File tree

5 files changed

+90
-3
lines changed

5 files changed

+90
-3
lines changed

dev/App.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Inspector from 'react-inspector';
1212
import tips from './tips';
1313
import 'brace/mode/json';
1414
import 'brace/theme/textmate';
15+
import {categoryLayout, traceTypes, chartCategory} from 'lib/traceTypes';
1516

1617
// https://github.com/plotly/react-chart-editor#mapbox-access-tokens
1718
import ACCESS_TOKENS from '../accessTokens';
@@ -41,6 +42,41 @@ const dataSourceOptions = Object.keys(dataSources).map(name => ({
4142

4243
const config = {mapboxAccessToken: ACCESS_TOKENS.MAPBOX, editable: true};
4344

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+
4480
class App extends Component {
4581
constructor() {
4682
super();
@@ -120,6 +156,8 @@ class App extends Component {
120156
debug
121157
advancedTraceTypeSelector
122158
showFieldTooltips
159+
traceTypesConfig={traceTypesConfig}
160+
useAsDefaultTrace={{type: 'scattergl'}}
123161
>
124162
<DefaultEditor>
125163
<GraphTransformsPanel group="Dev" name="Transforms" />

src/EditorControls.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ class EditorControls extends Component {
118118
if (this.props.beforeAddTrace) {
119119
this.props.beforeAddTrace(payload);
120120
}
121-
graphDiv.data.push({type: 'scatter', mode: 'markers'});
121+
122+
graphDiv.data.push(this.props.useAsDefaultTrace);
123+
122124
if (this.props.afterAddTrace) {
123125
this.props.afterAddTrace(payload);
124126
}
@@ -298,6 +300,7 @@ EditorControls.propTypes = {
298300
plotly: PropTypes.object,
299301
showFieldTooltips: PropTypes.bool,
300302
traceTypesConfig: PropTypes.object,
303+
useAsDefaultTrace: PropTypes.object,
301304
};
302305

303306
EditorControls.defaultProps = {
@@ -308,6 +311,7 @@ EditorControls.defaultProps = {
308311
traces: _ => traceTypes(_),
309312
complex: true,
310313
},
314+
useAsDefaultTrace: {type: 'scatter', mode: 'markers'},
311315
};
312316

313317
EditorControls.childContextTypes = {

src/PlotlyEditor.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class PlotlyEditor extends Component {
2626
dictionaries={this.props.dictionaries}
2727
showFieldTooltips={this.props.showFieldTooltips}
2828
srcConverters={this.props.srcConverters}
29+
useAsDefaultTrace={this.props.useAsDefaultTrace}
2930
>
3031
{this.props.children}
3132
</EditorControls>
@@ -75,6 +76,7 @@ PlotlyEditor.propTypes = {
7576
toSrc: PropTypes.func.isRequired,
7677
fromSrc: PropTypes.func.isRequired,
7778
}),
79+
useAsDefaultTrace: PropTypes.object,
7880
};
7981

8082
PlotlyEditor.defaultProps = {

src/components/widgets/TraceTypeSelector.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,53 @@ class TraceTypeSelector extends Component {
121121
});
122122
}
123123

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+
124162
render() {
125-
const {localize: _} = this.context;
163+
const {
164+
traceTypesConfig: {categories},
165+
localize: _,
166+
} = this.context;
167+
126168
return (
127169
<Modal title={_('Select Trace Type')}>
128-
<div className="trace-grid">{this.renderCategories()}</div>
170+
{categories ? this.renderGrid() : this.renderSingleBlock()}
129171
</Modal>
130172
);
131173
}

src/styles/components/widgets/_trace-type-selector.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ $item-size: 90px;
175175
color: var(--color-text-base);
176176
text-transform: capitalize;
177177
font-size: var(--font-size-small);
178+
text-align: center;
178179
}
179180
}
180181

0 commit comments

Comments
 (0)