@@ -3658,11 +3658,29 @@ export class ULabel {
36583658 current_subtask [ "state" ] [ "visible_dialogs" ] [ esid ] [ "top" ] = new_top ;
36593659 // Decide confidence card position from the un-offset cbox so it stays stable during moves.
36603660 // Account for annbox scroll: what matters is the visible position, not the image-space position.
3661- const cbox_center_y_imwrap = ( ( cbox [ "tly" ] + cbox [ "bry" ] ) / 2 ) * this . state [ "zoom_val" ] ;
36623661 const scroll_top = $ ( "#" + this . config [ "annbox_id" ] ) . scrollTop ( ) || 0 ;
36633662 const conf_id = `global_annotation_confidence__${ subtask_key } ` ;
3664- const flip_below = ( cbox_center_y_imwrap - scroll_top ) < 100 ;
3665- $ ( `#${ conf_id } ` ) . css ( "margin-top" , flip_below ? "-1em" : "-9.5em" ) ;
3663+ const conf_jq = $ ( `#${ conf_id } ` ) ;
3664+ // The dialog container is CSS-scaled about the anchor, so a margin
3665+ // set here lands `scale` times as far. `outerHeight` is already in
3666+ // that local space; the cbox measurements are in screen px.
3667+ const es_el = esjq [ 0 ] ;
3668+ const scale = es_el . offsetWidth > 0 ?
3669+ es_el . getBoundingClientRect ( ) . width / es_el . offsetWidth :
3670+ 1 ;
3671+ const card_height = conf_jq . outerHeight ( ) || 0 ;
3672+ const gap = 10 ;
3673+ // The anchor is the box centre, so clear it by half the on-screen
3674+ // box height or the card covers whatever is being hovered.
3675+ const half_height = Math . abs ( cbox [ "bry" ] - cbox [ "tly" ] ) / 2 * this . state [ "zoom_val" ] ;
3676+ const box_top_visible = ( cbox [ "tly" ] * this . state [ "zoom_val" ] ) - scroll_top ;
3677+ const flip_below = box_top_visible - ( card_height * scale ) - gap < 0 ;
3678+ conf_jq . css (
3679+ "margin-top" ,
3680+ flip_below ?
3681+ `${ ( half_height + gap ) / scale } px` :
3682+ `${ - ( ( half_height + gap ) / scale + card_height ) } px` ,
3683+ ) ;
36663684 this . reposition_dialogs ( ) ;
36673685 idd_x = ( cbox [ "tlx" ] + cbox [ "brx" ] + 2 * diffX ) / 2 ;
36683686 idd_y = ( cbox [ "tly" ] + cbox [ "bry" ] + 2 * diffY ) / 2 ;
@@ -6236,6 +6254,14 @@ export class ULabel {
62366254 let minsize = Infinity ;
62376255 let found_containing_annotation = false ;
62386256 const active_class_layer = this . get_current_subtask ( ) [ "state" ] [ "active_class_layer" ] ?? null ;
6257+ // A read-only subtask has nothing to grab, so the near-miss fallback
6258+ // below is just noise: require a real hit wherever one can be tested.
6259+ const require_exact_hit = this . is_current_subtask_read_only ( ) ;
6260+ // One cursor pixel spans several image pixels when zoomed out, so the
6261+ // exact tests get that much slack. Without it a thin mask or the edge
6262+ // of a large one is unhittable: the pixel under the cursor is empty
6263+ // even though the downscaled render looks filled there.
6264+ const slack = 2 / this . get_empirical_scale ( ) ;
62396265 // TODO(3d)
62406266 for ( let edi = 0 ; edi < this . get_current_subtask ( ) [ "annotations" ] [ "ordering" ] . length ; edi ++ ) {
62416267 const annotation_id = this . get_current_subtask ( ) [ "annotations" ] [ "ordering" ] [ edi ] ;
@@ -6273,6 +6299,9 @@ export class ULabel {
62736299 ( this . state [ "current_frame" ] <= cbox [ "brz" ] )
62746300 ) {
62756301 let is_a_containing_annotation = false ;
6302+ // Whether this spatial type can be hit-tested against its real
6303+ // boundary rather than just its containing box.
6304+ let has_exact_test = true ;
62766305 let boxsize = ( cbox [ "brx" ] - cbox [ "tlx" ] ) * ( cbox [ "bry" ] - cbox [ "tly" ] ) ;
62776306 switch ( spatial_type ) {
62786307 case "polygon" :
@@ -6292,14 +6321,28 @@ export class ULabel {
62926321 is_a_containing_annotation = true ;
62936322 }
62946323 break ;
6324+ case "polyline" :
6325+ // Within the drawn stroke of the line itself
6326+ if ( GeometricUtils . point_is_near_polyline (
6327+ [ gblx , gbly ] ,
6328+ annotation [ "spatial_payload" ] ,
6329+ ( annotation [ "line_size" ] ?? this . get_subtask_line_size ( ) ) / 2 + slack ,
6330+ ) ) {
6331+ is_a_containing_annotation = true ;
6332+ }
6333+ break ;
62956334 case "bitmask" :
62966335 // The mouse must be over a painted pixel of the mask
6297- if ( this . get_bitmask ( annotation ) . get_pixel ( Math . round ( gblx ) , Math . round ( gbly ) ) ) {
6336+ if ( this . get_bitmask ( annotation ) . has_foreground_in_circle (
6337+ Math . round ( gblx ) ,
6338+ Math . round ( gbly ) ,
6339+ slack ,
6340+ ) ) {
62986341 is_a_containing_annotation = true ;
62996342 }
63006343 break ;
63016344 default :
6302-
6345+ has_exact_test = false ;
63036346 break ;
63046347 }
63056348
@@ -6321,7 +6364,7 @@ export class ULabel {
63216364 } ;
63226365 }
63236366 }
6324- } else if ( boxsize < minsize ) {
6367+ } else if ( ! ( require_exact_hit && has_exact_test ) && boxsize < minsize ) {
63256368 ret [ "candidate_ids" ] . push ( annotation_id ) ;
63266369 minsize = boxsize ;
63276370 ret [ "best" ] = {
@@ -6452,18 +6495,31 @@ export class ULabel {
64526495
64536496 // ================= Mouse event interpreters =================
64546497
6498+ /**
6499+ * Page coordinates of the annbox's content origin, which is where the image
6500+ * starts. `offset()` gives the border box, so any border on the annbox would
6501+ * otherwise shift every position by its width.
6502+ */
6503+ get_annbox_content_origin ( ) {
6504+ const annbox = $ ( "#" + this . config [ "annbox_id" ] ) ;
6505+ const offset = annbox . offset ( ) ;
6506+ const el = annbox [ 0 ] ;
6507+ return {
6508+ left : offset . left + ( el ?. clientLeft ?? 0 ) - annbox . scrollLeft ( ) ,
6509+ top : offset . top + ( el ?. clientTop ?? 0 ) - annbox . scrollTop ( ) ,
6510+ } ;
6511+ }
6512+
64556513 // Get the mouse position on the screen
64566514 get_global_mouse_x ( mouse_event ) {
64576515 const scale = this . get_empirical_scale ( ) ;
6458- const annbox = $ ( "#" + this . config [ "annbox_id" ] ) ;
6459- const raw = ( mouse_event . pageX - annbox . offset ( ) . left + annbox . scrollLeft ( ) ) / scale ;
6516+ const raw = ( mouse_event . pageX - this . get_annbox_content_origin ( ) . left ) / scale ;
64606517 return raw ;
64616518 }
64626519
64636520 get_global_mouse_y ( mouse_event ) {
64646521 const scale = this . get_empirical_scale ( ) ;
6465- const annbox = $ ( "#" + this . config [ "annbox_id" ] ) ;
6466- const raw = ( mouse_event . pageY - annbox . offset ( ) . top + annbox . scrollTop ( ) ) / scale ;
6522+ const raw = ( mouse_event . pageY - this . get_annbox_content_origin ( ) . top ) / scale ;
64676523 return raw ;
64686524 }
64696525
@@ -6491,16 +6547,14 @@ export class ULabel {
64916547
64926548 get_global_element_center_x ( jqel ) {
64936549 const scale = this . get_empirical_scale ( ) ;
6494- const annbox = $ ( "#" + this . config [ "annbox_id" ] ) ;
6495- const raw = ( jqel . offset ( ) . left + jqel . width ( ) / 2 - annbox . offset ( ) . left + annbox . scrollLeft ( ) ) / scale ;
6550+ const raw = ( jqel . offset ( ) . left + jqel . width ( ) / 2 - this . get_annbox_content_origin ( ) . left ) / scale ;
64966551 // return Math.round(raw);
64976552 return raw ;
64986553 }
64996554
65006555 get_global_element_center_y ( jqel ) {
65016556 const scale = this . get_empirical_scale ( ) ;
6502- const annbox = $ ( "#" + this . config [ "annbox_id" ] ) ;
6503- const raw = ( jqel . offset ( ) . top + jqel . height ( ) / 2 - annbox . offset ( ) . top + annbox . scrollTop ( ) ) / scale ;
6557+ const raw = ( jqel . offset ( ) . top + jqel . height ( ) / 2 - this . get_annbox_content_origin ( ) . top ) / scale ;
65046558 // return Math.round();
65056559 return raw ;
65066560 }
@@ -6829,10 +6883,11 @@ export class ULabel {
68296883 class_name = class_def . name ;
68306884 }
68316885 }
6886+ const display_name = this . config . annotation_display_name_resolver ?. ( active_annotation ) ?? class_name ;
68326887
68336888 // Update the display dialog
68346889 const global_id = `global_annotation_confidence__${ subtask_key } ` ;
6835- $ ( `#${ global_id } .annotation-confidence-classname` ) . text ( class_name ) ;
6890+ $ ( `#${ global_id } .annotation-confidence-classname` ) . text ( display_name ) ;
68366891 $ ( `#${ global_id } .annotation-confidence-value` ) . text ( `Confidence: ${ confidence . toFixed ( 2 ) } ` ) ;
68376892 }
68386893
0 commit comments