hgweb: create Graph methods using a prototype

This way it's possible to call the original methods even if they were
overridden.
This commit is contained in:
Anton Shestakov 2017-12-06 12:01:07 +08:00
parent 01742a7db5
commit a4d9f6f538

View File

@ -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){