An example of Multidimensional Scaling (almost completely taken from this article by Ben Frederickson).
A matrix of distances between cities is fed into a simple javascript function (again, by Ben Frederickson) that uses numeric.js to compute the cities' position. Rotation and mirroring (manually adjusted in this example) are free.
Click on a city to see an indication of the distance errors.
Modified http://d3js.org/d3.v3.min.js to a secure url
https://d3js.org/d3.v3.min.js