Permalink
Browse files

Refactor.

  • Loading branch information...
1 parent d855f7a commit 96f22b2e4cab6b7f14b0af7863eab8281f027be2 @benbjohnson committed Dec 16, 2013
Showing with 8,599 additions and 464 deletions.
  1. +1 −0 .gitignore
  2. +3 −13 Makefile
  3. BIN css/.DS_Store
  4. +0 −9 css/bootstrap-theme.min.css
  5. +0 −9 css/bootstrap.min.css
  6. +3 −4 index.html
  7. +0 −170 js/core/layout/base_layout.js
  8. +0 −44 js/raft/model/bbox.js
  9. +11 −0 raft/Makefile
  10. +8 −7 raft/index.html
  11. +0 −1 {js/raft → raft/scripts}/frames/election.js
  12. 0 {js/raft → raft/scripts}/frames/init.js
  13. +1 −1 {js/raft → raft/scripts}/frames/intro.js
  14. +11 −11 {js/raft → raft/scripts}/frames/overview.js
  15. +1 −1 {js/raft → raft/scripts}/frames/playground.js
  16. 0 {js/raft → raft/scripts}/frames/title.js
  17. +14 −14 {js/raft → raft/scripts}/index.js
  18. 0 {js/raft → raft/scripts}/layout/client_layout.js
  19. +7 −7 {js/raft → raft/scripts}/layout/layout.js
  20. 0 {js/raft → raft/scripts}/layout/message_layout.js
  21. 0 {js/raft → raft/scripts}/layout/node_layout.js
  22. +3 −3 {js/raft → raft/scripts}/model/client.js
  23. +5 −5 {js/raft → raft/scripts}/model/controls.js
  24. +3 −3 {js/raft → raft/scripts}/model/log_entry.js
  25. +3 −3 {js/raft → raft/scripts}/model/message.js
  26. +6 −6 {js/raft → raft/scripts}/model/model.js
  27. +44 −13 {js/raft → raft/scripts}/model/node.js
  28. +22 −0 raft/test/index.html
  29. +12 −0 raft/test/index.js
  30. +90 −0 raft/test/model/node.js
  31. 0 js/bootstrap.min.js → scripts/bootstrap/bootstrap-3.0.2.min.js
  32. 0 test/chai.js → scripts/chai/chai-1.8.1.js
  33. 0 js/d3.v3.min.js → scripts/d3/d3-3.3.9.min.js
  34. 0 js/domReady.js → scripts/domReady/domReady-2.0.1.js
  35. 0 {js → scripts/jquery}/jquery-2.0.3.min.js
  36. +73 −90 test/mocha.js → scripts/mocha/mocha-1.14.0.js
  37. +1 −1 js/playback.js → scripts/playback/playback-0.1.1.js
  38. 0 js/require.js → scripts/require/require-2.1.9.js
  39. 0 {test → scripts/sinon}/sinon-1.7.3.js
  40. +483 −0 scripts/tsld/tsld.js
  41. +7,118 −0 styles/bootstrap/bootstrap-3.0.2.css
  42. +397 −0 styles/bootstrap/bootstrap-theme-3.0.2.css
  43. +270 −0 styles/mocha/mocha-1.14.0.css
  44. +9 −10 css/core.css → styles/tsld/tsld.css
  45. +0 −20 test/index.html
  46. +0 −7 test/index.js
  47. +0 −12 test/raft/node.js
View
@@ -1 +1,2 @@
+.DS_Store
node_modules
View
@@ -1,14 +1,4 @@
+test:
+ $(MAKE) -C raft test
-UGLIFY = node_modules/uglify-js/bin/uglifyjs
-PHANTOM = node_modules/.bin/mocha-phantomjs
-LINT = node_modules/.bin/jslint
-
-test: lint
- $(PHANTOM) test/index.html
-
-lint:
- $(LINT) raft/js/{,**/}*.js
-
-clean:
-
-.PHONY: clean test
+.PHONY: test
View
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
View
@@ -2,10 +2,9 @@
<html>
<head>
<title>The Secret Lives of Data</title>
- <link href="css/bootstrap.min.css" rel="stylesheet">
- <script src="js/jquery-2.0.3.min.js"></script>
- <script src="js/bootstrap.min.js"></script>
- <script src="js/d3.v3.min.js" charset="utf-8"></script>
+ <link href="styles/bootstrap-3.0.2.css" rel="stylesheet">
+ <script src="scripts/jquery/jquery-2.0.3.min.js"></script>
+ <script src="scripts/bootstrap/bootstrap-3.0.2.min.js"></script>
</head>
<body>
@@ -1,170 +0,0 @@
-
-"use strict";
-/*jslint browser: true, nomen: true*/
-/*global $, define, d3, playback*/
-
-define([], function () {
- var PAD = 5;
-
- function BaseLayout(selector) {
- this.selector = selector;
- this.prevTitle = this.prevSubtitle = "";
- this.padding = {
- top: 70,
- bottom: 160,
- left: 0,
- right: 0,
- };
- }
-
- BaseLayout.prototype = playback.layout();
-
- /**
- * Initializes the layout.
- */
- BaseLayout.prototype.initialize = function () {
- var self = this;
- this.container = $(this.selector);
- this.svg = d3.select(this.selector).append("svg");
- this.g = this.svg.append("g");
- this.title = d3.select(this.selector).append("div").attr("class", "container title-container").style("display", "none");
- this.subtitle = d3.select(this.selector).append("div").attr("class", "container subtitle-container");
-
- this.scales = {
- x: d3.scale.linear(),
- y: d3.scale.linear(),
- w: d3.scale.linear(),
- h: d3.scale.linear(),
- r: function(v) { return Math.min(self.scales.w(v), self.scales.h(v)); },
- font: function(v) { return Math.min(self.scales.font.x(v), self.scales.font.y(v)); },
- size: function(v) { return Math.min(self.scales.w(v), self.scales.h(v)); },
- };
- this.scales.font.x = d3.scale.linear();
- this.scales.font.y = d3.scale.linear();
-
- this.invalidateSize();
- };
-
- /**
- * Redraws the entire model.
- */
- BaseLayout.prototype.invalidate = function () {
- var model = this.model(),
- width = this.container.width(),
- height = $(window).height() - this.padding.top - this.padding.bottom,
- viewport = {
- width: width - (PAD * 2),
- height: height - (PAD * 2),
- };
-
- this.svg.attr("width", width).attr("height", height);
- this.g.attr("transform", "translate(" + PAD + "," + PAD + ")");
-
- if (model) {
- var zoom = {
- x:((model.domains.x[1] - model.domains.x[0]) / 100),
- y:((model.domains.y[1] - model.domains.y[0]) / 100),
- };
- this.scales.x.domain(model.domains.x).range([0, viewport.width]);
- this.scales.y.domain(model.domains.y).range([0, viewport.height]);
- this.scales.w.domain([0, model.domains.x[1] - model.domains.x[0]]).range([0, viewport.width]);
- this.scales.h.domain([0, model.domains.y[1] - model.domains.y[0]]).range([0, viewport.height]);
- this.scales.font.x.domain([0, 100 * zoom.x]).range([0, viewport.width * 0.35]);
- this.scales.font.y.domain([0, 100 * zoom.y]).range([0, viewport.height * 0.4]);
-
- this.invalidateTitle();
- this.invalidateSubtitle();
- }
- };
-
- /**
- * Redraws the title.
- */
- BaseLayout.prototype.invalidateTitle = function () {
- var titleHeight,
- self = this,
- pct = 0.4,
- viewportHeight = $(window).height() - this.padding.top - this.padding.bottom,
- top = (this.padding.top + (viewportHeight * pct)),
- title = this.model().title,
- html = '<div class="title">' + title + '</div>';
-
- if (this.prevTitle !== title) {
- // Fade title in.
- if(this.prevTitle === "" && title !== "") {
- this.title.style("display", "block");
- this.title.html(html);
- this.fadeIn($(this.title[0][0]));
- }
- // Fade title out.
- else if(this.prevTitle !== "" && title === "") {
- this.fadeOut($(this.title[0][0]), function() {
- self.title.html(html);
- self.title.style("display", "none");
- });
- }
- // Update title.
- else {
- this.title.html(html);
- }
-
- this.prevTitle = title;
- }
-
- var title = this.title.select(".title");
- title.style("top", (top - ($(title[0][0]).height() / 2)) + "px");
- };
-
- /**
- * Redraws the subtitle.
- */
- BaseLayout.prototype.invalidateSubtitle = function () {
- var self = this,
- text = this.model().subtitle,
- html = '<div class="subtitle">' + text + '</div>';
-
- if (this.prevSubtitle !== text) {
- // Fade in.
- if(this.prevSubtitle === "" && text !== "") {
- this.subtitle.style("display", "block");
- this.subtitle.html(html);
- this.fadeIn($(this.subtitle[0][0]));
- }
- // Fade out.
- else if(this.prevSubtitle !== "" && text === "") {
- this.fadeOut($(this.subtitle[0][0]));
- }
- // Update subtitle.
- else {
- this.subtitle.html(html);
- }
-
- this.prevSubtitle = text;
- }
- };
-
- /**
- * Adjusts the size of the layout and adjusts the scales.
- */
- BaseLayout.prototype.invalidateSize = function () {
- if (this.model()) {
- this.invalidate();
- }
- };
-
- /**
- * A helper function to fade in an element.
- */
- BaseLayout.prototype.fadeIn = function (el) {
- return el.css('visibility','visible').hide().fadeIn(600);
- };
-
- /**
- * A helper function to fade out an element.
- */
- BaseLayout.prototype.fadeOut = function (el, complete) {
- return el.css('visibility','hidden').fadeOut(600, complete);
- };
-
- return BaseLayout;
-});
View
@@ -1,44 +0,0 @@
-
-"use strict";
-/*jslint browser: true, nomen: true*/
-
-define([], function () {
- function BBox(top, right, bottom, left) {
- this.top = top;
- this.right = right;
- this.bottom = bottom;
- this.left = left;
- }
-
- /**
- * Determines if two bboxes are equal.
- */
- BBox.prototype.equal = function (b) {
- if (b === null || b === undefined) {
- return false;
- }
- return this.top === b.top
- && this.right === b.right
- && this.bottom === b.bottom
- && this.left === b.left;
- };
-
- /**
- * The smallest bounding box containing this bounding box and another.
- */
- BBox.prototype.union = function (b) {
- var top, right, bottom, left;
-
- if (b === null) {
- return this;
- }
-
- top = Math.min(this.top, b.top),
- right = Math.max(this.right, b.right),
- bottom = Math.max(this.bottom, b.bottom),
- left = Math.min(this.left, b.left);
- return new BBox(top, right, bottom, left);
- };
-
- return BBox;
-});
View
@@ -0,0 +1,11 @@
+
+PHANTOM = ../node_modules/.bin/mocha-phantomjs
+LINT = ../node_modules/.bin/jslint
+
+test:
+ $(PHANTOM) test/index.html
+
+lint:
+ $(LINT) scripts/*.js scripts/**/*.js
+
+.PHONY: test lint
View
@@ -3,16 +3,17 @@
<head>
<title>Raft</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
- <link href="../css/bootstrap.min.css" rel="stylesheet">
- <link href="../css/core.css" rel="stylesheet">
- <script src="../js/jquery-2.0.3.min.js"></script>
- <script src="../js/bootstrap.min.js"></script>
- <script src="../js/d3.v3.min.js"></script>
- <script src="../js/playback.js"></script>
+ <link href="../styles/bootstrap/bootstrap-3.0.2.css" rel="stylesheet">
+ <link href="../styles/tsld/tsld.css" rel="stylesheet">
+ <script src="../scripts/jquery/jquery-2.0.3.min.js"></script>
+ <script src="../scripts/bootstrap/bootstrap-3.0.2.min.js"></script>
+ <script src="../scripts/d3/d3-3.3.9.min.js"></script>
+ <script src="../scripts/playback/playback-0.1.1.js"></script>
+ <script src="../scripts/tsld/tsld.js"></script>
<script>
var require = {urlArgs: "t=" + (new Date()).getTime()};
</script>
- <script data-main="../js/raft/index.js" src="../js/require.js"></script>
+ <script data-main="scripts/index.js" src="../scripts/require/require-2.1.9.js"></script>
</head>
<body>
@@ -72,7 +72,6 @@ define([], function () {
.after(200, wait).indefinite()
.after(100, function () {
node("b").state("stopped");
- node("b").simulate();
model().subtitle = '<h2>If a follower hears no heartbeats within an election timeout then it will become a <strong>candidate</strong>.</h2>'
+ model().controls.html();
layout.invalidate();
File renamed without changes.
@@ -94,7 +94,7 @@ define([], function () {
layout.invalidate();
})
.after(1000, function () {
- frame.model().send("", client("X"), node("a"));
+ frame.model().send(client("X"), node("a"));
layout.invalidate();
})
.after(1000, function () {
@@ -97,8 +97,8 @@ define([], function () {
layout.invalidate();
})
.after(300, function () {
- model().send("", node("a"), node("b"))
- model().send("", node("a"), node("c"))
+ model().send(node("a"), node("b"))
+ model().send(node("a"), node("c"))
layout.invalidate();
})
.after(1000, function () { model().controls.show(); })
@@ -109,8 +109,8 @@ define([], function () {
layout.invalidate();
})
.after(300, function () {
- model().send("", node("b"), node("a"))
- model().send("", node("c"), node("a"))
+ model().send(node("b"), node("a"))
+ model().send(node("c"), node("a"))
layout.invalidate();
})
.after(1000, function () {
@@ -152,7 +152,7 @@ define([], function () {
layout.invalidate();
})
.after(500, function () {
- model().send("", client("x"), node("a"));
+ model().send(client("x"), node("a"));
layout.invalidate();
})
.after(1000, function () {
@@ -176,8 +176,8 @@ define([], function () {
})
.after(300, function () {
frame.snapshot();
- model().send("", node("a"), node("b"))
- model().send("", node("a"), node("c"))
+ model().send(node("a"), node("b"))
+ model().send(node("a"), node("c"))
model().subtitle = '<h2>To commit the entry the node first replicates it to the follower nodes...</h2>'
+ model().controls.html();
layout.invalidate();
@@ -190,8 +190,8 @@ define([], function () {
})
.after(100, function () {
frame.snapshot();
- model().send("", node("b"), node("a"))
- model().send("", node("c"), node("a"))
+ model().send(node("b"), node("a"))
+ model().send(node("c"), node("a"))
model().subtitle = '<h2>then the leader waits until a majority of nodes have written the entry.</h2>'
+ model().controls.html();
layout.invalidate();
@@ -211,8 +211,8 @@ define([], function () {
})
.after(300, function () {
frame.snapshot();
- model().send("", node("a"), node("b"))
- model().send("", node("a"), node("c"))
+ model().send(node("a"), node("b"))
+ model().send(node("a"), node("c"))
model().subtitle = '<h2>The leader then notifies the followers that the entry is committed.</h2>'
+ model().controls.html();
layout.invalidate();
@@ -74,7 +74,7 @@ define([], function () {
.after(500, function () {
client.value = "";
- model.send("", client, nodes.a)
+ model.send(client, nodes.a)
layout.invalidate();
})
File renamed without changes.
Oops, something went wrong.

0 comments on commit 96f22b2

Please sign in to comment.