From 94690bd2c4b30116aeee42fab5f97d5023ac750f Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Sun, 13 Nov 2011 13:58:45 +0200 Subject: [PATCH] Graph: base implementation --- app/assets/stylesheets/projects.css.scss | 11 +++++- app/controllers/projects_controller.rb | 4 +- app/views/layouts/project.html.haml | 2 +- app/views/projects/graph.html.haml | 9 +++++ lib/assets/javascripts/branch-graph.js | 47 ++++++++++++++---------- 5 files changed, 48 insertions(+), 25 deletions(-) create mode 100644 app/views/projects/graph.html.haml diff --git a/app/assets/stylesheets/projects.css.scss b/app/assets/stylesheets/projects.css.scss index b03ad1059e0..9c0eb591bdb 100644 --- a/app/assets/stylesheets/projects.css.scss +++ b/app/assets/stylesheets/projects.css.scss @@ -468,4 +468,13 @@ body.project-page table .commit { /** UI autocomplete **/ .ui-autocomplete { @include round-borders-all(5px); } .ui-menu-item { cursor: pointer } - + +#holder { + border: solid 1px #999; + cursor: move; + height: 70%; + overflow: scroll; + position: absolute; + width: auto; + margin: 6ex 3ex 0ex 0ex; +} diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a0e727954d8..0564a82b0fa 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -150,11 +150,9 @@ class ProjectsController < ApplicationController h[:id] = c.sha h[:date] = c.date h[:message] = c.message.force_encoding("UTF-8") - h[:email] = c.author.email + h[:login] = c.author.email h end.to_json - - render :text => @commits_json end def blob diff --git a/app/views/layouts/project.html.haml b/app/views/layouts/project.html.haml index ed289707af3..fc28b9307b3 100644 --- a/app/views/layouts/project.html.haml +++ b/app/views/layouts/project.html.haml @@ -22,7 +22,7 @@ = link_to "History", project_path(@project), :class => current_page?(:controller => "projects", :action => "show", :id => @project) ? "current" : nil = link_to "Tree", tree_project_path(@project), :class => current_page?(:controller => "projects", :action => "tree", :id => @project) ? "current" : nil = link_to "Commits", project_commits_path(@project), :class => current_page?(:controller => "commits", :action => "index", :project_id => @project) ? "current" : nil - = link_to "Network graph", graph_project_path(@project), :class => current_page?(:controller => "projects", :action => "graph", :project_id => @project) ? "current" : nil + = link_to "Network graph", graph_project_path(@project), :class => current_page?(:controller => "projects", :action => "graph", :id => @project) ? "current" : nil = link_to team_project_path(@project), :class => (current_page?(:controller => "projects", :action => "team", :id => @project) || controller.controller_name == "team_members") ? "current" : nil do Team - if @project.users_projects.count > 0 diff --git a/app/views/projects/graph.html.haml b/app/views/projects/graph.html.haml new file mode 100644 index 00000000000..b5f6921d407 --- /dev/null +++ b/app/views/projects/graph.html.haml @@ -0,0 +1,9 @@ +#holder.graph + +:javascript + var chunk1={commits:#{@commits_json}}; + var days=#{@days_json}; + initGraph(); + $(function(){ + branchGraph($("#holder")[0]); + }); diff --git a/lib/assets/javascripts/branch-graph.js b/lib/assets/javascripts/branch-graph.js index b98c836ff5c..f8b73660d11 100644 --- a/lib/assets/javascripts/branch-graph.js +++ b/lib/assets/javascripts/branch-graph.js @@ -1,30 +1,37 @@ -var commits = chunk1.commits, +var commits = {}, comms = {}, pixelsX = [], pixelsY = [], mmax = Math.max, mtime = 0, mspace = 0, - parents = {}; -for (var i = 0, ii = commits.length; i < ii; i++) { - for (var j = 0, jj = commits[i].parents.length; j < jj; j++) { - parents[commits[i].parents[j][0]] = true; - } - mtime = Math.max(mtime, commits[i].time); - mspace = Math.max(mspace, commits[i].space); -} -mtime = mtime + 4; -mspace = mspace + 10; -for (i = 0; i < ii; i++) { - if (commits[i].id in parents) { - commits[i].isParent = true; - } - comms[commits[i].id] = commits[i]; -} -var colors = ["#000"]; -for (var k = 0; k < mspace; k++) { - colors.push(Raphael.getColor()); + parents = {}, + ii = 0, + colors = ["#000"]; + +function initGraph(){ + commits = chunk1.commits; + ii = commits.length; + for (var i = 0; i < ii; i++) { + for (var j = 0, jj = commits[i].parents.length; j < jj; j++) { + parents[commits[i].parents[j][0]] = true; + } + mtime = Math.max(mtime, commits[i].time); + mspace = Math.max(mspace, commits[i].space); + } + mtime = mtime + 4; + mspace = mspace + 10; + for (i = 0; i < ii; i++) { + if (commits[i].id in parents) { + commits[i].isParent = true; + } + comms[commits[i].id] = commits[i]; + } + for (var k = 0; k < mspace; k++) { + colors.push(Raphael.getColor()); + } } + function branchGraph(holder) { var ch = mspace * 20 + 20, cw = mtime * 20 + 20, r = Raphael("holder", cw, ch),