Changeset 609462


Ignore:
Timestamp:
06/18/12 21:00:42 (12 months ago)
Author:
Tiago de Paula Peixoto <tiago@…>
Branches:
master
Children:
0adf28
Parents:
26c87a
git-author:
Tiago de Paula Peixoto <tiago@…> (06/18/12 21:00:42)
git-committer:
Tiago de Paula Peixoto <tiago@…> (06/18/12 21:00:42)
Message:
Implement fit_view option in cairo_draw()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/graph_tool/draw/cairo_draw.py

    r26c87a r609462  
    296296               nodesfirst=False, vcmap=matplotlib.cm.jet, 
    297297               ecmap=matplotlib.cm.jet, loop_angle=float("nan"), 
    298                parallel_distance=None, **kwargs): 
     298               parallel_distance=None, fit_view=False, **kwargs): 
    299299    r""" 
    300300    Draw a graph to a :mod:`cairo` context. 
     
    333333        Distance used between parallel edges. If not provided, it will be 
    334334        determined automatically. 
     335    fit_view : bool (optional, default: ``True``) 
     336        If ``True``, the layout will be scaled to fit the entire clip region. 
    335337    vertex_* : :class:`~graph_tool.PropertyMap` or arbitrary types (optional, default: ``None``) 
    336338        Parameters following the pattern ``vertex_<prop-name>`` specify the 
     
    353355    for k in kwargs: 
    354356        warnings.warn("Unknown parameter: " + k, UserWarning) 
     357 
     358    cr.save() 
     359    if fit_view: 
     360        extents = cr.clip_extents() 
     361        output_size = (extents[2] - extents[0], extents[3] - extents[1]) 
     362        offset, zoom = fit_to_view(g, pos, output_size, 
     363                                   vprops.get("size", _vdefaults["size"]), 
     364                                   vprops.get("pen_width", _vdefaults["pen_width"]), 
     365                                   None, vprops.get("text", None), 
     366                                   vprops.get("font_family", 
     367                                              _vdefaults["font_family"]), 
     368                                   vprops.get("font_size", 
     369                                              _vdefaults["font_size"]), 
     370                                   cr) 
     371        cr.translate(offset[0], offset[1]) 
     372        cr.scale(zoom, zoom) 
    355373 
    356374    if "control_points" not in eprops: 
     
    384402                                  _prop("v", g, vorder), _prop("e", g, eorder), 
    385403                                  nodesfirst, vattrs, eattrs, vdefs, edefs, cr) 
     404    cr.restore() 
    386405 
    387406 
Note: See TracChangeset for help on using the changeset viewer.