Last active
April 12, 2017 14:37
-
-
Save alexnum/9088e6ecaafb0a50a73089573483b819 to your computer and use it in GitHub Desktop.
Cluster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment