Skip to content

Instantly share code, notes, and snippets.

@alexnum
Last active April 12, 2017 14:37
Show Gist options
  • Save alexnum/9088e6ecaafb0a50a73089573483b819 to your computer and use it in GitHub Desktop.
Save alexnum/9088e6ecaafb0a50a73089573483b819 to your computer and use it in GitHub Desktop.
Cluster
var positions = [];
$('.stone.t5').each(function() {
if(parseFloat($(this).css('left').replace('px','')) != 0 ) positions.push([
parseFloat($(this).css('left').replace('px','')),
parseFloat($(this).css('top').replace('px',''))
]);
});
copy(JSON.stringify(positions))
//NODE
const kmeans = require('node-kmeans');
kmeans.clusterize(points, {k: 30}, (err,res) => {
if (err) console.error(err);
clusters = res;
});
//Copy Clusters to console
$('.stone').hide();
for(var i = 0; i < clusters.length; i++){
var pt = clusters[i];
var newElem = $('<div class="marker t3 stone" style="left: '+pt.centroid[0]+'; top: '+pt.centroid[1]+';" data-markertype="stone" data-markertier="3">'+pt.cluster.length+'</div>');
$("#markers").append(newElem);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment