@@ -18,6 +18,9 @@ var parcatConstants = require('./constants');
18
18
var Drawing = require ( '../../components/drawing' ) ;
19
19
var Lib = require ( '../../lib' ) ;
20
20
21
+
22
+ function visible ( dimension ) { return ! ( 'visible' in dimension ) || dimension . visible ; }
23
+
21
24
// Exports
22
25
// =======
23
26
/**
@@ -32,22 +35,18 @@ module.exports = function calc(gd, trace) {
32
35
33
36
// Process inputs
34
37
// --------------
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
37
40
return [ ] ;
38
41
}
39
42
40
43
// Compute unique information
41
44
// --------------------------
42
45
// UniqueInfo per dimension
43
- var uniqueInfoDims = trace . dimensions . map ( function ( dim ) {
46
+ var uniqueInfoDims = trace . dimensions . filter ( visible ) . map ( function ( dim ) {
44
47
return getUniqueInfo ( dim . values , dim . catValues ) ;
45
48
} ) ;
46
49
47
- // Number of values and counts
48
- // ---------------------------
49
- var numValues = trace . dimensions [ 0 ] . values . length ;
50
-
51
50
// Process counts
52
51
// --------------
53
52
var counts ,
@@ -65,7 +64,7 @@ module.exports = function calc(gd, trace) {
65
64
66
65
// Validate category display order
67
66
// -------------------------------
68
- trace . dimensions . forEach ( function ( dim , dimInd ) {
67
+ trace . dimensions . filter ( visible ) . forEach ( function ( dim , dimInd ) {
69
68
validateCategoryProperties ( dim , uniqueInfoDims [ dimInd ] ) ;
70
69
} ) ;
71
70
@@ -122,6 +121,10 @@ module.exports = function calc(gd, trace) {
122
121
// Category order logic
123
122
// 1)
124
123
124
+ // Number of values and counts
125
+ // ---------------------------
126
+ var numValues = trace . dimensions . filter ( visible ) [ 0 ] . values . length ;
127
+
125
128
// Build path info
126
129
// ---------------
127
130
// Mapping from category inds to PathModel objects
@@ -168,8 +171,8 @@ module.exports = function calc(gd, trace) {
168
171
// ---------------------
169
172
170
173
// 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 ) ;
173
176
} ) ;
174
177
175
178
@@ -178,13 +181,13 @@ module.exports = function calc(gd, trace) {
178
181
count = counts [ valueInd % counts . length ] ;
179
182
180
183
for ( d = 0 ; d < dimensionModels . length ; d ++ ) {
184
+ var containerInd = dimensionModels [ d ] . containerInd ;
181
185
var catInd = uniqueInfoDims [ d ] . inds [ valueInd ] ;
182
186
var cats = dimensionModels [ d ] . categories ;
183
187
184
-
185
188
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 ] ;
188
191
189
192
cats [ catInd ] = createCategoryModel ( d , catInd , displayInd , catLabel ) ;
190
193
}
@@ -226,6 +229,7 @@ module.exports = function calc(gd, trace) {
226
229
*/
227
230
function createParcatsModel ( dimensions , paths , count ) {
228
231
var maxCats = dimensions
232
+ . filter ( visible )
229
233
. map ( function ( d ) { return d . categories . length ; } )
230
234
. reduce ( function ( v1 , v2 ) { return Math . max ( v1 , v2 ) ; } ) ;
231
235
return { dimensions : dimensions , paths : paths , trace : undefined , maxCats : maxCats , count : count } ;
@@ -238,7 +242,10 @@ function createParcatsModel(dimensions, paths, count) {
238
242
* Object containing calculated information about a single dimension
239
243
*
240
244
* @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
242
249
* @property {Number } displayInd
243
250
* The display index of this dimension (where 0 is the left most dimension)
244
251
* @property {String } dimensionLabel
@@ -253,16 +260,17 @@ function createParcatsModel(dimensions, paths, count) {
253
260
/**
254
261
* Create and new DimensionModel object with an empty categories array
255
262
* @param {Number } dimensionInd
263
+ * @param {Number } containerInd
256
264
* @param {Number } displayInd
257
- * The display index of this dimension (where 0 is the left most dimension)
258
265
* @param {String } dimensionLabel
259
266
* @param {Number } count
260
267
* Total number of input values
261
268
* @return {DimensionModel }
262
269
*/
263
- function createDimensionModel ( dimensionInd , displayInd , dimensionLabel , count ) {
270
+ function createDimensionModel ( dimensionInd , containerInd , displayInd , dimensionLabel , count ) {
264
271
return {
265
272
dimensionInd : dimensionInd ,
273
+ containerInd : containerInd ,
266
274
displayInd : displayInd ,
267
275
dimensionLabel : dimensionLabel ,
268
276
count : count ,
@@ -464,9 +472,9 @@ function getUniqueInfo(values, uniqueValues) {
464
472
* @param {Object } trace
465
473
*/
466
474
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 ; } ) ;
468
476
if ( ! isRangePermutation ( displayInds ) ) {
469
- trace . dimensions . forEach ( function ( dim , i ) {
477
+ trace . dimensions . filter ( visible ) . forEach ( function ( dim , i ) {
470
478
dim . displayindex = i ;
471
479
} ) ;
472
480
}
0 commit comments