Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to add PolyLineEdges with multiple points #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
__pycache__/
.cache/
.DS_Store
notes.txt
*.graphml
*.xml
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
4 changes: 4 additions & 0 deletions .vs/PythonSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"TestFramework": "Pytest",
"Interpreter": "Global|PythonCore|3.9"
}
10 changes: 10 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ExpandedNodes": [
"",
"\\examples",
"\\pyyed",
"\\tests"
],
"SelectedNode": "\\pyyed\\__init__.py",
"PreviewInSolutionExplorer": false
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file added .vs/pyyed/v17/.suo
Binary file not shown.
Binary file added .vs/slnx.sqlite
Binary file not shown.
51 changes: 51 additions & 0 deletions examples/demo-edge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import pyyed

g = pyyed.Graph()

g.add_node('foo', font_family="Zapfino",x=0,y="50",width=100)
n2=g.add_node('foo2', shape="roundrectangle", font_style="bolditalic",
underlined_text="true",x="100",y="100",width='100',shape_fill='#ffff00')
n3=g.add_node('n3', shape="roundrectangle", font_style="bolditalic",
underlined_text="true",x="300",y=300,width='100',shape_fill='#ff0000')


#get first node
n1=g.nodes['foo']
geom1=n1.geom
w1=float(geom1['width'])
#x1=float(geom1['x'])
x1=0
y1=float(geom1['y'])


#add edge simple
g.add_edge('n3', 'foo2',color='#ff0000')
g.add_edge('foo', 'foo2',sx=50,sy=5,color='#3366ff')

#add edge with one point
geom2=n2.geom
w2=float(geom2['width'])
x2=float(geom2['x'])
y2=float(geom2['y'])
paras={"sx": "0",
"sy": "0.7",
"tx": str(-w1/2),
"ty":0,
'points':((-w1/2+x1,y2)),
'color':'#3366ff'}
g.add_edge('foo2', 'foo',**paras)

#add egdge with two points
g.add_edge('n3', 'foo',sx=10,sy=2,tx=3,ty=9,points=((400,300),(400,50)),arrowhead="diamond", arrowfoot="circle")

#print(g.get_graph())


# Write the graph to a GraphML file
filename="examples/demo-edge.graphml"
with open(filename, "w") as f:
f.write(g.get_graph())
# Write the graph to a Xml file
with open('examples/demo-edge.xml', "w") as f:
f.write(g.get_graph())
print(f"Graph has been saved as {filename}")
13 changes: 13 additions & 0 deletions pyyed.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Metadata-Version: 2.1
Name: pyyed
Version: 1.5.1
Summary: A simple Python library to export graphs to the yEd graph editor
Home-page: https://github.com/jamesscottbrown/pyyed
Author: James Scott-Brown
Author-email: [email protected]
License: UNKNOWN
Platform: UNKNOWN
License-File: LICENSE

UNKNOWN

9 changes: 9 additions & 0 deletions pyyed.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
LICENSE
README.md
setup.py
pyyed/__init__.py
pyyed.egg-info/PKG-INFO
pyyed.egg-info/SOURCES.txt
pyyed.egg-info/dependency_links.txt
pyyed.egg-info/top_level.txt
tests/test_pyyed.py
1 change: 1 addition & 0 deletions pyyed.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions pyyed.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyyed
29 changes: 27 additions & 2 deletions pyyed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import xml.etree.ElementTree as ET
from xml.dom import minidom


# Shared parameters
line_types = ["line", "dashed", "dotted", "dashed_dotted"]
font_styles = ["plain", "bold", "italic", "bolditalic"]
Expand Down Expand Up @@ -426,7 +427,8 @@ def convert(self):
shape = ET.SubElement(data, "y:" + self.node_type)

if self.geom:
ET.SubElement(shape, "y:Geometry", **self.geom)
str_geom = {key: str(value) for key, value in self.geom.items()}
ET.SubElement(shape, "y:Geometry", **str_geom)
# <y:Geometry height="30.0" width="30.0" x="475.0" y="727.0"/>

ET.SubElement(shape, "y:Fill", color=self.shape_fill,
Expand Down Expand Up @@ -485,7 +487,7 @@ def __init__(self, node1, node2, label=None, arrowhead="standard", arrowfoot="no
color="#000000", line_type="line", width="1.0", edge_id="",
label_background_color="", label_border_color="",
source_label=None, target_label=None,
custom_properties=None, description="", url=""):
custom_properties=None, description="", url="",sx=0,sy=0,tx=0,ty=0,points=()):
self.node1 = node1
self.node2 = node2

Expand Down Expand Up @@ -522,6 +524,17 @@ def __init__(self, node1, node2, label=None, arrowhead="standard", arrowfoot="no
self.description = description
self.url = url

self.sx=sx
self.sy=sy
self.tx=tx
self.ty=ty
if not isinstance(points,(list,tuple)):
print(f"invalid parameter points -> {type(points)}")
self.points=()
else:
self.points=points


# Handle Edge Custom Properties
for name, definition in Edge.custom_properties_defs.items():
if custom_properties:
Expand Down Expand Up @@ -561,6 +574,18 @@ def convert(self):
description_edge = ET.SubElement(edge, "data", key="description_edge")
description_edge.text = self.description

#process Polyline Edge Points
pts=self.points
yPath = ET.SubElement(pl, "y:Path", sx=str(self.sx),sy=str(self.sy),tx=str(self.tx),ty=str(self.ty)) #convert to string to allow float and integer values

if isinstance(pts, tuple) and len(pts) == 2 and all(isinstance(i, (int, float)) for i in pts): #Single Coordinates
x, y = pts
pt = ET.SubElement(yPath, "y:Point",x=str(x),y=str(y)) #absolute coordinates
elif isinstance(pts, (list, tuple)) and all(isinstance(item, tuple) and len(item) == 2 for item in pts):# Check if the parameter is a list or tuple of two-dimensional tuples
for x, y in pts:
pt = ET.SubElement(yPath, "y:Point",x=str(x),y=str(y)) #absolute coordinates


# Edge Custom Properties
for name, definition in Edge.custom_properties_defs.items():
edge_custom_prop = ET.SubElement(edge, "data", key=definition.id)
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


setup(name='pyyed',
version='1.5.0',
version='1.5.1',
description='A simple Python library to export graphs to the yEd graph editor',

author='James Scott-Brown',
Expand All @@ -17,3 +17,6 @@

requires=[]
)