Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var method = tableColumnStyle.colorBinMethod.toLowerCase();
if (method === "auto") {
if (numericalValues.length > 1000) {
// The quantile method is simpler and less accurate, but faster for large datasets.
method = "quantile";
} else {
method = "ckmeans";
}
}
if (method === "quantile") {
// One issue is we don't check to see if any values actually lie within a given quantile, so it's bad for small datasets.
for (i = 0; i < binCount; i++) {
binColors.push({
upperBound: quantile(numericalValues, (i + 1) / binCount),
colorArray: getColorArrayFromColorGradient(
colorGradient,
i / (binCount - 1)
)
});
}
} else if (method === "ckmeans") {
var clusters = ckmeans(numericalValues, binCount);
// Convert the ckmeans format [ [5, 20], [65, 80] ] into our format.
for (i = 0; i < clusters.length; i++) {
if (
i > 0 &&
clusters[i].length === 1 &&
clusters[i][0] === clusters[i - 1][clusters[i - 1].length - 1]
) {
// When there are few unique values, we can end up with clusters like [1], [2],[2],[2],[3]. Let's avoid that.