All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.build.lib.aggregationFns.js.map Maven / Gradle / Ivy

The newest version!
{"version":3,"file":"aggregationFns.js","sources":["../../src/aggregationFns.ts"],"sourcesContent":["import { AggregationFn } from './features/Grouping'\nimport { isNumberArray } from './utils'\n\nconst sum: AggregationFn = (columnId, _leafRows, childRows) => {\n  // It's faster to just add the aggregations together instead of\n  // process leaf nodes individually\n  return childRows.reduce((sum, next) => {\n    const nextValue = next.getValue(columnId)\n    return sum + (typeof nextValue === 'number' ? nextValue : 0)\n  }, 0)\n}\n\nconst min: AggregationFn = (columnId, _leafRows, childRows) => {\n  let min: number | undefined\n\n  childRows.forEach(row => {\n    const value = row.getValue(columnId)\n\n    if (\n      value != null &&\n      (min! > value || (min === undefined && value >= value))\n    ) {\n      min = value\n    }\n  })\n\n  return min\n}\n\nconst max: AggregationFn = (columnId, _leafRows, childRows) => {\n  let max: number | undefined\n\n  childRows.forEach(row => {\n    const value = row.getValue(columnId)\n    if (\n      value != null &&\n      (max! < value || (max === undefined && value >= value))\n    ) {\n      max = value\n    }\n  })\n\n  return max\n}\n\nconst extent: AggregationFn = (columnId, _leafRows, childRows) => {\n  let min: number | undefined\n  let max: number | undefined\n\n  childRows.forEach(row => {\n    const value = row.getValue(columnId)\n    if (value != null) {\n      if (min === undefined) {\n        if (value >= value) min = max = value\n      } else {\n        if (min > value) min = value\n        if (max! < value) max = value\n      }\n    }\n  })\n\n  return [min, max]\n}\n\nconst mean: AggregationFn = (columnId, leafRows) => {\n  let count = 0\n  let sum = 0\n\n  leafRows.forEach(row => {\n    let value = row.getValue(columnId)\n    if (value != null && (value = +value) >= value) {\n      ++count, (sum += value)\n    }\n  })\n\n  if (count) return sum / count\n\n  return\n}\n\nconst median: AggregationFn = (columnId, leafRows) => {\n  if (!leafRows.length) {\n    return\n  }\n\n  const values = leafRows.map(row => row.getValue(columnId))\n  if (!isNumberArray(values)) {\n    return\n  }\n  if (values.length === 1) {\n    return values[0]\n  }\n\n  const mid = Math.floor(values.length / 2)\n  const nums = values.sort((a, b) => a - b)\n  return values.length % 2 !== 0 ? nums[mid] : (nums[mid - 1]! + nums[mid]!) / 2\n}\n\nconst unique: AggregationFn = (columnId, leafRows) => {\n  return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values())\n}\n\nconst uniqueCount: AggregationFn = (columnId, leafRows) => {\n  return new Set(leafRows.map(d => d.getValue(columnId))).size\n}\n\nconst count: AggregationFn = (_columnId, leafRows) => {\n  return leafRows.length\n}\n\nexport const aggregationFns = {\n  sum,\n  min,\n  max,\n  extent,\n  mean,\n  median,\n  unique,\n  uniqueCount,\n  count,\n}\n\nexport type BuiltInAggregationFn = keyof typeof aggregationFns\n"],"names":["sum","columnId","_leafRows","childRows","reduce","next","nextValue","getValue","min","forEach","row","value","undefined","max","extent","mean","leafRows","count","median","length","values","map","isNumberArray","mid","Math","floor","nums","sort","a","b","unique","Array","from","Set","d","uniqueCount","size","_columnId","aggregationFns"],"mappings":";;;;;;;;;;;;;;;;AAGA,MAAMA,GAAuB,GAAGA,CAACC,QAAQ,EAAEC,SAAS,EAAEC,SAAS,KAAK;AAClE;AACA;EACA,OAAOA,SAAS,CAACC,MAAM,CAAC,CAACJ,GAAG,EAAEK,IAAI,KAAK;AACrC,IAAA,MAAMC,SAAS,GAAGD,IAAI,CAACE,QAAQ,CAACN,QAAQ,CAAC,CAAA;IACzC,OAAOD,GAAG,IAAI,OAAOM,SAAS,KAAK,QAAQ,GAAGA,SAAS,GAAG,CAAC,CAAC,CAAA;GAC7D,EAAE,CAAC,CAAC,CAAA;AACP,CAAC,CAAA;AAED,MAAME,GAAuB,GAAGA,CAACP,QAAQ,EAAEC,SAAS,EAAEC,SAAS,KAAK;AAClE,EAAA,IAAIK,GAAuB,CAAA;AAE3BL,EAAAA,SAAS,CAACM,OAAO,CAACC,GAAG,IAAI;AACvB,IAAA,MAAMC,KAAK,GAAGD,GAAG,CAACH,QAAQ,CAASN,QAAQ,CAAC,CAAA;A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