Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
0f58db6d
Commit
0f58db6d
authored
Jul 27, 2014
by
Tiago Peixoto
Browse files
Fix DrawingArea origin offsets in GraphWidget()
parent
e97f5ee1
Changes
1
Show whitespace changes
Inline
Side-by-side
src/graph_tool/draw/gtk_draw.py
View file @
0f58db6d
...
@@ -423,8 +423,8 @@ class GraphWidget(Gtk.DrawingArea):
...
@@ -423,8 +423,8 @@ class GraphWidget(Gtk.DrawingArea):
self
.
regenerate_surface
(
lazy
=
False
)
self
.
regenerate_surface
(
lazy
=
False
)
self
.
geometry
=
geometry
self
.
geometry
=
geometry
ul
=
self
.
pos_to_device
((
0
,
0
),
surface
=
True
)
ul
=
self
.
pos_to_device
((
0
,
0
),
surface
=
True
,
cr
=
cr
)
lr
=
self
.
pos_to_device
(
self
.
base_geometry
,
surface
=
True
)
lr
=
self
.
pos_to_device
(
self
.
base_geometry
,
surface
=
True
,
cr
=
cr
)
if
(
ul
[
0
]
>
0
or
lr
[
0
]
<
geometry
[
0
]
or
if
(
ul
[
0
]
>
0
or
lr
[
0
]
<
geometry
[
0
]
or
ul
[
1
]
>
0
or
lr
[
1
]
<
geometry
[
1
]):
ul
[
1
]
>
0
or
lr
[
1
]
<
geometry
[
1
]):
...
@@ -521,8 +521,9 @@ class GraphWidget(Gtk.DrawingArea):
...
@@ -521,8 +521,9 @@ class GraphWidget(Gtk.DrawingArea):
def
pos_to_device
(
self
,
pos
,
dist
=
False
,
surface
=
False
,
cr
=
None
):
def
pos_to_device
(
self
,
pos
,
dist
=
False
,
surface
=
False
,
cr
=
None
):
"""Convert a position from the graph space to the widget space."""
"""Convert a position from the graph space to the widget space."""
ox
,
oy
=
self
.
get_window
().
get_position
()
if
cr
is
None
:
if
cr
is
None
:
cr
=
Gdk
.
cairo_create
(
self
.
get_
root_
window
())
cr
=
self
.
get_window
()
.
cairo_create
(
)
if
surface
:
if
surface
:
cr
.
set_matrix
(
self
.
smatrix
)
cr
.
set_matrix
(
self
.
smatrix
)
else
:
else
:
...
@@ -530,12 +531,14 @@ class GraphWidget(Gtk.DrawingArea):
...
@@ -530,12 +531,14 @@ class GraphWidget(Gtk.DrawingArea):
if
dist
:
if
dist
:
return
cr
.
user_to_device_distance
(
pos
[
0
],
pos
[
1
])
return
cr
.
user_to_device_distance
(
pos
[
0
],
pos
[
1
])
else
:
else
:
return
cr
.
user_to_device
(
pos
[
0
],
pos
[
1
])
x
,
y
=
cr
.
user_to_device
(
pos
[
0
],
pos
[
1
])
return
(
x
-
ox
,
y
-
oy
)
def
pos_from_device
(
self
,
pos
,
dist
=
False
,
surface
=
False
,
cr
=
None
):
def
pos_from_device
(
self
,
pos
,
dist
=
False
,
surface
=
False
,
cr
=
None
):
"""Convert a position from the widget space to the device space."""
"""Convert a position from the widget space to the device space."""
ox
,
oy
=
self
.
get_window
().
get_position
()
if
cr
is
None
:
if
cr
is
None
:
cr
=
Gdk
.
cairo_create
(
self
.
get_
root_
window
())
cr
=
self
.
get_window
()
.
cairo_create
(
)
if
surface
:
if
surface
:
cr
.
set_matrix
(
self
.
smatrix
)
cr
.
set_matrix
(
self
.
smatrix
)
else
:
else
:
...
@@ -543,7 +546,7 @@ class GraphWidget(Gtk.DrawingArea):
...
@@ -543,7 +546,7 @@ class GraphWidget(Gtk.DrawingArea):
if
dist
:
if
dist
:
return
cr
.
device_to_user_distance
(
pos
[
0
],
pos
[
1
])
return
cr
.
device_to_user_distance
(
pos
[
0
],
pos
[
1
])
else
:
else
:
return
cr
.
device_to_user
(
pos
[
0
],
pos
[
1
])
return
cr
.
device_to_user
(
pos
[
0
]
+
ox
,
pos
[
1
]
+
oy
)
def
apply_transform
(
self
):
def
apply_transform
(
self
):
r
"""Apply current transform matrix to vertex coordinates."""
r
"""Apply current transform matrix to vertex coordinates."""
...
@@ -564,6 +567,7 @@ class GraphWidget(Gtk.DrawingArea):
...
@@ -564,6 +567,7 @@ class GraphWidget(Gtk.DrawingArea):
def
fit_to_window
(
self
,
ink
=
False
,
g
=
None
):
def
fit_to_window
(
self
,
ink
=
False
,
g
=
None
):
r
"""Fit graph to window."""
r
"""Fit graph to window."""
geometry
=
[
self
.
get_allocated_width
(),
self
.
get_allocated_height
()]
geometry
=
[
self
.
get_allocated_width
(),
self
.
get_allocated_height
()]
ox
,
oy
=
self
.
get_window
().
get_position
()
if
g
is
None
:
if
g
is
None
:
g
=
self
.
g
g
=
self
.
g
pos
=
g
.
own_property
(
self
.
pos
)
pos
=
g
.
own_property
(
self
.
pos
)
...
@@ -579,7 +583,7 @@ class GraphWidget(Gtk.DrawingArea):
...
@@ -579,7 +583,7 @@ class GraphWidget(Gtk.DrawingArea):
_vdefaults
[
"font_size"
]),
_vdefaults
[
"font_size"
]),
cr
)
cr
)
m
=
cairo
.
Matrix
()
m
=
cairo
.
Matrix
()
m
.
translate
(
offset
[
0
],
offset
[
1
])
m
.
translate
(
offset
[
0
]
+
ox
,
offset
[
1
]
+
oy
)
m
.
scale
(
zoom
,
zoom
)
m
.
scale
(
zoom
,
zoom
)
self
.
tmatrix
=
self
.
tmatrix
*
self
.
smatrix
*
m
self
.
tmatrix
=
self
.
tmatrix
*
self
.
smatrix
*
m
self
.
smatrix
=
cairo
.
Matrix
()
self
.
smatrix
=
cairo
.
Matrix
()
...
...
Tiago Peixoto
@count0
mentioned in issue
#149 (closed)
·
Aug 06, 2014
mentioned in issue
#149 (closed)
mentioned in issue #149
Toggle commit list
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