Skip to content

Commit 037fa5c

Browse files
committed
transforms: perf in groupby
- extend original traces with extendDeepNoArrays (no need to copy arrays - they are filled during the grouping operation) - swap .forEach for good old for loop
1 parent f722c5d commit 037fa5c

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/transforms/groupby.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ exports.supplyDefaults = function(transformIn) {
7272
coerce('groups');
7373
coerce('style');
7474

75-
// or some more complex logic using fullData and layout
76-
7775
return transformOut;
7876
};
7977

@@ -94,15 +92,11 @@ exports.supplyDefaults = function(transformIn) {
9492
* array of transformed traces
9593
*/
9694
exports.transform = function(data, state) {
97-
98-
// one-to-many case
99-
10095
var newData = [];
10196

102-
data.forEach(function(trace, i) {
103-
104-
newData = newData.concat(transformOne(trace, state, state.attributeSets[i]));
105-
});
97+
for(var i = 0; i < data.length; i++) {
98+
newData = newData.concat(transformOne(data[i], state));
99+
}
106100

107101
return newData;
108102
};
@@ -141,9 +135,7 @@ function transformOne(trace, state) {
141135
for(var i = 0; i < groupNames.length; i++) {
142136
var groupName = groupNames[i];
143137

144-
// TODO is this the best pattern ???
145-
// maybe we could abstract this out
146-
var newTrace = newData[i] = Lib.extendDeep({}, trace);
138+
var newTrace = newData[i] = Lib.extendDeepNoArrays({}, trace);
147139

148140
arrayAttrs.forEach(initializeArray.bind(null, newTrace));
149141

@@ -155,9 +147,9 @@ function transformOne(trace, state) {
155147

156148
newTrace.name = groupName;
157149

158-
// there's no need to coerce style[groupName] here
150+
// there's no need to coerce style[groupName] here
159151
// as another round of supplyDefaults is done on the transformed traces
160-
newTrace = Lib.extendDeep(newTrace, style[groupName] || {});
152+
newTrace = Lib.extendDeepNoArrays(newTrace, style[groupName] || {});
161153
}
162154

163155
return newData;

0 commit comments

Comments
 (0)