Skip to content

Commit 8b7059d

Browse files
authored
Merge pull request #715 from plotly/trace-examples
support for examples and tutorials
2 parents 620f88c + b9e8b11 commit 8b7059d

File tree

6 files changed

+124
-55
lines changed

6 files changed

+124
-55
lines changed

dev/App.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,41 @@ const traceTypesConfig = {
6565
complex: true,
6666
};
6767

68+
const chartHelp = {
69+
area: {
70+
helpDoc: 'https://help.plot.ly/make-an-area-graph/',
71+
examplePlot: () => {
72+
console.log('example bar plot!');
73+
},
74+
},
75+
bar: {
76+
helpDoc: 'https://help.plot.ly/stacked-bar-chart/',
77+
examplePlot: () => {
78+
console.log('example bar plot!');
79+
},
80+
},
81+
box: {helpDoc: 'https://help.plot.ly/make-a-box-plot/'},
82+
candlestick: {helpDoc: 'https://help.plot.ly/make-a-candlestick/'},
83+
choropleth: {helpDoc: 'https://help.plot.ly/make-a-choropleth-map/'},
84+
contour: {helpDoc: 'https://help.plot.ly/make-a-contour-plot/'},
85+
heatmap: {helpDoc: 'https://help.plot.ly/make-a-heatmap/'},
86+
histogram2d: {helpDoc: 'https://help.plot.ly/make-a-2d-histogram-heatmap/'},
87+
histogram2dcontour: {helpDoc: 'https://help.plot.ly/make-a-histogram/'},
88+
line: {helpDoc: 'https://help.plot.ly/make-a-line-graph/'},
89+
mesh3d: {helpDoc: null},
90+
ohlc: {helpDoc: 'https://help.plot.ly/make-a-ohlc/'},
91+
pie: {helpDoc: 'https://help.plot.ly/make-a-pie-chart/'},
92+
scatter3d: {helpDoc: 'https://help.plot.ly/make-a-3d-scatter-plot/'},
93+
line3d: {helpDoc: null},
94+
scatter: {helpDoc: 'https://help.plot.ly/how-to-make-a-scatter-plot/'},
95+
scattergeo: {helpDoc: 'https://help.plot.ly/make-scatter-map/'},
96+
scattermapbox: {helpDoc: 'https://help.plot.ly/make-a-mapbox-map/'},
97+
scatterternary: {helpDoc: 'https://help.plot.ly/ternary-scatter-plot/'},
98+
surface: {helpDoc: 'https://help.plot.ly/make-a-3d-surface-plot/'},
99+
table: {helpDoc: null},
100+
timeseries: {helpDoc: 'https://help.plot.ly/range-slider/'},
101+
};
102+
68103
class App extends Component {
69104
constructor() {
70105
super();
@@ -148,6 +183,7 @@ class App extends Component {
148183
// traceTypesConfig={traceTypesConfig}
149184
// makeDefaultTrace={() => ({type: 'scattergl', mode: 'markers'})}
150185
// fontOptions={[{label:'Arial', value: 'arial'}]}
186+
// chartHelp={chartHelp}
151187
>
152188
<DefaultEditor>
153189
<Panel group="Dev" name="JSON">
@@ -211,11 +247,7 @@ class App extends Component {
211247
Refresh
212248
</button>
213249
<div style={{height: '80vh'}}>
214-
<Inspector
215-
data={{_full: this.state.full}}
216-
expandLevel={2}
217-
sortObjectKeys={true}
218-
/>
250+
<Inspector data={{_full: this.state.full}} expandLevel={2} sortObjectKeys={true} />
219251
</div>
220252
</Panel>
221253
</DefaultEditor>

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
"babel-preset-react": "^6.24.1",
4444
"babel-preset-stage-2": "^6.24.1",
4545
"babel-traverse": "^6.26.0",
46-
"css-loader": "^1.0.0",
47-
"cssnano": "^4.1.0",
46+
"css-loader": "^0.28.11",
47+
"cssnano": "^3.10.0",
4848
"enzyme": "^3.1.0",
4949
"enzyme-adapter-react-16": "^1.0.4",
5050
"eslint": "^5.4.0",
@@ -59,9 +59,9 @@
5959
"jest-cli": "^23.5.0",
6060
"mkdirp": "^0.5.1",
6161
"node-sass": "^4.7.2",
62-
"postcss": "^7.0.2",
62+
"postcss": "^6.0.23",
6363
"postcss-combine-duplicated-selectors": "^6.0.2",
64-
"postcss-custom-properties": "^7.0.0",
64+
"postcss-custom-properties": "^6.3.1",
6565
"postcss-remove-root": "^0.0.2",
6666
"prettier": "1.14.2",
6767
"react": "^16.0.0",

src/EditorControls.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class EditorControls extends Component {
5757
glByDefault: this.props.glByDefault,
5858
mapBoxAccess: this.props.mapBoxAccess,
5959
fontOptions: this.props.fontOptions,
60+
chartHelp: this.props.chartHelp,
6061
};
6162
}
6263

@@ -335,6 +336,7 @@ EditorControls.propTypes = {
335336
glByDefault: PropTypes.bool,
336337
mapBoxAccess: PropTypes.bool,
337338
fontOptions: PropTypes.array,
339+
chartHelp: PropTypes.object,
338340
};
339341

340342
EditorControls.defaultProps = {
@@ -376,6 +378,7 @@ EditorControls.childContextTypes = {
376378
glByDefault: PropTypes.bool,
377379
mapBoxAccess: PropTypes.bool,
378380
fontOptions: PropTypes.array,
381+
chartHelp: PropTypes.object,
379382
};
380383

381384
export default EditorControls;

src/PlotlyEditor.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class PlotlyEditor extends Component {
3131
glByDefault={this.props.glByDefault}
3232
mapBoxAccess={Boolean(this.props.config && this.props.config.mapboxAccessToken)}
3333
fontOptions={this.props.fontOptions}
34+
chartHelp={this.props.chartHelp}
3435
>
3536
{this.props.children}
3637
</EditorControls>
@@ -80,6 +81,7 @@ PlotlyEditor.propTypes = {
8081
makeDefaultTrace: PropTypes.func,
8182
glByDefault: PropTypes.bool,
8283
fontOptions: PropTypes.array,
84+
chartHelp: PropTypes.object,
8385
};
8486

8587
PlotlyEditor.defaultProps = {

src/components/widgets/TraceTypeSelector.js

Lines changed: 77 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@ import {traceTypeToPlotlyInitFigure, renderTraceIcon, plotlyTraceToCustomTrace}
77

88
const renderActionItems = (actionItems, item) =>
99
actionItems
10-
? actionItems(item).map((action, i) => (
11-
<a
12-
className="trace-item__actions__item"
13-
key={i}
14-
aria-label={action.label}
15-
data-microtip-position={`top-left`}
16-
role="tooltip"
17-
href={action.href}
18-
target="_blank"
19-
>
20-
{action.icon}
21-
</a>
22-
))
10+
? actionItems(item).map(
11+
(action, i) =>
12+
!action.onClick ? null : (
13+
<a
14+
className="trace-item__actions__item"
15+
key={i}
16+
aria-label={action.label}
17+
data-microtip-position={`top-left`}
18+
role="tooltip"
19+
onClick={action.onClick}
20+
target="_blank"
21+
>
22+
{action.icon}
23+
</a>
24+
)
25+
)
2326
: null;
2427

2528
const Item = ({item, active, handleClick, actions, showActions, complex}) => {
@@ -28,10 +31,7 @@ const Item = ({item, active, handleClick, actions, showActions, complex}) => {
2831
const ComplexIcon = renderTraceIcon(icon ? icon : value, 'TraceType');
2932

3033
return (
31-
<div
32-
className={`trace-item${active ? ' trace-item--active' : ''}`}
33-
onClick={() => handleClick()}
34-
>
34+
<div className={`trace-item${active ? ' trace-item--active' : ''}`} onClick={handleClick}>
3535
<div className="trace-item__actions">
3636
{actions && showActions ? renderActionItems(actions, item) : null}
3737
</div>
@@ -52,7 +52,29 @@ const Item = ({item, active, handleClick, actions, showActions, complex}) => {
5252
);
5353
};
5454

55+
Item.propTypes = {
56+
item: PropTypes.object,
57+
active: PropTypes.bool,
58+
complex: PropTypes.bool,
59+
handleClick: PropTypes.func,
60+
actions: PropTypes.func,
61+
showActions: PropTypes.bool,
62+
};
63+
Item.contextTypes = {
64+
localize: PropTypes.func,
65+
};
66+
5567
class TraceTypeSelector extends Component {
68+
constructor(props) {
69+
super(props);
70+
71+
this.selectAndClose = this.selectAndClose.bind(this);
72+
this.actions = this.actions.bind(this);
73+
this.renderCategories = this.renderCategories.bind(this);
74+
this.renderGrid = this.renderGrid.bind(this);
75+
this.renderSingleBlock = this.renderSingleBlock.bind(this);
76+
}
77+
5678
selectAndClose(value) {
5779
const {
5880
updateContainer,
@@ -72,21 +94,38 @@ class TraceTypeSelector extends Component {
7294
}
7395

7496
actions({value}) {
75-
const {localize: _} = this.context;
97+
const {localize: _, chartHelp} = this.context;
98+
99+
const onClick = (e, func) => {
100+
e.stopPropagation();
101+
func();
102+
this.context.handleClose();
103+
};
104+
76105
return [
77106
{
78107
label: _('Charts like this by Plotly users.'),
79-
href: `https://plot.ly/feed/?q=plottype:${value}`,
108+
onClick:
109+
chartHelp[value] &&
110+
(e =>
111+
onClick(e, () =>
112+
window.open(
113+
`https://plot.ly/feed/?q=${chartHelp[value] ? chartHelp[value].feedQuery : value}`,
114+
'_blank'
115+
)
116+
)),
80117
icon: <SearchIcon />,
81118
},
82119
{
83120
label: _('View tutorials on this chart type.'),
84-
href: '#',
121+
onClick:
122+
chartHelp[value] &&
123+
(e => onClick(e, () => window.open(chartHelp[value].helpDoc, '_blank'))),
85124
icon: <ThumnailViewIcon />,
86125
},
87126
{
88127
label: _('See a basic example.'),
89-
href: '#',
128+
onClick: chartHelp[value] && (e => onClick(e, chartHelp[value].examplePlot)),
90129
icon: <GraphIcon />,
91130
},
92131
];
@@ -98,6 +137,7 @@ class TraceTypeSelector extends Component {
98137
traceTypesConfig: {traces, categories, complex},
99138
mapBoxAccess,
100139
localize: _,
140+
chartHelp,
101141
} = this.context;
102142

103143
return categories(_).map((category, i) => {
@@ -131,8 +171,8 @@ class TraceTypeSelector extends Component {
131171
active={fullValue === item.value}
132172
item={item}
133173
actions={this.actions}
134-
showActions={false}
135174
handleClick={() => this.selectAndClose(item.value)}
175+
showActions={Boolean(chartHelp)}
136176
/>
137177
))}
138178
</div>
@@ -193,6 +233,20 @@ class TraceTypeSelector extends Component {
193233
}
194234
}
195235

236+
TraceTypeSelector.propTypes = {
237+
updateContainer: PropTypes.func,
238+
fullValue: PropTypes.string,
239+
fullContainer: PropTypes.object,
240+
glByDefault: PropTypes.bool,
241+
};
242+
TraceTypeSelector.contextTypes = {
243+
traceTypesConfig: PropTypes.object,
244+
handleClose: PropTypes.func,
245+
localize: PropTypes.func,
246+
mapBoxAccess: PropTypes.bool,
247+
chartHelp: PropTypes.object,
248+
};
249+
196250
export class TraceTypeSelectorButton extends Component {
197251
render() {
198252
const {
@@ -209,7 +263,7 @@ export class TraceTypeSelectorButton extends Component {
209263
const Icon = renderTraceIcon(icon ? icon : value);
210264

211265
return (
212-
<div className="trace-type-select-button" onClick={handleClick ? () => handleClick() : null}>
266+
<div className="trace-type-select-button" onClick={handleClick ? handleClick : null}>
213267
<div className="trace-type-select-button__icon">
214268
<Icon />
215269
</div>
@@ -219,18 +273,6 @@ export class TraceTypeSelectorButton extends Component {
219273
}
220274
}
221275

222-
TraceTypeSelector.propTypes = {
223-
updateContainer: PropTypes.func,
224-
fullValue: PropTypes.string,
225-
fullContainer: PropTypes.object,
226-
glByDefault: PropTypes.bool,
227-
};
228-
TraceTypeSelector.contextTypes = {
229-
traceTypesConfig: PropTypes.object,
230-
handleClose: PropTypes.func,
231-
localize: PropTypes.func,
232-
mapBoxAccess: PropTypes.bool,
233-
};
234276
TraceTypeSelectorButton.propTypes = {
235277
handleClick: PropTypes.func.isRequired,
236278
container: PropTypes.object,
@@ -239,16 +281,5 @@ TraceTypeSelectorButton.propTypes = {
239281
TraceTypeSelectorButton.contextTypes = {
240282
localize: PropTypes.func,
241283
};
242-
Item.propTypes = {
243-
item: PropTypes.object,
244-
active: PropTypes.bool,
245-
complex: PropTypes.bool,
246-
handleClick: PropTypes.func,
247-
actions: PropTypes.func,
248-
showActions: PropTypes.bool,
249-
};
250-
Item.contextTypes = {
251-
localize: PropTypes.func,
252-
};
253284

254285
export default TraceTypeSelector;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ $item-size: 90px;
121121
display: block;
122122
width: 16px;
123123
height: 16px;
124+
fill: currentColor;
124125
}
125126
}
126127
}

0 commit comments

Comments
 (0)