Mercurial > kallithea
changeset 4338:42bc65838fd1
graph: cleanup of changelog
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Tue, 10 Dec 2013 19:30:37 +0100 |
parents | 394cafce8d31 |
children | 58fe03c0aad1 |
files | kallithea/controllers/changelog.py kallithea/lib/graphmod.py kallithea/public/js/graph.js kallithea/templates/changelog/changelog.html |
diffstat | 4 files changed, 44 insertions(+), 66 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/changelog.py Tue Dec 10 19:30:37 2013 +0100 +++ b/kallithea/controllers/changelog.py Tue Dec 10 19:30:37 2013 +0100 @@ -38,7 +38,7 @@ from kallithea.lib.base import BaseRepoController, render from kallithea.lib.helpers import RepoPage from kallithea.lib.compat import json -from kallithea.lib.graphmod import _colored, _dagwalker +from kallithea.lib.graphmod import graph_data from kallithea.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError,\ ChangesetError, NodeDoesNotExistError, EmptyRepositoryError from kallithea.lib.utils2 import safe_int, safe_str @@ -98,30 +98,6 @@ redirect(h.url('changelog_home', repo_name=repo.repo_name)) raise HTTPBadRequest() - def _graph(self, repo, revs_int, repo_size, size, p): - """ - Generates a DAG graph for repo - - :param repo: - :param revs_int: - :param repo_size: - :param size: - :param p: - """ - if not revs_int: - c.jsdata = json.dumps([]) - return - - data = [] - revs = revs_int - - dag = _dagwalker(repo, revs, repo.alias) - dag = _colored(dag) - for (_id, _type, ctx, vtx, edges) in dag: - data.append(['', vtx, edges]) - - c.jsdata = json.dumps(data) - @LoginRequired() @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 'repository.admin') @@ -192,10 +168,10 @@ prefix = _('(closed)') + ' ' c.branch_filters += [('-', '-')] + \ [(k, prefix + k) for k in c.db_repo_scm_instance.closed_branches.keys()] - _revs = [] + revs = [] if not f_path: - _revs = [x.revision for x in c.pagination] - self._graph(c.db_repo_scm_instance, _revs, c.total_cs, c.size, p) + revs = [x.revision for x in c.pagination] + c.jsdata = json.dumps(graph_data(c.db_repo_scm_instance, revs)) c.revision = revision # requested revision ref c.first_revision = c.pagination[0] # pagination is never empty here!
--- a/kallithea/lib/graphmod.py Tue Dec 10 19:30:37 2013 +0100 +++ b/kallithea/lib/graphmod.py Tue Dec 10 19:30:37 2013 +0100 @@ -39,6 +39,21 @@ seen.add(r) return sorted(kept) +def graph_data(repo, revs): + """Return a DAG with colored edge information for revs + + For each DAG node this function emits tuples:: + + ((col, color), [(col, nextcol, color)]) + + with the following new elements: + + - Tuple (col, color) with column and color index for the current node + - A list of tuples indicating the edges between the current node and its + parents. + """ + dag = _dagwalker(repo, revs, repo.alias) + return [(vtx, edges) for (_id, _type, ctx, vtx, edges) in _colored(dag)] def _dagwalker(repo, revs, alias): if not revs:
--- a/kallithea/public/js/graph.js Tue Dec 10 19:30:37 2013 +0100 +++ b/kallithea/public/js/graph.js Tue Dec 10 19:30:37 2013 +0100 @@ -22,9 +22,11 @@ [ 0.0, 0.0, 0.0 ] ]; -function BranchRenderer() { - - this.canvas = document.getElementById("graph_canvas"); +function BranchRenderer(canvas_id, content_id) { + + this.canvas = document.getElementById(canvas_id); + var t = document.getElementById(content_id); + this.canvas.setAttribute('height',t.clientHeight); if (!document.createElement("canvas").getContext) this.canvas = window.G_vmlCanvasManager.initElement(this.canvas); @@ -48,12 +50,21 @@ this.ctx.fillStyle = s; } - this.render = function(data,canvasWidth,lineCount) { + this.render = function(data,canvasWidth) { var idx = 1; - var rela = document.getElementById('graph'); + var rela = this.canvas; + + this.canvas.setAttribute('width',canvasWidth); - if (lineCount == 0) - lineCount = 1; + var lineCount = 1; + for (var i=0;i<data.length;i++) { + var in_l = data[i][1]; + for (var j in in_l) { + var m = in_l[j][0]; + if (m > lineCount) + lineCount = m; + } + } var edge_pad = this.dot_radius + 2; var box_size = Math.min(18, Math.floor((canvasWidth - edge_pad*2)/(lineCount))); @@ -68,8 +79,8 @@ var extra = 0; cur = data[i]; - node = cur[1]; - in_l = cur[2]; + node = cur[0]; + in_l = cur[1]; var rowY = row.offsetTop + row.offsetHeight/2 - rela.offsetTop; var nextY = (next == null) ? rowY + row.offsetHeight/2 : next.offsetTop + next.offsetHeight/2 - rela.offsetTop;
--- a/kallithea/templates/changelog/changelog.html Tue Dec 10 19:30:37 2013 +0100 +++ b/kallithea/templates/changelog/changelog.html Tue Dec 10 19:30:37 2013 +0100 @@ -37,7 +37,7 @@ </div> <div class="table"> % if c.pagination: - <div id="graph"> + <div> <div style="overflow:auto; display:${'none' if c.changelog_for_path else ''}"> <div class="container_header"> <div style="float:right; margin: 0px 0px 0px 4px">${h.select('branch_filter',c.branch_name,c.branch_filters)}</div> @@ -262,11 +262,9 @@ $(this).children('i').hide(); var cid = $(this).attr('commit_id'); $('#C-'+cid).css({'height': 'auto', 'margin': '4px 0px 4px 0px'}) - //redraw the graph, line_count and jsdata are global vars - set_canvas(100); - var r = new BranchRenderer(); - r.render(jsdata,100,line_count); + //redraw the graph, r and jsdata are bound outside function + r.render(jsdata,100); }); // change branch filter @@ -280,31 +278,9 @@ } }); - function set_canvas(width) { - var c = document.getElementById('graph_nodes'); - var t = document.getElementById('graph_content'); - canvas = document.getElementById('graph_canvas'); - var div_h = t.clientHeight; - canvas.setAttribute('height',div_h); - canvas.setAttribute('width',width); - }; - var heads = 1; - var line_count = 0; var jsdata = ${c.jsdata|n}; - - for (var i=0;i<jsdata.length;i++) { - var in_l = jsdata[i][2]; - for (var j in in_l) { - var m = in_l[j][1]; - if (m > line_count) - line_count = m; - } - } - set_canvas(100); - - var r = new BranchRenderer(); - r.render(jsdata,100,line_count); - + var r = new BranchRenderer('graph_canvas', 'graph_content'); + r.render(jsdata,100); }); </script>