Skip to content

Commit 0e2cc1a

Browse files
committed
Proper trace type initialization in TraceSelector component
1 parent 9824a02 commit 0e2cc1a

File tree

7 files changed

+30
-29
lines changed

7 files changed

+30
-29
lines changed

examples/simple/src/App.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import createPlotComponent from 'react-plotly.js/factory';
44
import PlotlyEditor, {dereference} from 'react-plotly.js-editor';
55
import 'react-plotly.js-editor/lib/react-plotly.js-editor.css';
66

7-
87
const Plot = createPlotComponent(plotly);
98

109
class App extends Component {
@@ -24,7 +23,7 @@ class App extends Component {
2423
// overwritten with a full DOM node that contains data, layout, _fullData,
2524
// _fullLayout etc in handlePlotUpdate()
2625
const graphDiv = {
27-
data: [{type: 'scatter', xsrc: 'col1', ysrc: 'col2', mode: 'markers'}],
26+
data: [{type: 'scatter', xsrc: 'col1', ysrc: 'col2'}],
2827
layout: {title: 'Room readings'},
2928
};
3029

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,19 @@
1313
"url": "https://github.com/plotly/react-plotly.js-editor/issues"
1414
},
1515
"scripts": {
16-
"make:combined-translation-keys":
17-
"babel-node utils/findTranslationKeys.js && babel-node utils/combineTranslationKeys.js",
16+
"make:combined-translation-keys": "babel-node utils/findTranslationKeys.js && babel-node utils/combineTranslationKeys.js",
1817
"make:translation-keys": "babel-node utils/findTranslationKeys.js",
19-
"make:lib":
20-
"mkdirp lib && babel src --out-dir lib --ignore=__tests__/* --source-maps && npm run make:lib:css",
21-
"make:lib:css":
22-
"mkdirp lib && node-sass src/styles/main.scss > lib/react-plotly.js-editor.css",
23-
"make:dist":
24-
"mkdirp dist && browserify src/PlotlyEditor.js -o ./dist/PlotlyEditor.js -t [ babelify --presets [ es2015 react ] ] -t browserify-global-shim --standalone createPlotlyComponent && uglifyjs ./dist/PlotlyEditor.js --compress --mangle --output ./dist/PlotlyEditor.min.js --source-map filename=dist/PlotlyEditor.min.js.map && make:dist:css",
25-
"make:dist:css":
26-
"mkdirp dist && node-sass --output-style compressed src/styles/main.scss > dist/react-plotly.js-editor.css",
18+
"make:lib": "mkdirp lib && babel src --out-dir lib --ignore=__tests__/* --source-maps && npm run make:lib:css",
19+
"make:lib:css": "mkdirp lib && node-sass src/styles/main.scss > lib/react-plotly.js-editor.css",
20+
"make:dist": "mkdirp dist && browserify src/PlotlyEditor.js -o ./dist/PlotlyEditor.js -t [ babelify --presets [ es2015 react ] ] -t browserify-global-shim --standalone createPlotlyComponent && uglifyjs ./dist/PlotlyEditor.js --compress --mangle --output ./dist/PlotlyEditor.min.js --source-map filename=dist/PlotlyEditor.min.js.map && make:dist:css",
21+
"make:dist:css": "mkdirp dist && node-sass --output-style compressed src/styles/main.scss > dist/react-plotly.js-editor.css",
2722
"prepublishOnly": "npm run make:lib",
2823
"lint": "prettier --write \"src/**/*.js\"",
29-
"test:lint":
30-
"eslint \"src/**/*.js\" && echo -e '\\033[0;32m'PASS'\\033[0m'",
31-
"test:pretty":
32-
"prettier -l \"src/**/*.js\" && echo -e '\\033[0;32m'PASS'\\033[0m'",
24+
"test:lint": "eslint \"src/**/*.js\" && echo -e '\\033[0;32m'PASS'\\033[0m'",
25+
"test:pretty": "prettier -l \"src/**/*.js\" && echo -e '\\033[0;32m'PASS'\\033[0m'",
3326
"test:js": "jest --setupTestFrameworkScriptFile=raf/polyfill",
3427
"test": "npm run test:lint && npm run test:pretty && npm run test:js",
35-
"watch":
36-
"babel src --watch --out-dir lib --source-maps | node-sass -w src/styles/main.scss lib/react-plotly.js-editor.css",
28+
"watch": "babel src --watch --out-dir lib --source-maps | node-sass -w src/styles/main.scss lib/react-plotly.js-editor.css",
3729
"watch-test": "jest --watch"
3830
},
3931
"keywords": [
@@ -99,7 +91,9 @@
9991
"react": "React"
10092
},
10193
"jest": {
102-
"roots": ["<rootDir>/src/"],
94+
"roots": [
95+
"<rootDir>/src/"
96+
],
10397
"moduleNameMapper": {
10498
"^.+\\.css$": "<rootDir>/config/CSSStub.js"
10599
}

src/PlotlyEditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class PlotlyEditor extends Component {
9393
if (this.props.onAddTrace) {
9494
this.props.onAddTrace(payload);
9595
}
96-
graphDiv.data.push({x: [], y: [], type: 'scatter', mode: 'markers'});
96+
graphDiv.data.push({x: [], y: [], type: 'scatter'});
9797
if (this.props.onUpdate) {
9898
this.props.onUpdate();
9999
}

src/components/fields/TraceSelector.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ class TraceSelector extends Component {
6565
this.traceOptions = [{label: 'Scatter', value: 'scatter'}];
6666
}
6767

68-
this.fullValue = plotlyTraceToCustomTrace(props.fullContainer);
68+
this.fullValue = plotlyTraceToCustomTrace(props.container);
69+
}
70+
71+
componentWillMount() {
72+
const {container} = this.props;
73+
const value = plotlyTraceToCustomTrace(container);
74+
this.updatePlot(value);
6975
}
7076

7177
componentWillReceiveProps(nextProps, nextContext) {
@@ -97,7 +103,7 @@ TraceSelector.contextTypes = {
97103

98104
TraceSelector.propTypes = {
99105
getValObject: PropTypes.func,
100-
fullContainer: PropTypes.object.isRequired,
106+
container: PropTypes.object.isRequired,
101107
fullValue: PropTypes.any.isRequired,
102108
updateContainer: PropTypes.func,
103109
};

src/lib/customTraceType.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
export function plotlyTraceToCustomTrace(trace) {
22
if (
33
trace.type === 'scatter' &&
4+
trace.fill &&
45
['tozeroy', 'tozerox', 'tonexty', 'tonextx', 'toself', 'tonext'].includes(
56
trace.fill
67
)
78
) {
89
return 'area';
910
} else if (
1011
trace.type === 'scatter' &&
12+
trace.mode &&
1113
(trace.mode === 'lines' || trace.mode === 'lines+markers')
1214
) {
1315
return 'line';

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5531,9 +5531,9 @@ planar-graph-to-polyline@^1.0.0:
55315531
two-product "^1.0.0"
55325532
uniq "^1.0.0"
55335533

5534-
plotly-icons@^1.0.0:
5535-
version "1.0.0"
5536-
resolved "https://registry.yarnpkg.com/plotly-icons/-/plotly-icons-1.0.0.tgz#161ca8354f8b32fe97235b1cb63ed71a81f42378"
5534+
plotly-icons@^1.0.1:
5535+
version "1.0.2"
5536+
resolved "https://registry.yarnpkg.com/plotly-icons/-/plotly-icons-1.0.2.tgz#0db46ceeda5f16cb56012f2201b1f3fd318156b9"
55375537
dependencies:
55385538
mdi-react "^2.1.19"
55395539

0 commit comments

Comments
 (0)