@@ -132,7 +132,8 @@ exports.transform = function(data, state) {
132
132
133
133
134
134
function transformOne ( trace , state ) {
135
- var i , j , k , attr , srcArray , groupName , newTrace , transforms ;
135
+ var i , j , k , attr , srcArray , groupName , newTrace , transforms , arrayLookup ;
136
+
136
137
var opts = state . transform ;
137
138
var groups = trace . transforms [ state . transformIndex ] . groups ;
138
139
@@ -152,13 +153,15 @@ function transformOne(trace, state) {
152
153
styleLookup [ styles [ i ] . target ] = styles [ i ] . value ;
153
154
}
154
155
155
- var newDataByGroup = { } ;
156
+ // An index to map group name --> expanded trace index
157
+ var groupIndex = { } ;
156
158
157
159
for ( i = 0 ; i < groupNames . length ; i ++ ) {
158
160
groupName = groupNames [ i ] ;
161
+ groupIndex [ groupName ] = i ;
159
162
160
163
// Start with a deep extend that just copies array references.
161
- newTrace = newData [ i ] = newDataByGroup [ groupName ] = Lib . extendDeepNoArrays ( { } , trace ) ;
164
+ newTrace = newData [ i ] = Lib . extendDeepNoArrays ( { } , trace ) ;
162
165
newTrace . name = groupName ;
163
166
164
167
// In order for groups to apply correctly to other transform data (e.g.
@@ -179,19 +182,24 @@ function transformOne(trace, state) {
179
182
}
180
183
}
181
184
182
-
183
185
// For each array attribute including those nested inside this and other
184
186
// transforms (small note that we technically only need to do this for
185
187
// transforms that have not yet been applied):
186
188
for ( k = 0 ; k < arrayAttrs . length ; k ++ ) {
187
189
attr = arrayAttrs [ k ] ;
188
190
191
+ // Cache all the arrays to which we'll push:
192
+ for ( j = 0 , arrayLookup = [ ] ; j < groupNames . length ; j ++ ) {
193
+ arrayLookup [ j ] = Lib . nestedProperty ( newData [ j ] , attr ) . get ( ) ;
194
+ }
195
+
189
196
// Get the input data:
190
197
srcArray = Lib . nestedProperty ( trace , attr ) . get ( ) ;
191
198
192
- // And push each value onto the appropriate destination for this group :
199
+ // Send each data point to the appropriate expanded trace :
193
200
for ( j = 0 ; j < len ; j ++ ) {
194
- Lib . nestedProperty ( newDataByGroup [ groups [ j ] ] , attr ) . get ( ) . push ( srcArray [ j ] ) ;
201
+ // Map group data --> trace index --> array and push data onto it
202
+ arrayLookup [ groupIndex [ groups [ j ] ] ] . push ( srcArray [ j ] ) ;
195
203
}
196
204
}
197
205
0 commit comments