From d2ec62108a5a5d9980f27a52466e5db7b83e4f6e Mon Sep 17 00:00:00 2001 From: Bruno Trecenti Date: Tue, 25 Feb 2014 10:47:04 -0300 Subject: [PATCH] added radar graphing and vertical line --- examples/default.html | 34 ++++++++++++++++++++++++++++++++++ src/graphing/radar.js | 21 +++++++++++++++++++++ test/graphing/radar-spec.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 examples/default.html create mode 100644 src/graphing/radar.js create mode 100644 test/graphing/radar-spec.js diff --git a/examples/default.html b/examples/default.html new file mode 100644 index 0000000..abe29ca --- /dev/null +++ b/examples/default.html @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + diff --git a/src/graphing/radar.js b/src/graphing/radar.js new file mode 100644 index 0000000..2f472f9 --- /dev/null +++ b/src/graphing/radar.js @@ -0,0 +1,21 @@ +tr.graphing.Radar = function (svg, size, radar) { + var self = {}; + + svg.attr('width', size).attr('height', size); + + function plotLines() { + svg.append('line') + .attr('x1', size / 2) + .attr('y1', 0) + .attr('x2', size / 2) + .attr('y2', size) + .attr('stroke-width', 5); + }; + + self.plot = function () { + plotLines(); + + }; + + return self; +}; diff --git a/test/graphing/radar-spec.js b/test/graphing/radar-spec.js new file mode 100644 index 0000000..f5747c6 --- /dev/null +++ b/test/graphing/radar-spec.js @@ -0,0 +1,34 @@ +describe('tr.graphing.Radar', function () { + function buildSvg() { + return d3.select("body").append("svg"); + } + + it('sets the size', function () { + var svg = buildSvg(); + spyOn(svg, 'attr').andReturn(svg); + + var radarGraph = new tr.graphing.Radar(svg, 500); + + 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 = buildSvg(); + spyOn(svg, 'append').andReturn(svg); + spyOn(svg, 'attr').andReturn(svg); + + var radarGraph = new tr.graphing.Radar(svg, 500); + + radarGraph.plot(); + + expect(svg.append).toHaveBeenCalledWith('line'); + expect(svg.attr).toHaveBeenCalledWith('x1', 500 / 2); + expect(svg.attr).toHaveBeenCalledWith('y1', 0); + expect(svg.attr).toHaveBeenCalledWith('x2', 500 / 2); + expect(svg.attr).toHaveBeenCalledWith('y2', 500); + expect(svg.attr).toHaveBeenCalledWith('stroke-width', 5); + }); + }) +}); -- 2.39.2