Commit e3c57b27 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

graph_draw(): fix bounding box calculation when using small line widths

parent 70eb73d6
Pipeline #711 passed with stage
in 91 minutes and 16 seconds
...@@ -1220,6 +1220,7 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None, ...@@ -1220,6 +1220,7 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None,
del srf del srf
return pos return pos
_min_pen_width = 0.05
def adjust_default_sizes(g, geometry, vprops, eprops, force=False): def adjust_default_sizes(g, geometry, vprops, eprops, force=False):
if "size" not in vprops or force: if "size" not in vprops or force:
...@@ -1231,9 +1232,9 @@ def adjust_default_sizes(g, geometry, vprops, eprops, force=False): ...@@ -1231,9 +1232,9 @@ def adjust_default_sizes(g, geometry, vprops, eprops, force=False):
size = vprops["size"] size = vprops["size"]
if isinstance(vprops["size"], PropertyMap): if isinstance(vprops["size"], PropertyMap):
size = vprops["size"].fa.mean() size = vprops["size"].fa.mean()
vprops["pen_width"] = size / 10 vprops["pen_width"] = max(size / 10, _min_pen_width)
if "pen_width" not in eprops or force: if "pen_width" not in eprops or force:
eprops["pen_width"] = size / 10 eprops["pen_width"] = max(size / 10, _min_pen_width)
if "marker_size" not in eprops or force: if "marker_size" not in eprops or force:
eprops["marker_size"] = size * 0.8 eprops["marker_size"] = size * 0.8
...@@ -1254,24 +1255,25 @@ def scale_ink(scale, vprops, eprops, copy=True): ...@@ -1254,24 +1255,25 @@ def scale_ink(scale, vprops, eprops, copy=True):
vink_props = ["size", "pen_width", "font_size", "text_out_width"] vink_props = ["size", "pen_width", "font_size", "text_out_width"]
eink_props = ["marker_size", "pen_width", "font_size", "text_distance", eink_props = ["marker_size", "pen_width", "font_size", "text_distance",
"text_out_width"] "text_out_width"]
for p in vink_props: for ink_props, props, defaults in zip([vink_props, eink_props],
if p not in vprops: [vprops, eprops],
vprops[p] = _vdefaults[p] [_vdefaults, _edefaults]):
if isinstance(vprops[p], PropertyMap): for p in ink_props:
if copy: if p not in props:
vprops[p] = vprops[p].copy() props[p] = defaults[p]
vprops[p].fa *= scale if isinstance(props[p], PropertyMap):
else: if copy:
vprops[p] *= scale props[p] = props[p].copy()
for p in eink_props: props[p].fa *= scale
if p not in eprops: if p == "pen_width":
eprops[p] = _edefaults[p] x = props[p].fa
if isinstance(eprops[p], PropertyMap): x[x<_min_pen_width] = _min_pen_width
if copy: props[p].fa = x
eprops[p] = eprops[p].copy() else:
eprops[p].fa *= scale props[p] *= scale
else: if p == "pen_width":
eprops[p] *= scale props[p] = max(props[p],
_min_pen_width)
def get_bb(g, pos): def get_bb(g, pos):
pos_x, pos_y = ungroup_vector_property(pos, [0, 1]) pos_x, pos_y = ungroup_vector_property(pos, [0, 1])
...@@ -1314,6 +1316,19 @@ def fit_to_view_ink(g, pos, output_size, vprops, eprops, adjust_aspect=False, ...@@ -1314,6 +1316,19 @@ def fit_to_view_ink(g, pos, output_size, vprops, eprops, adjust_aspect=False,
cr.scale(zoom, zoom) cr.scale(zoom, zoom)
cr.translate(-x, -y) cr.translate(-x, -y)
# work around cairo bug with small line widths
def min_lw(lw):
if isinstance(lw, PropertyMap):
lw = lw.copy()
x = lw.fa
x[x < 0.05] = 0.1
lw.fa = x
else:
lw = max(lw, 0.1)
return lw
vprops = dict(vprops, pen_width=min_lw(vprops.get("pen_width")))
eprops = dict(eprops, pen_width=min_lw(eprops.get("pen_width")))
cairo_draw(g, pos, cr, vprops, eprops) cairo_draw(g, pos, cr, vprops, eprops)
bb = list(srf.ink_extents()) bb = list(srf.ink_extents())
......
Supports Markdown
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