Skip to content

Commit

Permalink
fix: multi edges between two nodes by replacing DiGraph with MultiDiG…
Browse files Browse the repository at this point in the history
…raph for dot file (#17)
  • Loading branch information
iwatake2222 authored Nov 2, 2024
1 parent d965aea commit cbc7d7e
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
- uses: actions/checkout@v4
- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.13"
- name: Install dependencies
run: |
sudo apt update
Expand All @@ -40,7 +40,7 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Lint with pylint
run: |
pylint ./src/dear_ros_node_viewer --disable=E0401
pylint ./src/dear_ros_node_viewer --disable=E0401,W1203,C0301
- name: Test with pytest
run: |
pytest --doctest-modules -v --cov=./src/dear_ros_node_viewer
4 changes: 2 additions & 2 deletions src/dear_ros_node_viewer/dot2networkx.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
def dot2networkx_nodeonly(graph_org: nx.classes.digraph.DiGraph,
ignore_unconnected=True) -> nx.classes.digraph.DiGraph:
"""Create NetworkX Object from dot graph file (nodes only) by rqt_graph"""
graph = nx.DiGraph()
graph = nx.MultiDiGraph()
for node_org in graph_org.nodes:
if 'label' not in graph_org.nodes[node_org]:
continue
Expand Down Expand Up @@ -82,7 +82,7 @@ def dot2networkx_nodetopic(graph_org: nx.classes.digraph.DiGraph) -> nx.classes.

def dot2networkx(filename: str, ignore_unconnected=True) -> nx.classes.digraph.DiGraph:
"""Function to create NetworkX object from dot graph file (rosgraph.dot)"""
graph_org = nx.DiGraph(nx.nx_pydot.read_dot(filename))
graph_org = nx.MultiDiGraph(nx.nx_pydot.read_dot(filename))

is_node_only = True
for node_org in graph_org.nodes:
Expand Down
2 changes: 1 addition & 1 deletion src/dear_ros_node_viewer/graph_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def place_node(graph: nx.classes.digraph.DiGraph, group_name: str, prog: str = '
Dictionary of normalized positions keyed by node.
"""

graph_modified = nx.DiGraph()
graph_modified = nx.MultiDiGraph()
for node_name in graph.nodes:
if group_name in node_name:
graph_modified.add_node(node_name)
Expand Down
2 changes: 1 addition & 1 deletion src/dear_ros_node_viewer/graph_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, app_setting, group_setting):
self.app_setting = app_setting
self.group_setting = group_setting
self.dir = './'
self.graph: nx.DiGraph = nx.DiGraph()
self.graph: nx.DiGraph = nx.MultiDiGraph()
self.caret_path_dict: dict = {}

def load_graph_from_caret(self, filename: str, target_path: str = 'all_graph'):
Expand Down
2 changes: 1 addition & 1 deletion src/dear_ros_node_viewer/graph_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def _make_font_table(self, font_path):
if __name__ == '__main__':
def local_main():
"""main function for this file"""
graph = nx.DiGraph()
graph = nx.MultiDiGraph()
nx.add_path(graph, ['3', '5', '4', '1', '0', '2'])
nx.add_path(graph, ['3', '0', '4', '2', '1', '5'])
layout = nx.spring_layout(graph)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_graph_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


def test_graph_layout():
graph = nx.DiGraph()
graph = nx.MultiDiGraph()
nx.add_path(graph, ['"/3"', '"/5"', '"/4"', '"/1"', '"/0"', '"/2"'])

group_setting = {
Expand Down

0 comments on commit cbc7d7e

Please sign in to comment.