Skip to content

Commit 168b447

Browse files
committed
rename *filtersrc* filter transform attribute *target*
1 parent bf714d0 commit 168b447

File tree

6 files changed

+92
-81
lines changed

6 files changed

+92
-81
lines changed

src/transforms/filter.js

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

117120
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;
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

test/jasmine/tests/finance_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ describe('finance charts calc transforms:', function() {
423423
transforms: [{
424424
type: 'filter',
425425
operation: '>',
426-
filtersrc: 'open',
426+
target: 'open',
427427
value: 33
428428
}]
429429
});
@@ -433,7 +433,7 @@ describe('finance charts calc transforms:', function() {
433433
transforms: [{
434434
type: 'filter',
435435
operation: '{}',
436-
filtersrc: 'x',
436+
target: 'x',
437437
value: ['2016-09-01', '2016-09-10']
438438
}]
439439
});

test/jasmine/tests/plotschema_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ describe('plot schema', function() {
176176
var valObjects = plotSchema.transforms.filter.attributes,
177177
attrNames = Object.keys(valObjects);
178178

179-
['operation', 'value', 'filtersrc'].forEach(function(k) {
179+
['operation', 'value', 'target'].forEach(function(k) {
180180
expect(attrNames).toContain(k);
181181
});
182182
});

0 commit comments

Comments
 (0)