X-Git-Url: https://pwan.org/git/?p=tech-radar.git;a=blobdiff_plain;f=src%2Fgraphing%2Fradar.js;h=b6386c6c2af92bdc5969c2afec6aa8170c39b600;hp=ee8a14b2b106af3880c43231961ec420b7ae2255;hb=98727f4b22defac583218fbbde96b914638482e8;hpb=a38bbd158706ac00e91a29fa96b3f783e8cb555f diff --git a/src/graphing/radar.js b/src/graphing/radar.js index ee8a14b..b6386c6 100644 --- a/src/graphing/radar.js +++ b/src/graphing/radar.js @@ -3,42 +3,64 @@ tr.graphing.Radar = function (svg, size, radar) { svg.attr('width', size).attr('height', size); - function plotLines() { - var center = Math.round(size / 2); + function center () { + return Math.round(size/2); + } + function plotLines() { svg.append('line') - .attr('x1', center) + .attr('x1', center()) .attr('y1', 0) - .attr('x2', center) + .attr('x2', center()) .attr('y2', size) - .attr('stroke-width', 5); + .attr('stroke-width', 14); svg.append('line') .attr('x1', 0) - .attr('y1', center) + .attr('y1', center()) .attr('x2', size) - .attr('y2', center) - .attr('stroke-width', 5); + .attr('y2', center()) + .attr('stroke-width', 14); }; - function plotCircles() { - var center, cycles, increment; + function plotCircles(cycles) { + var increment; - center = Math.round(size / 2); - cycles = radar.cycles(); - increment = Math.round(center / cycles.length); + increment = Math.round(center() / cycles.length); cycles.forEach(function (cycle, i) { svg.append('circle') - .attr('cx', center) - .attr('cy', center) - .attr('r', (i + 1) * increment); + .attr('cx', center()) + .attr('cy', center()) + .attr('r', center() - increment * i); }); } + function plotTexts(cycles) { + var increment; + + increment = Math.round(center() / cycles.length); + + cycles.forEach(function (cycle, i) { + svg.append('text') + .attr('y', center() + 4) + .attr('x', (i * increment) + 10) + .text(cycle.name()); + + svg.append('text') + .attr('y', center() + 4) + .attr('x', size - (i * increment) - 10) + .attr('text-anchor', 'end') + .text(cycle.name()); + }); + }; + self.plot = function () { + var cycles = radar.cycles().reverse(); + + plotCircles(cycles); plotLines(); - plotCircles(); + plotTexts(cycles); }; return self;