@@ -132,7 +132,8 @@ exports.transform = function(data, state) {
132132
133133
134134function 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+
136137 var opts = state . transform ;
137138 var groups = trace . transforms [ state . transformIndex ] . groups ;
138139
@@ -152,13 +153,15 @@ function transformOne(trace, state) {
152153 styleLookup [ styles [ i ] . target ] = styles [ i ] . value ;
153154 }
154155
155- var newDataByGroup = { } ;
156+ // An index to map group name --> expanded trace index
157+ var groupIndex = { } ;
156158
157159 for ( i = 0 ; i < groupNames . length ; i ++ ) {
158160 groupName = groupNames [ i ] ;
161+ groupIndex [ groupName ] = i ;
159162
160163 // 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 ) ;
162165 newTrace . name = groupName ;
163166
164167 // In order for groups to apply correctly to other transform data (e.g.
@@ -179,19 +182,24 @@ function transformOne(trace, state) {
179182 }
180183 }
181184
182-
183185 // For each array attribute including those nested inside this and other
184186 // transforms (small note that we technically only need to do this for
185187 // transforms that have not yet been applied):
186188 for ( k = 0 ; k < arrayAttrs . length ; k ++ ) {
187189 attr = arrayAttrs [ k ] ;
188190
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+
189196 // Get the input data:
190197 srcArray = Lib . nestedProperty ( trace , attr ) . get ( ) ;
191198
192- // And push each value onto the appropriate destination for this group :
199+ // Send each data point to the appropriate expanded trace :
193200 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 ] ) ;
195203 }
196204 }
197205
0 commit comments