2
2
* Copyright 2017-2025, Voxel51, Inc.
3
3
*/
4
4
5
- import { CONTAINS , Overlay } from "./overlays/base" ;
5
+ import type { Overlay } from "./overlays/base" ;
6
+ import { CONTAINS } from "./overlays/base" ;
6
7
import { ClassificationsOverlay } from "./overlays/classifications" ;
7
8
import HeatmapOverlay from "./overlays/heatmap" ;
8
9
import SegmentationOverlay from "./overlays/segmentation" ;
9
- import { BaseState } from "./state" ;
10
+ import type { BaseState } from "./state" ;
10
11
import { rotate } from "./util" ;
11
12
12
13
const processOverlays = < State extends BaseState > (
@@ -30,33 +31,17 @@ const processOverlays = <State extends BaseState>(
30
31
continue ;
31
32
}
32
33
33
- if ( ! ( overlay . field && overlay . field in bins ) ) continue ;
34
-
35
- // todo: find a better approach / place for this.
36
- // for instance, this won't work in detection overlay, where
37
- // we might want the bounding boxes but masks might not have been loaded
38
- if (
39
- overlay instanceof SegmentationOverlay &&
40
- overlay . label . mask_path &&
41
- ! overlay . label . mask
42
- ) {
43
- continue ;
44
- }
45
-
46
- if (
47
- overlay instanceof HeatmapOverlay &&
48
- overlay . label . map_path &&
49
- ! overlay . label . map
50
- ) {
51
- continue ;
52
- }
53
-
54
34
if ( ! overlay . isShown ( state ) ) continue ;
55
35
36
+ if ( filter ( overlay , bins ) ) continue ;
37
+
56
38
bins [ overlay . field ] . push ( overlay ) ;
57
39
}
58
40
59
- let ordered = activePaths . reduce ( ( acc , cur ) => [ ...acc , ...bins [ cur ] ] , [ ] ) ;
41
+ let ordered = activePaths . reduce ( ( acc , cur ) => {
42
+ acc . push ( ...bins [ cur ] ) ;
43
+ return acc ;
44
+ } , [ ] ) ;
60
45
61
46
if ( classifications && ! state . config . thumbnail ) {
62
47
ordered = [ classifications , ...ordered ] ;
@@ -97,4 +82,26 @@ const processOverlays = <State extends BaseState>(
97
82
return [ [ ...contained , ...outside ] , newRotate ] ;
98
83
} ;
99
84
85
+ export const filter = < State extends BaseState > (
86
+ overlay : Overlay < State > ,
87
+ bins : {
88
+ [ k : string ] : Overlay < State > [ ] ;
89
+ }
90
+ ) => {
91
+ if ( ! ( overlay . field && overlay . field in bins ) ) return true ;
92
+
93
+ // todo: find a better approach / place for this.
94
+ // for instance, this won't work in detection overlay, where
95
+ // we might want the bounding boxes but masks might not have been loaded
96
+ if ( overlay instanceof HeatmapOverlay && ! overlay . label . map ) {
97
+ return true ;
98
+ }
99
+
100
+ if ( overlay instanceof SegmentationOverlay && ! overlay . label . mask ) {
101
+ return true ;
102
+ }
103
+
104
+ return false ;
105
+ } ;
106
+
100
107
export default processOverlays ;
0 commit comments