Published
Edited
Jun 27, 2020
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
graphData = []
Insert cell
graphData
Insert cell
accuracy = {
var error = 275;
var accuracy = 0;
var distanceAvg = 0;
for (var i = 0; i < graphData.length; i++) {
var smallest = 9999;
for (var j = 0; j < check.length; j++) {
var distance = Math.sqrt(Math.pow((check[j][0]-graphData[i][0]),2) + Math.pow((check[j][1]-graphData[i][1]),2));
if (smallest > distance) smallest = distance;
}
distanceAvg += smallest;
}
distanceAvg /= graphData.length
if (distanceAvg < error && distanceAvg > error * .8) accuracy = 0.2;
if (distanceAvg < error * .8 && distanceAvg > error * .6) accuracy = 0.4;
if (distanceAvg < error * .6 && distanceAvg > error * .4) accuracy = 0.6;
if (distanceAvg < error * .4 && distanceAvg > error * .2) accuracy = 0.8;
if (distanceAvg < error * .2 && distanceAvg > 0) accuracy = 1;
return accuracy
}
Insert cell
pathCoordinates = [[0,10], [20, 50], [20, 50], [40, 50], [50, 70], [60,80], [90,100]]
Insert cell
Insert cell
Insert cell
Insert cell
l = draw.getTotalLength();
Insert cell
Insert cell
check = d3.range(l+1).map((d,i)=> [draw.getPointAtLength(d).x,draw.getPointAtLength(d).y])
Insert cell
Insert cell
x = d3.scaleLinear()
.domain(d3.extent(pathCoordinates,(d,i)=>d[0]))
.range ([margin.left, width - margin.right])
Insert cell
y = d3.scaleLinear()
.domain(d3.extent(pathCoordinates,(d,i)=>d[1]))
.range ([ height - margin.bottom, margin.top ])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more