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

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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyyed's Issues

Groups in groups

It would be great if this library supported "groups in groups".

Confusing Node Class attribute names

Dear --
In order to be consistent and avoid confusion, please change the "edge_color", "edge_type" and "edge_width" Node Class attribute names to respectively "border_color", "border_type" and "border_width".

import from `networkx`

Hello, I was wondering if it's possible to import a networkx based network into pyyed ...

I'm asking this because, even though networkx has the method nx.write_graphml() when opening that file in yEd, I still need to do all the attributes mapping, for example, to see labels on nodes or edges, or the see color applied.

However, if the network is created from scratch with pyyed, then opening it in yEd is straight forward.

thanks!

custom properties for groups

First of all: Great toolbox, thanks a lot! :)

I´m struggeling with getting custom properties for nodes which are located inside a group?

group.add_node(name, custom_properties={'custom_properties': {'direction' : 'In'}})

is not working as the group has no "custom_properties" by itself.
Is there any workaround for this?

copy paste not modified error in warning

Starting from

if arrowhead not in arrow_types:
is written

        if arrowhead not in arrow_types:
            raise RuntimeWarning("Arrowhead type %s not recognised" % arrowhead)

        self.arrowhead = arrowhead

        if arrowfoot not in arrow_types:
            raise RuntimeWarning("Arrowhead type %s not recognised" % arrowfoot)

        self.arrowfoot = arrowfoot

        if line_type not in line_types:
            raise RuntimeWarning("Edge type %s not recognised" % line_type)

yet it should be

        if arrowhead not in arrow_types:
            raise RuntimeWarning("Arrowhead type %s not recognised" % arrowhead)

        self.arrowhead = arrowhead

        if arrowfoot not in arrow_types:
            raise RuntimeWarning("Arrowfoot type %s not recognised" % arrowfoot)

        self.arrowfoot = arrowfoot

        if line_type not in line_types:
            raise RuntimeWarning("Line type %s not recognised" % line_type)

in other words, Arrowfoot and Line type should be used in the last two warnings!

fix for target_label of Edge.addlabel

Hello, team!

first of all thanks for the great module. In the process of using it, I noticed a small optimization for the code:

        if target_label is not None:
            self.add_label(source_label, model_name="six_pos", model_position="shead", preferred_placement="source_on_edge",
            border_color=label_border_color, background_color = label_background_color)

i would suggest the following changes (target_label and thead):

        if target_label is not None:
            self.add_label(target_label, model_name="six_pos", model_position="thead", preferred_placement="source_on_edge",
            border_color=label_border_color, background_color = label_background_color)

Thanks!

Edge label

Hi,

Great stuff. But to edge label to an edge?
Much appreciated :-)

Br,
Christian

Edge Label Properties (Background/Border)

Hi there!
Loving what this library can do.

Is it possible to add new arguments to the edge properties ...
(Or point me in the direction so that I can figure out how to... Sorry newbie here)

def __init__(self, node1, node2, label="", arrowhead="standard", arrowfoot="none", color="#000000", line_type="line", width="1.0", edge_id=""):

... so we can further manipulate the properties of the edge labels? (Specifically label background fill colour, label border colour)

Many thanks,

Hagen

Invalid Byte 1 of 1-Byte UTF-8 Sequence on Opening .graphml File

I export a .graphml file using

filename = 'A File Name'
with(open(f{filename}.graphml, 'w') as fp:
    fp.write(g.get_graph())

The resulting .graphml file gives me the following error when opened in yEd:

y.H.B.B.a: SAX error: Invalid byte 1 of 1-byte UTF-8 sequence.
	at com.yworks.A.B.G.A.U$H.ā(Unknown Source)
	at com.yworks.A.B.G.A.U.ā(Unknown Source)
	at com.yworks.A.B.G.A.Q.ā(Unknown Source)
	at y.H.G.ā(Unknown Source)
	at y.B.A.M.Đ(Unknown Source)
	at y.B.d.č(Unknown Source)
	at y.B.d.ā(Unknown Source)
	at y.B.d.ă(Unknown Source)
	at com.yworks.A.B.W.ă(Unknown Source)
	at com.yworks.A.B.W.ā(Unknown Source)
	at com.yworks.A.J.P.ā(Unknown Source)
	at com.yworks.A.J.P.ā(Unknown Source)
	at com.yworks.A.J.G.ā(Unknown Source)
	at com.yworks.A.J.G.ą(Unknown Source)
	at com.yworks.A.yEd$3.run(Unknown Source)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 12; Invalid byte 1 of 1-byte UTF-8 sequence.
	at java.xml/com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:262)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
	at com.yworks.A.B.G.A.H.ā(Unknown Source)
	at com.yworks.A.B.G.A.H.ā(Unknown Source)
	... 28 more
Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
	at java.xml/com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:702)
	at java.xml/com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:568)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1904)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.peekChar(XMLEntityScanner.java:508)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2647)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:534)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:246)
	... 31 more

Add support for Entity/Relationship diagram

Currently, pyyed can generate UML diagrams by supporting a set of customizations in generated node object.

How is it possible to generate an entity-relationship diagram where entities are defined by the following XML fragment ?

    <node id="n0">
      <data key="d5"/>
      <data key="d6">
        <y:GenericNode configuration="com.yworks.entityRelationship.big_entity">
          <y:Geometry height="90.0" width="80.0" x="715.0" y="321.0"/>
          <y:Fill color="#E8EEF7" color2="#B7C9E3" transparent="false"/>
          <y:BorderStyle color="#000000" type="line" width="1.0"/>
          <y:NodeLabel alignment="center" autoSizePolicy="content" backgroundColor="#B7C9E3" configuration="com.yworks.entityRelationship.label.name" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasLineColor="false" height="18.701171875" horizontalTextPosition="center" iconTextGap="4" modelName="internal" modelPosition="t" textColor="#000000" verticalTextPosition="bottom" visible="true" width="34.01171875" x="22.994140625" y="4.0">Entity</y:NodeLabel>
          <y:NodeLabel alignment="left" autoSizePolicy="content" configuration="com.yworks.entityRelationship.label.attributes" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="48.103515625" horizontalTextPosition="center" iconTextGap="4" modelName="custom" textColor="#000000" verticalTextPosition="top" visible="true" width="57.3671875" x="2.0" y="30.701171875">attribute 1
attribute 2
attribute 3<y:LabelModel>
              <y:ErdAttributesNodeLabelModel/>
            </y:LabelModel>
            <y:ModelParameter>
              <y:ErdAttributesNodeLabelModelParameter/>
            </y:ModelParameter>
          </y:NodeLabel>
          <y:StyleProperties>
            <y:Property class="java.lang.Boolean" name="y.view.ShadowNodePainter.SHADOW_PAINTING" value="true"/>
          </y:StyleProperties>
        </y:GenericNode>
      </data>
    </node>

As far as I understand pyyed code, I should set the node_type to GenericType (this I can do) and configuration to com.yworks.entityRelationship.big_entity. But how to do that? (I think there is also someting to do for entity name ...

Please add a license

Hello,

in case you are not aware: without stating a license, this code cannot be legally used, modified or shared without explicit permission from the author(s). As it is shared on here, I am assuming that is not the intended legal status?

If it is not, could you please add a license to your project?

I am looking for something like this, but am in a commercial environment (i.e. no grey areas allowed).
Would be really cool if I could make use of it!

Thank you & best regards!

Opt into #hacktoberfest

I want to implement a feature to allow generation of entity-relation diagrams in yED using your library.
Can you add the #hacktoberfest tag in order for that contribution to be marked?

Multiple edges between two nodes

Hi James,
First of all great library, I just started using it and it is very useful.
I am trying to add multiples edges between two nodes, but seems like only the last edge in the sequence is being added, here:

g = pyyed.Graph()
g.add_node('Start', shape_fill="#8bc34a", shape="roundrectangle")
g.add_node('v_node_1', shape_fill="#ffffff", shape="roundrectangle")
g.add_edge('Start', 'v_node_1', label = "A")
g.add_edge('Start', 'v_node_1', label = "B")
g.add_edge('Start', 'v_node_1', label = "C")

The graph generated by the code above only shows edge "C", maybe I am missing something, is there a way to add multiple edges?

Regards

Massimo

custom properties for groups

Hello, great tools.
I want to create groups with custom_properties, but the group class does not accept the custom_properties argument, unlike the node class. Is there a reason for this choice? Is there another way to achieve the same result? If not, is it possible to add this feature? If you are interested, I could submit a working implementation I have done (mostly replicating what you do for nodes).

PolyLineEdge Example

Hello I would like to define the path of the edges as a polyline with your library. In your source code I found a line with the text "Polylineedge", so I assume it is possible. Therefore it would be nice to write an example how to define the Polylinedges points in the function "g.add_edge(...)".

node alredy exist

Hi, when try to run the code and appears this message, what means?

raise RuntimeWarning("Node %s already exists" % node_name)

this is my code:

    for s in self.periodi:
        
        s=yed.add_group(s[2])    
    
    for e in  self.sequence:
        s.add_node(e[0])  
        s.add_edge(e[0],e[1])
   
    
    for h in  self.negative:
        s.add_node(h[0])  
        s.add_edge(h[0],h[1])
    
    
    for j in  self.conteporene:
        s.add_node(j[0]) 
        s.add_edge(j[0],j[1],arrowfoot= "none")

edge between a NODE and a GROUPNODE

yEd in native way permits to create edges between a node and a group node.
The current pyyed group class has unfortunately not this method available.
I would appreciate if it could be implemented or at least investigated.

I have attached a screen shot how it is looking in native yEd.

Cheers,

edge_between_node_and_node-group_constructed_in_yed

Thank you very much indeed

Hello,

I just wanted to reach out and say thanks. I found your repo whilst looking for a quick way to turn my custom raw data into something a bit more visual and your simple, yet very effective, module hit the sweetspot. You saved me hours of work to roll my own and I am grateful.

I'll try to find a solution to the Fit node label and One click layout problem for us.

import pyyed failed...

First, thanks for the tool... excited to try it out.

Unfortunately I can't get off the ground. I'm a bit of a novice, so go easy on me. The following doesn't work.

from pyyed import *

I'm using Python 3 and figured that might be the issue... I eventually got the following to import.

import pytest

Trying either of the following lines of code now fails however...

g = pyyed.Graph()
or
g = pytest.Graph()

Thanks in advance for the help!

Position of edge label

Hi! This is a grate library! Thanks for doing it...

Do you think is possible to add new arguments to ...

def __init__(self, node1, node2, label="", arrowhead="standard", arrowfoot="none",
                 color="#000000", line_type="line", width="1.0", edge_id=""):

... so as to be able to control label position (ie: center) for the edge label?

Thanks!

Lucas

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.