Skip to content

Commit 6cd09e6

Browse files
committed
add tests
1 parent 3d4891d commit 6cd09e6

File tree

2 files changed

+51
-16
lines changed

2 files changed

+51
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import HeatmapOverlay from "./overlays/heatmap";
4+
import SegmentationOverlay from "./overlays/segmentation";
5+
import { filter } from "./processOverlays";
6+
7+
const EMPTY = {
8+
id: "",
9+
tags: [],
10+
};
11+
12+
describe("test overlay processing", () => {
13+
it("filters heatmap without a map", () => {
14+
expect(filter(new HeatmapOverlay("test", EMPTY), {})).toBe(true);
15+
});
16+
17+
it("filters segmentations without a mask", () => {
18+
expect(filter(new SegmentationOverlay("test", EMPTY), {})).toBe(true);
19+
});
20+
});

app/packages/looker/src/processOverlays.ts

+31-16
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
* Copyright 2017-2025, Voxel51, Inc.
33
*/
44

5-
import { CONTAINS, Overlay } from "./overlays/base";
5+
import type { Overlay } from "./overlays/base";
6+
import { CONTAINS } from "./overlays/base";
67
import { ClassificationsOverlay } from "./overlays/classifications";
78
import HeatmapOverlay from "./overlays/heatmap";
89
import SegmentationOverlay from "./overlays/segmentation";
9-
import { BaseState } from "./state";
10+
import type { BaseState } from "./state";
1011
import { rotate } from "./util";
1112

1213
const processOverlays = <State extends BaseState>(
@@ -30,25 +31,17 @@ const processOverlays = <State extends BaseState>(
3031
continue;
3132
}
3233

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 (overlay instanceof SegmentationOverlay && !overlay.label.mask) {
39-
continue;
40-
}
41-
42-
if (overlay instanceof HeatmapOverlay && !overlay.label.map) {
43-
continue;
44-
}
45-
4634
if (!overlay.isShown(state)) continue;
4735

36+
if (filter(overlay, bins)) continue;
37+
4838
bins[overlay.field].push(overlay);
4939
}
5040

51-
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+
}, []);
5245

5346
if (classifications && !state.config.thumbnail) {
5447
ordered = [classifications, ...ordered];
@@ -89,4 +82,26 @@ const processOverlays = <State extends BaseState>(
8982
return [[...contained, ...outside], newRotate];
9083
};
9184

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+
92107
export default processOverlays;

0 commit comments

Comments
 (0)