MCPcopy Index your code
hub / github.com/plotly/plotly.js / getAggregateFunction

Function getAggregateFunction

src/transforms/aggregate.js:272–438  ·  view source on GitHub ↗
(opts, conversions)

Source from the content-addressed store, hash-verified

270}
271
272function getAggregateFunction(opts, conversions) {
273 var func = opts.func;
274 var d2c = conversions.d2c;
275 var c2d = conversions.c2d;
276
277 switch(func) {
278 // count, first, and last don't depend on anything about the data
279 // point back to pure functions for performance
280 case 'count':
281 return count;
282 case 'first':
283 return first;
284 case 'last':
285 return last;
286
287 case 'sum':
288 // This will produce output in all cases even though it's nonsensical
289 // for date or category data.
290 return function(array, indices) {
291 var total = 0;
292 for(var i = 0; i < indices.length; i++) {
293 var vi = d2c(array[indices[i]]);
294 if(vi !== BADNUM) total += vi;
295 }
296 return c2d(total);
297 };
298
299 case 'avg':
300 // Generally meaningless for category data but it still does something.
301 return function(array, indices) {
302 var total = 0;
303 var cnt = 0;
304 for(var i = 0; i < indices.length; i++) {
305 var vi = d2c(array[indices[i]]);
306 if(vi !== BADNUM) {
307 total += vi;
308 cnt++;
309 }
310 }
311 return cnt ? c2d(total / cnt) : BADNUM;
312 };
313
314 case 'min':
315 return function(array, indices) {
316 var out = Infinity;
317 for(var i = 0; i < indices.length; i++) {
318 var vi = d2c(array[indices[i]]);
319 if(vi !== BADNUM) out = Math.min(out, vi);
320 }
321 return (out === Infinity) ? BADNUM : c2d(out);
322 };
323
324 case 'max':
325 return function(array, indices) {
326 var out = -Infinity;
327 for(var i = 0; i < indices.length; i++) {
328 var vi = d2c(array[indices[i]]);
329 if(vi !== BADNUM) out = Math.max(out, vi);

Callers 1

aggregateOneArrayFunction · 0.85

Calls 1

d2cFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…