Skip to content

Commit 4910a07

Browse files
committed
refactor to get some global parameters and some initial functions
1 parent 55140c5 commit 4910a07

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

our_script.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,39 @@
1-
window.onload = function() {
1+
function makeNodes() {
22
var paper = new Raphael(document.getElementById('canvas_container'), 1000, 500);
3+
HORIZON = 200; // the y coordinate which gives us the x-axis, e.g. y=250px;
4+
LINE_ATTRS = {stroke: '#aaa', 'stroke-width': 5};
5+
NODE_ATTRS = {stroke: '#aaa', 'stroke-width': 2, fill: 'white'};
6+
NODE_RADIUS = 50;
37

4-
var ax1 = paper.path("M 0 250 l 900 0").attr({stroke: '#aaa', 'stroke-width': 5});
8+
function makeLine(len) {
9+
paper.path("M 0 " + HORIZON + "l "+ len +" 0").attr(LINE_ATTRS);
10+
};
511

6-
for(var i = 0; i < 5; i+=1) {
7-
paper.circle(200*i+100, 250, 50).attr({stroke: '#aaa', 'stroke-width': 2, fill: 'white'});
12+
function node(x, y) {
13+
paper.circle(x, y, NODE_RADIUS).attr(NODE_ATTRS);
814
};
915

10-
$('#canvas_container').on("click", function(){
11-
var req = paper.circle(0, 250, 5).attr({fill: 'red'});
12-
var node1 = Raphael.animation({cx: 100, cy: 250}, 500, function(){
13-
paper.circle(100, 250, 50).attr({fill: 'red'})
16+
function animateRequest(){
17+
var speed = 500;
18+
var req = paper.circle(0, HORIZON, 5).attr({fill: 'red'});
19+
var node1 = Raphael.animation({cx: 100, cy: HORIZON}, speed, function(){
20+
paper.circle(100, HORIZON, NODE_RADIUS).attr({fill: 'red'});
21+
paper.text(100, HORIZON, "Node 1").attr({"font-size": 12});
1422
});
1523
req.animate(node1);
16-
});
17-
}
24+
};
25+
26+
function main() {
27+
makeLine(900);
28+
for(var i = 0; i < 5; i+=1) {
29+
node(200*i+100, HORIZON);
30+
};
31+
};
32+
main();
33+
34+
// events
35+
$('#canvas_container').on("click", animateRequest);
36+
37+
};
38+
39+
$(document).ready(makeNodes);

0 commit comments

Comments
 (0)