|
1 | 1 | /*
|
2 | 2 | * DELETE THIS FILE. EVERYTHING NEEDS TO FIND A HOME.
|
3 | 3 | */
|
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'; |
5 | 6 |
|
6 | 7 | export function noShame(opts) {
|
7 | 8 | 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 | +var axLetters = ['x', 'y', 'z']; |
| 34 | +function clearAxisTypes(gd, traces) { |
| 35 | + for (var i = 0; i < traces.length; i++) { |
| 36 | + var trace = gd._fullData[i]; |
| 37 | + for (var 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 types 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 | + } |
11 | 50 | }
|
12 | 51 | }
|
0 commit comments