-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdji.js
More file actions
61 lines (54 loc) · 1.72 KB
/
Copy pathdji.js
File metadata and controls
61 lines (54 loc) · 1.72 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
var w = 960,
pw = 14,
z = ~~((w - pw * 2) / 53),
ph = z >> 1,
h = z * 7;
var vis = d3.select("#chart")
.selectAll("svg")
.data(d3.range(1990, 2011))
.enter().append("svg:svg")
.attr("width", w)
.attr("height", h + ph * 2)
.attr("class", "RdYlGn")
.append("svg:g")
.attr("transform", "translate(" + pw + "," + ph + ")");
vis.append("svg:text")
.attr("transform", "translate(-6," + h / 2 + ")rotate(-90)")
.attr("text-anchor", "middle")
.text(function(d) { return d; });
vis.selectAll("rect.day")
.data(calendar.dates)
.enter().append("svg:rect")
.attr("x", function(d) { return d.week * z; })
.attr("y", function(d) { return d.day * z; })
.attr("class", "day")
.attr("width", z)
.attr("height", z);
vis.selectAll("path.month")
.data(calendar.months)
.enter().append("svg:path")
.attr("class", "month")
.attr("d", function(d) {
return "M" + (d.firstWeek + 1) * z + "," + d.firstDay * z
+ "H" + d.firstWeek * z
+ "V" + 7 * z
+ "H" + d.lastWeek * z
+ "V" + (d.lastDay + 1) * z
+ "H" + (d.lastWeek + 1) * z
+ "V" + 0
+ "H" + (d.firstWeek + 1) * z
+ "Z";
});
d3.csv("dji.csv", function(csv) {
var data = d3.nest()
.key(function(d) { return d.Date; })
.rollup(function(d) { return (d[0].Close - d[0].Open) / d[0].Open; })
.map(csv);
var color = d3.scale.quantize()
.domain([-.05, .05])
.range(d3.range(9));
vis.selectAll("rect.day")
.attr("class", function(d) { return "day q" + color(data[d.Date]) + "-9"; })
.append("svg:title")
.text(function(d) { return d.Date + ": " + (data[d.Date] * 100).toFixed(1) + "%"; });
});