/*! Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one or more contributor license agreements. * Licensed under the Elastic License 2.0; you may not use this file except in compliance with the Elastic License 2.0. */ (window.lens_bundle_jsonpfunction=window.lens_bundle_jsonpfunction||[]).push([[18],{575:function(n,e,t){"use strict";t.r(e),t.d(e,"collapseFn",(function(){return o}));var l=t(33);const o=(n,{by:e,metric:t,fn:o})=>{const r=o.length>1?o:t?new Array(t.length).fill(o[0]):[];if(t&&t.length!==r.length)throw Error(`lens_collapse - Called with ${t.length} metrics and ${o.length} collapse functions. \nMust be called with either a single collapse function for all metrics,\nor a number of collapse functions matching the number of metrics.`);const c={},i={};null==t||t.forEach((n=>{c[n]={},i[n]={}}));const a={};return n.rows.forEach((n=>{const o=Object(l.getBucketIdentifier)(n,e);null==t||t.forEach(((e,t)=>{var l;const a=c[e][o],s=n[e];if(null!=s){const n=(u=s,Array.isArray(u)?u.map((n=>Number(n))):[Number(u)]);switch(r[t]){case"avg":i[e][o]=(null!==(l=i[e][o])&&void 0!==l?l:0)+n.length;case"sum":c[e][o]=n.reduce(((n,e)=>n+e),a||0);break;case"min":c[e][o]=void 0!==a?Math.min(a,...n):Math.min(...n);break;case"max":c[e][o]=void 0!==a?Math.max(a,...n):Math.max(...n)}}var u}))})),null==t||t.forEach(((n,e)=>{"avg"===r[e]&&Object.keys(c[n]).forEach((e=>{const t=c[n][e],l=i[n][e];void 0!==t&&void 0!==l&&(c[n][e]=t/l)}))})),{...n,columns:n.columns.filter((n=>-1!==(null==e?void 0:e.indexOf(n.id))||-1!==(null==t?void 0:t.indexOf(n.id)))),rows:n.rows.map((n=>{const o=Object(l.getBucketIdentifier)(n,e);if(a[o])return;a[o]=!0;const r={};return null==t||t.forEach((n=>{r[n]=c[n][o]})),null==e||e.forEach((e=>{r[e]=n[e]})),r})).filter(Boolean)}}}}]);