source: Dev/trunk/d3/examples/calendar/vix.js @ 76

Last change on this file since 76 was 76, checked in by fpvanagthoven, 14 years ago

d3

File size: 1.6 KB
RevLine 
[76]1var w = 960,
2    pw = 14,
3    z = ~~((w - pw * 2) / 53),
4    ph = z >> 1,
5    h = z * 7;
6
7var vis = d3.select("#chart")
8  .selectAll("svg")
9    .data(d3.range(1993, 2011))
10  .enter().append("svg:svg")
11    .attr("width", w)
12    .attr("height", h + ph * 2)
13    .attr("class", "RdYlGn")
14  .append("svg:g")
15    .attr("transform", "translate(" + pw + "," + ph + ")");
16
17vis.append("svg:text")
18    .attr("transform", "translate(-6," + h / 2 + ")rotate(-90)")
19    .text(function(d) { return d; });
20
21vis.selectAll("rect.day")
22    .data(calendar.dates)
23  .enter().append("svg:rect")
24    .attr("x", function(d) { return d.week * z; })
25    .attr("y", function(d) { return d.day * z; })
26    .attr("class", "day")
27    .attr("width", z)
28    .attr("height", z);
29
30vis.selectAll("path.month")
31    .data(calendar.months)
32  .enter().append("svg:path")
33    .attr("class", "month")
34    .attr("d", function(d) {
35      return "M" + (d.firstWeek + 1) * z + "," + d.firstDay * z
36          + "H" + d.firstWeek * z
37          + "V" + 7 * z
38          + "H" + d.lastWeek * z
39          + "V" + (d.lastDay + 1) * z
40          + "H" + (d.lastWeek + 1) * z
41          + "V" + 0
42          + "H" + (d.firstWeek + 1) * z
43          + "Z";
44    });
45
46d3.csv("vix.csv", function(csv) {
47  var data = d3.nest()
48      .key(function(d) { return d.Date; })
49      .rollup(function(d) { return d[0].Open; })
50      .map(csv);
51
52  var color = d3.scale.quantile()
53      .domain(d3.values(data))
54      .range(d3.range(9).reverse());
55
56  vis.selectAll("rect.day")
57      .attr("class", function(d) { return "day q" + color(data[d.Date]) + "-9"; })
58    .append("svg:title")
59      .text(function(d) { return d.Date + ": " + data[d.Date]; });
60});
Note: See TracBrowser for help on using the repository browser.