From 4974c6c250e199797c1bedf8b4c8847b421a160f Mon Sep 17 00:00:00 2001 From: Matteo Visconti di Oleggio Castello Date: Fri, 18 Feb 2022 12:10:19 -0800 Subject: [PATCH 1/2] FIX do not show labels for invisible shapes --- cortex/svgoverlay.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cortex/svgoverlay.py b/cortex/svgoverlay.py index 5513d8068..5030fb580 100644 --- a/cortex/svgoverlay.py +++ b/cortex/svgoverlay.py @@ -249,23 +249,23 @@ def get_texture(self, layer_name, height, name=None, background=None, labels=Tru # separate kwargs starting with "label-" label_kwargs = {k[6:]:v for k, v in kwargs.items() if k[:6] == "label-"} kwargs = {k:v for k, v in kwargs.items() if k[:6] != "label-"} - for layer in self: - if layer.name==layer_name: + if layer.name == layer_name: layer.visible = True layer.labels.visible = labels - if shape_list is not None: - for name_, shape_ in layer.shapes.items(): + for name_, shape_ in layer.shapes.items(): + # honor visibility set in the svg + if shape_list is not None: shape_.visible = name_ in shape_list - # Set visibility of labels (by setting text alpha to 0) - # This could be less baroque, but text elements currently - # do not have individually settable visibility / style params - tmp_style = copy.deepcopy(layer.labels.text_style) - tmp_style['fill-opacity'] = '1' if shape_.visible else '0' - tmp_style.update(label_kwargs) - tmp_style_str = ';'.join(['%s:%s'%(k,v) for k, v in tmp_style.items() if v != 'None']) - for i in range(len(layer.labels.elements[name_])): - layer.labels.elements[name_][i].set('style', tmp_style_str) + # Set visibility of labels (by setting text alpha to 0) + # This could be less baroque, but text elements currently + # do not have individually settable visibility / style params + tmp_style = copy.deepcopy(layer.labels.text_style) + tmp_style['fill-opacity'] = '1' if shape_.visible else '0' + tmp_style.update(label_kwargs) + tmp_style_str = ';'.join(['%s:%s'%(k,v) for k, v in tmp_style.items() if v != 'None']) + for i in range(len(layer.labels.elements[name_])): + layer.labels.elements[name_][i].set('style', tmp_style_str) layer.set(**kwargs) else: layer.visible = False From e5089742b8eb8f563654d17dc96e3d1773ed8b40 Mon Sep 17 00:00:00 2001 From: Matteo Visconti di Oleggio Castello Date: Fri, 18 Feb 2022 14:11:16 -0800 Subject: [PATCH 2/2] FIX visible property for shapes without style set --- cortex/svgoverlay.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cortex/svgoverlay.py b/cortex/svgoverlay.py index 5030fb580..e604b874f 100644 --- a/cortex/svgoverlay.py +++ b/cortex/svgoverlay.py @@ -329,7 +329,11 @@ def __getitem__(self, name): @property def visible(self): - return 'none' not in self.layer.attrib['style'] + # assume visible if "style" property is not set + if 'style' not in self.layer.attrib: + return True + else: + return 'none' not in self.layer.attrib['style'] @visible.setter def visible(self, value): @@ -499,7 +503,11 @@ def splines(self): @property def visible(self): - return 'none' not in self.layer.attrib['style'] + # assume visible if "style" property is not set + if "style" not in self.layer.attrib: + return True + else: + return 'none' not in self.layer.attrib['style'] @visible.setter def visible(self, value):