Skip to content

Commit 6d2d32c

Browse files
committed
aggregations[i].enabled
1 parent ffc4ee2 commit 6d2d32c

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/transforms/aggregate.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,18 @@ var attrs = exports.attributes = {
7474
'the first (last) linked value.'
7575
].join(' ')
7676
},
77+
enabled: {
78+
valType: 'boolean',
79+
dflt: true,
80+
description: [
81+
'Determines whether this aggregation function is enabled or disabled.'
82+
].join(' ')
83+
}
7784
}
7885
};
7986

87+
var aggAttrs = attrs.aggregations;
88+
8089
/**
8190
* Supply transform attributes defaults
8291
*
@@ -129,20 +138,22 @@ exports.supplyDefaults = function(transformIn, traceOut) {
129138
}
130139

131140
var aggregationsIn = transformIn.aggregations;
132-
var aggregationsOut = transformOut.aggregations = [];
141+
var aggregationsOut = transformOut.aggregations = new Array(aggregationsIn.length);
133142

134143
if(aggregationsIn) {
135144
for(i = 0; i < aggregationsIn.length; i++) {
136145
var aggregationOut = {};
137-
var target = Lib.coerce(aggregationsIn[i], aggregationOut, attrs.aggregations, 'target');
138-
var func = Lib.coerce(aggregationsIn[i], aggregationOut, attrs.aggregations, 'func');
146+
var target = Lib.coerce(aggregationsIn[i], aggregationOut, aggAttrs, 'target');
147+
var func = Lib.coerce(aggregationsIn[i], aggregationOut, aggAttrs, 'func');
148+
var enabledi = Lib.coerce(aggregationsIn[i], aggregationOut, aggAttrs, 'enabled');
139149

140150
// add this aggregation to the output only if it's the first instance
141151
// of a valid target attribute - or an unused target attribute with "count"
142-
if(target && (arrayAttrs[target] || (func === 'count' && arrayAttrs[target] === undefined))) {
152+
if(enabledi && target && (arrayAttrs[target] || (func === 'count' && arrayAttrs[target] === undefined))) {
143153
arrayAttrs[target] = 0;
144-
aggregationsOut.push(aggregationOut);
154+
aggregationsOut[i] = aggregationOut;
145155
}
156+
else aggregationsOut[i] = {enabled: false};
146157
}
147158
}
148159

@@ -151,7 +162,8 @@ exports.supplyDefaults = function(transformIn, traceOut) {
151162
if(arrayAttrs[arrayAttrArray[i]]) {
152163
aggregationsOut.push({
153164
target: arrayAttrArray[i],
154-
func: attrs.aggregations.func.dflt
165+
func: aggAttrs.func.dflt,
166+
enabled: true
155167
});
156168
}
157169
}
@@ -189,11 +201,17 @@ exports.calcTransform = function(gd, trace, opts) {
189201
}
190202

191203
if(typeof groups === 'string') {
192-
aggregateOneArray(gd, trace, groupings, {target: groups, func: 'first'});
204+
aggregateOneArray(gd, trace, groupings, {
205+
target: groups,
206+
func: 'first',
207+
enabled: true
208+
});
193209
}
194210
};
195211

196212
function aggregateOneArray(gd, trace, groupings, aggregation) {
213+
if(!aggregation.enabled) return;
214+
197215
var attr = aggregation.target;
198216
var targetNP = Lib.nestedProperty(trace, attr);
199217
var arrayIn = targetNP.get();

0 commit comments

Comments
 (0)