@@ -17,11 +17,6 @@ var filterUnique = require('../../lib/filter_unique.js');
17
17
var Drawing = require ( '../../components/drawing' ) ;
18
18
var Lib = require ( '../../lib' ) ;
19
19
20
-
21
- function visible ( dimension ) { return ! ( 'visible' in dimension ) || dimension . visible ; }
22
-
23
- // Exports
24
- // =======
25
20
/**
26
21
* Create a wrapped ParcatsModel object from trace
27
22
*
@@ -31,24 +26,18 @@ function visible(dimension) { return !('visible' in dimension) || dimension.visi
31
26
* @return {Array.<ParcatsModel> }
32
27
*/
33
28
module . exports = function calc ( gd , trace ) {
29
+ var visibleDims = Lib . filterVisible ( trace . dimensions ) ;
34
30
35
- // Process inputs
36
- // --------------
37
- if ( trace . dimensions . filter ( visible ) . length === 0 ) {
38
- // No visible dimensions specified. Nothing to compute
39
- return [ ] ;
40
- }
31
+ if ( visibleDims . length === 0 ) return [ ] ;
41
32
42
- // Compute unique information
43
- // --------------------------
44
- // UniqueInfo per dimension
45
- var uniqueInfoDims = trace . dimensions . filter ( visible ) . map ( function ( dim ) {
33
+ var uniqueInfoDims = visibleDims . map ( function ( dim ) {
46
34
var categoryValues ;
47
35
if ( dim . categoryorder === 'trace' ) {
48
36
// Use order of first occurrence in trace
49
37
categoryValues = null ;
50
38
} else if ( dim . categoryorder === 'array' ) {
51
- // Use categories specified in `categoryarray` first, then add extra to the end in trace order
39
+ // Use categories specified in `categoryarray` first,
40
+ // then add extra to the end in trace order
52
41
categoryValues = dim . categoryarray ;
53
42
} else {
54
43
// Get all categories up front so we can order them
@@ -61,8 +50,6 @@ module.exports = function calc(gd, trace) {
61
50
return getUniqueInfo ( dim . values , categoryValues ) ;
62
51
} ) ;
63
52
64
- // Process counts
65
- // --------------
66
53
var counts ,
67
54
count ,
68
55
totalCount ;
@@ -72,13 +59,9 @@ module.exports = function calc(gd, trace) {
72
59
counts = [ trace . counts ] ;
73
60
}
74
61
75
- // Validate dimension display order
76
- // --------------------------------
77
- validateDimensionDisplayInds ( trace ) ;
62
+ validateDimensionDisplayInds ( visibleDims ) ;
78
63
79
- // Validate category display order
80
- // -------------------------------
81
- trace . dimensions . filter ( visible ) . forEach ( function ( dim , dimInd ) {
64
+ visibleDims . forEach ( function ( dim , dimInd ) {
82
65
validateCategoryProperties ( dim , uniqueInfoDims [ dimInd ] ) ;
83
66
} ) ;
84
67
@@ -111,7 +94,7 @@ module.exports = function calc(gd, trace) {
111
94
112
95
// Number of values and counts
113
96
// ---------------------------
114
- var numValues = trace . dimensions . filter ( visible ) [ 0 ] . values . length ;
97
+ var numValues = visibleDims [ 0 ] . values . length ;
115
98
116
99
// Build path info
117
100
// ---------------
@@ -155,12 +138,8 @@ module.exports = function calc(gd, trace) {
155
138
updatePathModel ( pathModels [ pathKey ] , valueInd , count ) ;
156
139
}
157
140
158
- // Build categories info
159
- // ---------------------
160
-
161
- // Array of DimensionModel objects
162
- var dimensionModels = trace . dimensions . filter ( visible ) . map ( function ( di , i ) {
163
- return createDimensionModel ( i , di . _index , di . displayindex , di . label , totalCount ) ;
141
+ var dimensionModels = visibleDims . map ( function ( di , i ) {
142
+ return createDimensionModel ( i , di . _index , di . _displayindex , di . label , totalCount ) ;
164
143
} ) ;
165
144
166
145
@@ -174,8 +153,8 @@ module.exports = function calc(gd, trace) {
174
153
var cats = dimensionModels [ d ] . categories ;
175
154
176
155
if ( cats [ catInd ] === undefined ) {
177
- var catValue = trace . dimensions [ containerInd ] . categoryarray [ catInd ] ;
178
- var catLabel = trace . dimensions [ containerInd ] . ticktext [ catInd ] ;
156
+ var catValue = trace . dimensions [ containerInd ] . _categoryarray [ catInd ] ;
157
+ var catLabel = trace . dimensions [ containerInd ] . _ticktext [ catInd ] ;
179
158
cats [ catInd ] = createCategoryModel ( d , catInd , catValue , catLabel ) ;
180
159
}
181
160
@@ -216,7 +195,6 @@ module.exports = function calc(gd, trace) {
216
195
*/
217
196
function createParcatsModel ( dimensions , paths , count ) {
218
197
var maxCats = dimensions
219
- . filter ( visible )
220
198
. map ( function ( d ) { return d . categories . length ; } )
221
199
. reduce ( function ( v1 , v2 ) { return Math . max ( v1 , v2 ) ; } ) ;
222
200
return { dimensions : dimensions , paths : paths , trace : undefined , maxCats : maxCats , count : count } ;
@@ -456,43 +434,47 @@ function getUniqueInfo(values, uniqueValues) {
456
434
457
435
/**
458
436
* Validate the requested display order for the dimensions.
459
- * If the display order is a permutation of 0 through dimensions.length - 1 then leave it alone. Otherwise, repalce
460
- * the display order with the dimension order
437
+ * If the display order is a permutation of 0 through dimensions.length - 1, link to _displayindex
438
+ * Otherwise, replace the display order with the dimension order
461
439
* @param {Object } trace
462
440
*/
463
- function validateDimensionDisplayInds ( trace ) {
464
- var displayInds = trace . dimensions . filter ( visible ) . map ( function ( dim ) { return dim . displayindex ; } ) ;
465
- if ( ! isRangePermutation ( displayInds ) ) {
466
- trace . dimensions . filter ( visible ) . forEach ( function ( dim , i ) {
467
- dim . displayindex = i ;
468
- } ) ;
441
+ function validateDimensionDisplayInds ( visibleDims ) {
442
+ var displayInds = visibleDims . map ( function ( d ) { return d . displayindex ; } ) ;
443
+ var i ;
444
+
445
+ if ( isRangePermutation ( displayInds ) ) {
446
+ for ( i = 0 ; i < visibleDims . length ; i ++ ) {
447
+ visibleDims [ i ] . _displayindex = visibleDims [ i ] . displayindex ;
448
+ }
449
+ } else {
450
+ for ( i = 0 ; i < visibleDims . length ; i ++ ) {
451
+ visibleDims [ i ] . _displayindex = i ;
452
+ }
469
453
}
470
454
}
471
455
472
456
473
457
/**
474
- * Validate the requested display order for the dimensions.
475
- * If the display order is a permutation of 0 through dimensions.length - 1 then leave it alone. Otherwise, repalce
476
- * the display order with the dimension order
458
+ * Update category properties based on the unique values found for this dimension
477
459
* @param {Object } dim
478
460
* @param {UniqueInfo } uniqueInfoDim
479
461
*/
480
462
function validateCategoryProperties ( dim , uniqueInfoDim ) {
481
463
482
464
// Update categoryarray
483
- dim . categoryarray = uniqueInfoDim . uniqueValues ;
465
+ dim . _categoryarray = uniqueInfoDim . uniqueValues ;
484
466
485
467
// Handle ticktext
486
468
if ( dim . ticktext === null || dim . ticktext === undefined ) {
487
- dim . ticktext = [ ] ;
469
+ dim . _ticktext = [ ] ;
488
470
} else {
489
471
// Shallow copy to avoid modifying input array
490
- dim . ticktext = dim . ticktext . slice ( ) ;
472
+ dim . _ticktext = dim . ticktext . slice ( ) ;
491
473
}
492
474
493
475
// Extend ticktext with elements from uniqueInfoDim.uniqueValues
494
- for ( var i = dim . ticktext . length ; i < uniqueInfoDim . uniqueValues . length ; i ++ ) {
495
- dim . ticktext . push ( uniqueInfoDim . uniqueValues [ i ] ) ;
476
+ for ( var i = dim . _ticktext . length ; i < uniqueInfoDim . uniqueValues . length ; i ++ ) {
477
+ dim . _ticktext . push ( uniqueInfoDim . uniqueValues [ i ] ) ;
496
478
}
497
479
}
498
480
0 commit comments