moved number generation to the radar model
authorBruno Trecenti <btrecent@thoughtworks.com>
Thu, 27 Feb 2014 13:44:09 +0000 (10:44 -0300)
committerBruno Trecenti <btrecent@thoughtworks.com>
Thu, 27 Feb 2014 13:44:09 +0000 (10:44 -0300)
examples/default.html
src/graphing/radar.js
src/models/blip.js
src/models/radar.js
test/models/blip-spec.js
test/models/radar-spec.js

index 3a956a8..99a1b06 100644 (file)
         new tr.models.Blip('Enterprise Data Warehouse', hold, true)
     ]);
     languageFramework.add([
         new tr.models.Blip('Enterprise Data Warehouse', hold, true)
     ]);
     languageFramework.add([
-        new tr.models.Blip('Clojure', adopt),
+        new tr.models.Blip('Clojure', adopt, true),
         new tr.models.Blip('Dropwizard', adopt),
         new tr.models.Blip('Scala, the good parts', adopt),
         new tr.models.Blip('Sinatra', adopt),
         new tr.models.Blip('Dropwizard', adopt),
         new tr.models.Blip('Scala, the good parts', adopt),
         new tr.models.Blip('Sinatra', adopt),
index 0b3eb00..dd3abe0 100644 (file)
@@ -94,9 +94,8 @@ tr.graphing.Radar = function (size, radar) {
   }
 
   function plotBlips(cycles, quadrant, adjustX, adjustY) {
   }
 
   function plotBlips(cycles, quadrant, adjustX, adjustY) {
-    var blips, number;
+    var blips;
     blips = quadrant.blips();
     blips = quadrant.blips();
-    number = 0;
     cycles.forEach(function (cycle, i) {
       var maxRadius, minRadius, cycleBlips;
 
     cycles.forEach(function (cycle, i) {
       var maxRadius, minRadius, cycleBlips;
 
@@ -112,7 +111,7 @@ tr.graphing.Radar = function (size, radar) {
 
         var split = blip.name().split('');
         var sum = split.reduce(function (p, c) { return p + c.charCodeAt(0); }, 0);
 
         var split = blip.name().split('');
         var sum = split.reduce(function (p, c) { return p + c.charCodeAt(0); }, 0);
-        chance = new Chance(sum * cycle.name().length * number);
+        chance = new Chance(sum * cycle.name().length * blip.number());
 
         angleInRad = Math.PI * chance.integer({ min: 13, max: 85 }) / 180;
         radius = chance.floating({ min: minRadius + 25, max: maxRadius - 10 });
 
         angleInRad = Math.PI * chance.integer({ min: 13, max: 85 }) / 180;
         radius = chance.floating({ min: minRadius + 25, max: maxRadius - 10 });
@@ -131,7 +130,7 @@ tr.graphing.Radar = function (size, radar) {
           .attr('y', y + 4)
           .attr('class', 'blip-text')
           .attr('text-anchor', 'middle')
           .attr('y', y + 4)
           .attr('class', 'blip-text')
           .attr('text-anchor', 'middle')
-          .text(++number)
+          .text(blip.number())
       });
     });
   };
       });
     });
   };
index 0495a09..42257c5 100644 (file)
@@ -1,5 +1,8 @@
 tr.models.Blip = function (name, cycle, isNew) {
 tr.models.Blip = function (name, cycle, isNew) {
-  var self = {};
+  var self, number;
+
+  self = {};
+  number = -1;
 
   self.name = function () {
     return name;
 
   self.name = function () {
     return name;
@@ -13,5 +16,13 @@ tr.models.Blip = function (name, cycle, isNew) {
     return cycle;
   };
 
     return cycle;
   };
 
+  self.number = function () {
+    return number;
+  };
+
+  self.setNumber = function (newNumber) {
+    number = newNumber;
+  };
+
   return self;
 };
   return self;
 };
index 71af014..0b7f111 100644 (file)
@@ -1,23 +1,34 @@
 tr.models.Radar = function() {
 tr.models.Radar = function() {
-  var self, quadrants;
+  var self, quadrants, blipNumber;
 
 
+  blipNumber = 0;
   quadrants = { I: null, II: null, III: null, IV: null };
   self = {};
 
   quadrants = { I: null, II: null, III: null, IV: null };
   self = {};
 
+  function setNumbers(blips) {
+    blips.forEach(function (blip) {
+      blip.setNumber(++blipNumber);
+    });
+  }
+
   self.setFirstQuadrant = function (quadrant) {
     quadrants.I = quadrant;
   self.setFirstQuadrant = function (quadrant) {
     quadrants.I = quadrant;
+    setNumbers(quadrants.I.blips());
   };
 
   self.setSecondQuadrant = function (quadrant) {
     quadrants.II = quadrant;
   };
 
   self.setSecondQuadrant = function (quadrant) {
     quadrants.II = quadrant;
+    setNumbers(quadrants.II.blips());
   };
 
   self.setThirdQuadrant = function (quadrant) {
     quadrants.III = quadrant;
   };
 
   self.setThirdQuadrant = function (quadrant) {
     quadrants.III = quadrant;
+    setNumbers(quadrants.III.blips());
   };
 
   self.setFourthQuadrant = function (quadrant) {
     quadrants.IV = quadrant;
   };
 
   self.setFourthQuadrant = function (quadrant) {
     quadrants.IV = quadrant;
+    setNumbers(quadrants.IV.blips());
   };
 
   function allQuadrants() {
   };
 
   function allQuadrants() {
index 005e508..9318c20 100644 (file)
@@ -1,21 +1,31 @@
 describe('tr.models.Blip', function () {
 describe('tr.models.Blip', function () {
-  it('has a name', function () {
-    var blip = new tr.models.Blip('My Blip');
+  var blip;
+  beforeEach(function () {
+    blip = new tr.models.Blip(
+      'My Blip',
+      new tr.models.Cycle('My Cycle')
+    );
+  });
 
 
+  it('has a name', function () {
     expect(blip.name()).toEqual('My Blip');
   });
 
   it('has a cycle', function () {
     expect(blip.name()).toEqual('My Blip');
   });
 
   it('has a cycle', function () {
-    var blip = new tr.models.Blip(
-      'My Blip',
-      new tr.models.Cycle('My Cycle')
-    );
-
     expect(blip.cycle().name()).toEqual('My Cycle');
   });
 
     expect(blip.cycle().name()).toEqual('My Cycle');
   });
 
+  it('has a default number', function () {
+    expect(blip.number()).toEqual(-1);
+  });
+
+  it('sets the number', function () {
+    blip.setNumber(1);
+    expect(blip.number()).toEqual(1);
+  });
+
   it('is new', function () {
   it('is new', function () {
-    var blip = new tr.models.Blip(
+    blip = new tr.models.Blip(
       'My Blip',
       new tr.models.Cycle('My Cycle'),
       true
       'My Blip',
       new tr.models.Cycle('My Cycle'),
       true
@@ -25,7 +35,7 @@ describe('tr.models.Blip', function () {
   });
 
   it('is not new', function () {
   });
 
   it('is not new', function () {
-    var blip = new tr.models.Blip(
+    blip = new tr.models.Blip(
       'My Blip',
       new tr.models.Cycle('My Cycle'),
       false
       'My Blip',
       new tr.models.Cycle('My Cycle'),
       false
index 09043d6..2c4d883 100644 (file)
@@ -53,6 +53,40 @@ describe('tr.models.Radar', function () {
     expect(radar.quadrants().IV).toEqual(quadrant);
   });
 
     expect(radar.quadrants().IV).toEqual(quadrant);
   });
 
+  describe('blip numbers', function () {
+    var firstQuadrant, secondQuadrant, radar, firstCycle;
+
+    beforeEach(function () {
+      firstCycle = new tr.models.Cycle('Adopt', 0);
+      firstQuadrant = new tr.models.Quadrant('First');
+      secondQuadrant = new tr.models.Quadrant('Second');
+      firstQuadrant.add([
+        new tr.models.Blip('A', firstCycle),
+        new tr.models.Blip('B', firstCycle)
+      ]);
+      secondQuadrant.add([
+        new tr.models.Blip('C', firstCycle),
+        new tr.models.Blip('D', firstCycle)
+      ]);
+      radar = new tr.models.Radar();
+    });
+
+    it('sets blip numbers starting on the first quadrant', function () {
+      radar.setFirstQuadrant(firstQuadrant);
+
+      expect(radar.quadrants().I.blips()[0].number()).toEqual(1);
+      expect(radar.quadrants().I.blips()[1].number()).toEqual(2);
+    });
+
+    it('continues the number from the previous quadrant set', function () {
+      radar.setFirstQuadrant(firstQuadrant);
+      radar.setSecondQuadrant(secondQuadrant);
+
+      expect(radar.quadrants().II.blips()[0].number()).toEqual(3);
+      expect(radar.quadrants().II.blips()[1].number()).toEqual(4);
+    });
+  });
+
   describe('cycles', function () {
     var quadrant, radar, firstCycle, secondCycle;
 
   describe('cycles', function () {
     var quadrant, radar, firstCycle, secondCycle;