@@ -27,18 +27,21 @@ exports.attributes = {
27
27
'Determines whether this filter transform is enabled or disabled.'
28
28
] . join ( ' ' )
29
29
} ,
30
- filtersrc : {
30
+ target : {
31
31
valType : 'string' ,
32
32
strict : true ,
33
33
noBlank : true ,
34
34
dflt : 'x' ,
35
35
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.' ,
38
37
38
+ 'If a string, *target* is assumed to be a reference to a data array' ,
39
+ 'in the parent trace object.' ,
39
40
'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.'
42
45
] . join ( ' ' )
43
46
} ,
44
47
operation : {
@@ -77,7 +80,7 @@ exports.attributes = {
77
80
'Sets the value or values by which to filter by.' ,
78
81
79
82
'Values are expected to be in the same type as the data linked' ,
80
- 'to *filtersrc *.' ,
83
+ 'to *target *.' ,
81
84
82
85
'When `operation` is set to one of the inequality values' ,
83
86
'(' + INEQUALITY_OPS + ')' ,
@@ -108,25 +111,24 @@ exports.supplyDefaults = function(transformIn) {
108
111
if ( enabled ) {
109
112
coerce ( 'operation' ) ;
110
113
coerce ( 'value' ) ;
111
- coerce ( 'filtersrc ' ) ;
114
+ coerce ( 'target ' ) ;
112
115
}
113
116
114
117
return transformOut ;
115
118
} ;
116
119
117
120
exports . 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 ;
122
122
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 ;
125
126
126
- var filterArr = Lib . nestedProperty ( trace , filtersrc ) . get ( ) ,
127
- len = filterArr . length ;
127
+ if ( ! len ) return ;
128
128
129
- var arrayAttrs = Lib . findArrayAttributes ( trace ) ,
129
+ var dataToCoord = getDataToCoordFunc ( gd , trace , target ) ,
130
+ filterFunc = getFilterFunc ( opts , dataToCoord ) ,
131
+ arrayAttrs = Lib . findArrayAttributes ( trace ) ,
130
132
originalArrays = { } ;
131
133
132
134
// copy all original array attribute values,
@@ -147,7 +149,7 @@ exports.calcTransform = function(gd, trace, opts) {
147
149
}
148
150
149
151
for ( var i = 0 ; i < len ; i ++ ) {
150
- var v = filterArr [ i ] ;
152
+ var v = filterArray [ i ] ;
151
153
152
154
if ( ! filterFunc ( v ) ) continue ;
153
155
@@ -157,16 +159,26 @@ exports.calcTransform = function(gd, trace, opts) {
157
159
}
158
160
} ;
159
161
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 ) ;
162
174
163
- // if 'filtersrc ' has corresponding axis
175
+ // if 'target ' has corresponding axis
164
176
// -> use setConvert method
165
177
if ( ax ) return ax . d2c ;
166
178
167
179
// special case for 'ids'
168
180
// -> cast to String
169
- if ( filtersrc === 'ids' ) return function ( v ) { return String ( v ) ; } ;
181
+ if ( target === 'ids' ) return function ( v ) { return String ( v ) ; } ;
170
182
171
183
// otherwise
172
184
// -> cast to Number
0 commit comments