# HG changeset patch # User Anton Shestakov # Date 1512533416 -28800 # Node ID ad0de63e1d6a1e389bd1517ea968a0822a66a077 # Parent 9c99541e3d56d275bd89e9d2c80645a9385d5f60 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,
  • to be used as a background and a
  • 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 -r 9c99541e3d56 -r ad0de63e1d6a mercurial/templates/gitweb/graph.tmpl --- a/mercurial/templates/gitweb/graph.tmpl Wed Dec 06 12:01:07 2017 +0800 +++ b/mercurial/templates/gitweb/graph.tmpl Wed Dec 06 12:10:16 2017 +0800 @@ -50,22 +50,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 = '
  • '; - 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 ['
  • ', '']; } graph.render(data); diff -r 9c99541e3d56 -r ad0de63e1d6a mercurial/templates/monoblue/graph.tmpl --- a/mercurial/templates/monoblue/graph.tmpl Wed Dec 06 12:01:07 2017 +0800 +++ b/mercurial/templates/monoblue/graph.tmpl Wed Dec 06 12:10:16 2017 +0800 @@ -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 = '
  • '; - 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 ['
  • ', '']; } graph.render(data); diff -r 9c99541e3d56 -r ad0de63e1d6a mercurial/templates/paper/graph.tmpl --- a/mercurial/templates/paper/graph.tmpl Wed Dec 06 12:01:07 2017 +0800 +++ b/mercurial/templates/paper/graph.tmpl Wed Dec 06 12:10:16 2017 +0800 @@ -63,22 +63,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 = '
  • '; - 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 ['
  • ', '']; } graph.render(data); diff -r 9c99541e3d56 -r ad0de63e1d6a mercurial/templates/spartan/graph.tmpl --- a/mercurial/templates/spartan/graph.tmpl Wed Dec 06 12:01:07 2017 +0800 +++ b/mercurial/templates/spartan/graph.tmpl Wed Dec 06 12:10:16 2017 +0800 @@ -44,21 +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 = '
  • '; - 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 ['
  • ', '']; } graph.render(data); diff -r 9c99541e3d56 -r ad0de63e1d6a mercurial/templates/static/mercurial.js --- a/mercurial/templates/static/mercurial.js Wed Dec 06 12:01:07 2017 +0800 +++ b/mercurial/templates/static/mercurial.js Wed Dec 06 12:10:16 2017 +0800 @@ -92,6 +92,21 @@ }, + 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 -r 9c99541e3d56 -r ad0de63e1d6a tests/test-hgweb-commands.t --- a/tests/test-hgweb-commands.t Wed Dec 06 12:01:07 2017 +0800 +++ b/tests/test-hgweb-commands.t Wed Dec 06 12:10:16 2017 +0800 @@ -1821,22 +1821,8 @@ 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 = '
  • '; - 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 ['
  • ', '']; } graph.render(data); diff -r 9c99541e3d56 -r ad0de63e1d6a tests/test-hgweb-empty.t --- a/tests/test-hgweb-empty.t Wed Dec 06 12:01:07 2017 +0800 +++ b/tests/test-hgweb-empty.t Wed Dec 06 12:10:16 2017 +0800 @@ -307,22 +307,8 @@ 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 = '
  • '; - 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 ['
  • ', '']; } graph.render(data);