Skip to content

Fix for axes types not updating with new data types fixes #103 #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
};

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

// Do not clear log type.
// Log type is 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);
}
}
}
}