Skip to content

Commit fa8efc3

Browse files
Merge pull request #936 from plotly/metaname
column names to meta
2 parents 1614165 + 240b73d commit fa8efc3

File tree

10 files changed

+61
-22
lines changed

10 files changed

+61
-22
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-chart-editor",
33
"description": "plotly.js chart editor react component UI",
4-
"version": "0.37.2",
4+
"version": "0.38.0",
55
"author": "Plotly, Inc.",
66
"bugs": {
77
"url": "https://github.com/plotly/react-chart-editor/issues"
@@ -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/containers/AnnotationAccordion.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AnnotationAccordion extends Component {
2222
<AnnotationFold
2323
key={i}
2424
annotationIndex={i}
25-
name={getParsedTemplateString(ann.text, meta)}
25+
name={getParsedTemplateString(ann.text, {meta})}
2626
canDelete={canAdd}
2727
>
2828
{children}

src/components/containers/RangeSelectorAccordion.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class RangeSelectorAccordion extends Component {
3333
<RangeSelectorFold
3434
key={i}
3535
rangeselectorIndex={i}
36-
name={getParsedTemplateString(btn.label, meta)}
36+
name={getParsedTemplateString(btn.label, {meta})}
3737
canDelete={true}
3838
>
3939
{children}

src/components/fields/AxesCreator.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,9 @@ class UnconnectedAxesCreator extends Component {
134134

135135
function getOptions(axisType) {
136136
return fullLayout._subplots[axisType].map(axisId => ({
137-
label: getParsedTemplateString(
138-
getAxisTitle(fullLayout[axisIdToAxisName(axisId)]),
139-
fullLayout.meta
140-
),
137+
label: getParsedTemplateString(getAxisTitle(fullLayout[axisIdToAxisName(axisId)]), {
138+
meta: fullLayout.meta,
139+
}),
141140
value: axisId,
142141
}));
143142
}

src/components/fields/AxesSelector.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
33
import Dropdown from '../widgets/Dropdown';
44
import RadioBlocks from '../widgets/RadioBlocks';
55
import React, {Component} from 'react';
6+
import {getParsedTemplateString} from 'lib';
67

78
class AxesSelector extends Component {
89
constructor(props, context) {
@@ -30,7 +31,9 @@ class AxesSelector extends Component {
3031
option.value === 'allaxes'
3132
? option
3233
: {
33-
label: option.title,
34+
label: getParsedTemplateString(option.title, {
35+
meta: fullLayout.meta,
36+
}),
3437
value: option.value,
3538
}
3639
)

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/connectTraceToPlot.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function connectTraceToPlot(WrappedComponent) {
2929

3030
setLocals(props, context) {
3131
const {traceIndexes} = props;
32-
const {data, fullData, plotly, layout: meta} = context;
32+
const {data, fullData, plotly} = context;
3333

3434
const trace = data[traceIndexes[0]];
3535
const fullTrace = getFullTrace(props, context);
@@ -71,7 +71,7 @@ export default function connectTraceToPlot(WrappedComponent) {
7171

7272
if (trace && fullTrace) {
7373
this.icon = renderTraceIcon(plotlyTraceToCustomTrace(trace));
74-
this.name = getParsedTemplateString(fullTrace.name, meta);
74+
this.name = getParsedTemplateString(fullTrace.name, {meta: fullTrace.meta});
7575
}
7676
}
7777

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
}

src/lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ function getFullTrace(props, context) {
203203
return fullTrace;
204204
}
205205

206-
function getParsedTemplateString(originalString, meta) {
206+
function getParsedTemplateString(originalString, context) {
207207
let text = originalString;
208208

209-
if (originalString && meta && meta.length) {
210-
text = templateString(originalString, {meta});
209+
if (originalString && context) {
210+
text = templateString(originalString, context);
211211
}
212212

213213
return text === '' && originalString ? originalString : text;

0 commit comments

Comments
 (0)