Commit 3d74d3c5 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

graph_draw(): implement option "vertex_rotation"

parent 4a4cebb7
......@@ -50,6 +50,7 @@ enum vertex_attr_t {
VERTEX_FILL_COLOR,
VERTEX_SIZE,
VERTEX_ASPECT,
VERTEX_ROTATION,
VERTEX_ANCHOR,
VERTEX_PENWIDTH,
VERTEX_HALO,
......@@ -66,7 +67,7 @@ enum vertex_attr_t {
VERTEX_FONT_SIZE,
VERTEX_SURFACE,
VERTEX_PIE_FRACTIONS,
VERTEX_PIE_COLORS
VERTEX_PIE_COLORS,
};
enum edge_attr_t {
......@@ -123,12 +124,13 @@ typedef pair<double, double> pos_t;
typedef std::tuple<double, double, double, double> color_t;
typedef gt_hash_map<int, boost::any> attrs_t;
typedef boost::mpl::map42<
typedef boost::mpl::map43<
boost::mpl::pair<boost::mpl::int_<VERTEX_SHAPE>, vertex_shape_t>,
boost::mpl::pair<boost::mpl::int_<VERTEX_COLOR>, color_t>,
boost::mpl::pair<boost::mpl::int_<VERTEX_FILL_COLOR>, color_t>,
boost::mpl::pair<boost::mpl::int_<VERTEX_SIZE>, double>,
boost::mpl::pair<boost::mpl::int_<VERTEX_ASPECT>, double>,
boost::mpl::pair<boost::mpl::int_<VERTEX_ROTATION>, double>,
boost::mpl::pair<boost::mpl::int_<VERTEX_ANCHOR>, int32_t>,
boost::mpl::pair<boost::mpl::int_<VERTEX_PENWIDTH>, double>,
boost::mpl::pair<boost::mpl::int_<VERTEX_HALO>, uint8_t>,
......@@ -638,7 +640,7 @@ public:
cr.get_text_extents(text, extents);
double s = max(extents.width, extents.height) * 1.4;
vertex_shape_t shape = _attrs.template get<vertex_shape_t>(VERTEX_SHAPE);
if (shape >= SHAPE_DOUBLE_CIRCLE)
if (shape >= SHAPE_DOUBLE_CIRCLE && shape != SHAPE_PIE)
{
s /= 0.7;
double pw = _attrs.template get<double>(VERTEX_PENWIDTH);
......@@ -660,8 +662,11 @@ public:
double angle = atan2(_pos.second - origin.second,
_pos.first - origin.first);
double rot = _attrs.template get<double>(VERTEX_ROTATION);
if (angle < 0)
angle += 2 * M_PI;
double r = get_size(cr) / 2;
double dr = r;
......@@ -689,7 +694,7 @@ public:
nsides = shape - SHAPE_TRIANGLE + 3;
if (nsides > 8)
nsides -= 7;
dr = get_polygon_anchor(nsides, r, angle);
dr = get_polygon_anchor(nsides, r, angle - rot);
break;
case SHAPE_CIRCLE:
case SHAPE_DOUBLE_CIRCLE:
......@@ -779,7 +784,7 @@ public:
void draw(Cairo::Context& cr, bool outline=false)
{
color_t color, fillcolor;
double size, pw, aspect;
double size, pw;
size = get_size(cr);
std::array<double, 4> clip;
......@@ -788,11 +793,13 @@ public:
(_pos.first - 2 * size > clip[2] && _pos.second - 2 * size > clip[3]))
return;
aspect = _attrs.template get<double>(VERTEX_ASPECT);
double aspect = _attrs.template get<double>(VERTEX_ASPECT);
double rot = _attrs.template get<double>(VERTEX_ROTATION);
if (!outline)
cr.save();
cr.translate(_pos.first, _pos.second);
cr.rotate(rot);
if (!outline && _attrs.template get<uint8_t>(VERTEX_HALO))
{
......@@ -1009,6 +1016,7 @@ public:
}
else
{
cr.rotate(-rot);
cr.translate(-_pos.first, -_pos.second);
}
}
......@@ -2173,6 +2181,7 @@ BOOST_PYTHON_MODULE(libgraph_tool_draw)
.value("fill_color", VERTEX_FILL_COLOR)
.value("size", VERTEX_SIZE)
.value("aspect", VERTEX_ASPECT)
.value("rotation", VERTEX_ROTATION)
.value("anchor", VERTEX_ANCHOR)
.value("pen_width", VERTEX_PENWIDTH)
.value("halo", VERTEX_HALO)
......
......@@ -104,6 +104,7 @@ _vdefaults = {
"fill_color": (0.6470588235294118, 0.058823529411764705, 0.08235294117647059, 0.8),
"size": 5,
"aspect": 1.,
"rotation": 0.,
"anchor": 1,
"pen_width": 0.8,
"halo": 0,
......@@ -152,6 +153,7 @@ _vtypes = {
"fill_color": "vector<double>",
"size": "double",
"aspect": "double",
"rotation": "double",
"anchor": "double",
"pen_width": "double",
"halo": "bool",
......@@ -814,6 +816,8 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None,
+---------------+---------------------------------------------------+------------------------+----------------------------------+
| aspect | The aspect ratio of the vertex. | ``float`` or ``int`` | ``1.0`` |
+---------------+---------------------------------------------------+------------------------+----------------------------------+
| rotation | Angle (in radians) to rotate the vertex. | ``float`` | ``0.`` |
+---------------+---------------------------------------------------+------------------------+----------------------------------+
| anchor | Specifies how the edges anchor to the vertices. | ``int`` | ``1`` |
| | If `0`, the anchor is at the center of the vertex,| | |
| | otherwise it is at the border. | | |
......@@ -1767,7 +1771,7 @@ def draw_hierarchy(state, pos=None, layout="radial", beta=0.8, vprops=None,
eprops.update(props)
eprops.setdefault("control_points", cts)
eprops.setdefault("pen_width", _edefaults["pen_width"])
eprops.setdefault("color", _edefaults["color"])
eprops.setdefault("color", list(_edefaults["color"][:-1]) + [.6])
eprops.setdefault("end_marker", "arrow" if g.is_directed() else "none")
eprops = _convert_props(eprops, "e", g, kwargs.get("ecmap", default_cm),
pmap_default=True)
......
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