Skip to content

Commit 24af02a

Browse files
committed
filter visible dimensions just once
1 parent 157a6e2 commit 24af02a

File tree

1 file changed

+10
-33
lines changed

1 file changed

+10
-33
lines changed

Diff for: src/traces/parcats/calc.js

+10-33
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ var filterUnique = require('../../lib/filter_unique.js');
1717
var Drawing = require('../../components/drawing');
1818
var 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
*/
3328
module.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,11 +138,7 @@ 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) {
141+
var dimensionModels = visibleDims.map(function(di, i) {
163142
return createDimensionModel(i, di._index, di._displayindex, di.label, totalCount);
164143
});
165144

@@ -216,7 +195,6 @@ module.exports = function calc(gd, trace) {
216195
*/
217196
function 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};
@@ -460,8 +438,7 @@ function getUniqueInfo(values, uniqueValues) {
460438
* Otherwise, replace the display order with the dimension order
461439
* @param {Object} trace
462440
*/
463-
function validateDimensionDisplayInds(trace) {
464-
var visibleDims = Lib.filterVisible(trace.dimensions);
441+
function validateDimensionDisplayInds(visibleDims) {
465442
var displayInds = visibleDims.map(function(d) { return d.displayindex; });
466443
var i;
467444

0 commit comments

Comments
 (0)