Skip to content

Commit 304b7db

Browse files
nicolaskruchtenVeraZab
authored andcommitted
multicat data selectors
1 parent 48f33cd commit 304b7db

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

dev/dataSources.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,16 +1728,10 @@ export default {
17281728
'jagged ints': [2, 1, 3, 5, 4, 6],
17291729
'toggle ints': [1, -1, 1, -1, 1, -1],
17301730
'big ints': [1000, 10100, 10000, 20000, 100000],
1731-
dates: [
1732-
'2010-01-01',
1733-
'2010-07-01',
1734-
'2011-01-01',
1735-
'2011-07-01',
1736-
'2012-01-01',
1737-
'2012-06-01',
1738-
],
1731+
dates: ['2010-01-01', '2010-07-01', '2011-01-01', '2011-07-01', '2012-01-01', '2012-06-01'],
17391732
months: ['January', 'February', 'March', 'April', 'May', 'June'],
17401733
colors: ['red', 'orange', 'yellow', 'green', 'blue', 'indigo'],
1734+
buckets: ['A', 'A', 'A', 'B', 'B', 'B'],
17411735
'blue and red': ['blue', 'red'],
17421736
countries: [
17431737
'Angola',

src/components/fields/DataSelector.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ export class UnconnectedDataSelector extends Component {
3535
this.is2D = false;
3636
if (props.container) {
3737
this.is2D =
38+
((props.attr === 'x' || props.attr === 'y') &&
39+
[
40+
'scatter',
41+
'scattergl',
42+
'bar',
43+
'heatmap',
44+
'heatmapgl',
45+
'violin',
46+
'box',
47+
'contour',
48+
'contourgl',
49+
].includes(props.container.type)) ||
3850
(props.attr === 'z' &&
3951
[
4052
'contour',
@@ -60,14 +72,23 @@ export class UnconnectedDataSelector extends Component {
6072
const update = {};
6173
let data;
6274

63-
if (Array.isArray(value)) {
64-
data = value.filter(v => Array.isArray(this.dataSources[v])).map(v => this.dataSources[v]);
75+
const adjustedValue =
76+
Array.isArray(value) &&
77+
value.length === 1 &&
78+
(this.props.attr === 'x' || this.props.attr === 'y')
79+
? value[0]
80+
: value;
81+
82+
if (Array.isArray(adjustedValue)) {
83+
data = adjustedValue
84+
.filter(v => Array.isArray(this.dataSources[v]))
85+
.map(v => this.dataSources[v]);
6586
} else {
66-
data = this.dataSources[value] || null;
87+
data = this.dataSources[adjustedValue] || null;
6788
}
6889

6990
update[this.props.attr] = maybeTransposeData(data, this.srcAttr, this.props.container.type);
70-
update[this.srcAttr] = maybeAdjustSrc(value, this.srcAttr, this.props.container.type, {
91+
update[this.srcAttr] = maybeAdjustSrc(adjustedValue, this.srcAttr, this.props.container.type, {
7192
fromSrc: this.context.srcConverters ? this.context.srcConverters.fromSrc : null,
7293
});
7394

0 commit comments

Comments
 (0)