|
1 | 1 | import React, {Component} from 'react';
|
2 | 2 | import PropTypes from 'prop-types';
|
3 | 3 | import nestedProperty from 'plotly.js/src/lib/nested_property';
|
4 |
| -import {MULTI_VALUED} from './constants'; |
5 |
| -import {getDisplayName, isPlainObject, localize} from '../lib'; |
6 |
| - |
7 |
| -/** |
8 |
| - * Simple replacer to use with JSON.stringify. |
9 |
| - * @param {*} key Current object key. |
10 |
| - * @param {*} value Current value in object at key. |
11 |
| - * @returns {*} If we return undefined, the key is skipped in JSON.stringify. |
12 |
| - */ |
13 |
| -function skipPrivateKeys(key, value) { |
14 |
| - if (key.startsWith('_')) { |
15 |
| - return void 0; |
16 |
| - } |
17 |
| - |
18 |
| - return value; |
19 |
| -} |
20 |
| - |
21 |
| -/** |
22 |
| - * Deep-copies the value using JSON. Underscored (private) keys are removed. |
23 |
| - * @param {*} value Some nested value from the plotDiv object. |
24 |
| - * @returns {*} A deepcopy of the value. |
25 |
| - */ |
26 |
| -function deepCopyPublic(value) { |
27 |
| - if (typeof value === 'undefined') { |
28 |
| - return value; |
29 |
| - } |
30 |
| - |
31 |
| - return window.JSON.parse(window.JSON.stringify(value, skipPrivateKeys)); |
32 |
| -} |
33 |
| - |
34 |
| -/* |
35 |
| - * Test that we can connectLayoutToPlot(connectAxesToLayout(Panel)) |
36 |
| - */ |
37 |
| -function setMultiValuedContainer(intoObj, fromObj, key, config = {}) { |
38 |
| - var intoVal = intoObj[key], |
39 |
| - fromVal = fromObj[key]; |
40 |
| - |
41 |
| - var searchArrays = config.searchArrays; |
42 |
| - |
43 |
| - // don't merge private attrs |
44 |
| - if ( |
45 |
| - (typeof key === 'string' && key.charAt(0) === '_') || |
46 |
| - typeof intoVal === 'function' || |
47 |
| - key === 'module' |
48 |
| - ) { |
49 |
| - return; |
50 |
| - } |
51 |
| - |
52 |
| - // already a mixture of values, can't get any worse |
53 |
| - if (intoVal === MULTI_VALUED) { |
54 |
| - return; |
55 |
| - } else if (intoVal === void 0) { |
56 |
| - // if the original doesn't have the key it's because that key |
57 |
| - // doesn't do anything there - so use the new value |
58 |
| - // note that if fromObj doesn't have a key in intoObj we will not |
59 |
| - // attempt to merge them at all, so this behavior makes the merge |
60 |
| - // independent of order. |
61 |
| - intoObj[key] = fromVal; |
62 |
| - } else if (key === 'colorscale') { |
63 |
| - // colorscales are arrays... need to stringify before comparing |
64 |
| - // (other vals we don't want to stringify, as differences could |
65 |
| - // potentially be real, like 'false' and false) |
66 |
| - if (String(intoVal) !== String(fromVal)) { |
67 |
| - intoObj[key] = MULTI_VALUED; |
68 |
| - } |
69 |
| - } else if (Array.isArray(intoVal)) { |
70 |
| - // in data, other arrays are data, which we don't care about |
71 |
| - // for styling purposes |
72 |
| - if (!searchArrays) { |
73 |
| - return; |
74 |
| - } |
75 |
| - // in layout though, we need to recurse into arrays |
76 |
| - for (var i = 0; i < fromVal.length; i++) { |
77 |
| - setMultiValuedContainer(intoVal, fromVal, i, searchArrays); |
78 |
| - } |
79 |
| - } else if (isPlainObject(fromVal)) { |
80 |
| - // recurse into objects |
81 |
| - if (!isPlainObject(intoVal)) { |
82 |
| - throw new Error('tried to merge object into non-object: ' + key); |
83 |
| - } |
84 |
| - Object.keys(fromVal).forEach(function(key2) { |
85 |
| - setMultiValuedContainer(intoVal, fromVal, key2, searchArrays); |
86 |
| - }); |
87 |
| - } else if (isPlainObject(intoVal)) { |
88 |
| - throw new Error('tried to merge non-object into object: ' + key); |
89 |
| - } else if (intoVal !== fromVal) { |
90 |
| - // different non-empty values - |
91 |
| - intoObj[key] = MULTI_VALUED; |
92 |
| - } |
93 |
| -} |
| 4 | +import {deepCopyPublic, setMultiValuedContainer} from './multiValues'; |
| 5 | +import {getDisplayName, localize} from '../lib'; |
94 | 6 |
|
95 | 7 | function computeAxesOptions(axes, _) {
|
96 | 8 | const options = [{label: _('All'), value: 'allaxes'}];
|
|
0 commit comments