Skip to content

Commit

Permalink
v0.3.2 - fix edge direction
Browse files Browse the repository at this point in the history
  • Loading branch information
kayjan committed Nov 7, 2022
1 parent 1729d0c commit ca169e5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Work In Progress
- Node: WeightedNode for weighted edge tree implementation.

## [0.3.2] - 2022-11-07
### Added
- Tree Exporter: Fix edge direction error

## [0.3.1] - 2022-11-07
### Added
- Tree Exporter and DAG Exporter: More customizations for Node to dot and DAGNode to dot.
Expand Down Expand Up @@ -35,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Utility Iterators: Tree traversal methods.
- Workflow To Do App: Tree use case with to-do list implementation.

[0.3.2]: https://github.com/kayjan/bigtree/compare/v0.3.1...v0.3.2
[0.3.1]: https://github.com/kayjan/bigtree/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/kayjan/bigtree/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/kayjan/bigtree/compare/v0.1.0...v0.2.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ tree_to_dataframe(
# 3 /a/b/e e b 35
# 4 /a/c c a 60

graph = tree_to_dot(root, rankdir="BT", node_colour="gold")
graph = tree_to_dot(root, node_colour="gold")
graph.write_png("assets/demo.png")
```

Expand Down
Binary file modified assets/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion bigtree/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.3.1"
__version__ = "0.3.2"

from bigtree.dag.construct import dataframe_to_dag, dict_to_dag, list_to_dag
from bigtree.dag.export import dag_to_dot
Expand Down
2 changes: 1 addition & 1 deletion bigtree/tree/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def recursive_create_node_and_edges(parent_name, child_node):
node = pydot.Node(name=child_name, label=child_name, **node_style)
_graph.add_node(node)
if parent_name is not None:
edge = pydot.Edge(child_name, parent_name, **edge_style)
edge = pydot.Edge(parent_name, child_name, **edge_style)
_graph.add_edge(edge)
for child in child_node.children:
recursive_create_node_and_edges(child_name, child)
Expand Down
12 changes: 6 additions & 6 deletions tests/tree/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ class TestTreeToDot:
@staticmethod
def test_tree_to_dot(tree_node):
graph = tree_to_dot(tree_node)
expected = """strict digraph G {\na [label=a];\nb [label=b];\nb -> a;\nd [label=d];\nd -> b;\ne [label=e];\ne -> b;\ng [label=g];\ng -> e;\nh [label=h];\nh -> e;\nc [label=c];\nc -> a;\nf [label=f];\nf -> c;\n}\n"""
expected = """strict digraph G {\nrankdir=TB;\na [label=a];\nb [label=b];\na -> b;\nd [label=d];\nb -> d;\ne [label=e];\nb -> e;\ng [label=g];\ne -> g;\nh [label=h];\ne -> h;\nc [label=c];\na -> c;\nf [label=f];\nc -> f;\n}\n"""
actual = graph.to_string()
graph.write_png("tests/tree.png")
for expected_str in expected.split():
Expand All @@ -709,7 +709,7 @@ def test_tree_to_dot_type_error(dag_node):
@staticmethod
def test_tree_to_dot_directed(tree_node):
graph = tree_to_dot(tree_node, directed=False)
expected = """strict graph G {\na [label=a];\nb [label=b];\nb -- a;\nd [label=d];\nd -- b;\ne [label=e];\ne -- b;\ng [label=g];\ng -- e;\nh [label=h];\nh -- e;\nc [label=c];\nc -- a;\nf [label=f];\nf -- c;\n}\n"""
expected = """strict graph G {\nrankdir=TB;\na [label=a];\nb [label=b];\na -- b;\nd [label=d];\nb -- d;\ne [label=e];\nb -- e;\ng [label=g];\ne -- g;\nh [label=h];\ne -- h;\nc [label=c];\na -- c;\nf [label=f];\nc -- f;\n}\n"""
actual = graph.to_string()
graph.write_png("tests/tree_undirected.png")
for expected_str in expected.split():
Expand All @@ -720,7 +720,7 @@ def test_tree_to_dot_directed(tree_node):
@staticmethod
def test_tree_to_dot_bg_color(tree_node):
graph = tree_to_dot(tree_node, bgcolor="blue")
expected = """strict digraph G {\nbgcolor=blue;\na [label=a];\nb [label=b];\nb -> a;\nd [label=d];\nd -> b;\ne [label=e];\ne -> b;\ng [label=g];\ng -> e;\nh [label=h];\nh -> e;\nc [label=c];\nc -> a;\nf [label=f];\nf -> c;\n}\n"""
expected = """strict digraph G {\nbgcolor=blue;\nrankdir=TB;\na [label=a];\nb [label=b];\na -> b;\nd [label=d];\nb -> d;\ne [label=e];\nb -> e;\ng [label=g];\ne -> g;\nh [label=h];\ne -> h;\nc [label=c];\na -> c;\nf [label=f];\nc -> f;\n}\n"""
actual = graph.to_string()
graph.write_png("tests/tree_bg.png")
for expected_str in expected.split():
Expand All @@ -731,7 +731,7 @@ def test_tree_to_dot_bg_color(tree_node):
@staticmethod
def test_tree_to_dot_fill_color(tree_node):
graph = tree_to_dot(tree_node, node_colour="gold")
expected = """strict digraph G {\na [fillcolor=gold, label=a, style=filled];\nb [fillcolor=gold, label=b, style=filled];\nb -> a;\nd [fillcolor=gold, label=d, style=filled];\nd -> b;\ne [fillcolor=gold, label=e, style=filled];\ne -> b;\ng [fillcolor=gold, label=g, style=filled];\ng -> e;\nh [fillcolor=gold, label=h, style=filled];\nh -> e;\nc [fillcolor=gold, label=c, style=filled];\nc -> a;\nf [fillcolor=gold, label=f, style=filled];\nf -> c;\n}\n"""
expected = """strict digraph G {\nrankdir=TB;\na [fillcolor=gold, label=a, style=filled];\nb [fillcolor=gold, label=b, style=filled];\na -> b;\nd [fillcolor=gold, label=d, style=filled];\nb -> d;\ne [fillcolor=gold, label=e, style=filled];\nb -> e;\ng [fillcolor=gold, label=g, style=filled];\ne -> g;\nh [fillcolor=gold, label=h, style=filled];\ne -> h;\nc [fillcolor=gold, label=c, style=filled];\na -> c;\nf [fillcolor=gold, label=f, style=filled];\nc -> f;\n}\n"""
actual = graph.to_string()
graph.write_png("tests/tree_fill.png")
for expected_str in expected.split():
Expand All @@ -742,7 +742,7 @@ def test_tree_to_dot_fill_color(tree_node):
@staticmethod
def test_tree_to_dot_edge_colour(tree_node):
graph = tree_to_dot(tree_node, edge_colour="red")
expected = """strict digraph G {\na [label=a];\nb [label=b];\nb -> a [color=red];\nd [label=d];\nd -> b [color=red];\ne [label=e];\ne -> b [color=red];\ng [label=g];\ng -> e [color=red];\nh [label=h];\nh -> e [color=red];\nc [label=c];\nc -> a [color=red];\nf [label=f];\nf -> c [color=red];\n}\n"""
expected = """strict digraph G {\nrankdir=TB;\na [label=a];\nb [label=b];\na -> b [color=red];\nd [label=d];\nb -> d [color=red];\ne [label=e];\nb -> e [color=red];\ng [label=g];\ne -> g [color=red];\nh [label=h];\ne -> h [color=red];\nc [label=c];\na -> c [color=red];\nf [label=f];\nc -> f [color=red];\n}\n"""
actual = graph.to_string()
graph.write_png("tests/tree_edge.png")
for expected_str in expected.split():
Expand All @@ -753,7 +753,7 @@ def test_tree_to_dot_edge_colour(tree_node):
@staticmethod
def test_tree_to_dot_node_attr(tree_node_style):
graph = tree_to_dot(tree_node_style, node_attr="node_style")
expected = """strict digraph G {\na [fillcolor=gold, label=a, style=filled];\nb [fillcolor=blue, label=b, style=filled];\nb -> a;\nd [fillcolor=green, label=d, style=filled];\nd -> b;\ng [fillcolor=red, label=g, style=filled];\ng -> d;\ne [fillcolor=green, label=e, style=filled];\ne -> b;\nh [fillcolor=red, label=h, style=filled];\nh -> e;\nc [fillcolor=blue, label=c, style=filled];\nc -> a;\nf [fillcolor=green, label=f, style=filled];\nf -> c;\n}\n"""
expected = """strict digraph G {\nrankdir=TB;\na [fillcolor=gold, label=a, style=filled];\nb [fillcolor=blue, label=b, style=filled];\na -> b;\nd [fillcolor=green, label=d, style=filled];\nb -> d;\ng [fillcolor=red, label=g, style=filled];\nd -> g;\ne [fillcolor=green, label=e, style=filled];\nb -> e;\nh [fillcolor=red, label=h, style=filled];\ne -> h;\nc [fillcolor=blue, label=c, style=filled];\na -> c;\nf [fillcolor=green, label=f, style=filled];\nc -> f;\n}\n"""
actual = graph.to_string()
graph.write_png("tests/tree_style.png")
for expected_str in expected.split():
Expand Down

0 comments on commit ca169e5

Please sign in to comment.