Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(roadtrip): draw the drive between connected days in the arrival day's colour

Maurice684a3bf5f5ee
diff --git a/client/src/components/Roadtrip/stageMap.test.ts b/client/src/components/Roadtrip/stageMap.test.ts
index 1daf870f3..bd45f76c3 100644
--- a/client/src/components/Roadtrip/stageMap.test.ts
+++ b/client/src/components/Roadtrip/stageMap.test.ts
@@ -125,14 +125,15 @@ describe('stageMapData with a stage', () => {
expect(stageMapData(routes(), stage, true).lines).toEqual([LINES[1], LINES[2]])
})
- it('FE-RTSTAGE-016: the drive into the next day is left off the stage', () => {
- // With "connect the days" on, that leg is drawn in the colour of the day it leaves, so
+ it('FE-RTSTAGE-016: the drive in from the day before is left off the stage', () => {
+ // With "connect the days" on, that leg is drawn as the day it arrives on (#3123), so
// filtering by day number alone handed the stage a line running off it to a place the
// day never visits. On a phone, where the stage IS the map, it was the longest thing
- // on screen and read as the day's own route.
- const withJoin = routes({ lineJoins: [false, false, true, false] })
+ // on screen and read as the day's own route. The assembler emits it first among the
+ // lines of the day it reaches, ahead of that day's own legs.
+ const withJoin = routes({ lineJoins: [false, true, false, false] })
- expect(stageMapData(withJoin, stage, true).lines).toEqual([LINES[1]])
+ expect(stageMapData(withJoin, stage, true).lines).toEqual([LINES[2]])
})
it('FE-RTSTAGE-020: a day that is nothing but driving keeps its connection rather than going blank', () => {
@@ -144,7 +145,7 @@ describe('stageMapData with a stage', () => {
})
it('FE-RTSTAGE-017: the colours still line up once a join has been dropped', () => {
- const data = stageMapData(routes({ lineJoins: [false, false, true, false] }), stage, true)
+ const data = stageMapData(routes({ lineJoins: [false, true, false, false] }), stage, true)
expect(data.lineColors).toHaveLength(data.lines.length)
expect(data.lineColors).toEqual([dayColor(2)])
@@ -153,7 +154,7 @@ describe('stageMapData with a stage', () => {
it('FE-RTSTAGE-018: the all-days view keeps the joins, which is the view they are for', () => {
// The setting draws the whole drive as one connected line; that is what it is for, and
// on this map the connection has the other days beside it.
- expect(stageMapData(routes({ lineJoins: [false, false, true, false] }), null, true).lines).toEqual(LINES)
+ expect(stageMapData(routes({ lineJoins: [false, true, false, false] }), null, true).lines).toEqual(LINES)
})
it('FE-RTSTAGE-019: routes from before the flag existed are drawn as they were', () => {
diff --git a/client/src/components/Roadtrip/stageMap.ts b/client/src/components/Roadtrip/stageMap.ts
index 51b45d4e3..b9f7cd819 100644
--- a/client/src/components/Roadtrip/stageMap.ts
+++ b/client/src/components/Roadtrip/stageMap.ts
@@ -50,15 +50,15 @@ export function stageMapData(
}
if (!routes.lines.length) return { ...EMPTY, placeIds: stagePlaceIds(stage), focusPoints: stagePoints(stage) }
- // A stage is ONE day, so the drive into the next day is left off it.
+ // A stage is ONE day, so the drive in from the day before is left off it.
//
- // With "connect the days" on, that leg is drawn in the colour of the day it leaves, so
- // on the whole-drive map it reads as that day carrying on. Filtering by day number
- // alone therefore handed a stage a line that runs off it to a place the day never
- // visits: on a phone, where the stage IS the map, that read as the day's own route and
- // was the longest thing on screen. The desktop has the same connection, but it has it
- // beside every other day, which is the view the setting exists for; here that view is
- // the "all days" one, a tap away on the same map.
+ // With "connect the days" on, that leg is drawn as the day it arrives on, the day whose
+ // distance counts it. Filtering by day number alone therefore handed a stage a line
+ // that runs off it to a place the day never visits: on a phone, where the stage IS the
+ // map, that read as the day's own route and was the longest thing on screen. The
+ // desktop has the same connection, but it has it beside every other day, which is the
+ // view the setting exists for; here that view is the "all days" one, a tap away on the
+ // same map.
const ofDay: number[] = []
routes.lineDays.forEach((n, i) => { if (n === stage.dayNumber) ofDay.push(i) })
const own = ofDay.filter(i => !routes.lineJoins?.[i])
diff --git a/client/src/components/Roadtrip/useRoadtripRoutes.test.ts b/client/src/components/Roadtrip/useRoadtripRoutes.test.ts
index bac86a128..5c735830e 100644
--- a/client/src/components/Roadtrip/useRoadtripRoutes.test.ts
+++ b/client/src/components/Roadtrip/useRoadtripRoutes.test.ts
@@ -631,7 +631,7 @@ describe('useRoadtripRoutes', () => {
expect(result.current.totalDistance).toBe(300000)
})
- it('FE-ROADTRIP-ROUTES-022: the joining stroke wears the day it leaves, its kilometres the day it reaches', async () => {
+ it('FE-ROADTRIP-ROUTES-022: the joining stroke wears the day it reaches, like its kilometres (#3123)', async () => {
setting({ roadtrip_connect_days: true })
const { days: daysList, assignments } = twoDays()
const { result } = renderHook(() => useRoadtripRoutes(7, daysList, assignments))
@@ -639,10 +639,9 @@ describe('useRoadtripRoutes', () => {
// Same length and same order as `lines`, or a colour lands on the wrong day.
expect(result.current.lineDays).toHaveLength(result.current.lines.length)
- // The stroke starts at a stop on day 1, so drawing it as day 2 would make day 2
- // look like it begins somewhere it has no stop.
- expect(result.current.lineDays).toEqual([1, 1, 2])
- // The kilometres go the other way: they are driven on the day they arrive.
+ // Day 1 ends at its last stop, so the drive on to day 2 is driven on day 2: its
+ // kilometres are counted there, and drawn in day 1's colour the map said otherwise.
+ expect(result.current.lineDays).toEqual([1, 2, 2])
expect(result.current.days.map(d => d.distance)).toEqual([100000, 200000])
})
@@ -666,7 +665,8 @@ describe('useRoadtripRoutes', () => {
setting({ roadtrip_connect_days: true })
expect(result.current.lines).toHaveLength(3)
- expect(result.current.lineDays).toEqual([1, 2, 2])
+ // The drive past midnight lands on day 2 and is drawn there, like day 2's own legs.
+ expect(result.current.lineDays).toEqual([2, 2, 2])
expect(result.current.days[0].distance).toBe(300000)
})
diff --git a/shared/src/roadtrip/assemble.spec.ts b/shared/src/roadtrip/assemble.spec.ts
index 112301969..1b12116ba 100644
--- a/shared/src/roadtrip/assemble.spec.ts
+++ b/shared/src/roadtrip/assemble.spec.ts
@@ -1,5 +1,5 @@
/**
- * ROADTRIP-ASSEMBLE-001..024: what the assembler does with the model's warnings, and
+ * ROADTRIP-ASSEMBLE-001..027: what the assembler does with the model's warnings, and
* what it tells a surface about the drive between connected days. From 017 on: a booked
* night seated at both ends of its days (`seatNightBookends`) is one spot overnight,
* driven to and from like any stop and never between.
@@ -201,16 +201,130 @@ describe('assembleRoadtrip connected days', () => {
expect(routes.days[1]!.geometry[0]).toEqual([60, 10]);
});
- it('ROADTRIP-ASSEMBLE-006: that drive is marked as the connection it is, in the colour of the day it leaves', () => {
+ it('ROADTRIP-ASSEMBLE-006: that drive is marked as the connection it is, in the colour of the day it arrives on (#3123)', () => {
const routes = assembleTwoDays(true);
- // Day 1 drives two of its own legs and then on into day 2; day 2 drives one.
- expect(routes.lineDays).toEqual([1, 1, 1, 2]);
+ // Day 1 drives two of its own legs; day 2 drives on from yesterday's last stop and then
+ // one of its own. The connecting drive counts toward day 2 on the card, so the map draws
+ // it as day 2 too: drawn as day 1, the map said the drive was day 1's while the card's
+ // figures said day 2's.
+ expect(routes.lineDays).toEqual([1, 1, 2, 2]);
+ expect(routes.days.map((d) => d.distance)).toEqual([200_000, 200_000]);
expect(routes.lines).toHaveLength(routes.lineJoins.length);
- // The third line is drawn as day 1 but runs into day 2, and only it is a join. A
- // surface showing one day needs that apart from the day number, which says day 1 for
- // both the day's own legs and for the drive leading off it.
+ // The third line is the connection, and only it is a join. A surface showing one day
+ // needs that apart from the day number, which says day 2 for both the day's own leg and
+ // the drive leading into it.
+ expect(routes.lineJoins).toEqual([false, false, true, false]);
+ });
+
+ it('ROADTRIP-ASSEMBLE-025: a stop reached after midnight is drawn in the colour of the day it lands on (#3123)', () => {
+ // Day 1 sets off at 22:00 and drives two 100 km legs of 67 minutes each, so its last
+ // stop is reached at 00:14 and the card files it under day 2, with its drive counted
+ // there. The line into it has to say day 2 as well.
+ const first = [stop({ ownerIndex: 0, time: '22:00' }), stop({ ownerIndex: 1 }), stop({ ownerIndex: 2 })];
+ const second = [
+ stop({ ownerDayId: 2, ownerIndex: 0, assignmentId: 300, placeId: 400, lat: 60 }),
+ stop({ ownerDayId: 2, ownerIndex: 1, assignmentId: 301, placeId: 401, lat: 61 }),
+ ];
+ const allLegs: Record<string, RoutedLeg> = {};
+ for (const run of [first, second, [first[2]!, second[0]!]]) {
+ run.slice(0, -1).forEach((from, i) => {
+ allLegs[legKey(from, run[i + 1]!)] = lineFrom(from, run[i + 1]!);
+ });
+ }
+ const routes = assembleRoadtrip({
+ plan: [
+ { dayId: 1, dayNumber: 1, date: '2026-06-01', title: null, stops: first },
+ { dayId: 2, dayNumber: 2, date: '2026-06-02', title: null, stops: second },
+ ],
+ quietDays: [],
+ window: null,
+ distanceUnit: 'metric',
+ allLegs,
+ snapByDay: {},
+ missedByDay: {},
+ loading: false,
+ limits: { rangeKm: null, legMinutes: null, dayMinutes: null },
+ vehicleKind: null,
+ connectDays: true,
+ boundaries: [],
+ labels: { start: 'start', end: 'end' },
+ });
+
+ const landed = routes.days.find((d) => d.dayNumber === 2)!;
+ expect(landed.spills).toEqual([expect.objectContaining({ at: 0, fromDayNumber: 1 })]);
+ // Day 1 keeps one leg; the drive past midnight and day 2's own two legs are day 2's.
+ expect(routes.days.map((d) => d.distance)).toEqual([100_000, 300_000]);
+ expect(routes.lineDays).toEqual([1, 2, 2, 2]);
+ expect(routes.lineJoins).toEqual([false, true, false, false]);
+ });
+
+ /**
+ * The same two days under daily travel times that end each day "At the last place", the
+ * setting #3123 was filed with. `joinKm` sets the drive between the days: 100 km fits the
+ * window, 2000 km does not, so the window plan gives up (`legTooLong`) and the days fall
+ * back to being drawn as stored.
+ */
+ function assembleAtLastPlace(joinKm: number) {
+ const first = [stop({ ownerIndex: 0 }), stop({ ownerIndex: 1 }), stop({ ownerIndex: 2 })];
+ const second = [
+ stop({ ownerDayId: 2, ownerIndex: 0, assignmentId: 300, placeId: 400, lat: 60 }),
+ stop({ ownerDayId: 2, ownerIndex: 1, assignmentId: 301, placeId: 401, lat: 61 }),
+ ];
+ const allLegs: Record<string, RoutedLeg> = {};
+ for (const run of [first, second]) {
+ run.slice(0, -1).forEach((from, i) => {
+ allLegs[legKey(from, run[i + 1]!)] = lineFrom(from, run[i + 1]!);
+ });
+ }
+ const join = lineFrom(first[2]!, second[0]!);
+ allLegs[legKey(first[2]!, second[0]!)] = {
+ ...join,
+ seg: { ...join.seg, distance: joinKm * 1000, duration: joinKm * 40 },
+ };
+ return assembleRoadtrip({
+ plan: [
+ { dayId: 1, dayNumber: 1, date: '2026-06-01', title: null, stops: first },
+ { dayId: 2, dayNumber: 2, date: '2026-06-02', title: null, stops: second },
+ ],
+ quietDays: [],
+ window: { start: 8 * 60, end: 20 * 60, endMode: 'stop' },
+ distanceUnit: 'metric',
+ allLegs,
+ snapByDay: {},
+ missedByDay: {},
+ loading: false,
+ limits: { rangeKm: null, legMinutes: null, dayMinutes: null },
+ vehicleKind: null,
+ connectDays: true,
+ boundaries: [],
+ labels: { start: 'start', end: 'end' },
+ });
+ }
+
+ /** Each day's distance, rebuilt from the lines the map draws in that day's colour. */
+ const drawnKm = (routes: ReturnType<typeof assembleAtLastPlace>, dayNumber: number) =>
+ routes.lineDays.filter((n) => n === dayNumber).length * 100_000;
+
+ it('ROADTRIP-ASSEMBLE-026: ending each day at the last place, the drive between the days is drawn as the next day (#3123)', () => {
+ const routes = assembleAtLastPlace(100);
+
+ expect(routes.dayWindowIssue).toBeNull();
+ expect(routes.lineDays).toEqual([1, 1, 2, 2]);
+ expect(routes.lineJoins).toEqual([false, false, true, false]);
+ // Every 100 km line drawn as a day is counted in that day's distance, and no other.
+ expect(routes.days.map((d) => d.distance)).toEqual([drawnKm(routes, 1), drawnKm(routes, 2)]);
+ });
+
+ it('ROADTRIP-ASSEMBLE-027: when the window cannot be kept, the stored days still draw the drive as the day it reaches (#3123)', () => {
+ const routes = assembleAtLastPlace(2000);
+
+ expect(routes.dayWindowIssue).toBe('legTooLong');
+ expect(routes.lineDays).toEqual([1, 1, 2, 2]);
expect(routes.lineJoins).toEqual([false, false, true, false]);
+ // Day 2 carries the 2000 km drive and its own 100 km leg: the line the map draws as
+ // day 2 is the one the card counts there.
+ expect(routes.days.map((d) => d.distance)).toEqual([200_000, 2_100_000]);
});
it('ROADTRIP-ASSEMBLE-007: with the days unconnected there is no join to mark', () => {
diff --git a/shared/src/roadtrip/assemble.ts b/shared/src/roadtrip/assemble.ts
index 96f0c7f9f..8585cab7b 100644
--- a/shared/src/roadtrip/assemble.ts
+++ b/shared/src/roadtrip/assemble.ts
@@ -101,8 +101,8 @@ export function assembleRoadtrip({
const lines: [number, number][][] = [];
const lineDays: number[] = [];
- // Parallel to `lines`: true where the line is the drive into the NEXT day, drawn in the
- // leaving day's colour. See `lineJoins` on RoadtripRoutes.
+ // Parallel to `lines`: true where the line is the drive in from the PREVIOUS day, drawn
+ // as the day it arrives on. See `lineJoins` on RoadtripRoutes.
const lineJoins: boolean[] = [];
const segments: RouteSegment[] = [];
const accessLines: RoadtripRoutes['accessLines'] = [];
@@ -113,18 +113,16 @@ export function assembleRoadtrip({
let carryKm: number | null = 0;
let previousStop: RoadtripStop | undefined;
-
- let previousDayNumber: number | undefined;
for (const chain of displayChains) {
const routed = chain.stops.slice(0, -1).map((s, i) => legFor(s, chain.stops[i + 1]!));
- const inboundAt = new Map<number, { seg: RouteSegment | undefined; line: [number, number][]; drawnAs: number }>();
+ const inboundAt = new Map<number, { seg: RouteSegment | undefined; line: [number, number][] }>();
let arrivingLeg: RouteSegment | undefined;
let arrivingLine: [number, number][] | undefined;
let arrivingFrom: RoadtripStop | undefined;
if (connectDays && !automaticSchedule) {
for (const spill of chain.spills) {
- inboundAt.set(spill.at, { seg: spill.leg, line: spill.line, drawnAs: spill.fromDayNumber });
+ inboundAt.set(spill.at, { seg: spill.leg, line: spill.line });
}
// No band for a night spent at one hotel: nothing is driven between the evening and
@@ -135,24 +133,27 @@ export function assembleRoadtrip({
? undefined
: legFor(previousStop, first);
if (joined) {
- inboundAt.set(0, { seg: joined.seg, line: joined.line, drawnAs: previousDayNumber ?? chain.dayNumber });
+ inboundAt.set(0, { seg: joined.seg, line: joined.line });
arrivingLeg = joined.seg;
arrivingLine = joined.line;
arrivingFrom = previousStop;
}
}
previousStop = chain.stops[chain.stops.length - 1]! ?? previousStop;
- previousDayNumber = chain.stops.length ? chain.dayNumber : previousDayNumber;
for (let i = 0; i < chain.stops.length; i++) {
const inbound = inboundAt.get(i);
if (inbound) {
if (inbound.line.length > 1) {
lines.push(inbound.line);
- lineDays.push(inbound.drawnAs);
- // A spill carries its own `fromDayNumber` and a joined day the number of the day
- // it left: either way, a line drawn as a day other than the one it runs in is
- // the connection into this one.
- lineJoins.push(inbound.drawnAs !== chain.dayNumber);
+ // Drawn as the day it arrives on, because that is the day whose figures count it
+ // (`distance` below adds every inbound leg) and under which the card shows it: the
+ // drive from yesterday's last stop and a stop reached after midnight alike. A day
+ // window builds the same connection as this day's own first leg, so it is drawn
+ // as this day too, and map and card agree whichever way the days end (#3123).
+ lineDays.push(chain.dayNumber);
+ // Either way the line leaves from another day's stop, so it is the connection
+ // into this one.
+ lineJoins.push(true);
}
if (inbound.seg) segments.push(inbound.seg);
}
diff --git a/shared/src/roadtrip/planning-types.ts b/shared/src/roadtrip/planning-types.ts
index c59ac38bf..0d804fba8 100644
--- a/shared/src/roadtrip/planning-types.ts
+++ b/shared/src/roadtrip/planning-types.ts
@@ -262,14 +262,13 @@ export interface RoadtripRoutes {
lineDays: number[];
/**
- * Which of `lines` is the drive INTO the following day rather than a drive within the
+ * Which of `lines` is the drive in from the PREVIOUS day rather than a drive within the
* day it is drawn as, parallel to `lines` and `lineDays`.
*
* With "connect the days" on, the leg from one day's last stop to the next day's first
- * is drawn in the colour of the day it leaves, so on a map showing the whole drive it
- * reads as that day continuing. A surface showing ONE day has to tell the two apart:
- * the connection leads off the day on screen and belongs to the next one, and drawn
- * there it is a line to a place that day never visits.
+ * is drawn as the day it arrives on, the day whose distance counts it (#3123). A surface
+ * showing ONE day has to tell the two apart: the connection starts at a place the day on
+ * screen never visits.
*/
lineJoins: boolean[];