author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Sat, 09 Oct 2010 00:05:52 +0200 | |
changeset 6427 | c8a5ac2d1eaa |
parent 5658 | 7b9553a9db65 |
permissions | -rw-r--r-- |
4700
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
1 |
function ProgressBar() { |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
2 |
this.budget = 100; |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
3 |
this.todo = 100; |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
4 |
this.done = 100; |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
5 |
this.color_done = "green"; |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
6 |
this.color_budget = "blue"; |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
7 |
this.color_todo = "#cccccc"; // grey |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
8 |
this.height = 16; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
9 |
this.middle = this.height / 2; |
4700
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
10 |
this.radius = 4; |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
11 |
} |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
12 |
|
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
13 |
ProgressBar.prototype.draw_one_rect = function(ctx, pos, color, fill) { |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
14 |
ctx.beginPath(); |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
15 |
ctx.lineWidth = 1; |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
16 |
ctx.strokeStyle = color; |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
17 |
if (fill) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
18 |
ctx.fillStyle = color; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
19 |
ctx.fillRect(0, 0, pos, this.middle * 2); |
4700
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
20 |
} else { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
21 |
ctx.lineWidth = 2; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
22 |
ctx.strokeStyle = "black"; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
23 |
ctx.moveTo(pos, 0); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
24 |
ctx.lineTo(pos, this.middle * 2); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
25 |
ctx.stroke(); |
4700
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
26 |
} |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
27 |
}; |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
28 |
|
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
29 |
ProgressBar.prototype.draw_one_circ = function(ctx, pos, color) { |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
30 |
ctx.beginPath(); |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
31 |
ctx.lineWidth = 2; |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
32 |
ctx.strokeStyle = color; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
33 |
ctx.moveTo(0, this.middle); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
34 |
ctx.lineTo(pos, this.middle); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
35 |
ctx.arc(pos, this.middle, this.radius, 0, Math.PI * 2, true); |
4700
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
36 |
ctx.stroke(); |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
37 |
}; |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
38 |
|
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
39 |
ProgressBar.prototype.draw_circ = function(ctx) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
40 |
this.draw_one_circ(ctx, this.budget, this.color_budget); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
41 |
this.draw_one_circ(ctx, this.todo, this.color_todo); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
42 |
this.draw_one_circ(ctx, this.done, this.color_done); |
4700
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
43 |
}; |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
44 |
|
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
45 |
ProgressBar.prototype.draw_rect = function(ctx) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
46 |
this.draw_one_rect(ctx, this.todo, this.color_todo, true); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
47 |
this.draw_one_rect(ctx, this.done, this.color_done, true); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
48 |
this.draw_one_rect(ctx, this.budget, this.color_budget, false); |
4700
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
49 |
}; |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
50 |
|
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
51 |
function draw_progressbar(cid, done, todo, budget, color) { |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
52 |
var canvas = document.getElementById(cid); |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
53 |
if (canvas.getContext) { |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
54 |
var ctx = canvas.getContext("2d"); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
55 |
var bar = new ProgressBar(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
56 |
bar.budget = budget; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
57 |
bar.todo = todo; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
58 |
bar.done = done; |
4700
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
59 |
bar.color_done = color; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
60 |
bar.draw_rect(ctx); |
4700
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
61 |
} |
b981c7d3e3c0
[iprogress] missing js file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
62 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4700
diff
changeset
|
63 |