@@ -17,11 +17,6 @@ var filterUnique = require('../../lib/filter_unique.js');
1717var Drawing = require ( '../../components/drawing' ) ;
1818var Lib = require ( '../../lib' ) ;
1919
20-
21- function visible ( dimension ) { return ! ( 'visible' in dimension ) || dimension . visible ; }
22-
23- // Exports
24- // =======
2520/**
2621 * Create a wrapped ParcatsModel object from trace
2722 *
@@ -31,24 +26,18 @@ function visible(dimension) { return !('visible' in dimension) || dimension.visi
3126 * @return {Array.<ParcatsModel> }
3227 */
3328module . exports = function calc ( gd , trace ) {
29+ var visibleDims = Lib . filterVisible ( trace . dimensions ) ;
3430
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 [ ] ;
4132
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 ) {
4634 var categoryValues ;
4735 if ( dim . categoryorder === 'trace' ) {
4836 // Use order of first occurrence in trace
4937 categoryValues = null ;
5038 } 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
5241 categoryValues = dim . categoryarray ;
5342 } else {
5443 // Get all categories up front so we can order them
@@ -61,8 +50,6 @@ module.exports = function calc(gd, trace) {
6150 return getUniqueInfo ( dim . values , categoryValues ) ;
6251 } ) ;
6352
64- // Process counts
65- // --------------
6653 var counts ,
6754 count ,
6855 totalCount ;
@@ -72,13 +59,9 @@ module.exports = function calc(gd, trace) {
7259 counts = [ trace . counts ] ;
7360 }
7461
75- // Validate dimension display order
76- // --------------------------------
77- validateDimensionDisplayInds ( trace ) ;
62+ validateDimensionDisplayInds ( visibleDims ) ;
7863
79- // Validate category display order
80- // -------------------------------
81- trace . dimensions . filter ( visible ) . forEach ( function ( dim , dimInd ) {
64+ visibleDims . forEach ( function ( dim , dimInd ) {
8265 validateCategoryProperties ( dim , uniqueInfoDims [ dimInd ] ) ;
8366 } ) ;
8467
@@ -111,7 +94,7 @@ module.exports = function calc(gd, trace) {
11194
11295 // Number of values and counts
11396 // ---------------------------
114- var numValues = trace . dimensions . filter ( visible ) [ 0 ] . values . length ;
97+ var numValues = visibleDims [ 0 ] . values . length ;
11598
11699 // Build path info
117100 // ---------------
@@ -155,12 +138,8 @@ module.exports = function calc(gd, trace) {
155138 updatePathModel ( pathModels [ pathKey ] , valueInd , count ) ;
156139 }
157140
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 ) ;
164143 } ) ;
165144
166145
@@ -174,8 +153,8 @@ module.exports = function calc(gd, trace) {
174153 var cats = dimensionModels [ d ] . categories ;
175154
176155 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 ] ;
179158 cats [ catInd ] = createCategoryModel ( d , catInd , catValue , catLabel ) ;
180159 }
181160
@@ -216,7 +195,6 @@ module.exports = function calc(gd, trace) {
216195 */
217196function createParcatsModel ( dimensions , paths , count ) {
218197 var maxCats = dimensions
219- . filter ( visible )
220198 . map ( function ( d ) { return d . categories . length ; } )
221199 . reduce ( function ( v1 , v2 ) { return Math . max ( v1 , v2 ) ; } ) ;
222200 return { dimensions : dimensions , paths : paths , trace : undefined , maxCats : maxCats , count : count } ;
@@ -456,43 +434,47 @@ function getUniqueInfo(values, uniqueValues) {
456434
457435/**
458436 * 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
461439 * @param {Object } trace
462440 */
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+ }
469453 }
470454}
471455
472456
473457/**
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
477459 * @param {Object } dim
478460 * @param {UniqueInfo } uniqueInfoDim
479461 */
480462function validateCategoryProperties ( dim , uniqueInfoDim ) {
481463
482464 // Update categoryarray
483- dim . categoryarray = uniqueInfoDim . uniqueValues ;
465+ dim . _categoryarray = uniqueInfoDim . uniqueValues ;
484466
485467 // Handle ticktext
486468 if ( dim . ticktext === null || dim . ticktext === undefined ) {
487- dim . ticktext = [ ] ;
469+ dim . _ticktext = [ ] ;
488470 } else {
489471 // Shallow copy to avoid modifying input array
490- dim . ticktext = dim . ticktext . slice ( ) ;
472+ dim . _ticktext = dim . ticktext . slice ( ) ;
491473 }
492474
493475 // 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 ] ) ;
496478 }
497479}
498480
0 commit comments