# How to use the simple-statistics/src/ckmeans.default function in simple-statistics

## To help you get started, we’ve selected a few simple-statistics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

TerriaJS / terriajs / lib / Models / LegendHelper.js View on Github
``````}
}

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 &lt; 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 &lt; clusters.length; i++) {
if (
i &gt; 0 &amp;&amp;
clusters[i].length === 1 &amp;&amp;
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.
continue;
}
binColors.push({
upperBound: clusters[i][clusters[i].length - 1]
});
}
if (binColors.length &gt; 1) {
for (i = 0; i &lt; binColors.length; i++) {``````

## simple-statistics

Simple Statistics

ISC
Latest version published 1 year ago

67 / 100