tsmpy
is a Python implementation of an orthogonal layout algorithm based on the Topology-Shape-Metrics (TSM) approach. The algorithm is inspired by A Generic Framework for the Topology-Shape-Metrics Based Layout.
pip install -r requirements.txt
import networkx as nx
from matplotlib import pyplot as plt
from tsmpy import TSM
# Load a planar graph from the test data
G = nx.Graph(nx.read_gml("test/inputs/case2.gml"))
# Optional: provide an initial embedding
pos = {node: eval(node) for node in G}
# Solve the minimum cost flow problem using linear programming
tsm = TSM(G, pos)
# tsm = TSM(G, pos, uselp=False) # use networkx.min_cost_flow instead
# Display and save the layout
tsm.display()
plt.savefig("test/outputs/case2.lp.svg")
plt.close()
case1 | case2 |
---|---|
bend case | grid case |
---|---|
# show help
python test.py -h
# run all tests
python test.py
# run all tests in TestGML
python test.py TestGML
Try editing the original case2
graph with yed.
- Planar
- Connected
- Maximum node degree is 4
- No self-loops
- Linear programming based minimum-cost flow formulation to reduce the number of bends
- Cleaner code
- More comments
- Fix overlay
- Support node degree > 4
- Support cut-edges