Skip to content

Commit

Permalink
dag: prevent tag label overlapping with respect to current DAG orient…
Browse files Browse the repository at this point in the history
…ation

Currently, DAG orientation along x-axis could be easily turned by changing sign
of x_off attribute. So, row allocation algorithm must adapt to current x_off
value during prevention of label overlapping.

Signed-off-by: Efimov Vasily <real@ispras.ru>
  • Loading branch information
laerreal committed Feb 1, 2017
1 parent ef05426 commit dd164d1
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions cola/widgets/dag.py
Expand Up @@ -1606,34 +1606,25 @@ def alloc_cell(self, column, tags):
cell_row = self.frontier[column]

if tags:
# Prevent overlapping with right cells. Do not occupy row if the
# row is occupied by a commit at right side.
for c in range(column + 1, len(self.frontier)):
# Prevent overlapping of tag with cells already allocated a row.
if self.x_off > 0:
can_overlap = list(range(column + 1, self.max_column + 1))
else:
can_overlap = list(range(column - 1, self.min_column - 1, -1))
for c in can_overlap:
frontier = self.frontier[c]
if frontier > cell_row:
cell_row = frontier

# Avoid overlapping with tags of left cells.
# Sorting is a part for column overlapping check optimization.
columns = sorted(range(0, column), key=lambda c: self.frontier[c])
while columns:
# Optimization. Remove columns which cannot contain overlapping
# tags because all its commits are below.
while columns:
c = columns[0]
if self.frontier[c] <= cell_row:
# The column cannot overlap.
columns.pop(0)
else:
# This column may overlap because the frontier is above.
# Consequent columns may overlap too because columns
# sorting criteria.
break

for c in columns:
# Avoid overlapping with tags of commits at cell_row.
if self.x_off > 0:
can_overlap = list(range(self.min_column, column))
else:
can_overlap = list(range(self.max_column, column, -1))
for cell_row in count(cell_row):
for c in can_overlap:
if (c, cell_row) in self.tagged_cells:
# Overlapping. Try next row.
cell_row += 1
break
else:
# No overlapping was found.
Expand Down

0 comments on commit dd164d1

Please sign in to comment.