Skip to content

Commit c8e3cc9

Browse files
committed
Added support for dimensions with visible=false
1 parent 2c14168 commit c8e3cc9

File tree

3 files changed

+47
-20
lines changed

3 files changed

+47
-20
lines changed

src/traces/parcats/calc.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ var parcatConstants = require('./constants');
1818
var Drawing = require('../../components/drawing');
1919
var Lib = require('../../lib');
2020

21+
22+
function visible(dimension) { return !('visible' in dimension) || dimension.visible; }
23+
2124
// Exports
2225
// =======
2326
/**
@@ -32,22 +35,18 @@ module.exports = function calc(gd, trace) {
3235

3336
// Process inputs
3437
// --------------
35-
if(trace.dimensions.length === 0) {
36-
// No dimensions specified. Nothing to compute
38+
if(trace.dimensions.filter(visible).length === 0) {
39+
// No visible dimensions specified. Nothing to compute
3740
return [];
3841
}
3942

4043
// Compute unique information
4144
// --------------------------
4245
// UniqueInfo per dimension
43-
var uniqueInfoDims = trace.dimensions.map(function(dim) {
46+
var uniqueInfoDims = trace.dimensions.filter(visible).map(function(dim) {
4447
return getUniqueInfo(dim.values, dim.catValues);
4548
});
4649

47-
// Number of values and counts
48-
// ---------------------------
49-
var numValues = trace.dimensions[0].values.length;
50-
5150
// Process counts
5251
// --------------
5352
var counts,
@@ -65,7 +64,7 @@ module.exports = function calc(gd, trace) {
6564

6665
// Validate category display order
6766
// -------------------------------
68-
trace.dimensions.forEach(function(dim, dimInd) {
67+
trace.dimensions.filter(visible).forEach(function(dim, dimInd) {
6968
validateCategoryProperties(dim, uniqueInfoDims[dimInd]);
7069
});
7170

@@ -122,6 +121,10 @@ module.exports = function calc(gd, trace) {
122121
// Category order logic
123122
// 1)
124123

124+
// Number of values and counts
125+
// ---------------------------
126+
var numValues = trace.dimensions.filter(visible)[0].values.length;
127+
125128
// Build path info
126129
// ---------------
127130
// Mapping from category inds to PathModel objects
@@ -168,8 +171,8 @@ module.exports = function calc(gd, trace) {
168171
// ---------------------
169172

170173
// Array of DimensionModel objects
171-
var dimensionModels = trace.dimensions.map(function(di, i) {
172-
return createDimensionModel(i, di.displayindex, di.label, totalCount);
174+
var dimensionModels = trace.dimensions.filter(visible).map(function(di, i) {
175+
return createDimensionModel(i, di._index, di.displayindex, di.label, totalCount);
173176
});
174177

175178

@@ -178,13 +181,13 @@ module.exports = function calc(gd, trace) {
178181
count = counts[valueInd % counts.length];
179182

180183
for(d = 0; d < dimensionModels.length; d++) {
184+
var containerInd = dimensionModels[d].containerInd;
181185
var catInd = uniqueInfoDims[d].inds[valueInd];
182186
var cats = dimensionModels[d].categories;
183187

184-
185188
if(cats[catInd] === undefined) {
186-
var catLabel = trace.dimensions[d].catLabels[catInd];
187-
var displayInd = trace.dimensions[d].catDisplayInds[catInd];
189+
var catLabel = trace.dimensions[containerInd].catLabels[catInd];
190+
var displayInd = trace.dimensions[containerInd].catDisplayInds[catInd];
188191

189192
cats[catInd] = createCategoryModel(d, catInd, displayInd, catLabel);
190193
}
@@ -226,6 +229,7 @@ module.exports = function calc(gd, trace) {
226229
*/
227230
function createParcatsModel(dimensions, paths, count) {
228231
var maxCats = dimensions
232+
.filter(visible)
229233
.map(function(d) {return d.categories.length;})
230234
.reduce(function(v1, v2) {return Math.max(v1, v2);});
231235
return {dimensions: dimensions, paths: paths, trace: undefined, maxCats: maxCats, count: count};
@@ -238,7 +242,10 @@ function createParcatsModel(dimensions, paths, count) {
238242
* Object containing calculated information about a single dimension
239243
*
240244
* @property {Number} dimensionInd
241-
* The index of this dimension
245+
* The index of this dimension among the *visible* dimensions
246+
* @property {Number} containerInd
247+
* The index of this dimension in the original dimensions container,
248+
* irrespective of dimension visibility
242249
* @property {Number} displayInd
243250
* The display index of this dimension (where 0 is the left most dimension)
244251
* @property {String} dimensionLabel
@@ -253,16 +260,17 @@ function createParcatsModel(dimensions, paths, count) {
253260
/**
254261
* Create and new DimensionModel object with an empty categories array
255262
* @param {Number} dimensionInd
263+
* @param {Number} containerInd
256264
* @param {Number} displayInd
257-
* The display index of this dimension (where 0 is the left most dimension)
258265
* @param {String} dimensionLabel
259266
* @param {Number} count
260267
* Total number of input values
261268
* @return {DimensionModel}
262269
*/
263-
function createDimensionModel(dimensionInd, displayInd, dimensionLabel, count) {
270+
function createDimensionModel(dimensionInd, containerInd, displayInd, dimensionLabel, count) {
264271
return {
265272
dimensionInd: dimensionInd,
273+
containerInd: containerInd,
266274
displayInd: displayInd,
267275
dimensionLabel: dimensionLabel,
268276
count: count,
@@ -464,9 +472,9 @@ function getUniqueInfo(values, uniqueValues) {
464472
* @param {Object} trace
465473
*/
466474
function validateDimensionDisplayInds(trace) {
467-
var displayInds = trace.dimensions.map(function(dim) {return dim.displayindex;});
475+
var displayInds = trace.dimensions.filter(visible).map(function(dim) {return dim.displayindex;});
468476
if(!isRangePermutation(displayInds)) {
469-
trace.dimensions.forEach(function(dim, i) {
477+
trace.dimensions.filter(visible).forEach(function(dim, i) {
470478
dim.displayindex = i;
471479
});
472480
}

src/traces/parcats/parcats.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,8 @@ function dragDimensionEnd(d) {
10581058

10591059
if(anyDimsReordered) {
10601060
finalDragDimensionDisplayInds.forEach(function(finalDimDisplay, dimInd) {
1061-
restyleData['dimensions[' + dimInd + '].displayindex'] = finalDimDisplay;
1061+
var containerInd = d.parcatsViewModel.model.dimensions[dimInd].containerInd;
1062+
restyleData['dimensions[' + containerInd + '].displayindex'] = finalDimDisplay;
10621063
});
10631064
}
10641065

@@ -1074,7 +1075,7 @@ function dragDimensionEnd(d) {
10741075
});
10751076

10761077
if(anyCatsReordered) {
1077-
restyleData['dimensions[' + d.model.dimensionInd + '].catDisplayInds'] = [finalDragCategoryDisplayInds];
1078+
restyleData['dimensions[' + d.model.containerInd + '].catDisplayInds'] = [finalDragCategoryDisplayInds];
10781079
}
10791080
}
10801081

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"data": [
3+
{"type": "parcats",
4+
"domain": {"x": [0.125, 0.625],"y": [0.25, 0.75]},
5+
"dimensions":[
6+
{"label": "One", "values": [1, 1, 2, 1, 2, 1, 1, 2, 1]},
7+
{"label": "Two",
8+
"values": ["A", "B", "A", "B", "C", "C", "A", "B", "C"],
9+
"visible": false},
10+
{"label": "Three", "values": [11, 11, 11, 11, 11, 11, 11, 11, 11]}]}
11+
],
12+
"layout": {
13+
"height": 602,
14+
"width": 592,
15+
"margin": {
16+
"l": 40, "r": 40, "t": 50, "b": 40
17+
}}
18+
}

0 commit comments

Comments
 (0)