hgweb: create Graph methods using a prototype
authorAnton Shestakov <av6@dwimlabs.net>
Wed, 06 Dec 2017 12:01:07 +0800
changeset 35254 9c99541e3d56
parent 35253 c2e2437f2b2e
child 35255 ad0de63e1d6a
hgweb: create Graph methods using a prototype This way it's possible to call the original methods even if they were overridden.
mercurial/templates/static/mercurial.js
--- a/mercurial/templates/static/mercurial.js	Wed Dec 06 11:59:19 2017 +0800
+++ b/mercurial/templates/static/mercurial.js	Wed Dec 06 12:01:07 2017 +0800
@@ -33,21 +33,24 @@
 	this.cell = [2, 0];
 	this.columns = 0;
 
-	this.reset = function() {
+}
+
+Graph.prototype = {
+	reset: function() {
 		this.bg = [0, 4];
 		this.cell = [2, 0];
 		this.columns = 0;
 		document.getElementById('nodebgs').innerHTML = '';
 		document.getElementById('graphnodes').innerHTML = '';
-	};
+	},
 
-	this.scale = function(height) {
+	scale: function(height) {
 		this.bg_height = height;
 		this.box_size = Math.floor(this.bg_height / 1.2);
 		this.cell_height = this.box_size;
-	};
+	},
 
-	this.setColor = function(color, bg, fg) {
+	setColor: function(color, bg, fg) {
 
 		// Set the colour.
 		//
@@ -75,9 +78,9 @@
 		this.ctx.fillStyle = s;
 		return s;
 
-	};
+	},
 
-	this.edge = function(x0, y0, x1, y1, color, width) {
+	edge: function(x0, y0, x1, y1, color, width) {
 
 		this.setColor(color, 0.0, 0.65);
 		if(width >= 0)
@@ -87,9 +90,9 @@
 		this.ctx.lineTo(x1, y1);
 		this.ctx.stroke();
 
-	};
+	},
 
-	this.render = function(data) {
+	render: function(data) {
 
 		var backgrounds = '';
 		var nodedata = '';
@@ -155,9 +158,9 @@
 		document.getElementById('nodebgs').innerHTML += backgrounds;
 		document.getElementById('graphnodes').innerHTML += nodedata;
 
-	};
+	}
 
-}
+};
 
 
 function process_dates(parentSelector){