Skip to content

Commit 99e6c88

Browse files
Calculate arrows in a smarter way
1 parent cfd7aca commit 99e6c88

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

git_story/git_story.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -140,35 +140,37 @@ def parseCommits(self, commit, i, prevCircle, toFadeOut):
140140
isNewCommit = commit.hexsha not in self.drawnCommits
141141

142142
if ( not self.args.reverse ):
143-
if ( not offset and isNewCommit ):
144-
arrow = Arrow(start=RIGHT, end=LEFT, color=self.fontColor).next_to(circle, LEFT, buff=0)
145-
length = 1
146-
elif ( offset and isNewCommit ):
147-
arrow = Arrow(end=prevCircle.get_center(), start=circle.get_center(), color=self.fontColor)
148-
length = numpy.linalg.norm(circle.get_center()-prevCircle.get_center())-3
149-
elif ( offset and not isNewCommit ):
150-
arrow = Arrow(end=prevCircle.get_center(), start=self.drawnCommits[commit.hexsha].get_center(), color=self.fontColor)
151-
length = numpy.linalg.norm(self.drawnCommits[commit.hexsha].get_center()-prevCircle.get_center())-3
152-
elif ( not offset and not isNewCommit ):
153-
arrow = Arrow(end=prevCircle.get_center(), start=self.drawnCommits[commit.hexsha].get_center(), color=self.fontColor)
154-
length = numpy.linalg.norm(self.drawnCommits[commit.hexsha].get_center()-prevCircle.get_center())-3
143+
if ( isNewCommit ):
144+
start = circle.get_center()
145+
end = prevCircle.get_center() if prevCircle else LEFT
146+
else:
147+
start = self.drawnCommits[commit.hexsha].get_center()
148+
end = prevCircle.get_center()
155149

156150
else:
157-
if ( not offset and isNewCommit ):
158-
arrow = Arrow(start=LEFT, end=RIGHT, color=self.fontColor).next_to(circle, LEFT, buff=0)
159-
length = 1
160-
elif ( offset and isNewCommit ):
161-
arrow = Arrow(start=prevCircle.get_center(), end=circle.get_center(), color=self.fontColor)
162-
length = numpy.linalg.norm(prevCircle.get_center()-circle.get_center())-3
163-
elif ( offset and not isNewCommit ):
164-
arrow = Arrow(start=prevCircle.get_center(), end=self.drawnCommits[commit.hexsha].get_center(), color=self.fontColor)
165-
length = numpy.linalg.norm(prevCircle.get_center()-self.drawnCommits[commit.hexsha].get_center())-3
166-
elif ( not offset and not isNewCommit ):
167-
arrow = Arrow(start=prevCircle.get_center(), end=self.drawnCommits[commit.hexsha].get_center(), color=self.fontColor)
168-
length = numpy.linalg.norm(prevCircle.get_center()-self.drawnCommits[commit.hexsha].get_center())-3
169-
151+
if ( isNewCommit ):
152+
start = prevCircle.get_center() if prevCircle else LEFT
153+
end = circle.get_center()
154+
else:
155+
start = prevCircle.get_center()
156+
end = self.drawnCommits[commit.hexsha].get_center()
157+
158+
arrow = Arrow(start, end, color=self.fontColor)
159+
length = numpy.linalg.norm(start-end) - ( 1.5 if start[1] == end[1] else 3 )
170160
arrow.set_length(length)
171161

162+
angle = arrow.get_angle()
163+
lineRect = Rectangle(height=0.1, width=length, color="#123456").move_to(arrow.get_center()).rotate(angle)
164+
165+
for commitCircle in self.drawnCommits.values():
166+
inter = Intersection(lineRect, commitCircle)
167+
if ( inter.has_points() ):
168+
arrow = CurvedArrow(start, end)
169+
if ( start[1] == end[1] ):
170+
arrow.shift(UP*1.25)
171+
if ( start[0] < end[0] and start[1] == end[1] ):
172+
arrow.flip(RIGHT).shift(UP)
173+
172174
commitId = Text(commit.hexsha[0:6], font="Monospace", font_size=20, color=self.fontColor).next_to(circle, UP)
173175

174176
commitMessage = commit.message[:40].replace("\n", " ")

0 commit comments

Comments
 (0)