Commit 26069101 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[gui] Layouts: Fix typos; add doc

parent 12cf18f9
......@@ -41,13 +41,40 @@
"""
Layouts are performed by a visitor of the chart model
"""
import sys
from string import atof
import pygraphviz as pgv
import cadbiom.commons as cm
LOGGER = cm.logger()
class LayoutVisitor(object):
"""
Visitor used to do a gt graph layout
"""Visitor used to do a gt graph layout
Available layouts::
- dot - "hierarchical" or layered drawings of directed graphs.
This is the default tool to use if edges have directionality.
- neato - "spring model'' layouts.
This is the default tool to use if the graph is not too large
(about 100 nodes) and you don't know anything else about it.
Neato attempts to minimize a global energy function, which is equivalent
to statistical multi-dimensional scaling.
- fdp - "spring model'' layouts similar to those of neato, but does
this by reducing forces rather than working with energy.
- sfdp - multiscale version of fdp for the layout of large graphs.
- twopi - radial layouts, after Graham Wills 97.
Nodes are placed on concentric circles depending their distance from a
given root node.
- circo - circular layout, after Six and Tollis 99, Kauffman and Wiese 02.
This is suitable for certain diagrams of multiple cyclic structures,
such as certain telecommunications networks.
"""
def __init__(self, view, layout_style):
self.view = view
......@@ -128,20 +155,24 @@ class LayoutVisitor(object):
elif layout_style == 'circo':
agraph.layout(prog='circo')
else:
print 'BUG IN MACRO LAYOUT!!'
sys.exit(1)
LOGGER.error(
"LayoutVisitor::visit_cmacro_node: Unknow layout: %s",
layout_style
)
exit(1)
# change coordinates
# bounding box for ratios
bbox = pgv.graphviz.agget(agraph.handle, 'bb')
bbox = bbox.split(',')
xmin = atof(bbox[0])
xmax = atof(bbox[2])
ymin = atof(bbox[1])
ymax = atof(bbox[3])
xmin = float(bbox[0])
xmax = float(bbox[2])
ymin = float(bbox[1])
ymax = float(bbox[3])
#adjust graphic window
view = self.view
cond = ((xmax - xmin) / 3.0 > view.draw_width)
cond = cond or ((xmax - xmin) / 3.0 < view.draw_width / 2.0)
cond = ((xmax - xmin) / 3.0 > view.draw_width)
cond = cond or ((xmax - xmin) / 3.0 < view.draw_width / 2.0)
if cond:
view.draw_width = min(int((xmax - xmin)/3.0), 10400) # 31200 max
view.draw_width = max(1300, view.draw_width)
......@@ -157,19 +188,23 @@ class LayoutVisitor(object):
gwidth = 1.0
gheight = 1.0 # virtual window for the macro node
if xmin == xmax or ymin == ymax:
# problem TODO
sys.exit(1)
pass
LOGGER.error(
"LayoutVisitor::visit_cmacro_node: Coordinates consistency: "
"x:(%s vs %s); y:(%s vs %s)",
xmin, xmax,
ymin, ymax,
)
exit(1)
x_ratio = gwidth/(xmax-xmin)
y_ratio = gheight/(ymax-ymin)
# changing coordinates
for node in agraph.nodes():
pos = node.attr['pos'].split(',')
cnn = node_dict[node]
xcoord = atof(pos[0]) * x_ratio
ycoord = atof(pos[1]) * y_ratio
xcoord = float(pos[0]) * x_ratio
ycoord = float(pos[1]) * y_ratio
cnn.set_layout_coordinates(xcoord, ycoord)
return
def visit_ctop_node(self, node):
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment