Skip to content

Commit

Permalink
feat: Add default value to false for code editor display (#29)
Browse files Browse the repository at this point in the history
Closes CC-131

Add default value to false for code editor display
  • Loading branch information
seankmartin authored Jan 15, 2025
2 parents 8605849 + 6f36504 commit b058255
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cryoet_data_portal_neuroglancer/models/json_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class ImageJSONGenerator(RenderingJSONGenerator):
can_hide_high_values_in_neuroglancer: bool = False
blend: str = "additive"
opacity: float = 1.0
is_code_editor_visible: bool = False

def __post_init__(self):
self._type = RenderingTypes.IMAGE
Expand Down Expand Up @@ -168,6 +169,7 @@ def generate_json(self) -> dict:
"visible": self.is_visible,
"volumeRendering": "on" if self.volume_rendering_is_visible else "off",
"volumeRenderingGain": self.volume_rendering_gain,
"codeVisible": self.is_code_editor_visible,
}
if self.has_volume_rendering_shader:
config["volumeRenderingDepthSamples"] = self.volume_rendering_depth_samples
Expand All @@ -182,6 +184,7 @@ class AnnotationJSONGenerator(RenderingJSONGenerator):
point_size_multiplier: float = 1.0
is_instance_segmentation: bool = False
is_visible: bool = True
is_code_editor_visible: bool = False

def __post_init__(self):
self._type = RenderingTypes.ANNOTATION
Expand All @@ -201,6 +204,7 @@ def generate_json(self) -> dict:
"source": create_source(f"precomputed://{self.source}", self.scale, self.scale),
"tab": "rendering",
"visible": self.is_visible,
"codeVisible": self.is_code_editor_visible,
**self._get_shader(),
}

Expand Down
4 changes: 4 additions & 0 deletions cryoet_data_portal_neuroglancer/state_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def generate_oriented_point_layer(
scale: float | tuple[float, float, float] = (1.0, 1.0, 1.0),
is_visible: bool = True,
is_instance_segmentation: bool = False,
is_code_editor_visible: bool = False,
) -> dict[str, Any]:
source, name, url, _, scale = _setup_creation(source, name, url, scale=scale)
_validate_color(color)
Expand All @@ -80,6 +81,7 @@ def generate_oriented_point_layer(
scale=scale,
is_visible=is_visible,
is_instance_segmentation=is_instance_segmentation,
is_code_editor_visible=is_code_editor_visible,
).to_json()


Expand Down Expand Up @@ -189,6 +191,7 @@ def generate_image_layer(
can_hide_high_values_in_neuroglancer: bool | None = None,
blend: str = "additive",
opacity: float = 1.0,
is_code_editor_visible: bool = False,
) -> dict[str, Any]:
"""Generates JSON for an image layer with optional contrast limits.
Expand Down Expand Up @@ -217,6 +220,7 @@ def generate_image_layer(
can_hide_high_values_in_neuroglancer=can_hide_high_values_in_neuroglancer,
blend=blend,
opacity=opacity,
is_code_editor_visible=is_code_editor_visible,
).to_json()


Expand Down
23 changes: 22 additions & 1 deletion tests/test_state_generators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from cryoet_data_portal_neuroglancer.state_generator import generate_image_layer, generate_segmentation_mask_layer
from cryoet_data_portal_neuroglancer.state_generator import (
generate_image_layer,
generate_oriented_point_layer,
generate_point_layer,
generate_segmentation_mask_layer,
)


def test__generate_image_layer_default_values():
Expand All @@ -7,10 +12,26 @@ def test__generate_image_layer_default_values():
assert "blend" in state
assert state["blend"] == "additive"
assert state["opacity"] == 1.0
assert "codeVisible" in state
assert state["codeVisible"] is False


def test__generate_segmentation_layer_default_values():
state = generate_segmentation_mask_layer(source="mysource")

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


def test__generate_oriented_point_layer_default_values():
state = generate_oriented_point_layer(source="mysource")

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


def test__generate_point_layer_default_values():
state = generate_point_layer(source="mysource")

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

0 comments on commit b058255

Please sign in to comment.