<meta charset="utf-8">
<script src="../bower_components/d3/d3.min.js"></script>
<script src="../src/namespaces.js"></script>
+ <script src="../src/util/fib.js"></script>
<script src="../src/models/cycle.js"></script>
<script src="../src/models/blip.js"></script>
<script src="../src/models/quadrant.js"></script>
new tr.models.Blip('A', adopt),
new tr.models.Blip('B', trial),
new tr.models.Blip('C', assess),
- new tr.models.Blip('D', hold),
+ new tr.models.Blip('D', hold)
]);
radar.setFirstQuadrant(toolsQuadrant);
tr.graphing.Radar = function (svg, size, radar) {
- var self = {};
+ var self, fib;
+ self = {};
+ fib = new tr.util.Fib();
svg.attr('width', size).attr('height', size);
.attr('stroke-width', 14);
};
+ function getRadius(cycles, i) {
+ var sequence = fib.sequence(cycles.length);
+ var total = fib.sum(cycles.length);
+ var sum = fib.sum(i);
+
+ return center() - (center() * sum / total);
+ }
+
function plotCircles(cycles) {
var increment;
- increment = Math.round(center() / cycles.length);
-
cycles.forEach(function (cycle, i) {
svg.append('circle')
.attr('cx', center())
.attr('cy', center())
- .attr('r', center() - increment * i);
+ .attr('r', getRadius(cycles, i));
});
}
cycles.forEach(function (cycle, i) {
svg.append('text')
.attr('y', center() + 4)
- .attr('x', (i * increment) + 10)
+ .attr('x', center() - getRadius(cycles, i) + 10)
.text(cycle.name());
svg.append('text')
.attr('y', center() + 4)
- .attr('x', size - (i * increment) - 10)
+ .attr('x', center() + getRadius(cycles, i) - 10)
.attr('text-anchor', 'end')
.text(cycle.name());
});
var tr = tr || {};
tr.models = {};
tr.graphing = {};
+tr.util = {};
--- /dev/null
+tr.util.Fib = function () {
+ var self = {};
+
+ self.sequence = function (length) {
+ var result = [0, 1];
+
+ for (var i = 2; i < length; i++) {
+ result[i] = result[i-2] + result[i-1];
+ }
+
+ return result;
+ };
+
+ self.sum = function (length) {
+ if (length === 0) { return 0; }
+ if (length === 1) { return 1; }
+
+ return self.sequence(length + 1).reduce(function (previous, current) {
+ return previous + current;
+ }, 0);
+ };
+
+ return self;
+};
--- /dev/null
+describe('tr.util.Fib', function () {
+ it('returns the fibonacci sequence', function () {
+ var fib = new tr.util.Fib();
+
+ expect(fib.sequence(5)).toEqual([0, 1, 1, 2, 3]);
+ });
+
+ it('returns the sum of a sequence', function () {
+ var fib = new tr.util.Fib();
+
+ expect(fib.sum(5)).toEqual(12);
+ });
+});