mercurial/templates/static/mercurial.js
author Constantine Linnick <theaspect@gmail.com>
Sun, 22 Jan 2012 19:35:26 +0700
changeset 16129 5e50982c633c
parent 14881 2e54387976d4
child 16130 33f702e52906
permissions -rw-r--r--
graph: in hgrc specify line width for main branch You can specify width to visually distinguish main branch (trunk) on hgweb's graph page. Settings format is branch_name.width = value, where width in px e.g.: [graph] default.width = 3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
14571
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
     5
// Show or hide diffstat
14046
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
     6
//
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
     7
// 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
     8
// 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
     9
//
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    10
// 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
    11
// Copyright 2005 Canonical Ltd.
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    12
//
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    13
// 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
    14
// 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
    15
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    16
var colors = [
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    17
	[ 1.0, 0.0, 0.0 ],
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    18
	[ 1.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, 0.0 ],
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    20
	[ 0.0, 1.0, 1.0 ],
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    21
	[ 0.0, 0.0, 1.0 ],
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    22
	[ 1.0, 0.0, 1.0 ]
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
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    25
function Graph() {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    26
	
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    27
	this.canvas = document.getElementById('graph');
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    28
	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
    29
	this.ctx = this.canvas.getContext('2d');
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    30
	this.ctx.strokeStyle = 'rgb(0, 0, 0)';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    31
	this.ctx.fillStyle = 'rgb(0, 0, 0)';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    32
	this.cur = [0, 0];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    33
	this.line_width = 3;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    34
	this.bg = [0, 4];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    35
	this.cell = [2, 0];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    36
	this.columns = 0;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    37
	this.revlink = '';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    38
	
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    39
	this.scale = function(height) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    40
		this.bg_height = height;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    41
		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
    42
		this.cell_height = this.box_size;
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
	
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    45
	function colorPart(num) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    46
		num *= 255
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    47
		num = num < 0 ? 0 : num;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    48
		num = num > 255 ? 255 : num;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    49
		var digits = Math.round(num).toString(16);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    50
		if (num < 16) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    51
			return '0' + digits;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    52
		} else {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    53
			return digits;
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
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    57
	this.setColor = function(color, bg, fg) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    58
		
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    59
		// Set the colour.
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    60
		//
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    61
		// 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
    62
		// 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
    63
		// 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
    64
		// applied to the foreground colours.
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    65
		
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    66
		color %= colors.length;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    67
		var red = (colors[color][0] * fg) || bg;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    68
		var green = (colors[color][1] * fg) || bg;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    69
		var blue = (colors[color][2] * fg) || bg;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    70
		red = Math.round(red * 255);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    71
		green = Math.round(green * 255);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    72
		blue = Math.round(blue * 255);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    73
		var s = 'rgb(' + red + ', ' + green + ', ' + blue + ')';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    74
		this.ctx.strokeStyle = s;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    75
		this.ctx.fillStyle = s;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    76
		return s;
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
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    80
	this.render = function(data) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    81
		
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    82
		var backgrounds = '';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    83
		var nodedata = '';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    84
		
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    85
		for (var i in data) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    86
			
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    87
			var parity = i % 2;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    88
			this.cell[1] += this.bg_height;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    89
			this.bg[1] += this.bg_height;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    90
			
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    91
			var cur = data[i];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    92
			var node = cur[1];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    93
			var edges = cur[2];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    94
			var fold = false;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    95
			
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    96
			for (var j in edges) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    97
				
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    98
				line = edges[j];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
    99
				start = line[0];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   100
				end = line[1];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   101
				color = line[2];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   102
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   103
				if (end > this.columns || start > this.columns) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   104
					this.columns += 1;
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
				
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   107
				if (start == this.columns && start > end) {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   108
					var fold = true;
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
				
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   111
				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
   112
				y0 = this.bg[1] - this.bg_height / 2;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   113
				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
   114
				y1 = this.bg[1] + this.bg_height / 2;
16129
5e50982c633c graph: in hgrc specify line width for main branch
Constantine Linnick <theaspect@gmail.com>
parents: 14881
diff changeset
   115
				// Width if exists
5e50982c633c graph: in hgrc specify line width for main branch
Constantine Linnick <theaspect@gmail.com>
parents: 14881
diff changeset
   116
				if(line[3] && line[3]['width']){
5e50982c633c graph: in hgrc specify line width for main branch
Constantine Linnick <theaspect@gmail.com>
parents: 14881
diff changeset
   117
					this.ctx.lineWidth = line[3]['width'];
5e50982c633c graph: in hgrc specify line width for main branch
Constantine Linnick <theaspect@gmail.com>
parents: 14881
diff changeset
   118
				}
14046
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   119
				this.edge(x0, y0, x1, y1, color);
16129
5e50982c633c graph: in hgrc specify line width for main branch
Constantine Linnick <theaspect@gmail.com>
parents: 14881
diff changeset
   120
				this.ctx.lineWidth = 1;
14046
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   121
			}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   122
			
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   123
			// Draw the revision node in the right column
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   124
			
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   125
			column = node[0]
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   126
			color = node[1]
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   127
			
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   128
			radius = this.box_size / 8;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   129
			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
   130
			y = this.bg[1] - this.bg_height / 2;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   131
			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
   132
			backgrounds += add[0];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   133
			nodedata += add[1];
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
			if (fold) this.columns -= 1;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   136
			
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
		document.getElementById('nodebgs').innerHTML += backgrounds;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   140
		document.getElementById('graphnodes').innerHTML += nodedata;
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
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
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
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
   148
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   149
	// derived from code from mercurial/templatefilter.py
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   150
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   151
	var scales = {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   152
		'year':  365 * 24 * 60 * 60,
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   153
		'month':  30 * 24 * 60 * 60,
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   154
		'week':    7 * 24 * 60 * 60,
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   155
		'day':    24 * 60 * 60,
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   156
		'hour':   60 * 60,
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   157
		'minute': 60,
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   158
		'second': 1
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   159
	};
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   160
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   161
	function format(count, string){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   162
		var ret = count + ' ' + string;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   163
		if (count > 1){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   164
			ret = ret + 's';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   165
		}
14881
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   166
 		return ret;
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   167
 	}
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   168
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   169
	function shortdate(date){
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   170
		var ret = date.getFullYear() + '-';
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   171
		// getMonth() gives a 0-11 result
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   172
		var month = date.getMonth() + 1;
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   173
		if (month <= 9){
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   174
			ret += '0' + month;
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   175
		} else {
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   176
			ret += month;
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   177
		}
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   178
		ret += '-';
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   179
		var day = date.getDate();
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   180
		if (day <= 9){
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   181
			ret += '0' + day;
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   182
		} else {
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   183
			ret += day;
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   184
		}
14046
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   185
		return ret;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   186
	}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   187
14881
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   188
 	function age(datestr){
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   189
 		var now = new Date();
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   190
 		var once = new Date(datestr);
14046
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   191
		if (isNaN(once.getTime())){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   192
			// parsing error
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   193
			return datestr;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   194
		}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   195
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   196
		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
   197
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   198
		var future = _false;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   199
		if (delta < 0){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   200
			future = _true;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   201
			delta = -delta;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   202
			if (delta > (30 * scales.year)){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   203
				return "in the distant future";
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   204
			}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   205
		}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   206
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   207
		if (delta > (2 * scales.year)){
14881
2e54387976d4 web: Output a correct date in short format (issue2902)
Benoit Allard <benoit@aeteurope.nl>
parents: 14571
diff changeset
   208
			return shortdate(once);
14046
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   209
		}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   210
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   211
		for (unit in scales){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   212
			var s = scales[unit];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   213
			var n = Math.floor(delta / s);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   214
			if ((n >= 2) || (s == 1)){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   215
				if (future){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   216
					return format(n, unit) + ' from now';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   217
				} else {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   218
					return format(n, unit) + ' ago';
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
			}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   221
		}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   222
	}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   223
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   224
	return function(){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   225
		var nodes = document.getElementsByTagName('*');
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   226
		var ageclass = new RegExp('\\bage\\b');
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   227
		var dateclass = new RegExp('\\bdate\\b');
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   228
		for (var i=0; i<nodes.length; ++i){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   229
			var node = nodes[i];
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   230
			var classes = node.className;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   231
			if (ageclass.test(classes)){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   232
				var agevalue = age(node.textContent);
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   233
				if (dateclass.test(classes)){
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   234
					// We want both: date + (age)
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   235
					node.textContent += ' ('+agevalue+')';
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   236
				} else {
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   237
					node.textContent = agevalue;
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   238
				}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   239
			}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   240
		}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   241
	}
b24e5a708fad web: Made elapsed time calculation dynamic (javascript).
Benoit Allard <benoit@aeteurope.nl>
parents:
diff changeset
   242
})(document, RegExp, Math, isNaN, Date, false, true)
14571
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   243
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   244
function showDiffstat() {
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   245
	document.getElementById('diffstatdetails').style.display = 'inline';
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   246
	document.getElementById('diffstatexpand').style.display = 'none';
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   247
}
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   248
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   249
function hideDiffstat() {
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   250
	document.getElementById('diffstatdetails').style.display = 'none';
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   251
	document.getElementById('diffstatexpand').style.display = 'inline';
17c0cb1045e5 paper, coal: display diffstat on the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents: 14046
diff changeset
   252
}