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
40
Issues
40
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
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
23b6457d
Commit
23b6457d
authored
Aug 23, 2020
by
Tiago Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
graph_draw(): add option fit_view_ink
parent
e3c57b27
Pipeline
#713
passed with stage
in 96 minutes and 8 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
11 deletions
+42
-11
src/graph_tool/draw/cairo_draw.py
src/graph_tool/draw/cairo_draw.py
+22
-7
src/graph_tool/draw/gtk_draw.py
src/graph_tool/draw/gtk_draw.py
+20
-4
No files found.
src/graph_tool/draw/cairo_draw.py
View file @
23b6457d
...
...
@@ -730,9 +730,9 @@ 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
,
adjust_aspect
=
True
,
ink_scale
=
1
,
inline
=
is_draw_inline
,
inline
_scale
=
2
,
mplfig
=
None
,
output
=
None
,
fmt
=
"auto"
,
bg_color
=
None
,
**
kwargs
):
fit_view_ink
=
None
,
adjust_aspect
=
True
,
ink_scale
=
1
,
inline
=
is_draw_inline
,
inline_scale
=
2
,
mplfig
=
None
,
output
=
None
,
fmt
=
"auto"
,
bg_color
=
None
,
**
kwargs
):
r
"""Draw a graph to screen or to a file using :mod:`cairo`.
Parameters
...
...
@@ -765,6 +765,13 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None,
addition the viewport will be scaled out by that factor. If a tuple
value is given, it should have four values ``(x, y, w, h)`` that
specify the view in user coordinates.
fit_view_ink : bool (optional, default: ``None``)
If ``True``, and ``fit_view == True`` the drawing will be performed once
to figure out the bounding box, before the actual drawing is
made. Otherwise, only the vertex positions will be used for this
purpose. If the value is ``None``, then it will be assumed ``True`` for
networks of size 10,000 nodes or less, otherwise it will be assumed
``False``.
adjust_aspect : bool (optional, default: ``True``)
If ``True``, and ``fit_view == True`` the output size will be decreased
in the width or height to remove empty spaces.
...
...
@@ -1140,8 +1147,16 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None,
except
TypeError
:
pad
=
fit_view
if
fit_view
is
not
True
else
0.9
output_size
=
list
(
output_size
)
x
,
y
,
zoom
=
fit_to_view_ink
(
g
,
pos
,
output_size
,
vprops
,
eprops
,
adjust_aspect
,
pad
=
pad
)
if
fit_view_ink
is
None
:
fit_view_ink
=
g
.
num_vertices
()
<=
1000
if
fit_view_ink
:
x
,
y
,
zoom
=
fit_to_view_ink
(
g
,
pos
,
output_size
,
vprops
,
eprops
,
adjust_aspect
,
pad
=
pad
)
else
:
x
,
y
,
zoom
=
fit_to_view
(
get_bb
(
g
,
pos
),
output_size
,
adjust_aspect
=
adjust_aspect
,
pad
=
pad
)
else
:
x
,
y
,
zoom
=
0
,
0
,
1
...
...
@@ -1279,11 +1294,11 @@ def get_bb(g, pos):
pos_x
,
pos_y
=
ungroup_vector_property
(
pos
,
[
0
,
1
])
x_range
=
[
pos_x
.
fa
.
min
(),
pos_x
.
fa
.
max
()]
y_range
=
[
pos_y
.
fa
.
min
(),
pos_y
.
fa
.
max
()]
return
x_range
[
0
],
y_range
[
1
],
x_range
[
1
]
-
x_range
[
0
],
y_range
[
1
]
-
y_range
[
0
]
return
x_range
[
0
],
y_range
[
0
],
x_range
[
1
]
-
x_range
[
0
],
y_range
[
1
]
-
y_range
[
0
]
def
fit_to_view
(
rec
,
output_size
,
adjust_aspect
=
False
,
pad
=
.
9
):
x
,
y
,
w
,
h
=
rec
d
=
max
(
w
,
h
)
if
adjust_aspect
:
if
h
>
w
:
output_size
[
0
]
=
int
(
round
(
float
(
output_size
[
1
]
*
w
/
h
)))
...
...
src/graph_tool/draw/gtk_draw.py
View file @
23b6457d
...
...
@@ -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
,
fit_view
=
True
,
bg_color
=
None
,
max_render_time
=
300
,
layout_callback
=
None
,
display_props_size
=
11
,
fit_view
=
True
,
fit_view_ink
=
None
,
bg_color
=
None
,
max_render_time
=
300
,
layout_callback
=
None
,
key_press_callback
=
None
,
highlight_color
=
None
,
**
kwargs
):
r
"""Interactive GTK+ widget displaying a given graph.
...
...
@@ -172,6 +172,13 @@ class GraphWidget(Gtk.DrawingArea):
addition the viewport will be scaled out by that factor. If a tuple
value is given, it should have four values ``(x, y, w, h)`` that
specify the view in user coordinates.
fit_view_ink : bool (optional, default: ``None``)
If ``True``, and ``fit_view == True`` the drawing will be performed
once to figure out the bounding box, before the actual drawing is
made. Otherwise, only the vertex positions will be used for this
purpose. If the value is ``None``, then it will be assumed ``True``
for networks of size 10,000 nodes or less, otherwise it will be
assumed ``False``.
bg_color : str or sequence (optional, default: ``None``)
Background color. The default is white.
max_render_time : int (optional, default: ``300``)
...
...
@@ -276,6 +283,10 @@ class GraphWidget(Gtk.DrawingArea):
self
.
moved_picked
=
False
self
.
vertex_matrix
=
None
self
.
fit_view
=
fit_view
if
fit_view_ink
is
None
:
self
.
fit_view_ink
=
self
.
g
.
num_vertices
()
<=
1000
else
:
self
.
fit_view_ink
=
fit_view_ink
self
.
display_prop
=
g
.
vertex_index
if
display_props
is
None
\
else
display_props
...
...
@@ -787,8 +798,13 @@ class GraphWidget(Gtk.DrawingArea):
pos_y
.
fa
=
P
[
1
,
:]
pos
=
group_vector_property
([
pos_x
,
pos_y
])
x
,
y
,
zoom
=
fit_to_view_ink
(
g
,
pos
,
geometry
,
self
.
vprops
,
self
.
eprops
,
pad
=
pad
)
if
self
.
fit_view_ink
:
x
,
y
,
zoom
=
fit_to_view_ink
(
g
,
pos
,
geometry
,
self
.
vprops
,
self
.
eprops
,
pad
=
pad
)
else
:
x
,
y
,
zoom
=
fit_to_view
(
get_bb
(
g
,
pos
),
geometry
,
pad
=
pad
)
else
:
x
,
y
,
zoom
=
0
,
0
,
1
...
...
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