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

With "Connect the days" and "A colour per day" on, the drive from one day's
last stop to the next day's first stop was coloured as the day it left. A stop
reached after midnight was handled the same way: the line into it kept the
colour of the day it came from. The road trip panel counts both drives toward
the arriving day (its distance includes them, and the setting's hint says
connecting drives count toward the arrival day). So the map showed the drive
under one day while the panel counted it under the other. This also happened
with daily travel times set to end the day at the last place, whenever the
schedule could not be kept (a drive longer than the window) and the days were
drawn as stored.

assembleRoadtrip now puts every line drawn into a day under that day's
number, the day whose figures count it, and still marks it as a join, so the
one-day stage view still leaves it off. Every map takes its day colours
from this list: desktop Leaflet and Mapbox GL, the phone map and its stage
view. The client tests that pinned the old colouring and the old join order
now expect the new ones.

Closes #3123
This commit is contained in:
Maurice
2026-11-18 16:52:04 +01:00
parent 26122a4208
commit 684a3bf5f5
6 changed files with 161 additions and 46 deletions
@@ -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', () => {
+8 -8
View File
@@ -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])
@@ -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)
})