var clock = function(d, attr) { var _d = d; var _rr = -Math.PI/2; var _running = 0; var _a = { interval: attr.interval || 1000, time: attr.time || new Date(), center: attr.center || [0,0], radius: attr.radius || 100, lineStroke: attr.lineStroke || "2px", lineColor: attr.lineColor || "#000", fillColor: attr.fillColor || "#fff" }; var topx = function(i) { return Math.round(i) + "px"; }; var drawperim = function(g, i) { var _cxy = _a.center; var _c = { x: topx(_cxy[0]), y: topx(_cxy[1]), r: topx(_a.radius), strokewidth: g.lineStroke || _a.lineStroke, strokecolor: g.lineColor || _a.lineColor, fillcolor: g.fillColor || _a.fillColor }; if(g.children.length < 1) { g.children.push(_d.circle(_d.drawing, _c)); } else { g.children[0].set(_c); } }; var drawhand = function(g, i) { var _cxy = _a.center; var _s = ((2*Math.PI)/g.teeth); // spread var _i = i; // hours var _rad = _a.radius * g.radius; var _l = { x1: topx(_cxy[0]), y1: topx(_cxy[1]), x2: topx(_rad * Math.cos(_i*_s+_rr) + _cxy[0]), y2: topx(_rad * Math.sin(_i*_s+_rr) + _cxy[1]), strokewidth: g.lineStroke || _a.lineStroke, strokecolor: g.lineColor || _a.lineColor, linecap: "round" }; if(g.children.length < 1) { g.children.push(_d.line(_d.drawing, _l)); } else { g.children[0].set(_l); } if (g.numbers && g.children.length == 1) { // because my girlfriend said it needed numbers for (var i=1; i<=g.teeth; i++) { var _nrad = _a.radius * g.numberradius; var xy = [ topx(_nrad * Math.cos(i*_s+_rr) + _cxy[0]), topx(_nrad * Math.sin(i*_s+_rr) + _cxy[1])]; // gotta add vector text object var n = document.createElement("span"); n.appendChild(document.createTextNode(i)); n.style.position = "absolute"; n.style.color = _a.lineColor; n.style.left = xy[0]; n.style.top = xy[1]; // _d.drawing.appendChild(n); g.children.push(n); } } // return g; }; // this.gearorder = ["hourhand", "minhand", "sechand", "numbers", "perimeter", "hub"]; var gears = []; gears.push({ name: "perimeter", radius: 1, teeth: 2, children: [], draw: drawperim, index: function() { return (_a.time.getHours() > 11) ? 1 : 0; } }); gears.push({ name: "hourhand", radius: 0.5, teeth: 12, children: [], draw: drawhand, numbers: true, numberradius: 0.95, index: function() { return _a.time.getHours(); } }); gears.push({ name: "minhand", radius: 0.8, teeth: 60, children: [], draw: drawhand, index: function() { return _a.time.getMinutes(); } }); gears.push({ name: "sechand", radius: 0.9, lineStroke: "1px", lineColor: "#f00", teeth: 60, children: [], draw: drawhand, index: function() { return _a.time.getSeconds(); } }); var _draw = function () { for ( var i=0; i