-tr.graphing.Radar = function (svg, size, radar) {
- var self, fib;
- self = {};
+tr.graphing.Radar = function (size, radar) {
+ var self, fib, svg;
+
+ svg = d3.select("body").append("svg");
fib = new tr.util.Fib();
- svg.attr('width', size).attr('height', size);
+ self = {};
+ self.svg = svg;
function center () {
return Math.round(size/2);
self.plot = function () {
var cycles, quadrants;
+
cycles = radar.cycles().reverse();
quadrants = radar.quadrants();
+ svg.attr('width', size).attr('height', size);
+
plotCircles(cycles);
plotLines();
plotTexts(cycles);
describe('tr.graphing.Radar', function () {
var radar;
- function buildSvg() {
- return d3.select("body").append("svg");
- }
-
beforeEach(function () {
radar = new tr.models.Radar();
spyOn(radar, 'cycles').andReturn([]);
it('sets the size', function () {
var svg, radarGraph;
- svg = buildSvg();
+
+ radarGraph = new tr.graphing.Radar(500, radar);
+ svg = radarGraph.svg;
spyOn(svg, 'attr').andReturn(svg);
- radarGraph = new tr.graphing.Radar(svg, 500, radar);
+ radarGraph.plot();
expect(svg.attr).toHaveBeenCalledWith('width', 500);
expect(svg.attr).toHaveBeenCalledWith('height', 500);
describe('lines', function () {
it('plots a vertical line in the center', function () {
- var svg, radarGraph;
+ var radarGraph, svg;
- svg = buildSvg();
+ radarGraph = new tr.graphing.Radar(500, radar);
+
+ svg = radarGraph.svg;
spyOn(svg, 'append').andReturn(svg);
spyOn(svg, 'attr').andReturn(svg);
- radarGraph = new tr.graphing.Radar(svg, 500, radar);
-
radarGraph.plot();
expect(svg.append).toHaveBeenCalledWith('line');
it('plots a horizontal line in the center', function () {
var svg, radarGraph;
- svg = buildSvg();
+ radarGraph = new tr.graphing.Radar(500, radar);
+ svg = radarGraph.svg;
spyOn(svg, 'append').andReturn(svg);
spyOn(svg, 'attr').andReturn(svg);
- radarGraph = new tr.graphing.Radar(svg, 500, radar);
-
radarGraph.plot();
expect(svg.append).toHaveBeenCalledWith('line');
beforeEach(function () {
var radar;
- svg = buildSvg();
- spyOn(svg, 'append').andReturn(svg);
- spyOn(svg, 'attr').andReturn(svg);
-
radar = new tr.models.Radar();
spyOn(radar, 'cycles').andReturn([
new tr.models.Cycle('Adopt'),
new tr.models.Cycle('Hold')
]);
- radarGraph = new tr.graphing.Radar(svg, 500, radar);
+ radarGraph = new tr.graphing.Radar(500, radar);
+ svg = radarGraph.svg;
+ spyOn(svg, 'append').andReturn(svg);
+ spyOn(svg, 'attr').andReturn(svg);
});
it('plots the circles for the cycles', function () {