1
// Based on http://vis.stanford.edu/protovis/ex/clock.html
2
// Based on http://blog.pixelbreaker.com/polarclock
6
radius = Math.min(width, height) / 1.8,
8
fsec = d3.time.format("%S s"),
9
fmin = d3.time.format("%M m"),
10
fhou = d3.time.format("%H h"),
11
fwee = d3.time.format("%a"),
12
fdat = d3.time.format("%d d"),
13
fmon = d3.time.format("%b");
15
var fill = d3.scale.linear()
16
.range(["hsl(-180, 50%, 50%)", "hsl(180, 50%, 50%)"])
17
.interpolate(d3.interpolateHsl);
19
var arc = d3.svg.arc()
21
.endAngle(function(d) { return d.value * 2 * Math.PI; })
22
.innerRadius(function(d) { return d.index * radius; })
23
.outerRadius(function(d) { return (d.index + sectorWidth) * radius; });
25
var vis = d3.select("#clock").append("svg")
27
.attr("height", height)
29
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
31
var g = vis.selectAll("g")
36
.style("fill", function(d) { return fill(d.value); })
40
.attr("text-anchor", "middle")
42
.text(function(d) { return d.text; });
47
var g = vis.selectAll("g")
51
.style("fill", function(d) { return fill(d.value); })
55
.attr("dy", function(d) { return d.value < .5 ? "-.5em" : "1em"; })
56
.attr("transform", function(d) {
57
return "rotate(" + 360 * d.value + ")"
58
+ "translate(0," + -(d.index + sectorWidth / 2) * radius + ")"
59
+ "rotate(" + (d.value < .5 ? -90 : 90) + ")"
61
.text(function(d) { return d.text; });
64
// Generate the fields for the current date/time.
69
return 32 - new Date(d.getYear(), d.getMonth(), 32).getDate();
72
var second = (d.getSeconds() + d.getMilliseconds() / 1000) / 60,
73
minute = (d.getMinutes() + second) / 60,
74
hour = (d.getHours() + minute) / 24,
75
weekday = (d.getDay() + hour) / 7,
76
date = (d.getDate() - 1 + hour) / days(),
77
month = (d.getMonth() + date) / 12;
80
{value: second, index: .7, text: fsec(d)},
81
{value: minute, index: .6, text: fmin(d)},
82
{value: hour, index: .5, text: fhou(d)},
83
{value: weekday, index: .3, text: fwee(d)},
84
{value: date, index: .2, text: fdat(d)},
85
{value: month, index: .1, text: fmon(d)},