@@ -215,17 +215,22 @@ def toggle_label(self, labels_layer, event):
215
215
Callback for when a label is clicked. It then updates the color of that
216
216
label in the annotation layer.
217
217
"""
218
- # Need to scale position that event.position returns by the
218
+ # Need to translate & scale position that event.position returns by the
219
219
# label_layer scale.
220
220
# If scale is (1, 1, 1), nothing changes
221
+ # If translate is (0, 0, 0)
221
222
# If scale is anything else, this makes the click still match the
222
223
# correct label
224
+ # translate before scale
223
225
scaled_position = tuple (
224
- pos / scale for pos , scale in zip (event .position , labels_layer .scale )
226
+ (pos - trans ) / scale
227
+ for pos , trans , scale in zip (
228
+ event .position , labels_layer .translate , labels_layer .scale
229
+ )
225
230
)
226
231
label = labels_layer .get_value (scaled_position )
227
232
if label == 0 or not label :
228
- napari_info ("No label clicked." )
233
+ napari_info (f "No label clicked on the { labels_layer } label layer ." )
229
234
return
230
235
231
236
# Left click: add annotation
@@ -269,6 +274,8 @@ def _init_annotation(self, label_layer: napari.layers.Labels):
269
274
# label_layer.opacity = 0.4
270
275
self ._annotations_layer .data = label_layer .data
271
276
self ._annotations_layer .scale = label_layer .scale
277
+ self ._annotations_layer .translate = label_layer .translate
278
+
272
279
reset_display_colormaps (
273
280
label_layer ,
274
281
feature_col = "annotations" ,
0 commit comments