Conversation
Reviewer's GuideThis pull request implements a multi-channel grid view feature. It introduces a new File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @melonora - I've reviewed your changes - here's some feedback:
- Consider refactoring
MultiChannelGridCanvasto reuse logic from the existingGridCanvasto reduce code duplication. - Clarify the distinction and relationship between the existing
GridCanvasand the newMultiChannelGridCanvas.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| for y in range(grid_shape[0]) | ||
| for x in range(grid_shape[1]) | ||
| if x * y < n_gridboxes |
There was a problem hiding this comment.
suggestion (bug_risk): Review grid view index calculation in the list comprehension.
Use (y * grid_shape[1] + x) instead of x * y to compute the grid index and preserve row-major ordering.
| for y in range(grid_shape[0]) | |
| for x in range(grid_shape[1]) | |
| if x * y < n_gridboxes | |
| for y in range(grid_shape[0]) | |
| for x in range(grid_shape[1]) | |
| if y * grid_shape[1] + x < n_gridboxes |
| """Enable playing of animation. False if awaiting a draw event""" | ||
| self.viewer.dims._play_ready = True | ||
|
|
||
| def _on_grid_change(self): |
There was a problem hiding this comment.
issue (complexity): Consider refactoring the _on_grid_change method by extracting the enabling/disabling logic into separate helper functions.
Refactor the method by offloading the enabling/disabling logic to helper functions. This will keep the functionality intact while reducing the inline branching and list comprehensions. For example:
def _enable_grid_mode(self):
grid_shape, n_gridboxes = self.viewer.multi_channel_gridcanvas.actual_shape(
len(self.layer_to_visual)
)
self.grid = self.central_widget.add_grid()
camera = self.camera._view.camera
self.grid_views = [
self.grid.add_view(
row=y,
col=x,
camera=camera if y == 0 and x == 0 else None
)
for y in range(grid_shape[0])
for x in range(grid_shape[1])
if x * y < n_gridboxes
]
self.camera._view = self.grid_views[0]
self.central_widget.remove_widget(self.view)
self.grid_cameras = [
VispyCamera(self.grid_views[i], self.viewer.camera, self.viewer.dims)
for i in range(len(self.grid_views[1:]))
]
for ind, layer in enumerate(self.layer_to_visual.values()):
if ind != 0:
self.grid_views[ind].camera = self.grid_cameras[ind - 1]._view.camera
self.grid_views[ind].camera.link(self.grid_views[0].camera)
layer.node.parent = self.grid_views[ind].scene
def _disable_grid_mode(self):
for layer in self.layer_to_visual.values():
layer.node.parent = self.view.scene
self.central_widget.remove_widget(self.grid)
self.central_widget.add_widget(self.view)
self.camera._view = self.view
# TODO: properly disconnect grid events and delete all viewboxes
del self.grid
for camera in self.grid_cameras:
camera.disconnect()
del camera
# TODO: respect 3D camera if enabled
self.camera._view.camera = self.camera._2D_camera
def _on_grid_change(self):
"""Change grid view"""
if self.viewer.multi_channel_gridcanvas.enabled:
self._enable_grid_mode()
else:
self._disable_grid_mode()Actionable Steps:
- Create two focused helper functions:
_enable_grid_modeand_disable_grid_mode. - Move the corresponding code from
_on_grid_changeinto these helper functions. - In
_on_grid_change, simply check the condition and call the appropriate helper.
This refactoring decouples responsibilities, making the control flow easier to follow and maintain.
| def _on_grid_change(self): | ||
| """Change grid view""" | ||
| if self.viewer.multi_channel_gridcanvas.enabled: | ||
| grid_shape, n_gridboxes = ( |
There was a problem hiding this comment.
issue (code-quality): Extract code out into method (extract-method)
References and relevant issues
Description
Summary by Sourcery
Implement a new multichannel grid canvas feature for displaying layers in a configurable grid layout
New Features:
Enhancements: