Coder Social home page Coder Social logo

pyyed's Introduction

PyPI PyPI - Downloads

yEd Py

A simple Python library to export networks to yEd.

Is is available from PyPI.

The yEd Graph Editor supports the GraphML (GraphML Primer) file format. This is an open standard based on XML, and is supported by Python libraries such as NetworkX. However, the details of formatting (rather than network topology) are handled by yEd specific extensions to the standard, which are not supported by other libraries.

I therefore wrote this library to provide an easy interface that lets you specify how a graph should look, and generates corresponding graphML that can be opened in yEd.

Usage

The interface is similar to that of NetworkX:

import pyyed

g = pyyed.Graph()

g.add_node('foo', font_family="Zapfino")
g.add_node('foo2', shape="roundrectangle", font_style="bolditalic", underlined_text="true")

g.add_edge('foo1', 'foo2')
g.add_node('abc', font_size="72", height="100", shape_fill="#FFFFFF")

g.add_node('bar', label="Multi\nline\ntext")
g.add_node('foobar', label="""Multi
    Line
    Text!""")

g.add_edge('foo', 'foo1', label="EDGE!", width="3.0", color="#0000FF", 
               arrowhead="white_diamond", arrowfoot="standard", line_type="dotted")

print(g.get_graph())

# To write to file:
with open('test_graph.graphml', 'w') as fp:
    fp.write(g.get_graph())

# Or:
g.write_graph('example.graphml')

# Or, to pretty-print with whitespace:
g.write_graph('pretty_example.graphml', pretty_print=True)

Saving this to a file with a .graphml extension, opening in yEd, applying Tools -> Fit Node to Label and Layout -> One-click layout produces something like the following:

UML

The file examples/demo-uml.py, includes an example UML diagram:

The arrowheads used in UML class diagrams correspond to crows_foot_one_optional (association or dependency), white_delta (inheritance or implementation), white_diamond (aggregation), and diamond (composition).

The line_type is either line or dashed.

Options

Valid node shapes are: "rectangle", "rectangle3d", "roundrectangle", "diamond", "ellipse", "fatarrow", "fatarrow2", "hexagon", "octagon", "parallelogram", "parallelogram2", "star5", "star6", "star6", "star8", "trapezoid", "trapezoid2", "triangle", "trapezoid2", "triangle"

Valid line_types are: "line", "dashed", "dotted", "dashed_dotted"

Valid font_styles are: "plain", "bold", "italic", "bolditalic"

Valid arrow_types are: "none", "standard", "white_delta", "diamond", "white_diamond", "short", "plain", "concave", "concave", "convex", "circle", "transparent_circle", "dash", "skewed_dash", "t_shape", "crows_foot_one_mandatory", "crows_foot_many_mandatory", "crows_foot_many_optional", "crows_foot_many_optional", "crows_foot_one", "crows_foot_many", "crows_foot_optional"

Development

Requirements:

$ pip install pytest

Run the tests:

$ PYTHONPATH=. pytest tests

pyyed's People

Contributors

jamesscottbrown avatar bockor avatar chriskn avatar gcsepregi avatar lundstrj avatar martinus-maximus avatar nakami avatar rcorvino avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.