-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Filter fixes #1062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Filter fixes #1062
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
168b447
rename *filtersrc* filter transform attribute *target*
etpinard 046dd32
add backward-compatibility map for *filtersrc*
etpinard c80f144
transforms: link up tranform module to fullData transform container
etpinard e39d447
filter: auto-type filter target arrays
etpinard 48ed675
test: fixup transition transform cases to use objectContaining
etpinard b7c2b17
Merge branch 'master' into filter-fixes
etpinard 14fd327
filter: swap Plots.supplyDefaults call for more granular approach
etpinard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
'use strict'; | ||
|
||
var Lib = require('../lib'); | ||
var Plots = require('../plots/plots'); | ||
var axisIds = require('../plots/cartesian/axis_ids'); | ||
|
||
var INEQUALITY_OPS = ['=', '<', '>=', '>', '<=']; | ||
|
@@ -27,18 +28,22 @@ exports.attributes = { | |
'Determines whether this filter transform is enabled or disabled.' | ||
].join(' ') | ||
}, | ||
filtersrc: { | ||
target: { | ||
valType: 'string', | ||
strict: true, | ||
noBlank: true, | ||
arrayOk: true, | ||
dflt: 'x', | ||
description: [ | ||
'Sets the variable in the parent trace object', | ||
'by which the filter will be applied.', | ||
'Sets the filter target by which the filter is applied.', | ||
|
||
'If a string, *target* is assumed to be a reference to a data array', | ||
'in the parent trace object.', | ||
'To filter about nested variables, use *.* to access them.', | ||
'For example, set `filtersrc` to *marker.color* to filter', | ||
'about the marker color array.' | ||
'For example, set `target` to *marker.color* to filter', | ||
'about the marker color array.', | ||
|
||
'If an array, *target* is then the data array by which the filter is applied.' | ||
].join(' ') | ||
}, | ||
operation: { | ||
|
@@ -77,7 +82,7 @@ exports.attributes = { | |
'Sets the value or values by which to filter by.', | ||
|
||
'Values are expected to be in the same type as the data linked', | ||
'to *filtersrc*.', | ||
'to *target*.', | ||
|
||
'When `operation` is set to one of the inequality values', | ||
'(' + INEQUALITY_OPS + ')', | ||
|
@@ -108,25 +113,24 @@ exports.supplyDefaults = function(transformIn) { | |
if(enabled) { | ||
coerce('operation'); | ||
coerce('value'); | ||
coerce('filtersrc'); | ||
coerce('target'); | ||
} | ||
|
||
return transformOut; | ||
}; | ||
|
||
exports.calcTransform = function(gd, trace, opts) { | ||
var filtersrc = opts.filtersrc, | ||
filtersrcOk = filtersrc && Array.isArray(Lib.nestedProperty(trace, filtersrc).get()); | ||
|
||
if(!opts.enabled || !filtersrcOk) return; | ||
if(!opts.enabled) return; | ||
|
||
var dataToCoord = getDataToCoordFunc(gd, trace, filtersrc), | ||
filterFunc = getFilterFunc(opts, dataToCoord); | ||
var target = opts.target, | ||
filterArray = getFilterArray(trace, target), | ||
len = filterArray.length; | ||
|
||
var filterArr = Lib.nestedProperty(trace, filtersrc).get(), | ||
len = filterArr.length; | ||
if(!len) return; | ||
|
||
var arrayAttrs = Lib.findArrayAttributes(trace), | ||
var dataToCoord = getDataToCoordFunc(gd, trace, target), | ||
filterFunc = getFilterFunc(opts, dataToCoord), | ||
arrayAttrs = Lib.findArrayAttributes(trace), | ||
originalArrays = {}; | ||
|
||
// copy all original array attribute values, | ||
|
@@ -147,7 +151,7 @@ exports.calcTransform = function(gd, trace, opts) { | |
} | ||
|
||
for(var i = 0; i < len; i++) { | ||
var v = filterArr[i]; | ||
var v = filterArray[i]; | ||
|
||
if(!filterFunc(v)) continue; | ||
|
||
|
@@ -157,18 +161,45 @@ exports.calcTransform = function(gd, trace, opts) { | |
} | ||
}; | ||
|
||
function getDataToCoordFunc(gd, trace, filtersrc) { | ||
var ax = axisIds.getFromTrace(gd, trace, filtersrc); | ||
function getFilterArray(trace, target) { | ||
if(typeof target === 'string' && target) { | ||
var array = Lib.nestedProperty(trace, target).get(); | ||
|
||
return Array.isArray(array) ? array : []; | ||
} | ||
else if(Array.isArray(target)) return target.slice(); | ||
|
||
return false; | ||
} | ||
|
||
function getDataToCoordFunc(gd, trace, target) { | ||
var ax; | ||
|
||
// In the case of an array target, make a mock data array | ||
// and call supplyDefaults to the data type and | ||
// setup the data-to-calc method. | ||
if(Array.isArray(target)) { | ||
var mockGd = { | ||
data: [{ x: target }], | ||
layout: {} | ||
}; | ||
|
||
Plots.supplyDefaults(mockGd); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
ax = mockGd._fullLayout.xaxis; | ||
} | ||
else { | ||
ax = axisIds.getFromTrace(gd, trace, target); | ||
} | ||
|
||
// if 'filtersrc' has corresponding axis | ||
// if 'target' has corresponding axis | ||
// -> use setConvert method | ||
if(ax) return ax.d2c; | ||
|
||
// special case for 'ids' | ||
// -> cast to String | ||
if(filtersrc === 'ids') return function(v) { return String(v); }; | ||
if(target === 'ids') return function(v) { return String(v); }; | ||
|
||
// otherwise | ||
// otherwise (e.g. numeric-array of 'marker.color' or 'marker.size') | ||
// -> cast to Number | ||
return function(v) { return +v; }; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loop through transform container found in the trace, use the transform module attributes declaration to determine which attributes are
data_array
orarrayOk
.