@@ -27,18 +27,21 @@ exports.attributes = {
2727 'Determines whether this filter transform is enabled or disabled.'
2828 ] . join ( ' ' )
2929 } ,
30- filtersrc : {
30+ target : {
3131 valType : 'string' ,
3232 strict : true ,
3333 noBlank : true ,
3434 dflt : 'x' ,
3535 description : [
36- 'Sets the variable in the parent trace object' ,
37- 'by which the filter will be applied.' ,
36+ 'Sets the filter target by which the filter is applied.' ,
3837
38+ 'If a string, *target* is assumed to be a reference to a data array' ,
39+ 'in the parent trace object.' ,
3940 'To filter about nested variables, use *.* to access them.' ,
40- 'For example, set `filtersrc` to *marker.color* to filter' ,
41- 'about the marker color array.'
41+ 'For example, set `target` to *marker.color* to filter' ,
42+ 'about the marker color array.' ,
43+
44+ 'If an array, *target* is then the data array by which the filter is applied.'
4245 ] . join ( ' ' )
4346 } ,
4447 operation : {
@@ -77,7 +80,7 @@ exports.attributes = {
7780 'Sets the value or values by which to filter by.' ,
7881
7982 'Values are expected to be in the same type as the data linked' ,
80- 'to *filtersrc *.' ,
83+ 'to *target *.' ,
8184
8285 'When `operation` is set to one of the inequality values' ,
8386 '(' + INEQUALITY_OPS + ')' ,
@@ -108,25 +111,24 @@ exports.supplyDefaults = function(transformIn) {
108111 if ( enabled ) {
109112 coerce ( 'operation' ) ;
110113 coerce ( 'value' ) ;
111- coerce ( 'filtersrc ' ) ;
114+ coerce ( 'target ' ) ;
112115 }
113116
114117 return transformOut ;
115118} ;
116119
117120exports . calcTransform = function ( gd , trace , opts ) {
118- var filtersrc = opts . filtersrc ,
119- filtersrcOk = filtersrc && Array . isArray ( Lib . nestedProperty ( trace , filtersrc ) . get ( ) ) ;
120-
121- if ( ! opts . enabled || ! filtersrcOk ) return ;
121+ if ( ! opts . enabled ) return ;
122122
123- var dataToCoord = getDataToCoordFunc ( gd , trace , filtersrc ) ,
124- filterFunc = getFilterFunc ( opts , dataToCoord ) ;
123+ var target = opts . target ,
124+ filterArray = getFilterArray ( trace , target ) ,
125+ len = filterArray . length ;
125126
126- var filterArr = Lib . nestedProperty ( trace , filtersrc ) . get ( ) ,
127- len = filterArr . length ;
127+ if ( ! len ) return ;
128128
129- var arrayAttrs = Lib . findArrayAttributes ( trace ) ,
129+ var dataToCoord = getDataToCoordFunc ( gd , trace , target ) ,
130+ filterFunc = getFilterFunc ( opts , dataToCoord ) ,
131+ arrayAttrs = Lib . findArrayAttributes ( trace ) ,
130132 originalArrays = { } ;
131133
132134 // copy all original array attribute values,
@@ -147,7 +149,7 @@ exports.calcTransform = function(gd, trace, opts) {
147149 }
148150
149151 for ( var i = 0 ; i < len ; i ++ ) {
150- var v = filterArr [ i ] ;
152+ var v = filterArray [ i ] ;
151153
152154 if ( ! filterFunc ( v ) ) continue ;
153155
@@ -157,16 +159,26 @@ exports.calcTransform = function(gd, trace, opts) {
157159 }
158160} ;
159161
160- function getDataToCoordFunc ( gd , trace , filtersrc ) {
161- var ax = axisIds . getFromTrace ( gd , trace , filtersrc ) ;
162+ function getFilterArray ( trace , target ) {
163+ if ( typeof target === 'string' && target ) {
164+ var array = Lib . nestedProperty ( trace , target ) . get ( ) ;
165+
166+ return Array . isArray ( array ) ? array : [ ] ;
167+ }
168+
169+ return false ;
170+ }
171+
172+ function getDataToCoordFunc ( gd , trace , target ) {
173+ var ax = axisIds . getFromTrace ( gd , trace , target ) ;
162174
163- // if 'filtersrc ' has corresponding axis
175+ // if 'target ' has corresponding axis
164176 // -> use setConvert method
165177 if ( ax ) return ax . d2c ;
166178
167179 // special case for 'ids'
168180 // -> cast to String
169- if ( filtersrc === 'ids' ) return function ( v ) { return String ( v ) ; } ;
181+ if ( target === 'ids' ) return function ( v ) { return String ( v ) ; } ;
170182
171183 // otherwise
172184 // -> cast to Number
0 commit comments