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
1d2ac65c
Commit
1d2ac65c
authored
Feb 24, 2014
by
Tiago Peixoto
Browse files
Fix handling of "pie" vertex shape properties
parent
c7689e67
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/graph/draw/graph_cairo_draw.cc
View file @
1d2ac65c
...
...
@@ -303,7 +303,7 @@ struct Converter
}
};
// color
// color
_t
template
<
class
T2
>
struct
specific_convert
<
color_t
,
vector
<
T2
>
>
{
...
...
@@ -316,6 +316,26 @@ struct Converter
}
};
// vector<color_t>
template
<
class
T2
>
struct
specific_convert
<
vector
<
color_t
>
,
vector
<
T2
>
>
{
specific_convert
<
double
,
T2
>
c
;
vector
<
color_t
>
operator
()(
const
vector
<
T2
>&
cv
)
const
{
if
(
cv
.
size
()
<
4
)
throw
bad_lexical_cast
();
vector
<
color_t
>
color
;
for
(
size_t
i
=
0
;
i
<
cv
.
size
()
/
4
;
++
i
)
{
if
(
4
*
i
+
3
>=
cv
.
size
())
throw
bad_lexical_cast
();
color
.
push_back
(
std
::
make_tuple
(
c
(
cv
[
4
*
i
]),
c
(
cv
[
4
*
i
+
1
]),
c
(
cv
[
4
*
i
+
2
]),
c
(
cv
[
4
*
i
+
3
])));
}
return
color
;
}
};
// vertex_shape_t
template
<
class
T2
>
...
...
src/graph_tool/draw/cairo_draw.py
View file @
1d2ac65c
...
...
@@ -38,6 +38,7 @@ try:
import
matplotlib.cm
import
matplotlib.colors
from
matplotlib.cbook
import
flatten
default_cm
=
matplotlib
.
cm
.
jet
except
ImportError
:
msg
=
"Error importing matplotlib module. Graph drawing will not work."
warnings
.
filterwarnings
(
"always"
,
msg
,
ImportWarning
)
...
...
@@ -210,11 +211,23 @@ def _convert(attr, val, cmap):
if
isinstance
(
val
,
PropertyMap
):
if
val
.
value_type
()
in
[
"vector<double>"
,
"vector<long double>"
]:
return
val
if
val
.
value_type
()
in
[
"vector<int32_t>"
,
"vector<int32_t>"
,
"vector<bool>"
]:
g
=
val
.
get_graph
()
new_val
=
g
.
new_vertex_property
(
"vector<double>"
)
rg
=
[
float
(
"inf"
),
-
float
(
"inf"
)]
for
v
in
g
.
vertices
():
for
x
in
val
[
v
]:
rg
=
[
min
(
x
,
rg
[
0
]),
max
(
x
,
rg
[
0
])]
if
rg
[
0
]
==
rg
[
1
]:
rg
[
1
]
=
1
for
v
in
g
.
vertices
():
new_val
[
v
]
=
flatten
([
default_cm
((
x
-
rg
[
0
])
/
(
rg
[
1
]
-
rg
[
0
]))
for
x
in
val
[
v
]])
return
new_val
if
val
.
value_type
()
==
"vector<string>"
:
g
=
val
.
get_graph
()
new_val
=
g
.
new_vertex_property
(
"vector<double>"
)
for
v
in
g
.
vertices
():
new_val
[
v
]
=
[
matplotlib
.
colors
.
ColorConverter
().
to_rgba
(
x
)
for
x
in
val
[
v
]]
new_val
[
v
]
=
flatten
(
[
matplotlib
.
colors
.
ColorConverter
().
to_rgba
(
x
)
for
x
in
val
[
v
]]
)
return
new_val
if
val
.
value_type
()
==
"python::object"
:
try
:
...
...
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