summaryrefslogtreecommitdiffstats
path: root/public
diff options
context:
space:
mode:
authorJan Tuomi <jan-sebastian.tuomi@aalto.fi>2016-08-14 13:16:10 +0300
committerJan Tuomi <jan-sebastian.tuomi@aalto.fi>2016-08-14 13:16:10 +0300
commitd3d9b6861dc5c6871ad138ab9f428bcdb1d61398 (patch)
tree7c49f8911a7a25c477ebe3f6ac9ad268179d41d5 /public
parent17a154cb51a729e043ce555e68ef9ebbe40f14b5 (diff)
Add placeholder view and visuals, add express and d3
Diffstat (limited to 'public')
-rw-r--r--public/graph.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/public/graph.js b/public/graph.js
new file mode 100644
index 0000000..11ed599
--- /dev/null
+++ b/public/graph.js
@@ -0,0 +1,53 @@
+var n = 40,
+ random = d3.randomNormal(0, .2),
+ data = d3.range(n).map(random);
+var svg = d3.select("svg"),
+ margin = {top: 20, right: 20, bottom: 20, left: 40},
+ 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()
+ .domain([0, n - 1])
+ .range([0, width]);
+var y = d3.scaleLinear()
+ .domain([-1, 1])
+ .range([height, 0]);
+var line = d3.line()
+ .x(function(d, i) { return x(i); })
+ .y(function(d, i) { return y(d); });
+g.append("defs").append("clipPath")
+ .attr("id", "clip")
+ .append("rect")
+ .attr("width", width)
+ .attr("height", height);
+g.append("g")
+ .attr("class", "axis axis--x")
+ .attr("transform", "translate(0," + y(0) + ")")
+ .call(d3.axisBottom(x));
+g.append("g")
+ .attr("class", "axis axis--y")
+ .call(d3.axisLeft(y));
+g.append("g")
+ .attr("clip-path", "url(#clip)")
+ .append("path")
+ .datum(data)
+ .attr("class", "line")
+ .transition()
+ .duration(500)
+ .ease(d3.easeLinear)
+ .on("start", tick);
+function tick() {
+ // Push a new data point onto the back.
+ data.push(random());
+ // Redraw the line.
+ d3.select(this)
+ .attr("d", line)
+ .attr("transform", null);
+ // Slide it to the left.
+ d3.active(this)
+ .attr("transform", "translate(" + x(-1) + ",0)")
+ .transition()
+ .on("start", tick);
+ // Pop the old data point off the front.
+ data.shift();
+}