Changeset - 42bc65838fd1
[Not reviewed]
default
0 4 0
Mads Kiilerich - 12 years ago 2013-12-10 19:30:37
madski@unity3d.com
graph: cleanup of changelog
4 files changed with 44 insertions and 66 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/changelog.py
Show inline comments
 
@@ -38,7 +38,7 @@ from kallithea.lib.auth import LoginRequ
 
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 @@ class ChangelogController(BaseRepoContro
 
                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 @@ class ChangelogController(BaseRepoContro
 
            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!
kallithea/lib/graphmod.py
Show inline comments
 
@@ -39,6 +39,21 @@ def grandparent(parentrev_func, lowestre
 
            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:
kallithea/public/js/graph.js
Show inline comments
 
@@ -22,9 +22,11 @@ var colors = [
 
	[ 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 @@ function BranchRenderer() {
 
		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 @@ function BranchRenderer() {
 
			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;
kallithea/templates/changelog/changelog.html
Show inline comments
 
@@ -37,7 +37,7 @@ ${self.repo_context_bar('changelog', c.f
 
    </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 @@ ${self.repo_context_bar('changelog', c.f
 
                    $(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 @@ ${self.repo_context_bar('changelog', c.f
 
                    }
 
                });
 

	
 
                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>
0 comments (0 inline, 0 general)