Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(webv2): restyle every array the map's highlight overlay carries

Lincoln Stein57bb7042b58f
diff --git a/invokeai/frontend/webv2/src/workbench/image-map/clusterSelection.test.ts b/invokeai/frontend/webv2/src/workbench/image-map/clusterSelection.test.ts
index 3aa4905bba..fc7af4281e 100644
--- a/invokeai/frontend/webv2/src/workbench/image-map/clusterSelection.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-map/clusterSelection.test.ts
@@ -11,6 +11,7 @@ import {
buildHighlightedPointsTrace,
declutterAnnotations,
HIGHLIGHTED_POINTS_TRACE,
+ toHighlightRestyle,
} from './imageMapTraces';
const point = (name: string, x: number, y: number, cluster: number): ImageMapPoint => {
@@ -85,6 +86,32 @@ describe('buildHighlightedPointsTrace', () => {
});
});
+describe('toHighlightRestyle', () => {
+ it('carries every per-point array the highlight trace holds', () => {
+ // plotly keeps whatever a restyle omits, so an array left behind is then
+ // indexed at the new point count — which crashes inside scattergl's own
+ // marker lookup, nowhere near the omission. Selecting a cluster is what
+ // resizes this trace, so the failure lands on an ordinary click.
+ const trace = buildHighlightedPointsTrace(POINTS, new Set(['image:a.png' as const, 'video:clip.mp4' as const]));
+ const payload = toHighlightRestyle(trace);
+
+ const perPointKeys = Object.entries(trace.marker)
+ .filter(([, value]) => Array.isArray(value))
+ .map(([name]) => `marker.${name}`);
+
+ expect(perPointKeys.length).toBeGreaterThan(0);
+ for (const key of [...perPointKeys, 'customdata', 'x', 'y']) {
+ expect(Object.keys(payload)).toContain(key);
+ }
+ // Every entry is wrapped for the one trace it restyles, and describes the
+ // same points.
+ for (const value of Object.values(payload)) {
+ expect(value).toHaveLength(1);
+ expect(value[0]).toHaveLength(trace.x.length);
+ }
+ });
+});
+
describe('buildClusterAnnotations', () => {
it('places one annotation per labeled cluster, centered above its topmost point', () => {
const varied = [point('a.png', 0, 1, 0), point('b.png', 3, 5, 0), point('c.png', 1, 3, 0)];
diff --git a/invokeai/frontend/webv2/src/workbench/image-map/imageMapTraces.ts b/invokeai/frontend/webv2/src/workbench/image-map/imageMapTraces.ts
index 9a3b222d5f..fcfa43ba57 100644
--- a/invokeai/frontend/webv2/src/workbench/image-map/imageMapTraces.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-map/imageMapTraces.ts
@@ -126,6 +126,23 @@ export const buildCurrentImageTrace = (): ScatterTrace => ({
const GRID_LINE_COLOR = 'rgba(128, 128, 128, 0.16)';
const GRID_ZERO_COLOR = 'rgba(128, 128, 128, 0.32)';
+/**
+ * The restyle payload for the highlight overlay: every per-point array the
+ * trace carries, so the overlay can be updated in place.
+ *
+ * Derived from the trace rather than listed at the call site, because plotly
+ * keeps whatever a restyle omits — so leaving one array behind means it is
+ * indexed at the NEW point count, and scattergl dies inside its own marker
+ * lookup rather than anywhere near the omission.
+ */
+export const toHighlightRestyle = (trace: ScatterTrace): Record<string, unknown[]> => ({
+ customdata: [trace.customdata],
+ 'marker.color': [trace.marker.color as string[]],
+ 'marker.symbol': [trace.marker.symbol as string[]],
+ x: [trace.x],
+ y: [trace.y],
+});
+
export const buildMapLayout = (
initialRanges?: AxisRanges | null,
annotations: ClusterAnnotation[] = []
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapPlot.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapPlot.tsx
index 2c94ab70ad..505ffd3de4 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapPlot.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapPlot.tsx
@@ -25,6 +25,7 @@ import {
CURRENT_IMAGE_TRACE,
declutterAnnotations,
HIGHLIGHTED_POINTS_TRACE,
+ toHighlightRestyle,
} from '@workbench/image-map/imageMapTraces';
import {
computePercentileRanges,
@@ -415,18 +416,7 @@ const ImageMapPlot = ({
}
const trace = buildHighlightedPointsTrace(points, selectedKeys);
- swallow(
- Plotly.restyle(
- container,
- {
- customdata: [trace.customdata],
- 'marker.color': [trace.marker.color as string[]],
- x: [trace.x],
- y: [trace.y],
- },
- [highlightIndex]
- )
- );
+ swallow(Plotly.restyle(container, toHighlightRestyle(trace), [highlightIndex]));
}, [plotRevision, points, selectedKeys]);
// The timer must not outlive the component; the scene effect used to do