calculate center gravity in js.