Comparing version 1.0.0-alpha.14.0 to 1.0.0-alpha.15.0
@@ -39,3 +39,2 @@ define(['exports', 'simple-statistics', 'nerdamer/nerdamer.core.js', 'nerdamer/Algebra.js', 'nerdamer/Calculus.js', 'nerdamer/Solve.js'], (function (exports, ss, nerdamer, Algebra_js, Calculus_js, Solve_js) { 'use strict'; | ||
const GEOMETRIC_INTERVAL = "geometricInterval"; | ||
const LOGARITHMIC_INTERVAL = "logarithmicInterval"; | ||
const UNCLASSED = "unclassed"; | ||
@@ -496,35 +495,2 @@ const UNIQUE = "unique"; | ||
/** | ||
* Logarithmic Interval | ||
* Intervals grow exponentially, based on a logarithmic scale, to accommodate a wide range of data values and emphasize relative differences at both small and large scales. | ||
* @returns { binCount: number, binBreaks: number[], binSizes: object, dataRange: number[], dataBinAssignments: object } | ||
*/ | ||
logarithmicInterval() { | ||
let context = this; | ||
let binBreaks = []; | ||
let binBreak = context.min; | ||
// Calculate the logarithmic interval size | ||
context.max; | ||
context.min; | ||
const logIntervalSize = (Math.log10(context.max) - Math.log10(context.min)) / context.binCount; | ||
for (let i = 0; i < context.binCount; i++) { | ||
if (i != 0) | ||
binBreaks.push(binBreak); | ||
binBreak *= Math.pow(10, logIntervalSize); | ||
} | ||
// Compute Bin Sizes | ||
let binSizes = context.computeBinSizes(binBreaks); | ||
// Compute Data-> Bin Assignments | ||
let dataBinAssignments = context.computeDataBinAssignments(binBreaks); | ||
// Return final Bin Object | ||
return { | ||
"rawData": context.rawData, | ||
"data": context.data, | ||
"dataRange": [context.min, context.max], | ||
"binCount": binBreaks.length + 1, | ||
"binBreaks": context.roundToPrecision(binBreaks, context.precision), | ||
"binSizes": binSizes, | ||
"dataBinAssignments": dataBinAssignments | ||
}; | ||
} | ||
/** | ||
* Exponential Bin Size | ||
@@ -786,83 +752,68 @@ * Intervals are selected so that the number of observations in each successive interval increases (or decreases) exponentially | ||
*/ | ||
resiliency(binningMethods = []) { | ||
resiliency(binningMethods = [], binningMethodObjs = {}) { | ||
let context = this; | ||
let binBreaks = []; | ||
// Data structure to store the binObj corresponding to each binningMethod. | ||
let binObjs = {}; | ||
binningMethods.forEach(function (binningMethod) { | ||
let binObj = {}; | ||
switch (binningMethod) { | ||
case EQUAL_INTERVAL: | ||
binObj = context.equalInterval(); | ||
binObjs[EQUAL_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case PERCENTILE: | ||
binObj = context.percentile(); | ||
binObjs[PERCENTILE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case QUANTILE: | ||
binObj = context.quantile(); | ||
binObjs[QUANTILE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case STANDARD_DEVIATION: | ||
binObj = context.standardDeviation(); | ||
binObjs[STANDARD_DEVIATION] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case MANUAL_INTERVAL: | ||
binObj = context.manualInterval(); | ||
binObjs[MANUAL_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case PRETTY_BREAKS: | ||
binObj = context.prettyBreaks(); | ||
binObjs[PRETTY_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case MAXIMUM_BREAKS: | ||
binObj = context.maximumBreaks(); | ||
binObjs[MAXIMUM_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case HEAD_TAIL_BREAKS: | ||
binObj = context.headTailBreaks(); | ||
binObjs[HEAD_TAIL_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case CK_MEANS: | ||
binObj = context.ckMeans(); | ||
binObjs[CK_MEANS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case BOXPLOT: | ||
binObj = context.boxPlot(); | ||
binObjs[BOXPLOT] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case DEFINED_INTERVAL: | ||
binObj = context.definedInterval(); | ||
binObjs[DEFINED_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case EXPONENTIAL_BIN_SIZE: | ||
binObj = context.exponentialBinSizes(); | ||
binObjs[EXPONENTIAL_BIN_SIZE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case LOGARITHMIC_INTERVAL: | ||
binObj = context.logarithmicInterval(); | ||
binObjs[LOGARITHMIC_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case GEOMETRIC_INTERVAL: | ||
binObj = context.geometricInterval(); | ||
binObjs[GEOMETRIC_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case FISHER_JENKS: | ||
binObj = context.fisherJenks(); | ||
binObjs[FISHER_JENKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
default: | ||
binObj = { | ||
"rawData": context.rawData, | ||
"data": context.data, | ||
"dataRange": [context.min, context.max], | ||
"binCount": null, | ||
"binBreaks": [], | ||
"binSizes": { "valids": null, "invalids": null }, | ||
"dataBinAssignments": {} | ||
}; | ||
binObjs["default"] = JSON.parse(JSON.stringify(binObj)); | ||
} | ||
}); | ||
if (binningMethods.length > 0) { | ||
binningMethods.forEach(function (binningMethod) { | ||
let binObj = {}; | ||
switch (binningMethod) { | ||
case EQUAL_INTERVAL: | ||
binObj = context.equalInterval(); | ||
binningMethodObjs[EQUAL_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case PERCENTILE: | ||
binObj = context.percentile(); | ||
binningMethodObjs[PERCENTILE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case QUANTILE: | ||
binObj = context.quantile(); | ||
binningMethodObjs[QUANTILE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case STANDARD_DEVIATION: | ||
binObj = context.standardDeviation(); | ||
binningMethodObjs[STANDARD_DEVIATION] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case MANUAL_INTERVAL: | ||
binObj = context.manualInterval(); | ||
binningMethodObjs[MANUAL_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case PRETTY_BREAKS: | ||
binObj = context.prettyBreaks(); | ||
binningMethodObjs[PRETTY_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case MAXIMUM_BREAKS: | ||
binObj = context.maximumBreaks(); | ||
binningMethodObjs[MAXIMUM_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case HEAD_TAIL_BREAKS: | ||
binObj = context.headTailBreaks(); | ||
binningMethodObjs[HEAD_TAIL_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case CK_MEANS: | ||
binObj = context.ckMeans(); | ||
binningMethodObjs[CK_MEANS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case BOXPLOT: | ||
binObj = context.boxPlot(); | ||
binningMethodObjs[BOXPLOT] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case DEFINED_INTERVAL: | ||
binObj = context.definedInterval(); | ||
binningMethodObjs[DEFINED_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case EXPONENTIAL_BIN_SIZE: | ||
binObj = context.exponentialBinSizes(); | ||
binningMethodObjs[EXPONENTIAL_BIN_SIZE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case GEOMETRIC_INTERVAL: | ||
binObj = context.geometricInterval(); | ||
binningMethodObjs[GEOMETRIC_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case FISHER_JENKS: | ||
binObj = context.fisherJenks(); | ||
binningMethodObjs[FISHER_JENKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
} | ||
}); | ||
} | ||
let frequencyOfMostFrequentBins = {}; | ||
@@ -874,3 +825,3 @@ let mostFrequentBins = {}; | ||
if (context.isValid(val)) { | ||
let binAssignmentsForPrimaryKey = Array.from(Object.values(binObjs)).map((binObj) => binObj["dataBinAssignments"][primaryKey]); | ||
let binAssignmentsForPrimaryKey = Array.from(Object.values(binningMethodObjs)).map((binObj) => binObj["dataBinAssignments"][primaryKey]); | ||
if (!(primaryKey in frequencyOfMostFrequentBins)) { | ||
@@ -894,3 +845,3 @@ frequencyOfMostFrequentBins[primaryKey] = 0; | ||
binningMethods.forEach(function (binningMethod) { | ||
obj["binCandidates"].push(JSON.parse(JSON.stringify(binObjs[binningMethod]["dataBinAssignments"][primaryKey]))); | ||
obj["binCandidates"].push(JSON.parse(JSON.stringify(binningMethodObjs[binningMethod]["dataBinAssignments"][primaryKey]))); | ||
}); | ||
@@ -957,3 +908,3 @@ resiliencyData.push(obj); | ||
"dataBinAssignments": dataBinAssignments, | ||
"binObjs": binObjs, | ||
"binObjs": binningMethodObjs, | ||
"mostFrequentBins": mostFrequentBins, | ||
@@ -1046,4 +997,6 @@ "frequencyOfMostFrequentBins": frequencyOfMostFrequentBins | ||
let binBreaks = binningMethodName == UNCLASSED ? binguruRes["dataRange"] : binguruRes["binBreaks"]; | ||
let [binMin, binMax] = [Math.min(...[dataMin, binguruRes["binBreaks"][0]]), Math.max(...[dataMax, binguruRes["binBreaks"][binguruRes["binBreaks"].length - 1]])]; | ||
[binMin, binMax] = [parseFloat((binMin * 0.9).toFixed(context.precision)), parseFloat((binMax * 1.1).toFixed(context.precision))]; | ||
let [binMin, binMax] = [Math.min(...[dataMin, binBreaks[0]]), Math.max(...[dataMax, binBreaks[binBreaks.length - 1]])]; | ||
if (binningMethodName != UNCLASSED) { | ||
[binMin, binMax] = [parseFloat((binMin * 0.9).toFixed(context.precision)), parseFloat((binMax * 1.1).toFixed(context.precision))]; | ||
} | ||
let data = []; | ||
@@ -1281,3 +1234,2 @@ let dataTicks = []; | ||
exports.HEAD_TAIL_BREAKS = HEAD_TAIL_BREAKS; | ||
exports.LOGARITHMIC_INTERVAL = LOGARITHMIC_INTERVAL; | ||
exports.MANUAL_INTERVAL = MANUAL_INTERVAL; | ||
@@ -1284,0 +1236,0 @@ exports.MAXIMUM_BREAKS = MAXIMUM_BREAKS; |
@@ -43,3 +43,2 @@ (function (global, factory) { | ||
const GEOMETRIC_INTERVAL = "geometricInterval"; | ||
const LOGARITHMIC_INTERVAL = "logarithmicInterval"; | ||
const UNCLASSED = "unclassed"; | ||
@@ -500,35 +499,2 @@ const UNIQUE = "unique"; | ||
/** | ||
* Logarithmic Interval | ||
* Intervals grow exponentially, based on a logarithmic scale, to accommodate a wide range of data values and emphasize relative differences at both small and large scales. | ||
* @returns { binCount: number, binBreaks: number[], binSizes: object, dataRange: number[], dataBinAssignments: object } | ||
*/ | ||
logarithmicInterval() { | ||
let context = this; | ||
let binBreaks = []; | ||
let binBreak = context.min; | ||
// Calculate the logarithmic interval size | ||
context.max; | ||
context.min; | ||
const logIntervalSize = (Math.log10(context.max) - Math.log10(context.min)) / context.binCount; | ||
for (let i = 0; i < context.binCount; i++) { | ||
if (i != 0) | ||
binBreaks.push(binBreak); | ||
binBreak *= Math.pow(10, logIntervalSize); | ||
} | ||
// Compute Bin Sizes | ||
let binSizes = context.computeBinSizes(binBreaks); | ||
// Compute Data-> Bin Assignments | ||
let dataBinAssignments = context.computeDataBinAssignments(binBreaks); | ||
// Return final Bin Object | ||
return { | ||
"rawData": context.rawData, | ||
"data": context.data, | ||
"dataRange": [context.min, context.max], | ||
"binCount": binBreaks.length + 1, | ||
"binBreaks": context.roundToPrecision(binBreaks, context.precision), | ||
"binSizes": binSizes, | ||
"dataBinAssignments": dataBinAssignments | ||
}; | ||
} | ||
/** | ||
* Exponential Bin Size | ||
@@ -790,83 +756,68 @@ * Intervals are selected so that the number of observations in each successive interval increases (or decreases) exponentially | ||
*/ | ||
resiliency(binningMethods = []) { | ||
resiliency(binningMethods = [], binningMethodObjs = {}) { | ||
let context = this; | ||
let binBreaks = []; | ||
// Data structure to store the binObj corresponding to each binningMethod. | ||
let binObjs = {}; | ||
binningMethods.forEach(function (binningMethod) { | ||
let binObj = {}; | ||
switch (binningMethod) { | ||
case EQUAL_INTERVAL: | ||
binObj = context.equalInterval(); | ||
binObjs[EQUAL_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case PERCENTILE: | ||
binObj = context.percentile(); | ||
binObjs[PERCENTILE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case QUANTILE: | ||
binObj = context.quantile(); | ||
binObjs[QUANTILE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case STANDARD_DEVIATION: | ||
binObj = context.standardDeviation(); | ||
binObjs[STANDARD_DEVIATION] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case MANUAL_INTERVAL: | ||
binObj = context.manualInterval(); | ||
binObjs[MANUAL_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case PRETTY_BREAKS: | ||
binObj = context.prettyBreaks(); | ||
binObjs[PRETTY_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case MAXIMUM_BREAKS: | ||
binObj = context.maximumBreaks(); | ||
binObjs[MAXIMUM_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case HEAD_TAIL_BREAKS: | ||
binObj = context.headTailBreaks(); | ||
binObjs[HEAD_TAIL_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case CK_MEANS: | ||
binObj = context.ckMeans(); | ||
binObjs[CK_MEANS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case BOXPLOT: | ||
binObj = context.boxPlot(); | ||
binObjs[BOXPLOT] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case DEFINED_INTERVAL: | ||
binObj = context.definedInterval(); | ||
binObjs[DEFINED_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case EXPONENTIAL_BIN_SIZE: | ||
binObj = context.exponentialBinSizes(); | ||
binObjs[EXPONENTIAL_BIN_SIZE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case LOGARITHMIC_INTERVAL: | ||
binObj = context.logarithmicInterval(); | ||
binObjs[LOGARITHMIC_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case GEOMETRIC_INTERVAL: | ||
binObj = context.geometricInterval(); | ||
binObjs[GEOMETRIC_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case FISHER_JENKS: | ||
binObj = context.fisherJenks(); | ||
binObjs[FISHER_JENKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
default: | ||
binObj = { | ||
"rawData": context.rawData, | ||
"data": context.data, | ||
"dataRange": [context.min, context.max], | ||
"binCount": null, | ||
"binBreaks": [], | ||
"binSizes": { "valids": null, "invalids": null }, | ||
"dataBinAssignments": {} | ||
}; | ||
binObjs["default"] = JSON.parse(JSON.stringify(binObj)); | ||
} | ||
}); | ||
if (binningMethods.length > 0) { | ||
binningMethods.forEach(function (binningMethod) { | ||
let binObj = {}; | ||
switch (binningMethod) { | ||
case EQUAL_INTERVAL: | ||
binObj = context.equalInterval(); | ||
binningMethodObjs[EQUAL_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case PERCENTILE: | ||
binObj = context.percentile(); | ||
binningMethodObjs[PERCENTILE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case QUANTILE: | ||
binObj = context.quantile(); | ||
binningMethodObjs[QUANTILE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case STANDARD_DEVIATION: | ||
binObj = context.standardDeviation(); | ||
binningMethodObjs[STANDARD_DEVIATION] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case MANUAL_INTERVAL: | ||
binObj = context.manualInterval(); | ||
binningMethodObjs[MANUAL_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case PRETTY_BREAKS: | ||
binObj = context.prettyBreaks(); | ||
binningMethodObjs[PRETTY_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case MAXIMUM_BREAKS: | ||
binObj = context.maximumBreaks(); | ||
binningMethodObjs[MAXIMUM_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case HEAD_TAIL_BREAKS: | ||
binObj = context.headTailBreaks(); | ||
binningMethodObjs[HEAD_TAIL_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case CK_MEANS: | ||
binObj = context.ckMeans(); | ||
binningMethodObjs[CK_MEANS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case BOXPLOT: | ||
binObj = context.boxPlot(); | ||
binningMethodObjs[BOXPLOT] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case DEFINED_INTERVAL: | ||
binObj = context.definedInterval(); | ||
binningMethodObjs[DEFINED_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case EXPONENTIAL_BIN_SIZE: | ||
binObj = context.exponentialBinSizes(); | ||
binningMethodObjs[EXPONENTIAL_BIN_SIZE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case GEOMETRIC_INTERVAL: | ||
binObj = context.geometricInterval(); | ||
binningMethodObjs[GEOMETRIC_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case FISHER_JENKS: | ||
binObj = context.fisherJenks(); | ||
binningMethodObjs[FISHER_JENKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
} | ||
}); | ||
} | ||
let frequencyOfMostFrequentBins = {}; | ||
@@ -878,3 +829,3 @@ let mostFrequentBins = {}; | ||
if (context.isValid(val)) { | ||
let binAssignmentsForPrimaryKey = Array.from(Object.values(binObjs)).map((binObj) => binObj["dataBinAssignments"][primaryKey]); | ||
let binAssignmentsForPrimaryKey = Array.from(Object.values(binningMethodObjs)).map((binObj) => binObj["dataBinAssignments"][primaryKey]); | ||
if (!(primaryKey in frequencyOfMostFrequentBins)) { | ||
@@ -898,3 +849,3 @@ frequencyOfMostFrequentBins[primaryKey] = 0; | ||
binningMethods.forEach(function (binningMethod) { | ||
obj["binCandidates"].push(JSON.parse(JSON.stringify(binObjs[binningMethod]["dataBinAssignments"][primaryKey]))); | ||
obj["binCandidates"].push(JSON.parse(JSON.stringify(binningMethodObjs[binningMethod]["dataBinAssignments"][primaryKey]))); | ||
}); | ||
@@ -961,3 +912,3 @@ resiliencyData.push(obj); | ||
"dataBinAssignments": dataBinAssignments, | ||
"binObjs": binObjs, | ||
"binObjs": binningMethodObjs, | ||
"mostFrequentBins": mostFrequentBins, | ||
@@ -1050,4 +1001,6 @@ "frequencyOfMostFrequentBins": frequencyOfMostFrequentBins | ||
let binBreaks = binningMethodName == UNCLASSED ? binguruRes["dataRange"] : binguruRes["binBreaks"]; | ||
let [binMin, binMax] = [Math.min(...[dataMin, binguruRes["binBreaks"][0]]), Math.max(...[dataMax, binguruRes["binBreaks"][binguruRes["binBreaks"].length - 1]])]; | ||
[binMin, binMax] = [parseFloat((binMin * 0.9).toFixed(context.precision)), parseFloat((binMax * 1.1).toFixed(context.precision))]; | ||
let [binMin, binMax] = [Math.min(...[dataMin, binBreaks[0]]), Math.max(...[dataMax, binBreaks[binBreaks.length - 1]])]; | ||
if (binningMethodName != UNCLASSED) { | ||
[binMin, binMax] = [parseFloat((binMin * 0.9).toFixed(context.precision)), parseFloat((binMax * 1.1).toFixed(context.precision))]; | ||
} | ||
let data = []; | ||
@@ -1285,3 +1238,2 @@ let dataTicks = []; | ||
exports.HEAD_TAIL_BREAKS = HEAD_TAIL_BREAKS; | ||
exports.LOGARITHMIC_INTERVAL = LOGARITHMIC_INTERVAL; | ||
exports.MANUAL_INTERVAL = MANUAL_INTERVAL; | ||
@@ -1288,0 +1240,0 @@ exports.MAXIMUM_BREAKS = MAXIMUM_BREAKS; |
{ | ||
"name": "binguru", | ||
"version": "1.0.0-alpha.14.0", | ||
"version": "1.0.0-alpha.15.0", | ||
"description": "BinGuru is a Javascript package with an API to several established data binning / data classification methods, often used for visualizing data on choropleth maps. It also includes an implementation of a new, consensus binning method, 'Resiliency'.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.mjs", |
233
src/index.ts
@@ -27,3 +27,2 @@ /*********************************************************** | ||
export const GEOMETRIC_INTERVAL = "geometricInterval"; | ||
export const LOGARITHMIC_INTERVAL = "logarithmicInterval"; | ||
export const UNCLASSED = "unclassed"; | ||
@@ -585,46 +584,2 @@ export const UNIQUE = "unique"; | ||
/** | ||
* Logarithmic Interval | ||
* Intervals grow exponentially, based on a logarithmic scale, to accommodate a wide range of data values and emphasize relative differences at both small and large scales. | ||
* @returns { binCount: number, binBreaks: number[], binSizes: object, dataRange: number[], dataBinAssignments: object } | ||
*/ | ||
logarithmicInterval() { | ||
let context = this; | ||
let binBreaks: number[] = []; | ||
let binBreak: number = context.min; | ||
// Calculate the logarithmic interval size | ||
let max = context.max; | ||
let min = context.min; | ||
const epsilon = 1e-10; | ||
if(max == 0){ | ||
max = epsilon; | ||
} | ||
if(min == 0){ | ||
min = epsilon; | ||
} | ||
const logIntervalSize = (Math.log10(context.max) - Math.log10(context.min)) / context.binCount; | ||
for (let i = 0; i < context.binCount; i++) { | ||
if (i != 0) binBreaks.push(binBreak); | ||
binBreak *= Math.pow(10, logIntervalSize); | ||
} | ||
// Compute Bin Sizes | ||
let binSizes = context.computeBinSizes(binBreaks); | ||
// Compute Data-> Bin Assignments | ||
let dataBinAssignments = context.computeDataBinAssignments(binBreaks); | ||
// Return final Bin Object | ||
return { | ||
"rawData": context.rawData, | ||
"data": context.data, | ||
"dataRange": [context.min, context.max], | ||
"binCount": binBreaks.length + 1, | ||
"binBreaks": context.roundToPrecision(binBreaks, context.precision), | ||
"binSizes": binSizes, | ||
"dataBinAssignments": dataBinAssignments | ||
} | ||
} | ||
/** | ||
* Exponential Bin Size | ||
@@ -941,101 +896,86 @@ * Intervals are selected so that the number of observations in each successive interval increases (or decreases) exponentially | ||
*/ | ||
resiliency(binningMethods = []) { | ||
resiliency(binningMethods: string[] = [], binningMethodObjs:any = {}) { | ||
let context = this; | ||
let binBreaks: number[] = []; | ||
// Data structure to store the binObj corresponding to each binningMethod. | ||
let binObjs: any = {}; | ||
if(binningMethods.length > 0){ | ||
binningMethods.forEach(function (binningMethod) { | ||
let binObj: any = {}; | ||
switch (binningMethod) { | ||
case EQUAL_INTERVAL: | ||
binObj = context.equalInterval(); | ||
binningMethodObjs[EQUAL_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case PERCENTILE: | ||
binObj = context.percentile(); | ||
binningMethodObjs[PERCENTILE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case QUANTILE: | ||
binObj = context.quantile(); | ||
binningMethodObjs[QUANTILE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case STANDARD_DEVIATION: | ||
binObj = context.standardDeviation(); | ||
binningMethodObjs[STANDARD_DEVIATION] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case MANUAL_INTERVAL: | ||
binObj = context.manualInterval(); | ||
binningMethodObjs[MANUAL_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case PRETTY_BREAKS: | ||
binObj = context.prettyBreaks(); | ||
binningMethodObjs[PRETTY_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case MAXIMUM_BREAKS: | ||
binObj = context.maximumBreaks(); | ||
binningMethodObjs[MAXIMUM_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case HEAD_TAIL_BREAKS: | ||
binObj = context.headTailBreaks(); | ||
binningMethodObjs[HEAD_TAIL_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case CK_MEANS: | ||
binObj = context.ckMeans(); | ||
binningMethodObjs[CK_MEANS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case BOXPLOT: | ||
binObj = context.boxPlot(); | ||
binningMethodObjs[BOXPLOT] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case DEFINED_INTERVAL: | ||
binObj = context.definedInterval(); | ||
binningMethodObjs[DEFINED_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case EXPONENTIAL_BIN_SIZE: | ||
binObj = context.exponentialBinSizes(); | ||
binningMethodObjs[EXPONENTIAL_BIN_SIZE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case GEOMETRIC_INTERVAL: | ||
binObj = context.geometricInterval(); | ||
binningMethodObjs[GEOMETRIC_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case FISHER_JENKS: | ||
binObj = context.fisherJenks(); | ||
binningMethodObjs[FISHER_JENKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
default: | ||
; | ||
} | ||
}); | ||
} | ||
binningMethods.forEach(function (binningMethod) { | ||
let binObj: any = {}; | ||
switch (binningMethod) { | ||
case EQUAL_INTERVAL: | ||
binObj = context.equalInterval(); | ||
binObjs[EQUAL_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case PERCENTILE: | ||
binObj = context.percentile(); | ||
binObjs[PERCENTILE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case QUANTILE: | ||
binObj = context.quantile(); | ||
binObjs[QUANTILE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case STANDARD_DEVIATION: | ||
binObj = context.standardDeviation(); | ||
binObjs[STANDARD_DEVIATION] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case MANUAL_INTERVAL: | ||
binObj = context.manualInterval(); | ||
binObjs[MANUAL_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case PRETTY_BREAKS: | ||
binObj = context.prettyBreaks(); | ||
binObjs[PRETTY_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case MAXIMUM_BREAKS: | ||
binObj = context.maximumBreaks(); | ||
binObjs[MAXIMUM_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case HEAD_TAIL_BREAKS: | ||
binObj = context.headTailBreaks(); | ||
binObjs[HEAD_TAIL_BREAKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case CK_MEANS: | ||
binObj = context.ckMeans(); | ||
binObjs[CK_MEANS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case BOXPLOT: | ||
binObj = context.boxPlot(); | ||
binObjs[BOXPLOT] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case DEFINED_INTERVAL: | ||
binObj = context.definedInterval(); | ||
binObjs[DEFINED_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case EXPONENTIAL_BIN_SIZE: | ||
binObj = context.exponentialBinSizes(); | ||
binObjs[EXPONENTIAL_BIN_SIZE] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case LOGARITHMIC_INTERVAL: | ||
binObj = context.logarithmicInterval(); | ||
binObjs[LOGARITHMIC_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case GEOMETRIC_INTERVAL: | ||
binObj = context.geometricInterval(); | ||
binObjs[GEOMETRIC_INTERVAL] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
case FISHER_JENKS: | ||
binObj = context.fisherJenks(); | ||
binObjs[FISHER_JENKS] = JSON.parse(JSON.stringify(binObj)); | ||
break; | ||
default: | ||
binObj = { | ||
"rawData": context.rawData, | ||
"data": context.data, | ||
"dataRange": [context.min, context.max], | ||
"binCount": null, | ||
"binBreaks": [], | ||
"binSizes": { "valids": null, "invalids": null }, | ||
"dataBinAssignments": {} | ||
}; | ||
binObjs["default"] = JSON.parse(JSON.stringify(binObj)); | ||
} | ||
}); | ||
let frequencyOfMostFrequentBins: any = {}; | ||
@@ -1048,3 +988,3 @@ let mostFrequentBins: any = {}; | ||
if (context.isValid(val)) { | ||
let binAssignmentsForPrimaryKey = Array.from(Object.values(binObjs)).map((binObj: any) => binObj["dataBinAssignments"][primaryKey]); | ||
let binAssignmentsForPrimaryKey = Array.from(Object.values(binningMethodObjs)).map((binObj: any) => binObj["dataBinAssignments"][primaryKey]); | ||
if (!(primaryKey in frequencyOfMostFrequentBins)) { | ||
@@ -1071,3 +1011,3 @@ frequencyOfMostFrequentBins[primaryKey] = 0; | ||
binningMethods.forEach(function (binningMethod) { | ||
obj["binCandidates"].push(JSON.parse(JSON.stringify(binObjs[binningMethod]["dataBinAssignments"][primaryKey]))); | ||
obj["binCandidates"].push(JSON.parse(JSON.stringify(binningMethodObjs[binningMethod]["dataBinAssignments"][primaryKey]))); | ||
}); | ||
@@ -1149,3 +1089,3 @@ resiliencyData.push(obj); | ||
"dataBinAssignments": dataBinAssignments, | ||
"binObjs": binObjs, | ||
"binObjs": binningMethodObjs, | ||
"mostFrequentBins": mostFrequentBins, | ||
@@ -1254,5 +1194,8 @@ "frequencyOfMostFrequentBins": frequencyOfMostFrequentBins | ||
let binBreaks = binningMethodName == UNCLASSED ? binguruRes["dataRange"] : binguruRes["binBreaks"]; | ||
let [binMin, binMax] = [Math.min(...[dataMin, binguruRes["binBreaks"][0]]), Math.max(...[dataMax, binguruRes["binBreaks"][binguruRes["binBreaks"].length - 1]])]; | ||
[binMin, binMax] = [parseFloat((binMin * 0.9).toFixed(context.precision)), parseFloat((binMax * 1.1).toFixed(context.precision))]; | ||
let [binMin, binMax] = [Math.min(...[dataMin, binBreaks[0]]), Math.max(...[dataMax, binBreaks[binBreaks.length - 1]])]; | ||
if(binningMethodName != UNCLASSED){ | ||
[binMin, binMax] = [parseFloat((binMin * 0.9).toFixed(context.precision)), parseFloat((binMax * 1.1).toFixed(context.precision))]; | ||
} | ||
let data: object[] = []; | ||
@@ -1259,0 +1202,0 @@ let dataTicks: number[] = []; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
289387
6170