Mercurial > hg
annotate mercurial/templates/static/mercurial.js @ 14046:b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
This allow safe caching of the pages by the browser and still display the right
amount of elapsed time upon page refresh.
If javascript is disabled, absolute time is displayed, leaving it readable.
All the templates have been updated.
author | Benoit Allard <benoit@aeteurope.nl> |
---|---|
date | Thu, 28 Apr 2011 17:02:39 +0200 |
parents | |
children | 17c0cb1045e5 |
rev | line source |
---|---|
14046
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
1 // mercurial.js - JavaScript utility functions |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
2 // |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
3 // Rendering of branch DAGs on the client side |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
4 // Display of elapsed time |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
5 // |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
6 // Copyright 2008 Dirkjan Ochtman <dirkjan AT ochtman DOT nl> |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
7 // Copyright 2006 Alexander Schremmer <alex AT alexanderweb DOT de> |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
8 // |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
9 // derived from code written by Scott James Remnant <scott@ubuntu.com> |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
10 // Copyright 2005 Canonical Ltd. |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
11 // |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
12 // This software may be used and distributed according to the terms |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
13 // of the GNU General Public License, incorporated herein by reference. |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
14 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
15 var colors = [ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
16 [ 1.0, 0.0, 0.0 ], |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
17 [ 1.0, 1.0, 0.0 ], |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
18 [ 0.0, 1.0, 0.0 ], |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
19 [ 0.0, 1.0, 1.0 ], |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
20 [ 0.0, 0.0, 1.0 ], |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
21 [ 1.0, 0.0, 1.0 ] |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
22 ]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
23 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
24 function Graph() { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
25 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
26 this.canvas = document.getElementById('graph'); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
27 if (navigator.userAgent.indexOf('MSIE') >= 0) this.canvas = window.G_vmlCanvasManager.initElement(this.canvas); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
28 this.ctx = this.canvas.getContext('2d'); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
29 this.ctx.strokeStyle = 'rgb(0, 0, 0)'; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
30 this.ctx.fillStyle = 'rgb(0, 0, 0)'; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
31 this.cur = [0, 0]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
32 this.line_width = 3; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
33 this.bg = [0, 4]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
34 this.cell = [2, 0]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
35 this.columns = 0; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
36 this.revlink = ''; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
37 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
38 this.scale = function(height) { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
39 this.bg_height = height; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
40 this.box_size = Math.floor(this.bg_height / 1.2); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
41 this.cell_height = this.box_size; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
42 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
43 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
44 function colorPart(num) { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
45 num *= 255 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
46 num = num < 0 ? 0 : num; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
47 num = num > 255 ? 255 : num; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
48 var digits = Math.round(num).toString(16); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
49 if (num < 16) { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
50 return '0' + digits; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
51 } else { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
52 return digits; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
53 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
54 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
55 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
56 this.setColor = function(color, bg, fg) { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
57 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
58 // Set the colour. |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
59 // |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
60 // Picks a distinct colour based on an internal wheel; the bg |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
61 // parameter provides the value that should be assigned to the 'zero' |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
62 // colours and the fg parameter provides the multiplier that should be |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
63 // applied to the foreground colours. |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
64 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
65 color %= colors.length; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
66 var red = (colors[color][0] * fg) || bg; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
67 var green = (colors[color][1] * fg) || bg; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
68 var blue = (colors[color][2] * fg) || bg; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
69 red = Math.round(red * 255); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
70 green = Math.round(green * 255); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
71 blue = Math.round(blue * 255); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
72 var s = 'rgb(' + red + ', ' + green + ', ' + blue + ')'; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
73 this.ctx.strokeStyle = s; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
74 this.ctx.fillStyle = s; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
75 return s; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
76 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
77 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
78 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
79 this.render = function(data) { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
80 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
81 var backgrounds = ''; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
82 var nodedata = ''; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
83 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
84 for (var i in data) { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
85 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
86 var parity = i % 2; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
87 this.cell[1] += this.bg_height; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
88 this.bg[1] += this.bg_height; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
89 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
90 var cur = data[i]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
91 var node = cur[1]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
92 var edges = cur[2]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
93 var fold = false; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
94 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
95 for (var j in edges) { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
96 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
97 line = edges[j]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
98 start = line[0]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
99 end = line[1]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
100 color = line[2]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
101 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
102 if (end > this.columns || start > this.columns) { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
103 this.columns += 1; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
104 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
105 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
106 if (start == this.columns && start > end) { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
107 var fold = true; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
108 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
109 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
110 x0 = this.cell[0] + this.box_size * start + this.box_size / 2; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
111 y0 = this.bg[1] - this.bg_height / 2; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
112 x1 = this.cell[0] + this.box_size * end + this.box_size / 2; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
113 y1 = this.bg[1] + this.bg_height / 2; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
114 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
115 this.edge(x0, y0, x1, y1, color); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
116 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
117 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
118 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
119 // Draw the revision node in the right column |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
120 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
121 column = node[0] |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
122 color = node[1] |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
123 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
124 radius = this.box_size / 8; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
125 x = this.cell[0] + this.box_size * column + this.box_size / 2; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
126 y = this.bg[1] - this.bg_height / 2; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
127 var add = this.vertex(x, y, color, parity, cur); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
128 backgrounds += add[0]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
129 nodedata += add[1]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
130 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
131 if (fold) this.columns -= 1; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
132 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
133 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
134 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
135 document.getElementById('nodebgs').innerHTML += backgrounds; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
136 document.getElementById('graphnodes').innerHTML += nodedata; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
137 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
138 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
139 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
140 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
141 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
142 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
143 process_dates = (function(document, RegExp, Math, isNaN, Date, _false, _true){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
144 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
145 // derived from code from mercurial/templatefilter.py |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
146 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
147 var scales = { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
148 'year': 365 * 24 * 60 * 60, |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
149 'month': 30 * 24 * 60 * 60, |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
150 'week': 7 * 24 * 60 * 60, |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
151 'day': 24 * 60 * 60, |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
152 'hour': 60 * 60, |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
153 'minute': 60, |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
154 'second': 1 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
155 }; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
156 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
157 function format(count, string){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
158 var ret = count + ' ' + string; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
159 if (count > 1){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
160 ret = ret + 's'; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
161 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
162 return ret; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
163 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
164 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
165 function age(datestr){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
166 var now = new Date(); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
167 var once = new Date(datestr); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
168 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
169 if (isNaN(once.getTime())){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
170 // parsing error |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
171 return datestr; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
172 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
173 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
174 var delta = Math.floor((now.getTime() - once.getTime()) / 1000); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
175 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
176 var future = _false; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
177 if (delta < 0){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
178 future = _true; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
179 delta = -delta; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
180 if (delta > (30 * scales.year)){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
181 return "in the distant future"; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
182 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
183 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
184 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
185 if (delta > (2 * scales.year)){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
186 return once.getFullYear() + '-' + once.getMonth() + '-' + once.getDate(); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
187 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
188 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
189 for (unit in scales){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
190 var s = scales[unit]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
191 var n = Math.floor(delta / s); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
192 if ((n >= 2) || (s == 1)){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
193 if (future){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
194 return format(n, unit) + ' from now'; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
195 } else { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
196 return format(n, unit) + ' ago'; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
197 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
198 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
199 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
200 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
201 |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
202 return function(){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
203 var nodes = document.getElementsByTagName('*'); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
204 var ageclass = new RegExp('\\bage\\b'); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
205 var dateclass = new RegExp('\\bdate\\b'); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
206 for (var i=0; i<nodes.length; ++i){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
207 var node = nodes[i]; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
208 var classes = node.className; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
209 if (ageclass.test(classes)){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
210 var agevalue = age(node.textContent); |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
211 if (dateclass.test(classes)){ |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
212 // We want both: date + (age) |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
213 node.textContent += ' ('+agevalue+')'; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
214 } else { |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
215 node.textContent = agevalue; |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
216 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
217 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
218 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
219 } |
b24e5a708fad
web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff
changeset
|
220 })(document, RegExp, Math, isNaN, Date, false, true) |