# HG changeset patch # User Anton Shestakov <a...@dwimlabs.net> # Date 1512533416 -28800 # Wed Dec 06 12:10:16 2017 +0800 # Node ID 79a30ed12f58880967716869bf8989ba505a6fb2 # Parent 330a0bb55f4da059ca9039e3ac2a94e21a2a3525 # EXP-Topic hgweb-cleanup hgweb: move common vertex code to Graph.prototype
Just to give some context to the return values: vertex() needs to return two HTML elements as strings, <li> to be used as a background and a <li> to be shown in foreground. The latter was made obsolete recently when changesets started to be rendered server-side, but background elements are still useful for now. diff --git a/mercurial/templates/gitweb/graph.tmpl b/mercurial/templates/gitweb/graph.tmpl --- a/mercurial/templates/gitweb/graph.tmpl +++ b/mercurial/templates/gitweb/graph.tmpl @@ -50,22 +50,8 @@ var graph = new Graph(); graph.scale({bg_height}); graph.vertex = function(x, y, radius, color, parity, cur) \{ - - this.ctx.beginPath(); - color = this.setColor(color, 0.25, 0.75); - this.ctx.arc(x, y, radius, 0, Math.PI * 2, true); - this.ctx.fill(); - - var bg = '<li class="bg parity' + parity + '"></li>'; - var left = (this.bg_height - this.box_size) + (this.columns + 1) * this.box_size; - - var item = document.querySelector('[data-node="' + cur.node + '"]'); - if (item) \{ - item.style.paddingLeft = left + 'px'; - } - - return [bg, '']; - + Graph.prototype.vertex.apply(this, arguments); + return ['<li class="bg parity' + parity + '"></li>', '']; } graph.render(data); diff --git a/mercurial/templates/monoblue/graph.tmpl b/mercurial/templates/monoblue/graph.tmpl --- a/mercurial/templates/monoblue/graph.tmpl +++ b/mercurial/templates/monoblue/graph.tmpl @@ -44,22 +44,8 @@ graph.scale({bg_height}); graph.vertex = function(x, y, radius, color, parity, cur) \{ - - this.ctx.beginPath(); - color = this.setColor(color, 0.25, 0.75); - this.ctx.arc(x, y, radius, 0, Math.PI * 2, true); - this.ctx.fill(); - - var bg = '<li class="bg parity' + parity + '"></li>'; - var left = (this.bg_height - this.box_size) + (this.columns + 1) * this.box_size; - - var item = document.querySelector('[data-node="' + cur.node + '"]'); - if (item) \{ - item.style.paddingLeft = left + 'px'; - } - - return [bg, '']; - + Graph.prototype.vertex.apply(this, arguments); + return ['<li class="bg parity' + parity + '"></li>', '']; } graph.render(data); diff --git a/mercurial/templates/paper/graph.tmpl b/mercurial/templates/paper/graph.tmpl --- a/mercurial/templates/paper/graph.tmpl +++ b/mercurial/templates/paper/graph.tmpl @@ -63,22 +63,8 @@ var graph = new Graph(); graph.scale({bg_height}); graph.vertex = function(x, y, radius, color, parity, cur) \{ - - this.ctx.beginPath(); - color = this.setColor(color, 0.25, 0.75); - this.ctx.arc(x, y, radius, 0, Math.PI * 2, true); - this.ctx.fill(); - - var bg = '<li class="bg"></li>'; - var left = (this.bg_height - this.box_size) + (this.columns + 1) * this.box_size; - - var item = document.querySelector('[data-node="' + cur.node + '"]'); - if (item) \{ - item.style.paddingLeft = left + 'px'; - } - - return [bg, '']; - + Graph.prototype.vertex.apply(this, arguments); + return ['<li class="bg"></li>', '']; } graph.render(data); diff --git a/mercurial/templates/spartan/graph.tmpl b/mercurial/templates/spartan/graph.tmpl --- a/mercurial/templates/spartan/graph.tmpl +++ b/mercurial/templates/spartan/graph.tmpl @@ -44,21 +44,8 @@ var graph = new Graph(); graph.scale({bg_height}); graph.vertex = function(x, y, radius, color, parity, cur) \{ - - this.ctx.beginPath(); - color = this.setColor(color, 0.25, 0.75); - this.ctx.arc(x, y, radius, 0, Math.PI * 2, true); - this.ctx.fill(); - - var bg = '<li class="bg parity' + parity + '"></li>'; - var left = (this.bg_height - this.box_size) + (this.columns + 1) * this.box_size; - var item = document.querySelector('[data-node="' + cur.node + '"]'); - if (item) \{ - item.style.paddingLeft = left + 'px'; - } - - return [bg, '']; - + Graph.prototype.vertex.apply(this, arguments); + return ['<li class="bg parity' + parity + '"></li>', '']; } graph.render(data); 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 @@ -92,6 +92,21 @@ Graph.prototype = { }, + vertex: function(x, y, radius, color, parity, cur) { + this.ctx.beginPath(); + this.setColor(color, 0.25, 0.75); + this.ctx.arc(x, y, radius, 0, Math.PI * 2, true); + this.ctx.fill(); + + var left = (this.bg_height - this.box_size) + (this.columns + 1) * this.box_size; + var item = document.querySelector('[data-node="' + cur.node + '"]'); + if (item) { + item.style.paddingLeft = left + 'px'; + } + + return ['', '']; + }, + render: function(data) { var backgrounds = ''; diff --git a/tests/test-hgweb-commands.t b/tests/test-hgweb-commands.t --- a/tests/test-hgweb-commands.t +++ b/tests/test-hgweb-commands.t @@ -1821,22 +1821,8 @@ Overviews graph.scale(39); graph.vertex = function(x, y, radius, color, parity, cur) { - - this.ctx.beginPath(); - color = this.setColor(color, 0.25, 0.75); - this.ctx.arc(x, y, radius, 0, Math.PI * 2, true); - this.ctx.fill(); - - var bg = '<li class="bg parity' + parity + '"></li>'; - var left = (this.bg_height - this.box_size) + (this.columns + 1) * this.box_size; - - var item = document.querySelector('[data-node="' + cur.node + '"]'); - if (item) { - item.style.paddingLeft = left + 'px'; - } - - return [bg, '']; - + Graph.prototype.vertex.apply(this, arguments); + return ['<li class="bg parity' + parity + '"></li>', '']; } graph.render(data); diff --git a/tests/test-hgweb-empty.t b/tests/test-hgweb-empty.t --- a/tests/test-hgweb-empty.t +++ b/tests/test-hgweb-empty.t @@ -307,22 +307,8 @@ Some tests for hgweb in an empty reposit graph.scale(39); graph.vertex = function(x, y, radius, color, parity, cur) { - - this.ctx.beginPath(); - color = this.setColor(color, 0.25, 0.75); - this.ctx.arc(x, y, radius, 0, Math.PI * 2, true); - this.ctx.fill(); - - var bg = '<li class="bg"></li>'; - var left = (this.bg_height - this.box_size) + (this.columns + 1) * this.box_size; - - var item = document.querySelector('[data-node="' + cur.node + '"]'); - if (item) { - item.style.paddingLeft = left + 'px'; - } - - return [bg, '']; - + Graph.prototype.vertex.apply(this, arguments); + return ['<li class="bg"></li>', '']; } graph.render(data); _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel