Skip to content

Commit 499fedc

Browse files
committed
Fix issue where visualisation is not possible when an agent doesn't move
1 parent bfc3f36 commit 499fedc

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

client/src/pages/visualiser/useSolution.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { useQuery } from "@tanstack/react-query";
22
import {
3+
assign,
34
clamp,
45
entries,
6+
fill,
57
floor,
68
head,
79
last,
@@ -30,6 +32,12 @@ import {
3032
import { optimiseGridMap } from "./optimiseGridMap";
3133
import { text } from "queries/query";
3234

35+
function padArray<T>(arr: T[], size: number, value: T) {
36+
if (arr.length >= size) return arr;
37+
const padding = fill(new Array(size - arr.length), value);
38+
return [...arr, ...padding];
39+
}
40+
3341
export function processAgent(agent: string) {
3442
const reader = new Reader(agent);
3543
const seeker = new Seeker(reader, -1);
@@ -204,8 +212,12 @@ export function useSolution({
204212
const { sources, paths, timespan } = result ?? {};
205213

206214
const getters = useMemo(
207-
() => createAgentPositionGetter(sources ?? [], paths ?? [], timespan),
208-
[sources, paths, timespan]
215+
() => createAgentPositionGetter(sources ?? [], padArray(
216+
paths ?? [],
217+
instance?.agents ?? 0,
218+
""
219+
), timespan),
220+
[sources, paths, timespan, instance?.agents]
209221
);
210222

211223
return {

0 commit comments

Comments
 (0)