Skip to content

Commit 8046e9b

Browse files
ensure meta.columnNames is populated
1 parent 1614165 commit 8046e9b

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"fast-isnumeric": "^1.1.2",
1616
"immutability-helper": "^3.0.0",
1717
"plotly-icons": "1.3.12",
18-
"plotly.js": "1.48.1",
18+
"plotly.js": "1.48.3",
1919
"prop-types": "^15.7.2",
2020
"raf": "^3.4.1",
2121
"react-color": "^2.17.0",

src/components/fields/DataSelector.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Field from './Field';
55
import nestedProperty from 'plotly.js/src/lib/nested_property';
66
import {connectToContainer, maybeAdjustSrc, maybeTransposeData} from 'lib';
77
import {TRANSFORMS_LIST} from 'lib/constants';
8+
import {getColumnNames} from 'lib/dereference';
89

910
export function attributeIsData(meta = {}) {
1011
return meta.valType === 'data_array' || meta.arrayOk;
@@ -94,6 +95,14 @@ export class UnconnectedDataSelector extends Component {
9495
fromSrc: this.context.srcConverters ? this.context.srcConverters.fromSrc : null,
9596
});
9697

98+
if (this.props.container.type) {
99+
// this means we're at the top level of the trace
100+
update['meta.columnNames.' + this.props.attr] = getColumnNames(
101+
Array.isArray(adjustedValue) ? adjustedValue : [adjustedValue],
102+
this.dataSourceOptions
103+
);
104+
}
105+
97106
this.props.updateContainer(update);
98107
}
99108

src/components/fields/__tests__/DataSelector-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('DataSelector', () => {
4545
beforeUpdateTraces.mockClear();
4646
wrapper.prop('onChange')('y1');
4747
expect(beforeUpdateTraces.mock.calls[0][0]).toEqual({
48-
update: {xsrc: 'y1', x: [2, 3, 4]},
48+
update: {'meta.columnNames.x': 'yCol', xsrc: 'y1', x: [2, 3, 4]},
4949
traceIndexes: [1],
5050
});
5151
});

src/lib/dereference.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,26 @@ import {maybeTransposeData} from './index';
33

44
const SRC_ATTR_PATTERN = /src$/;
55

6-
export default function dereference(container, dataSources, config = {deleteKeys: false}) {
6+
export function getColumnNames(srcArray, dataSourceOptions) {
7+
return srcArray
8+
.map(src => {
9+
const columns = dataSourceOptions.filter(dso => dso.value === src);
10+
if (columns.length === 1) {
11+
return columns[0].columnName || columns[0].label;
12+
}
13+
return '';
14+
})
15+
.join(' - ');
16+
}
17+
18+
export default function dereference(
19+
container,
20+
dataSources,
21+
config = {deleteKeys: false},
22+
dataSourceOptions = null
23+
) {
24+
const containerIsData = Array.isArray(container);
25+
726
const replacer = (key, parent, srcPath) => {
827
if (!SRC_ATTR_PATTERN.test(key)) {
928
return;
@@ -34,22 +53,31 @@ export default function dereference(container, dataSources, config = {deleteKeys
3453
return;
3554
}
3655

37-
if (Array.isArray(container)) {
38-
// Case where we were originally given data to dereference
39-
const traceType = parent.type;
40-
parent[dataKey] = maybeTransposeData(dereferencedData, srcPath, traceType);
56+
if (containerIsData) {
57+
if (parent.type !== null) {
58+
// we're at the top level of the trace
59+
if (dataSourceOptions !== null) {
60+
parent.meta = parent.meta || {};
61+
parent.meta.columnNames = parent.meta.columnNames || {};
62+
parent.meta.columnNames[dataKey] = getColumnNames(srcRef, dataSourceOptions);
63+
}
64+
parent[dataKey] = maybeTransposeData(dereferencedData, srcPath, parent.type);
65+
} else {
66+
parent[dataKey] = dereferencedData;
67+
}
4168
} else {
42-
// This means we're dereferencing layout
69+
// container is layout
4370
parent[dataKey] = dereferencedData;
4471
}
4572
};
4673

47-
if (Array.isArray(container)) {
74+
if (containerIsData) {
4875
walkObject(container, replacer, {
4976
walkArraysMatchingKeys: ['data', 'transforms'],
5077
pathType: 'nestedProperty',
5178
});
5279
} else {
80+
// container is layout
5381
walkObject(container, replacer, {pathType: 'nestedProperty'});
5482
}
5583
}

0 commit comments

Comments
 (0)