Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
graph_drawing
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
graph_drawing
Commits
decaaecb
Commit
decaaecb
authored
Dec 01, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed parent edge centration issue.
parent
35dfadad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
11 deletions
+11
-11
graph.py
graph.py
+10
-10
tests/test_graph.py
tests/test_graph.py
+1
-1
No files found.
graph.py
View file @
decaaecb
...
...
@@ -42,9 +42,9 @@ def generate_graph(root, separator=' ', verbose=False):
# Leaves do not have children and therefore the length of its title is
# the width of the leaf.
if
not
isinstance
(
node
,
Node
):
if
isinstance
(
node
,
Leaf
):
node_width
[
node
]
=
title_len
node_middle
[
node
]
=
int
(
title_len
/
2
)
node_middle
[
node
]
=
int
(
(
title_len
-
1
)
/
2
)
return
title_len
node_len
=
len
(
node
)
...
...
@@ -64,7 +64,7 @@ def generate_graph(root, separator=' ', verbose=False):
middle
+=
max
(
middle_pos
-
int
(
node_len
%
2
==
0
),
0
)
*
separator_len
# Add a separator between each node (thus n - 1 separators).
width
+=
separator_len
*
(
len
(
node
)
-
1
)
width
+=
separator_len
*
(
node_len
-
1
)
# If the title of the node is wider than the sum of its children, the
# title's width should be used.
...
...
@@ -80,7 +80,7 @@ def generate_graph(root, separator=' ', verbose=False):
return
width
def
format_lines
(
node
):
if
not
isinstance
(
node
,
Node
):
if
isinstance
(
node
,
Leaf
):
# Leaf titles do not need to be centered, since the parent will
# center those lines. And if there are no parents, the entire graph
# consists of a single leaf, so in that case there still is no
...
...
@@ -171,7 +171,7 @@ def generate_graph(root, separator=' ', verbose=False):
if
i
<
middle_node
:
marker
=
(
left_sign
if
i
==
0
else
tsplit_dn_sign
)
edge_line
+=
center_text
(
marker
,
box_widths
[
i
],
middle
=
0
,
middle
=
node_middle
[
child
]
,
right
=
dash_sign
)
else
:
if
i
==
node_len
-
1
:
...
...
@@ -180,7 +180,7 @@ def generate_graph(root, separator=' ', verbose=False):
marker
=
tsplit_dn_sign
edge_line
+=
center_text
(
marker
,
box_widths
[
i
],
middle
=
0
,
middle
=
node_middle
[
child
]
,
left
=
dash_sign
)
try
:
...
...
@@ -200,10 +200,10 @@ def generate_graph(root, separator=' ', verbose=False):
calculate_node_sizes
(
root
)
#if verbose:
#
print '------- node_{width,middle} ---------'
#
for node, width in node_width.iteritems():
#
print node.title(), 'width:', width, 'middle:', node_middle[node]
if
verbose
:
# pragma: nocover
print
'------- node_{width,middle} ---------'
for
node
,
width
in
node_width
.
iteritems
():
print
node
.
title
(),
'width:'
,
width
,
'middle:'
,
node_middle
[
node
]
lines
=
format_lines
(
root
)
...
...
tests/test_graph.py
View file @
decaaecb
...
...
@@ -157,7 +157,7 @@ class TestGraph(unittest.TestCase):
root
=
Node
(
'+'
,
Node
(
'+'
,
Node
(
'+'
,
ac
,
ad
),
bc
),
bd
)
g
=
generate_graph
(
root
,
verbose
=
True
)
g
=
generate_graph
(
root
)
self
.
assertEqualGraphs
(
g
,
"""
+
╭───┴─╮
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment