Skip to content

Commit

Permalink
Merge pull request #2415 from plotly/parcoords-multiselect-squashed
Browse files Browse the repository at this point in the history
multiple selections on parcoords axes
  • Loading branch information
alexcjohnson authored Mar 21, 2018
2 parents 6e0b63a + c3cc927 commit f9a15be
Show file tree
Hide file tree
Showing 23 changed files with 2,320 additions and 1,207 deletions.
25 changes: 18 additions & 7 deletions src/lib/coerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,11 @@ exports.valObjectMeta = {
'An {array} of plot information.'
].join(' '),
requiredOpts: ['items'],
// set dimensions=2 for a 2D array
// set `dimensions=2` for a 2D array or '1-2' for either
// `items` may be a single object instead of an array, in which case
// `freeLength` must be true.
// if `dimensions='1-2'` and items is a 1D array, then the value can
// either be a matching 1D array or an array of such matching 1D arrays
otherOpts: ['dflt', 'freeLength', 'dimensions'],
coerceFunction: function(v, propOut, dflt, opts) {

Expand All @@ -278,7 +280,7 @@ exports.valObjectMeta = {
return out;
}

var twoD = opts.dimensions === 2;
var twoD = opts.dimensions === 2 || (opts.dimensions === '1-2' && Array.isArray(v) && Array.isArray(v[0]));

if(!Array.isArray(v)) {
propOut.set(dflt);
Expand All @@ -288,19 +290,28 @@ exports.valObjectMeta = {
var items = opts.items;
var vOut = [];
var arrayItems = Array.isArray(items);
var len = arrayItems ? items.length : v.length;
var arrayItems2D = arrayItems && twoD && Array.isArray(items[0]);
var innerItemsOnly = twoD && arrayItems && !arrayItems2D;
var len = (arrayItems && !innerItemsOnly) ? items.length : v.length;

var i, j, len2, vNew;
var i, j, row, item, len2, vNew;

dflt = Array.isArray(dflt) ? dflt : [];

if(twoD) {
for(i = 0; i < len; i++) {
vOut[i] = [];
var row = Array.isArray(v[i]) ? v[i] : [];
len2 = arrayItems ? items[i].length : row.length;
row = Array.isArray(v[i]) ? v[i] : [];
if(innerItemsOnly) len2 = items.length;
else if(arrayItems) len2 = items[i].length;
else len2 = row.length;

for(j = 0; j < len2; j++) {
vNew = coercePart(row[j], arrayItems ? items[i][j] : items, (dflt[i] || [])[j]);
if(innerItemsOnly) item = items[j];
else if(arrayItems) item = items[i][j];
else item = items;

vNew = coercePart(row[j], item, (dflt[i] || [])[j]);
if(vNew !== undefined) vOut[i][j] = vNew;
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/traces/parcoords/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ module.exports = {
editType: 'calc',
description: 'The shown name of the dimension.'
},
// TODO: better way to determine ordinal vs continuous axes,
// so users can use tickvals/ticktext with a continuous axis.
tickvals: extendFlat({}, axesAttrs.tickvals, {editType: 'calc'}),
ticktext: extendFlat({}, axesAttrs.ticktext, {editType: 'calc'}),
tickformat: {
Expand Down Expand Up @@ -79,16 +81,26 @@ module.exports = {
constraintrange: {
valType: 'info_array',
role: 'info',
freeLength: true,
dimensions: '1-2',
items: [
{valType: 'number', editType: 'calc'},
{valType: 'number', editType: 'calc'}
],
editType: 'calc',
description: [
'The domain range to which the filter on the dimension is constrained. Must be an array',
'of `[fromValue, toValue]` with finite numbers as elements.'
'of `[fromValue, toValue]` with `fromValue <= toValue`, or if `multiselect` is not',
'disabled, you may give an array of arrays, where each inner array is `[fromValue, toValue]`.'
].join(' ')
},
multiselect: {
valType: 'boolean',
dflt: true,
role: 'info',
editType: 'calc',
description: 'Do we allow multiple selection ranges or just a single range?'
},
values: {
valType: 'data_array',
role: 'info',
Expand Down
Loading

0 comments on commit f9a15be

Please sign in to comment.