(function() { var HEIGHT, SAMPLES, THETA_SLIDER_Y, WIDTH, a, brushed, handle, redraw, slider, spiral, svg, theta_max_brush, theta_max_scale; WIDTH = 960; HEIGHT = 500; svg = d3.select('body').append('svg').attr({ width: WIDTH, height: HEIGHT }).append('g').attr({ transform: "translate(" + (WIDTH / 2) + ",80)" }); a = 0; SAMPLES = 80; svg.append('line').attr({ "class": 'my_axis', x1: -WIDTH, x2: WIDTH }); svg.append('line').attr({ "class": 'my_axis', y1: -HEIGHT, y2: HEIGHT }); spiral = svg.append('path').attr({ "class": 'spiral' }); theta_max_scale = d3.scale.linear().domain([0, 360 * 12]).range([-WIDTH / 2 + 50, WIDTH / 2 - 50]).clamp(true); theta_max_brush = d3.svg.brush().x(theta_max_scale).extent([0, 0]); THETA_SLIDER_Y = -50; svg.append('g').attr('class', 'x axis').attr('transform', "translate(0," + THETA_SLIDER_Y + ")").call(d3.svg.axis().scale(theta_max_scale).orient('bottom').tickFormat(function(d) { return d + '°'; }).tickSize(0).tickPadding(12)).select('.domain').select(function() { return this.parentNode.appendChild(this.cloneNode(true)); }).attr('class', 'halo'); slider = svg.append('g').attr('class', 'slider').call(theta_max_brush); slider.selectAll('.extent,.resize').remove(); slider.select('.background').attr('transform', "translate(0," + (THETA_SLIDER_Y - 11) + ")").attr('height', 22); handle = slider.append('circle').attr('class', 'handle').attr('transform', "translate(0," + THETA_SLIDER_Y + ")").attr('r', 9); slider.call(theta_max_brush.event).transition().duration(750).call(theta_max_brush.extent([2 * 360, 2 * 360])).call(theta_max_brush.event); brushed = function() { var value; value = theta_max_brush.extent()[0]; if (d3.event.sourceEvent) { value = theta_max_scale.invert(d3.mouse(this)[0]); theta_max_brush.extent([value, value]); } handle.attr('cx', theta_max_scale(value)); return redraw(2 * Math.PI * value / 360, 16); }; theta_max_brush.on('brush', brushed); redraw = function(theta_max, dist) { var b, line_generator, number_of_points, points, radius; b = dist / (2 * Math.PI); radius = a + b * theta_max; number_of_points = Math.ceil(theta_max / (2 * Math.PI) * SAMPLES); points = d3.range(0, number_of_points).map(function(i) { var theta; theta = i * 2 * Math.PI / SAMPLES; return { theta: theta - Math.PI / 2 - theta_max, r: a + b * theta }; }); points.push({ theta: -Math.PI / 2, r: radius }); line_generator = d3.svg.line().x(function(d) { return d.r * Math.cos(d.theta); }).y(function(d) { return radius + d.r * Math.sin(d.theta); }).interpolate('cardinal'); return spiral.datum(points).attr({ d: line_generator }); }; }).call(this);