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

feat: Add dimension selector tool palette at bottom of screen #35

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions cryoet_data_portal_neuroglancer/state_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def combine_json_layers(
projection_quaternion: list[float] | None = None,
set_slices_visible_in_3d: bool | None = None,
show_axis_lines: bool = True,
enable_layer_color_legend: bool = True,
) -> dict[str, Any]:
"""Note, if set_slices_visible_in_3d is not provided, it will be set to False if there are any image layers in the list with volume rendering."""
image_layers = [layer for layer in layers if layer["type"] == "image"]
Expand All @@ -275,6 +276,7 @@ def combine_json_layers(
"layout": "4panel",
"showSlices": set_slices_visible_in_3d,
"showAxisLines": show_axis_lines,
"enableLayerColorWidget": enable_layer_color_legend,
"layerListPanel": {
"row": 1,
"visible": True,
Expand All @@ -291,6 +293,17 @@ def combine_json_layers(
"row": 2,
"visible": False,
},
"toolPalettes": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few changes which would be helpful here! The first is to have it stack horizontally, which would be controlled by "verticalStacking". The second is to make this a query, because that way the user can't delete the controls.

Something like

"toolPalettes": {
    "Palette": {
      "side": "bottom",
      "row": 1,
      "size": 120,
      "query": "type:dimension",
      "verticalStacking": false
    }
  }

The size would depend on whether it is vertically or horizontally stacked to be honest, but let's try this size for now.

"Dimensions": {
"side": "bottom",
"row": 1,
"tools": [
{"type": "dimension", "dimension": "x"},
{"type": "dimension", "dimension": "y"},
{"type": "dimension", "dimension": "z"},
],
},
},
}
if len(image_layers) > 0 and "_position" in image_layers[0]:
combined_json["position"] = image_layers[0]["_position"]
Expand Down
38 changes: 37 additions & 1 deletion tests/test_state_generators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from cryoet_data_portal_neuroglancer.state_generator import generate_image_layer, generate_segmentation_mask_layer
from cryoet_data_portal_neuroglancer.state_generator import (
combine_json_layers,
generate_image_layer,
generate_segmentation_mask_layer,
)


def test__generate_image_layer_default_values():
Expand All @@ -14,3 +18,35 @@ def test__generate_segmentation_layer_default_values():

assert "pick" in state
assert state["pick"] is False


def test__generate_configuration_default_values():
state = combine_json_layers(layers=[{"type": "image", "volumeRendering": "OK", "name": "myname"}], scale=1.0)

assert "enableLayerColorWidget" in state
assert state["enableLayerColorWidget"] is True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I think we'll need to pull out the color widget related changes, because I don't think we can merge this PR until horizontal stacking and our scroll fix are available. Unlike some of the other changes which can sit in the state and wait until neuroglancer understands the state changes


assert "toolPalettes" in state
assert len(state["toolPalettes"]) == 1

palette = state["toolPalettes"]["Dimensions"]
assert palette.get("side") == "bottom"
assert palette.get("row") == 1
assert len(palette.get("tools", [])) == 3

tools = palette["tools"]
assert "type" in tools[0]
assert "type" in tools[1]
assert "type" in tools[2]

assert tools[0]["type"] == "dimension"
assert tools[1]["type"] == "dimension"
assert tools[2]["type"] == "dimension"

assert "dimension" in tools[0]
assert "dimension" in tools[1]
assert "dimension" in tools[2]

assert tools[0]["dimension"] == "x"
assert tools[1]["dimension"] == "y"
assert tools[2]["dimension"] == "z"
Loading