|
1 | | -window.onload = function() { |
| 1 | +function makeNodes() { |
2 | 2 | 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; |
3 | 7 |
|
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 | + }; |
5 | 11 |
|
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); |
8 | 14 | }; |
9 | 15 |
|
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}); |
14 | 22 | }); |
15 | 23 | 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