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

NickAkhmetov/Add allow_multiple_scopes_per_type boolean arg to use_coordination and link_views #274

Merged
merged 4 commits into from
Aug 11, 2023
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
18 changes: 14 additions & 4 deletions vitessce/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,13 @@ def get_coordination_scope(self, c_type):
"""
return self.view["coordinationScopes"].get(c_type)

def use_coordination(self, *c_scopes):
def use_coordination(self, *c_scopes, allow_multiple_scopes_per_type=False):
"""
Attach a coordination scope to this view instance. All views using the same coordination scope for a particular coordination type will effectively be linked together.

:param \\*c_scopes: A variable number of coordination scope instances can be passed.
:type \\*c_scopes: VitessceConfigCoordinationScope
:param bool allow_multiple_scopes_per_type: Whether to allow multiple coordination scopes per coordination type. If true, multiple values for the same coordination type are treated as a list. If false, latest value for same coordination type is used. Defaults to False.

:returns: Self, to allow chaining.
:rtype: VitessceConfigView
Expand All @@ -402,7 +403,15 @@ def use_coordination(self, *c_scopes):
"""
for c_scope in c_scopes:
assert isinstance(c_scope, VitessceConfigCoordinationScope)
self.view["coordinationScopes"][c_scope.c_type] = c_scope.c_scope
existing_value = self.view["coordinationScopes"].get(c_scope.c_type)
new_value = c_scope.c_scope
if (existing_value is not None and allow_multiple_scopes_per_type):
if (isinstance(existing_value, list)):
self.view["coordinationScopes"][c_scope.c_type] = existing_value + [new_value]
else:
self.view["coordinationScopes"][c_scope.c_type] = [existing_value, new_value]
else:
self.view["coordinationScopes"][c_scope.c_type] = new_value
return self

def set_xywh(self, x, y, w, h):
Expand Down Expand Up @@ -813,7 +822,7 @@ def set_coordination_value(self, c_type, c_scope, c_value):
self.config["coordinationSpace"][scope.c_type][scope.c_scope] = scope
return scope

def link_views(self, views, c_types, c_values=None):
def link_views(self, views, c_types, c_values=None, allow_multiple_scopes_per_type=False):
"""
A convenience function for setting up new coordination scopes across a set of views.

Expand All @@ -822,14 +831,15 @@ def link_views(self, views, c_types, c_values=None):
:param c_types: The coordination types on which to coordinate the views.
:type c_types: list of str or list of vitessce.constants.CoordinationType
:param list c_values: Initial values corresponding to each coordination type. Should have the same length as the c_types array. Optional.
:param bool allow_multiple_scopes_per_type: Whether to allow multiple coordination scopes per coordination type. If true, multiple values for the same coordination type are treated as a list. If false, latest value for same coordination type is used. Defaults to False.

:returns: Self, to allow chaining.
:rtype: VitessceConfig
"""
c_scopes = self.add_coordination(*c_types)
for view in views:
for c_scope in c_scopes:
view.use_coordination(c_scope)
view.use_coordination(c_scope, allow_multiple_scopes_per_type=allow_multiple_scopes_per_type)

if c_values is not None and len(c_values) == len(c_types):
for i, c_scope in enumerate(c_scopes):
Expand Down
Loading