tr.graphing.Radar = function (size, radar) {
var self, fib, svg;
- svg = d3.select("body").append("svg");
fib = new tr.util.Fib();
self = {};
- self.svg = svg;
+ self.svg = function () {
+ return svg;
+ }
function center () {
return Math.round(size/2);
plotName(quadrants.IV.name(), 'end', size -10, size - 10)
}
+ self.init = function (selector) {
+ svg = d3.select(selector || 'body').append("svg");
+ return self;
+ };
+
self.plot = function () {
var cycles, quadrants;
spyOn(radar, 'cycles').andReturn([]);
});
+ describe('init', function () {
+ it('appends the svg', function () {
+ var radarGraph, selection;
+
+ radarGraph = new tr.graphing.Radar(500, radar);
+ selection = { append: jasmine.createSpy() };
+ spyOn(d3, 'select').andReturn(selection);
+
+ radarGraph.init();
+
+ expect(selection.append).toHaveBeenCalledWith('svg');
+ });
+
+ it('selects body if no selector provided', function () {
+ var radarGraph;
+
+ radarGraph = new tr.graphing.Radar(500, radar);
+ spyOn(d3, 'select').andCallThrough();
+
+ radarGraph.init();
+
+ expect(d3.select).toHaveBeenCalledWith('body');
+ });
+
+ it('selects the selector if provided', function () {
+ var radarGraph;
+
+ radarGraph = new tr.graphing.Radar(500, radar);
+ spyOn(d3, 'select').andCallThrough();
+
+ radarGraph.init('#radar');
+
+ expect(d3.select).toHaveBeenCalledWith('#radar');
+ });
+ });
+
it('sets the size', function () {
var svg, radarGraph;
radarGraph = new tr.graphing.Radar(500, radar);
- svg = radarGraph.svg;
+ radarGraph.init();
+
+ svg = radarGraph.svg();
spyOn(svg, 'attr').andReturn(svg);
radarGraph.plot();
var radarGraph, svg;
radarGraph = new tr.graphing.Radar(500, radar);
+ radarGraph.init();
- svg = radarGraph.svg;
+ svg = radarGraph.svg();
spyOn(svg, 'append').andReturn(svg);
spyOn(svg, 'attr').andReturn(svg);
var svg, radarGraph;
radarGraph = new tr.graphing.Radar(500, radar);
- svg = radarGraph.svg;
+ radarGraph.init();
+
+ svg = radarGraph.svg();
spyOn(svg, 'append').andReturn(svg);
spyOn(svg, 'attr').andReturn(svg);
new tr.models.Cycle('Hold')
]);
radarGraph = new tr.graphing.Radar(500, radar);
- svg = radarGraph.svg;
+ radarGraph.init();
+
+ svg = radarGraph.svg();
spyOn(svg, 'append').andReturn(svg);
spyOn(svg, 'attr').andReturn(svg);
});