diff --git a/CHANGES.md b/CHANGES.md index 264e10b2a..39d238b43 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,9 @@ Full changelog v0.10.2 (unreleased) -------------------- +* Fixed a bug that caused components that were linked to then disappear from + drop-down lists of available components in new viewers. [#1270] + * Fixed a bug that caused Data.find_component_id to return incorrect results when string components were present in the data. [#1269] diff --git a/glue/core/data.py b/glue/core/data.py index 1e9531f79..c1cd2180d 100644 --- a/glue/core/data.py +++ b/glue/core/data.py @@ -391,7 +391,8 @@ def add_component(self, component, label, hidden=False): if isinstance(label, ComponentID): component_id = label - component_id.parent = self + if component_id.parent is None: + component_id.parent = self else: component_id = ComponentID(label, hidden=hidden, parent=self) @@ -471,7 +472,7 @@ def visible_components(self): :rtype: list """ return [cid for cid, comp in self._components.items() - if not cid.hidden and not comp.hidden] + if not cid.hidden and not comp.hidden and cid.parent is self] @property def coordinate_components(self): @@ -931,7 +932,7 @@ def update_values_from_data(self, data): if cname in new_labels - old_labels: cid = data.find_component_id(cname) comp_new = data.get_component(cname) - self.add_component(comp_new, cid) + self.add_component(comp_new, cid.label) # Update data label self.label = data.label diff --git a/glue/core/link_manager.py b/glue/core/link_manager.py index 7e865714b..aa92138ed 100644 --- a/glue/core/link_manager.py +++ b/glue/core/link_manager.py @@ -196,9 +196,6 @@ def _add_deriveable_components(self, data): for cid, link in six.iteritems(links): d = DerivedComponent(data, link) if cid not in data.components: - # Need to hide component since we don't want to show components - # that are auto-generated in datasets by default. - cid.hidden = True data.add_component(d, cid) @property diff --git a/glue/core/tests/test_data.py b/glue/core/tests/test_data.py index cfc283e03..badb99c41 100644 --- a/glue/core/tests/test_data.py +++ b/glue/core/tests/test_data.py @@ -583,7 +583,8 @@ def test_update_values_from_data(): assert d1a not in d1.components assert d1b in d1.components assert d2b not in d1.components - assert d2c in d1.components + assert d2c not in d1.components + assert [cid.label for cid in d1.visible_components] == ['b', 'c'] assert d1.shape == (4,) @@ -624,8 +625,7 @@ def test_update_values_from_data_order(): d2.update_values_from_data(d1) - assert d2.visible_components == [d2.id['j'], d2.id['a'], d1.id['c'], - d1.id['b'], d1.id['f']] + assert [cid.label for cid in d2.visible_components] == ['j', 'a', 'c', 'b', 'f'] def test_find_component_id_with_cid(): @@ -639,3 +639,39 @@ def test_find_component_id_with_cid(): assert d1.find_component_id(d1.id['a']) is d1.id['a'] assert d1.find_component_id(d1.id['b']) is d1.id['b'] + + +def test_linked_component_visible(): + + # Regression test for a bug that caused components to become hidden once + # they were linked with another component. + + from ..link_helpers import LinkSame + from ..data_collection import DataCollection + + d1 = Data(x=[1], y=[2]) + d2 = Data(w=[3], v=[4]) + + assert not d1.id['x'].hidden + assert not d2.id['w'].hidden + + dc = DataCollection([d1, d2]) + dc.add_link(LinkSame(d1.id['x'], d2.id['w'])) + + assert d1.id['x'] is d2.id['x'] + assert d1.id['w'] is d2.id['w'] + + assert not d1.id['x'].hidden + assert not d2.id['w'].hidden + + assert not d1.id['w'].hidden + assert not d2.id['x'].hidden + + assert d1.id['x'].parent is d1 + assert d1.id['y'].parent is d1 + + assert d2.id['w'].parent is d2 + assert d2.id['v'].parent is d2 + + assert d1.visible_components == [d1.id['x'], d1.id['y']] + assert d2.visible_components == [d2.id['v'], d2.id['w']]