Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
graph-tool
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
43
Issues
43
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tiago Peixoto
graph-tool
Commits
627015f1
Commit
627015f1
authored
Jun 14, 2015
by
Tiago Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
graph_draw(): honor float values passed to 'fit_view' as described in documentation
parent
8664f7f2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
9 deletions
+19
-9
src/graph_tool/draw/cairo_draw.py
src/graph_tool/draw/cairo_draw.py
+12
-6
src/graph_tool/draw/gtk_draw.py
src/graph_tool/draw/gtk_draw.py
+7
-3
No files found.
src/graph_tool/draw/cairo_draw.py
View file @
627015f1
...
...
@@ -504,6 +504,7 @@ def cairo_draw(g, pos, cr, vprops=None, eprops=None, vorder=None, eorder=None,
cr
.
scale
(
output_size
[
0
]
/
w
,
output_size
[
1
]
/
h
)
cr
.
translate
(
-
x
,
-
y
)
except
TypeError
:
pad
=
fit_view
if
fit_view
!=
True
else
0.95
offset
,
zoom
=
fit_to_view
(
g
,
pos
,
output_size
,
vprops
.
get
(
"size"
,
_vdefaults
[
"size"
]),
vprops
.
get
(
"pen_width"
,
_vdefaults
[
"pen_width"
]),
...
...
@@ -512,7 +513,7 @@ def cairo_draw(g, pos, cr, vprops=None, eprops=None, vorder=None, eorder=None,
_vdefaults
[
"font_family"
]),
vprops
.
get
(
"font_size"
,
_vdefaults
[
"font_size"
]),
cr
)
pad
,
cr
)
cr
.
translate
(
offset
[
0
],
offset
[
1
])
if
not
isinstance
(
fit_view
,
bool
):
zoom
/=
fit_view
...
...
@@ -590,7 +591,8 @@ def auto_colors(g, bg, pos, back):
def
graph_draw
(
g
,
pos
=
None
,
vprops
=
None
,
eprops
=
None
,
vorder
=
None
,
eorder
=
None
,
nodesfirst
=
False
,
output_size
=
(
600
,
600
),
fit_view
=
True
,
inline
=
is_draw_inline
,
mplfig
=
None
,
output
=
None
,
fmt
=
"auto"
,
**
kwargs
):
inline
=
is_draw_inline
,
mplfig
=
None
,
output
=
None
,
fmt
=
"auto"
,
**
kwargs
):
r
"""Draw a graph to screen or to a file using :mod:`cairo`.
Parameters
...
...
@@ -935,6 +937,9 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None,
b
,
t
=
y
.
a
.
min
(),
y
.
a
.
max
()
w
=
r
-
l
h
=
t
-
b
if
fit_view
!=
True
:
w
*=
float
(
fit_view
)
h
*=
float
(
fit_view
)
ax
.
set_xlim
(
l
-
w
*
.
1
,
r
+
w
*
.
1
)
ax
.
set_ylim
(
b
-
h
*
.
1
,
t
+
h
*
.
1
)
...
...
@@ -958,8 +963,9 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None,
if
isinstance
(
val
,
PropertyMap
):
eprops
[
p
]
=
_convert
(
edge_attrs
.
__dict__
[
p
],
val
,
kwargs
.
get
(
"ecmap"
,
default_cm
))
fit_area
=
fit_view
if
fit_view
!=
True
else
0.95
return
interactive_window
(
g
,
pos
,
vprops
,
eprops
,
vorder
,
eorder
,
nodesfirst
,
**
kwargs
)
nodesfirst
,
fit_area
=
fit_area
,
**
kwargs
)
else
:
if
isinstance
(
output
,
str
):
out
,
auto_fmt
=
open_file
(
output
,
mode
=
"wb"
)
...
...
@@ -993,6 +999,7 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None,
x
,
y
,
w
,
h
=
fit_view
offset
,
zoom
=
[
0
,
0
],
1
except
TypeError
:
pad
=
fit_view
if
fit_view
!=
True
else
0.95
offset
,
zoom
=
fit_to_view
(
g
,
pos
,
output_size
,
vprops
[
"size"
],
vprops
[
"pen_width"
],
None
,
vprops
.
get
(
"text"
,
None
),
...
...
@@ -1000,7 +1007,7 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None,
_vdefaults
[
"font_family"
]),
vprops
.
get
(
"font_size"
,
_vdefaults
[
"font_size"
]),
cr
)
pad
,
cr
)
fit_view
=
False
else
:
offset
,
zoom
=
[
0
,
0
],
1
...
...
@@ -1155,7 +1162,7 @@ def get_bb(g, pos, size, pen_width, size_scale=1, text=None, font_family=None,
def
fit_to_view
(
g
,
pos
,
geometry
,
size
,
pen_width
,
M
=
None
,
text
=
None
,
font_family
=
None
,
font_size
=
None
,
cr
=
None
):
font_family
=
None
,
font_size
=
None
,
pad
=
0.95
,
cr
=
None
):
if
g
.
num_vertices
()
==
0
:
return
[
0
,
0
],
1
if
M
is
not
None
:
...
...
@@ -1187,7 +1194,6 @@ def fit_to_view(g, pos, geometry, size, pen_width, M=None, text=None,
zoom_x
=
1
if
np
.
isnan
(
zoom_y
)
or
np
.
isinf
(
zoom_y
)
or
zoom_y
==
0
:
zoom_y
=
1
pad
=
0.95
zoom
=
min
(
zoom_x
,
zoom_y
)
*
pad
empty_x
=
(
geometry
[
0
]
-
sum
(
x_delta
))
-
dx
*
zoom
empty_y
=
(
geometry
[
1
]
-
sum
(
y_delta
))
-
dy
*
zoom
...
...
src/graph_tool/draw/gtk_draw.py
View file @
627015f1
...
...
@@ -130,8 +130,8 @@ class GraphWidget(Gtk.DrawingArea):
def
__init__
(
self
,
g
,
pos
,
vprops
=
None
,
eprops
=
None
,
vorder
=
None
,
eorder
=
None
,
nodesfirst
=
False
,
update_layout
=
False
,
layout_K
=
1.
,
multilevel
=
False
,
display_props
=
None
,
display_props_size
=
11
,
bg_color
=
None
,
layout_callback
=
None
,
key_press_callback
=
None
,
**
kwargs
):
display_props_size
=
11
,
fit_area
=
0.95
,
bg_color
=
None
,
layout_callback
=
None
,
key_press_callback
=
None
,
**
kwargs
):
r
"""Interactive GTK+ widget displaying a given graph.
Parameters
...
...
@@ -163,8 +163,10 @@ class GraphWidget(Gtk.DrawingArea):
Parameter ``multilevel`` passed to :func:`~graph_tool.draw.sfdp_layout`.
display_props : list of :class:`~graph_tool.PropertyMap` instances (optional, default: ``None``)
List of properties to be displayed when the mouse passes over a vertex.
display_props_size : float (optional, default: ``11``)
display_props_size : float (optional, default: ``11
.
``)
Font size used to display the vertex properties.
fit_area : float (optional, default: ``.95``)
Fraction of the drawing area to fit the graph initially.
bg_color : str or sequence (optional, default: ``None``)
Background color. The default is white.
layout_callback : function (optional, default: ``Node``)
...
...
@@ -262,6 +264,7 @@ class GraphWidget(Gtk.DrawingArea):
self
.
drag_begin
=
None
self
.
moved_picked
=
False
self
.
vertex_matrix
=
None
self
.
pad
=
fit_area
self
.
display_prop
=
g
.
vertex_index
if
display_props
is
None
\
else
display_props
...
...
@@ -620,6 +623,7 @@ class GraphWidget(Gtk.DrawingArea):
_vdefaults
[
"font_family"
]),
self
.
vprops
.
get
(
"font_size"
,
_vdefaults
[
"font_size"
]),
self
.
pad
,
cr
)
m
=
cairo
.
Matrix
()
m
.
translate
(
offset
[
0
]
+
ox
,
offset
[
1
]
+
oy
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment