Skip to content

Commit 3f5b4c4

Browse files
fixes #103
This is temporary fix until plotly/react-plotly.js#2 has been released
1 parent a07914d commit 3f5b4c4

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

src/PlotlyEditor.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import React, {Component} from 'react';
44
import dictionaries from './locales';
55
import {bem} from './lib';
6-
import {noShame} from './shame';
6+
import {noShame, maybeClearAxisTypes} from './shame';
77
import {EDITOR_ACTIONS} from './lib/constants';
88
import isNumeric from 'fast-isnumeric';
99
import nestedProperty from 'plotly.js/src/lib/nested_property';
@@ -60,6 +60,11 @@ class PlotlyEditor extends Component {
6060
if (this.props.onUpdateTraces) {
6161
this.props.onUpdateTraces(payload);
6262
}
63+
64+
// until we start utilizing Plotly.react in `react-plotly.js`
65+
// force clear axes types when a `src` has changed.
66+
maybeClearAxisTypes(graphDiv, payload.traceIndexes, payload.update);
67+
6368
for (let i = 0; i < payload.traceIndexes.length; i++) {
6469
for (const attr in payload.update) {
6570
const traceIndex = payload.traceIndexes[i];

src/shame.js

+43-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,51 @@
11
/*
22
* DELETE THIS FILE. EVERYTHING NEEDS TO FIND A HOME.
33
*/
4-
import {list} from 'plotly.js/src/plots/cartesian/axis_ids';
4+
import {list, getFromId} from 'plotly.js/src/plots/cartesian/axis_ids';
5+
import nestedProperty from 'plotly.js/src/lib/nested_property';
56

67
export function noShame(opts) {
78
if (opts.plotly && !opts.plotly.Axes) {
8-
opts.plotly.Axes = {
9-
list,
10-
};
9+
opts.plotly.Axes = {list};
10+
}
11+
}
12+
13+
// Temporary fix for:
14+
// https://github.com/plotly/react-plotly.js-editor/issues/103
15+
// We should be able to remove this once the plotly.react method has
16+
// been integrated into react-plotly.js and released:
17+
// https://github.com/plotly/react-plotly.js/issues/2
18+
export const maybeClearAxisTypes = (graphDiv, traceIndexes, update) => {
19+
if (!Array.isArray(graphDiv._fullData)) {
20+
return;
21+
}
22+
let hasSrc = false;
23+
for (const key in update) {
24+
if (key.substr(key.length - 3) === 'src') {
25+
hasSrc = true;
26+
}
27+
}
28+
if (hasSrc) {
29+
clearAxisTypes(graphDiv, traceIndexes);
30+
}
31+
};
32+
33+
const axLetters = ['x', 'y', 'z'];
34+
function clearAxisTypes(gd, traces) {
35+
for (let i = 0; i < traces.length; i++) {
36+
const trace = gd._fullData[i];
37+
for (let j = 0; j < 3; j++) {
38+
const type = axLetters[j];
39+
const ax = getFromId(gd, trace[type + 'axis'] || type);
40+
41+
// Do not clear log type.
42+
// Log type is never an auto result so must have been intentional.
43+
// We are also skipping clearing 3D which could cause bugs with 3D.
44+
if (ax && ax.type !== 'log') {
45+
const axAttr = ax._name;
46+
const typeAttr = axAttr + '.type';
47+
nestedProperty(gd.layout, typeAttr).set(null);
48+
}
49+
}
1150
}
1251
}

0 commit comments

Comments
 (0)