Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX do not show labels for invisible shapes #429

Merged
merged 2 commits into from
Feb 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions cortex/svgoverlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down