Commit 1d2ac65c authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix handling of "pie" vertex shape properties

parent c7689e67
......@@ -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>
......
......@@ -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:
......
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