Skip to main content

An orthogonal layout algorithm, using TSM approach

Project description

Introduction

An implementation of orthogonal drawing algorithm in Python

Main idea comes from A Generic Framework for the Topology-Shape-Metrics Based Layout

How to run code

Install requirements

pip install -r requirements.txt

Usage

# in root dir
import networkx as nx
from tsmpy import TSM
from matplotlib import pyplot as plt

G = nx.Graph(nx.read_gml("test/inputs/case2.gml"))

# initial layout, it will be converted to an embedding
pos = {node: eval(node) for node in G}

# pos is an optional, if pos is None, embedding will be given by nx.check_planarity

# use linear programming to solve minimum cost flow program
tsm = TSM(G, pos)

# or use nx.min_cost_flow to solve minimum cost flow program
# it is faster but produces worse result
# tsm = TSM(G, pos, uselp=False)

tsm.display()
plt.savefig("test/outputs/case2.lp.svg")
plt.close()

Example

case1 case2
case1 case2
bend case grid case
bend grid

Run tests

# show help
python test.py -h

# run all tests
python test.py

# run all tests in TestGML
python test.py TestGML

Playground

Try editing original case2 graph with yed

Requirements for input graph

  • Planar
  • Connected
  • Max node degree is no more than 4
  • No selfloop

Features

  • Using linear programing to solve minimum-cost flow problem, to reduce number of bends

TODO

  • Cleaner code
  • More comments
  • Fix overlay
  • Support node degree > 4
  • Support cut-edges

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tsmpy-0.9.3.tar.gz (12.9 kB view hashes)

Uploaded Source

Built Distribution

tsmpy-0.9.3-py3-none-any.whl (23.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page