1 describe('tr.graphing.Radar', function () {
5 return d3
.select("body").append("svg");
8 beforeEach(function () {
9 radar
= new tr
.models
.Radar();
10 spyOn(radar
, 'cycles').andReturn([]);
13 it('sets the size', function () {
16 spyOn(svg
, 'attr').andReturn(svg
);
18 radarGraph
= new tr
.graphing
.Radar(svg
, 500, radar
);
20 expect(svg
.attr
).toHaveBeenCalledWith('width', 500);
21 expect(svg
.attr
).toHaveBeenCalledWith('height', 500);
24 describe('lines', function () {
25 it('plots a vertical line in the center', function () {
29 spyOn(svg
, 'append').andReturn(svg
);
30 spyOn(svg
, 'attr').andReturn(svg
);
32 radarGraph
= new tr
.graphing
.Radar(svg
, 500, radar
);
36 expect(svg
.append
).toHaveBeenCalledWith('line');
37 expect(svg
.attr
).toHaveBeenCalledWith('x1', 500 / 2);
38 expect(svg
.attr
).toHaveBeenCalledWith('y1', 0);
39 expect(svg
.attr
).toHaveBeenCalledWith('x2', 500 / 2);
40 expect(svg
.attr
).toHaveBeenCalledWith('y2', 500);
41 expect(svg
.attr
).toHaveBeenCalledWith('stroke-width', 14);
44 it('plots a horizontal line in the center', function () {
48 spyOn(svg
, 'append').andReturn(svg
);
49 spyOn(svg
, 'attr').andReturn(svg
);
51 radarGraph
= new tr
.graphing
.Radar(svg
, 500, radar
);
55 expect(svg
.append
).toHaveBeenCalledWith('line');
56 expect(svg
.attr
).toHaveBeenCalledWith('x1', 0);
57 expect(svg
.attr
).toHaveBeenCalledWith('y1', 500 / 2);
58 expect(svg
.attr
).toHaveBeenCalledWith('x2', 500);
59 expect(svg
.attr
).toHaveBeenCalledWith('y2', 500 / 2);
60 expect(svg
.attr
).toHaveBeenCalledWith('stroke-width', 14);
64 describe('circles', function () {
67 beforeEach(function () {
71 spyOn(svg
, 'append').andReturn(svg
);
72 spyOn(svg
, 'attr').andReturn(svg
);
74 radar
= new tr
.models
.Radar();
75 spyOn(radar
, 'cycles').andReturn([
76 new tr
.models
.Cycle('Adopt'),
77 new tr
.models
.Cycle('Hold')
79 radarGraph
= new tr
.graphing
.Radar(svg
, 500, radar
);
82 it('plots the circles for the cycles', function () {
85 expect(svg
.append
).toHaveBeenCalledWith('circle');
86 expect(svg
.attr
).toHaveBeenCalledWith('cx', 500 / 2);
87 expect(svg
.attr
).toHaveBeenCalledWith('cy', 500 / 2);
88 expect(svg
.attr
).toHaveBeenCalledWith('r', Math
.round(250 / 2));
90 expect(svg
.append
).toHaveBeenCalledWith('circle');
91 expect(svg
.attr
).toHaveBeenCalledWith('cx', 500 / 2);
92 expect(svg
.attr
).toHaveBeenCalledWith('cy', 500 / 2);
93 expect(svg
.attr
).toHaveBeenCalledWith('r', 250);
96 it('adds the name of each cycle for the right side', function () {
98 spyOn(svg
, 'text').andReturn(svg
);
101 expect(svg
.append
).toHaveBeenCalledWith('text');
102 expect(svg
.attr
).toHaveBeenCalledWith('y', center
+ 4);
103 expect(svg
.attr
).toHaveBeenCalledWith('x', 0 + 10);
104 expect(svg
.text
).toHaveBeenCalledWith('Adopt');
106 expect(svg
.append
).toHaveBeenCalledWith('text');
107 expect(svg
.attr
).toHaveBeenCalledWith('y', center
+ 4);
108 expect(svg
.attr
).toHaveBeenCalledWith('x', 0 + (center
/ 2) + 10);
109 expect(svg
.text
).toHaveBeenCalledWith('Hold');
112 it('adds the name of each cycle for the right side', function () {
113 var center
= 500 / 2;
114 spyOn(svg
, 'text').andReturn(svg
);
117 expect(svg
.append
).toHaveBeenCalledWith('text');
118 expect(svg
.attr
).toHaveBeenCalledWith('y', center
+ 4);
119 expect(svg
.attr
).toHaveBeenCalledWith('x', 500 - 10);
120 expect(svg
.attr
).toHaveBeenCalledWith('text-anchor', 'end');
121 expect(svg
.text
).toHaveBeenCalledWith('Adopt');
123 expect(svg
.append
).toHaveBeenCalledWith('text');
124 expect(svg
.attr
).toHaveBeenCalledWith('y', center
+ 4);
125 expect(svg
.attr
).toHaveBeenCalledWith('x', 500 - (center
/ 2) - 10);
126 expect(svg
.attr
).toHaveBeenCalledWith('text-anchor', 'end');
127 expect(svg
.text
).toHaveBeenCalledWith('Hold');