forked from MaslowCNC/GroundControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalibrationValuesGraph.html
More file actions
98 lines (81 loc) · 2.75 KB
/
calibrationValuesGraph.html
File metadata and controls
98 lines (81 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!--
D3 calibration graph. Run the following to start a simple python web server in this directory:
python -m SimpleHTTPServer 8888
Now you can open the graph of calibrationValues.csv at
http://localhost:8888/calibrationValuesGraph.html
-->
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.line {
fill: none;
stroke-width: 1.5px;
}
</style>
<svg width="960" height="500"></svg>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script>
var svg = d3.select("svg"),
margin = {top: 20, right: 80, bottom: 30, left: 50},
width = svg.attr("width") - margin.left - margin.right,
height = svg.attr("height") - margin.top - margin.bottom,
g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var x = d3.scaleLinear().range([0, width]),
y = d3.scaleLinear().range([height, 0]),
z = d3.scaleSequential(d3.interpolateBrBG);
var line = d3.line()
.curve(d3.curveBasis)
.x(function(d) { return x(d.index); })
.y(function(d) { return y(d.value); });
d3.text("calibrationValues.csv").then(function(text) {
var data = d3.csvParseRows(text).slice(0, 15).map(function(row) {
return row.slice(0,31).map(function(d, i) {
return {
index: i-15,
value: +d
};
});
});
x.domain([-15, 15]);
y.domain([
d3.min(data, function(c) { return d3.min(c, function(d) { return d.value; }); }),
d3.max(data, function(c) { return d3.max(c, function(d) { return d.value; }); })
]);
z.domain(data.map(function(c, i) { return i; }));
g.append("g")
.attr("class", "axis axis--x")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
.append("text")
.attr("x", 37)
.attr("y", -3)
.attr("fill", "#000")
.text("Column index");
g.append("g")
.attr("class", "axis axis--y")
.call(d3.axisLeft(y))
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", "0.71em")
.attr("fill", "#000")
.text("Error (mm)");
var graphLine = g.selectAll(".graph-line")
.data(data)
.enter().append("g")
.attr("class", "graph-line");
graphLine.append("path")
.attr("class", "line")
.attr("d", function(d) { return line(d); })
.style("stroke", function(d, i) { return z(i/14); });
graphLine.append("text")
.attr("class", "line-label")
.datum(function(d, i) { return {id: i - 7, value: d[d.length - 1].value}; })
.attr("transform", function(d) { return "translate(" + (850 - ((d.id + 7) % 3) * 10) + "," + y(d.value) + ")"; })
.attr("x", 3)
.attr("dy", "0.35em")
.style("font", "10px sans-serif")
.style("stroke", function(d, i) { return z(i/14); })
.text(function(d) { return d.id; });
});
</script>