Is there an easy way to calculate the centroid of the svg path element?
currently, I am using this approximation:
function getCentroid(el){
var pah = el.attr("path");
var cnt = 0;
var ans={x:0,y:0};
for(var i=0;i<path.length;i++){
if(path[i][0]=='M' || path[i][0]=='L'){
ans.x+=path[i][1];
ans.y+=path[i][2];
cnt++;
}
}
ans.x/=cnt;
ans.y/=cnt;
return ans;
}