Skip to content

Commit 6dab0a4

Browse files
committed
Move DataSelector logic into shame
1 parent f6c3059 commit 6dab0a4

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed

src/EditorControls.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
shamefullyAdjustAxisRef,
88
shamefullyAdjustGeo,
99
shamefullyAddTableColumns,
10-
shamefullyCreateSplitStyles,
10+
shamefullyCreateSplitStyleProps,
11+
shamefullyAdjustSplitStyleTargetContainers,
1112
} from './shame';
1213
import {EDITOR_ACTIONS} from './lib/constants';
1314
import isNumeric from 'fast-isnumeric';
@@ -67,6 +68,7 @@ class EditorControls extends Component {
6768
shamefullyClearAxisTypes(graphDiv, payload);
6869
shamefullyAdjustAxisRef(graphDiv, payload);
6970
shamefullyAddTableColumns(graphDiv, payload);
71+
shamefullyAdjustSplitStyleTargetContainers(graphDiv, payload);
7072

7173
for (let i = 0; i < payload.traceIndexes.length; i++) {
7274
for (const attr in payload.update) {
@@ -79,7 +81,7 @@ class EditorControls extends Component {
7981
const value = payload.update[attr];
8082

8183
if (splitTraceGroup) {
82-
props = shamefullyCreateSplitStyles(
84+
props = shamefullyCreateSplitStyleProps(
8385
graphDiv,
8486
attr,
8587
traceIndex,

src/components/fields/DataSelector.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -84,39 +84,6 @@ export class UnconnectedDataSelector extends Component {
8484
}
8585
);
8686

87-
if (
88-
this.props.container.type &&
89-
this.props.container.type === 'groupby' &&
90-
this.props.container.styles &&
91-
!this.props.container.styles.length &&
92-
data
93-
) {
94-
const dedupedGroups = [];
95-
data.forEach(group => {
96-
if (!dedupedGroups.includes(group)) {
97-
dedupedGroups.push(group);
98-
}
99-
});
100-
101-
const styles = dedupedGroups.map(groupEl => ({
102-
target: groupEl,
103-
value: {},
104-
}));
105-
106-
update.styles = styles;
107-
}
108-
109-
// When clearing the data selector of groupby transforms, we want to clear
110-
// all the styles we've added
111-
if (
112-
this.props.container.type &&
113-
this.props.container.type === 'groupby' &&
114-
this.props.container.styles.length &&
115-
value === null
116-
) {
117-
update.styles = [];
118-
}
119-
12087
this.props.updateContainer(update);
12188
}
12289

src/shame.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,45 @@ export const shamefullyAddTableColumns = (graphDiv, {traceIndexes, update}) => {
113113
}
114114
};
115115

116-
export const shamefullyCreateSplitStyles = (
116+
export const shamefullyAdjustSplitStyleTargetContainers = (
117+
graphDiv,
118+
{traceIndexes, update}
119+
) => {
120+
for (const attr in update) {
121+
if (attr && attr.startsWith('transforms') && attr.endsWith('groups')) {
122+
const transformIndex = parseInt(attr.split('[')[1], 10);
123+
const transform =
124+
graphDiv.data[traceIndexes[0]].transforms[transformIndex];
125+
126+
if (transform && transform.type === 'groupby' && transform.styles) {
127+
// Create style containers for all groups
128+
if (!transform.styles.length && update[attr]) {
129+
const dedupedGroups = [];
130+
update[attr].forEach(group => {
131+
if (!dedupedGroups.includes(group)) {
132+
dedupedGroups.push(group);
133+
}
134+
});
135+
136+
const styles = dedupedGroups.map(groupEl => ({
137+
target: groupEl,
138+
value: {},
139+
}));
140+
141+
update[`transforms[${transformIndex}].styles`] = styles;
142+
}
143+
144+
// When clearing the data selector of groupby transforms, we want to clear
145+
// all the styles we've added
146+
if (transform.styles.length && !update[attr]) {
147+
update[`transforms[${transformIndex}].styles`] = [];
148+
}
149+
}
150+
}
151+
}
152+
};
153+
154+
export const shamefullyCreateSplitStyleProps = (
117155
graphDiv,
118156
attr,
119157
traceIndex,

0 commit comments

Comments
 (0)