+ function triangle(x, y, cssClass) {
+ var tsize, top, left, right, bottom, points;
+
+ tsize = 13
+ top = y - tsize;
+ left = (x - tsize + 1);
+ right = (x + tsize + 1);
+ bottom = (y + tsize - tsize / 2.5);
+
+ points = x + 1 + ',' + top + ' ' + left + ',' + bottom + ' ' + right + ',' + bottom;
+
+ return svg.append('polygon')
+ .attr('points', points)
+ .attr('class', cssClass)
+ .attr('stroke-width', 1.5);
+ }
+
+ function circle(x, y, cssClass) {
+ svg.append('circle')
+ .attr('cx', x)
+ .attr('cy', y)
+ .attr('class', cssClass)
+ .attr('stroke-width', 1.5)
+ .attr('r', 10);
+ }
+
+ function plotBlips(cycles, quadrant, adjustX, adjustY, cssClass) {
+ var blips;
+ blips = quadrant.blips();
+ cycles.forEach(function (cycle, i) {
+ var maxRadius, minRadius, cycleBlips;
+
+ maxRadius = getRadius(cycles, i);
+ minRadius = (i == cycles.length - 1) ? 0: getRadius(cycles, i + 1);
+
+ var cycleBlips = blips.filter(function (blip) {
+ return blip.cycle() == cycle;
+ });
+
+ cycleBlips.forEach(function (blip) {
+ var angleInRad, radius;
+
+ var split = blip.name().split('');
+ var sum = split.reduce(function (p, c) { return p + c.charCodeAt(0); }, 0);
+ chance = new Chance(sum * cycle.name().length * blip.number());
+
+ angleInRad = Math.PI * chance.integer({ min: 13, max: 85 }) / 180;
+ radius = chance.floating({ min: minRadius + 25, max: maxRadius - 10 });
+
+ var x = center() + radius * Math.cos(angleInRad) * adjustX;
+ var y = center() + radius * Math.sin(angleInRad) * adjustY;
+
+ if (blip.isNew()) {
+ triangle(x, y, cssClass);
+ } else {
+ circle(x, y, cssClass);
+ }
+
+ svg.append('text')
+ .attr('x', x)
+ .attr('y', y + 4)
+ .attr('class', 'blip-text')
+ .attr('text-anchor', 'middle')
+ .text(blip.number())
+ });
+ });
+ };
+
+ function plotQuadrantNames(quadrants) {
+ function plotName(name, anchor, x, y, cssClass) {
+ svg.append('text')
+ .attr('x', x)
+ .attr('y', y)
+ .attr('class', cssClass)
+ .attr('text-anchor', anchor)
+ .text(name);
+ }
+
+ plotName(quadrants.I.name(), 'end', size - 10, 10, 'first')
+ plotName(quadrants.II.name(), 'start', 10, 10, 'second')
+ plotName(quadrants.III.name(), 'start', 10, size - 10, 'third')
+ plotName(quadrants.IV.name(), 'end', size -10, size - 10, 'fourth')
+ }
+
+ self.init = function (selector) {
+ svg = d3.select(selector || 'body').append("svg");
+ return self;
+ };
+