Commit 3ca6c960ce39611de215fa2aa1497508de537218

Authored by Dmitriy Zaporozhets
2 parents 25f1a7ec 16339579

Merge pull request #942 from veprbl/network_graph_fix

Network graph fix (#909)
lib/graph_commit.rb
... ... @@ -50,10 +50,14 @@ class GraphCommit
50 50 end
51 51 end
52 52  
53   - j = 0
  53 + @_reserved = {}
  54 + days.each_index do |i|
  55 + @_reserved[i] = []
  56 + end
  57 +
54 58 heads.each do |h|
55 59 if map.include? h.commit.id then
56   - j = mark_chain(j+=1, map[h.commit.id], map)
  60 + place_chain(map[h.commit.id], map)
57 61 end
58 62 end
59 63 days
... ... @@ -61,23 +65,80 @@ class GraphCommit
61 65  
62 66 # Add space mark on commit and its parents
63 67 #
64   - # @param [Fixnum] space (row on the graph) to be set
  68 + # @param [GraphCommit] the commit object.
  69 + # @param [Hash<String,GraphCommit>] map of commits
  70 + def self.place_chain(commit, map, parent_time = nil)
  71 + leaves = take_left_leaves(commit, map)
  72 + if leaves.empty? then
  73 + return
  74 + end
  75 + space = find_free_space(leaves.last.time..leaves.first.time)
  76 + leaves.each{|l| l.space = space}
  77 + # and mark it as reserved
  78 + min_time = leaves.last.time
  79 + parents = leaves.last.parents.collect
  80 + parents.each do |p|
  81 + if map.include? p.id then
  82 + parent = map[p.id]
  83 + if parent.time < min_time then
  84 + min_time = parent.time
  85 + end
  86 + end
  87 + end
  88 + if parent_time.nil? then
  89 + max_time = leaves.first.time
  90 + else
  91 + max_time = parent_time - 1
  92 + end
  93 + mark_reserved(min_time..max_time, space)
  94 + # Visit branching chains
  95 + leaves.each do |l|
  96 + parents = l.parents.collect
  97 + .select{|p| map.include? p.id and map[p.id].space == 0}
  98 + for p in parents
  99 + place_chain(map[p.id], map, l.time)
  100 + end
  101 + end
  102 + end
  103 +
  104 + def self.mark_reserved(time_range, space)
  105 + for day in time_range
  106 + @_reserved[day].push(space)
  107 + end
  108 + end
  109 +
  110 + def self.find_free_space(time_range)
  111 + reserved = []
  112 + for day in time_range
  113 + reserved += @_reserved[day]
  114 + end
  115 + space = 1
  116 + while reserved.include? space do
  117 + space += 1
  118 + end
  119 + space
  120 + end
  121 +
  122 + # Takes most left subtree branch of commits
  123 + # which don't have space mark yet.
  124 + #
65 125 # @param [GraphCommit] the commit object.
66 126 # @param [Hash<String,GraphCommit>] map of commits
67 127 #
68   - # @return [Fixnum] max space used.
69   - def self.mark_chain(mark, commit, map)
70   - commit.space = mark if commit.space == 0
71   - m1 = mark - 1
72   - marks = commit.parents.collect do |p|
73   - if map.include? p.id and map[p.id].space == 0 then
74   - mark_chain(m1 += 1, map[p.id],map)
  128 + # @return [Array<GraphCommit>] list of branch commits
  129 + def self.take_left_leaves(commit, map)
  130 + leaves = []
  131 + leaves.push(commit) if commit.space == 0
  132 + while true
  133 + parent = commit.parents.collect
  134 + .select{|p| map.include? p.id and map[p.id].space == 0}
  135 + if parent.count == 0 then
  136 + return leaves
75 137 else
76   - m1 + 1
  138 + commit = map[parent.first.id]
  139 + leaves.push(commit)
77 140 end
78 141 end
79   - marks << mark
80   - marks.compact.max
81 142 end
82 143  
83 144  
... ...
vendor/assets/javascripts/branch-graph.js
... ... @@ -79,11 +79,11 @@ function branchGraph(holder) {
79 79 .attr({stroke: colors[c.space], "stroke-width": 2});
80 80  
81 81 } else if (c.space < commits[i].space) {
82   - r.path(["M", x - 5, y + .0001, "l-5-2,0,4,5,-2C",x-5,y,x -17, y+2, x -20, y-10,"L", cx,y-10,cx , cy])
  82 + r.path(["M", x - 5, y + .0001, "l-5-2,0,4,5,-2C", x - 5, y, x - 17, y + 2, x - 20, y - 5, "L", cx, y - 5, cx, cy])
83 83 .attr({stroke: colors[commits[i].space], "stroke-width": 2});
84 84 } else {
85   - r.path(["M", x-5, y, "l-5-2,0,4,5,-2C",x-5,y,x -17, y-2, x -20, y+10,"L", cx,y+10,cx , cy])
86   - .attr({stroke: colors[commits[i].space], "stroke-width": 2});
  85 + r.path(["M", x - 3, y + 6, "l-4,3,4,2,0,-5L", x - 10, y + 20, "L", x - 10, cy, cx, cy])
  86 + .attr({stroke: colors[c.space], "stroke-width": 2});
87 87 }
88 88 }
89 89 }
... ...