Skip to content

Commit

Permalink
fixes #103
Browse files Browse the repository at this point in the history
This is temporary fix until
plotly/react-plotly.js#2
has been released
  • Loading branch information
bpostlethwaite committed Jan 6, 2018
1 parent a07914d commit 48d6be1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/PlotlyEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import React, {Component} from 'react';
import dictionaries from './locales';
import {bem} from './lib';
import {noShame} from './shame';
import {noShame, maybeClearAxisTypes} from './shame';
import {EDITOR_ACTIONS} from './lib/constants';
import isNumeric from 'fast-isnumeric';
import nestedProperty from 'plotly.js/src/lib/nested_property';
Expand Down Expand Up @@ -60,6 +60,11 @@ class PlotlyEditor extends Component {
if (this.props.onUpdateTraces) {
this.props.onUpdateTraces(payload);
}

// until we start utilizing Plotly.react in `react-plotly.js`
// force clear axes types when a `src` has changed.
maybeClearAxisTypes(graphDiv, payload.traceIndexes, payload.update);

for (let i = 0; i < payload.traceIndexes.length; i++) {
for (const attr in payload.update) {
const traceIndex = payload.traceIndexes[i];
Expand Down
47 changes: 43 additions & 4 deletions src/shame.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,51 @@
/*
* DELETE THIS FILE. EVERYTHING NEEDS TO FIND A HOME.
*/
import {list} from 'plotly.js/src/plots/cartesian/axis_ids';
import {list, getFromId} from 'plotly.js/src/plots/cartesian/axis_ids';
import nestedProperty from 'plotly.js/src/lib/nested_property';

export function noShame(opts) {
if (opts.plotly && !opts.plotly.Axes) {
opts.plotly.Axes = {
list,
};
opts.plotly.Axes = {list};
}
}

// Temporary fix for:
// https://github.com/plotly/react-plotly.js-editor/issues/103
// We should be able to remove this once the plotly.react method has
// been integrated into react-plotly.js and released:
// https://github.com/plotly/react-plotly.js/issues/2
export const maybeClearAxisTypes = (graphDiv, traceIndexes, update) => {
if (!Array.isArray(graphDiv._fullData)) {
return;
}
let hasSrc = false;
for (const key in update) {
if (key.substr(key.length - 3) === 'src') {
hasSrc = true;
}
}
if (hasSrc) {
clearAxisTypes(graphDiv, traceIndexes, {});
}
};

var axLetters = ['x', 'y', 'z'];
function clearAxisTypes(gd, traces) {
for (var i = 0; i < traces.length; i++) {
var trace = gd._fullData[i];
for (var j = 0; j < 3; j++) {
const type = axLetters[j];
const ax = getFromId(gd, trace[type + 'axis'] || type);

// Do not clear log type.
// that's never an auto result so must have been intentional.
// We are also skipping clearing 3D which could cause bugs with 3D
if (ax && ax.type !== 'log') {
const axAttr = ax._name;
const typeAttr = axAttr + '.type';
nestedProperty(gd.layout, typeAttr).set(null);
}
}
}
}

0 comments on commit 48d6be1

Please sign in to comment.