[PATCH 2 of 3] hgweb: create Graph methods using a prototype

Anton Shestakov av6 at dwimlabs.net
Wed Dec 6 03:35:09 EST 2017


# HG changeset patch
# User Anton Shestakov <av6 at dwimlabs.net>
# Date 1512532867 -28800
#      Wed Dec 06 12:01:07 2017 +0800
# Node ID 330a0bb55f4da059ca9039e3ac2a94e21a2a3525
# Parent  20b6f1981b961369ce5004c5a48da3fe8b6b10ff
# EXP-Topic hgweb-cleanup
hgweb: create Graph methods using a prototype

This way it's possible to call the original methods even if they were
overridden.

diff --git a/mercurial/templates/static/mercurial.js b/mercurial/templates/static/mercurial.js
--- a/mercurial/templates/static/mercurial.js
+++ b/mercurial/templates/static/mercurial.js
@@ -33,21 +33,24 @@ function Graph() {
 	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 @@ function Graph() {
 		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 @@ function Graph() {
 		this.ctx.lineTo(x1, y1);
 		this.ctx.stroke();
 
-	};
+	},
 
-	this.render = function(data) {
+	render: function(data) {
 
 		var backgrounds = '';
 		var nodedata = '';
@@ -155,9 +158,9 @@ function Graph() {
 		document.getElementById('nodebgs').innerHTML += backgrounds;
 		document.getElementById('graphnodes').innerHTML += nodedata;
 
-	};
+	}
 
-}
+};
 
 
 function process_dates(parentSelector){


More information about the Mercurial-devel mailing list