Skip to content

Commit e7cfc42

Browse files
committed
compact comments
1 parent 761c810 commit e7cfc42

12 files changed

Lines changed: 65 additions & 178 deletions

src/pages/components/map-related/MapIndex.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ export function MapIndex({
77
subtitle,
88
}: {
99
lineColor: string
10-
/** The marker as it appears on the map. An element rather than a URL, so a glyph drawn inline
11-
* (the bearing arrow) can be painted by the same stylesheet as its counterpart on the map. */
1210
icon: ReactNode
1311
title: string
1412
subtitle?: ReactNode

src/pages/components/map-related/MapLayers/MapIndexLayer.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const meta = {
1111
component: MapIndexLayer,
1212
parameters: { layout: 'centered' },
1313
// Every legend rule in map.scss is nested under `.map-info` and its `.map-legend` slot, so
14-
// mounted bare the legend gets no grid and glyphs at their intrinsic size. Reproduce MapShell's
15-
// two levels; the wrapper needs a size because `.map-legend` is absolutely positioned in it.
14+
// mounted bare the legend gets no grid and glyphs at their intrinsic size. The outer size is
15+
// needed because `.map-legend` is absolutely positioned within it.
1616
decorators: [
1717
(Story) => (
1818
<div className="map-info" style={{ width: 340, height: 210 }}>

src/pages/components/map-related/MapLayers/MapIndexLayer.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ export function MapIndexLayer({ showPlannedRoute, positionGroups = [] }: MapInde
5959
<MapIndex
6060
key={idx}
6161
lineColor={group.color}
62-
// A mid-ramp arrow stands for the whole family here; MapSpeedIndex below spells the
63-
// bands out.
62+
// A mid-ramp arrow stands for the whole family; MapSpeedIndex below spells the bands out.
6463
icon={<VehicleBearingGlyph band={SPEED_BANDS[SPEED_BANDS.length - 2]} />}
6564
title={t('actualRoute')}
6665
subtitle={vehicleSubtitle(group, t)}

src/pages/components/map-related/MapLayers/MapRouteLayer.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,7 @@ interface MapRouteLayerProps {
2121
navigateMarkers: (groupIndex: number, id: number, marker: Layer) => void
2222
}
2323

24-
/**
25-
* A ping the vehicle reported moving becomes an arrow along its bearing, grown and filled in by
26-
* how fast; one it reported standing at (velocity exactly 0) becomes the compass badge, which
27-
* still faces the way the bus did. Both read the same `velocity` the tooltip prints, so the
28-
* shape can never contradict the number behind it — and both carry the stacking order that
29-
* keeps the small glyphs on top of the big ones.
30-
*
31-
* (`Point.color` holds that velocity, not a colour — see `toPoint`.)
32-
*/
24+
/** `Point.color` holds the ping's velocity, not a colour — see `toPoint`. */
3325
function pingMarker({ bearing, color: velocity }: Point) {
3426
// Only the standing badge can say "heading unknown" (it drops its needle); a moving ping has
3527
// to point somewhere, and `toPoint` has already defaulted a missing SIRI bearing to 0 anyway.
@@ -69,8 +61,7 @@ export function MapRouteLayer({
6961
/>
7062
{group.positions.map((pos, i) => {
7163
const markerKey = `${groupIndex}-${i}`
72-
// The ride is bookended: its operator's logo where it started, a chequered disc
73-
// where it was last seen. A one-ping ride keeps the logo — it never got to finish.
64+
// A one-ping ride keeps the operator's logo — it never got to finish.
7465
const { icon, zIndexOffset } =
7566
i === 0
7667
? {

src/pages/components/map-related/MapSpeedIndex.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import {
77
VehicleStandingGlyph,
88
} from './vehicleBearingGlyph'
99

10-
/**
11-
* Key to the ping markers' speed ramp: the compass badge for a bus reported standing, then an
12-
* arrow per band, growing as it goes faster and red across the slow half.
13-
*/
1410
export function MapSpeedIndex() {
1511
const { t } = useTranslation()
1612

src/pages/components/map-related/map-types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { SiriVehicleLocationWithRelatedPydanticModel } from '@hasadna/open-bus-api-client'
22
import { BusStop } from 'src/model/busStop'
33

4-
/** One per concurrent ride on the map, cycled. Deliberately no red — that belongs to the ping
5-
* speed ramp (`.ping-arrow--slow`), and red arrows over a red line read as neither. */
4+
/** Deliberately no red — that belongs to the ping speed ramp (`.ping-arrow--slow`), and red
5+
* arrows over a red line read as neither. */
66
export const ROUTE_COLORS = ['#f97316', '#3b82f6', '#22c55e', '#a855f7', '#0891b2']
77

88
export interface Point {

src/pages/components/map-related/mapMarkers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('rideEndMarker', () => {
8686
it('clips the chequer to the badge, so it runs to the edge without escaping the disc', () => {
8787
const clipId = /<clipPath id="([^"]+)">/.exec(html)![1]
8888
expect(html).toContain(`clip-path="url(#${clipId})"`)
89-
// the clip circle is the badge, a hair smaller so the rim survives on top of the cells
89+
// a hair smaller than the disc, so the rim survives on top of the cells
9090
const clipR = Number(/<clipPath[^>]*><circle[^>]*r="([\d.]+)"/.exec(html)![1])
9191
const discR = Number(/<circle class="ping-badge"[^>]*r="([\d.]+)"/.exec(html)![1])
9292
expect(clipR).toBeLessThan(discR)

src/pages/components/map-related/mapMarkers.ts

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
2-
* Every Leaflet icon and line colour the map draws with, and nothing that renders.
3-
*
4-
* Apart from `MapContent` because the layers it renders need these too, which made
2+
* Every Leaflet icon and line colour the map draws with, and nothing that renders. Apart from
3+
* `MapContent` because the layers it renders need these too, which made
54
* `MapContent → MapLayers/* → MapContent` an import cycle — `madge --circular` fails CI on it.
65
* Keep this module free of component imports.
76
*/
@@ -26,17 +25,14 @@ const getIcon = (
2625
})
2726
}
2827

29-
/** Carried by both vehicle-ping shapes (standing ring and bearing arrow) so a ping can be
30-
* selected without knowing which of the two it got. */
28+
/** Carried by every ping shape, so a ping can be selected without knowing which one it got. */
3129
export const vehiclePingMarkerClass = 'vehicle-ping-marker'
3230

33-
/** Leaflet's box for a ping glyph, in px. It stays the same across every speed band and the
34-
* standing glyph too, so the click target doesn't shrink with the speed and the icon keeps
35-
* centring on its ping without per-band anchor arithmetic. */
31+
/** One box for every speed band and the standing glyph alike, so the click target doesn't shrink
32+
* with the speed and the icon centres on its ping without per-band anchor arithmetic. */
3633
const PING_ICON_PX = 28
3734

38-
/** The ride-end badge gets the ride-start circle's 30px instead, so a ride's two ends are the
39-
* same size — and its chequer gets the pixels it needs to read as one. */
35+
/** The ride-start circle's 30px in `map.scss`, so a ride's two ends are the same size. */
4036
const RIDE_END_ICON_PX = 30
4137

4238
const pingIconOptions = (className: string, html: string, px: number = PING_ICON_PX) => ({
@@ -51,14 +47,8 @@ const standingMarkers = new Map<string, DivIcon>()
5147
/** Onto 0-359, the convention SVG `rotate()` shares with SIRI (0 = north, clockwise). */
5248
const normalizeBearing = (bearing: number) => ((Math.round(bearing) % 360) + 360) % 360
5349

54-
/**
55-
* Arrow marker pointing where the vehicle was heading, from the ping's SIRI bearing
56-
* (0 = north, clockwise — the same convention SVG `rotate()` uses), grown by how fast it was
57-
* travelling and reddened if that was slow (see {@link speedBand}).
58-
*
59-
* Instances are cached per whole degree and band, so a ride's hundreds of pings share at most
60-
* 360 × 4 icons and re-renders reuse the same object.
61-
*/
50+
/** Cached per whole degree and band, so a ride's hundreds of pings share at most 360 × 6 icons
51+
* and re-renders hand Leaflet the same object back. */
6252
export const vehicleBearingMarker = (bearing: number, speedKmh: number): DivIcon => {
6353
const deg = normalizeBearing(bearing)
6454
const band = speedBand(speedKmh)
@@ -71,13 +61,6 @@ export const vehicleBearingMarker = (bearing: number, speedKmh: number): DivIcon
7161
return icon
7262
}
7363

74-
/**
75-
* Marker for a ping the vehicle reported standing at: the ride-start marker's white disc, with a
76-
* compass needle inside showing the way it was facing. Nothing else on the map is a disc this
77-
* size, so the one exact reading the arrows can never carry — velocity 0 — keeps its own shape.
78-
*
79-
* A bearing of `undefined` drops the needle rather than inventing a heading.
80-
*/
8164
export const vehicleStandingMarker = (bearing?: number): DivIcon => {
8265
const deg = bearing === undefined ? undefined : normalizeBearing(bearing)
8366
const key = `${deg}`
@@ -89,10 +72,6 @@ export const vehicleStandingMarker = (bearing?: number): DivIcon => {
8972
return icon
9073
}
9174

92-
/**
93-
* Marker for the ride's last ping: a chequered disc, the finish line to the operator's logo at
94-
* the start. One per ride, so it is built once rather than cached per bearing.
95-
*/
9675
export const rideEndMarker = new DivIcon(
9776
pingIconOptions('vehicle-ride-end-marker', rideEndSvgMarkup(), RIDE_END_ICON_PX),
9877
)

src/pages/components/map-related/vehicleBearingGlyph.test.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,9 @@ import {
1313
standingSvgMarkup,
1414
} from './vehicleBearingGlyph'
1515

16-
/**
17-
* The speed ramp the ping arrows are drawn from. Bands are a deliberate quantisation, not a
18-
* rounding artefact: they keep the marker cache to a few hundred icons, and they give the
19-
* legend something finite to spell out.
20-
*/
21-
2216
const TOP = SPEED_BAND_MAX.length
2317

2418
describe('isStanding', () => {
25-
// The whole point of the standing glyph is that it means one exact reading, so that the
26-
// marker can never say "stopped" over a tooltip that says 3 km/h.
2719
it('is the exact zero the vehicle reported, with no tolerance band under it', () => {
2820
expect(isStanding(0)).toBe(true)
2921
expect(isStanding(1)).toBe(false)
@@ -46,9 +38,8 @@ describe('speedBand', () => {
4638
})
4739

4840
describe('speedBandLabel', () => {
49-
// Spelled out rather than rebuilt from SPEED_BAND_MAX: a change to the ramp then has to be
50-
// read back off the legend it produces, and the standing glyph's 0 has to still meet the
51-
// first band's 1 with no km/h left unaccounted for between any two rungs.
41+
// Spelled out rather than rebuilt from SPEED_BAND_MAX, so a change to the ramp has to be read
42+
// back off the legend it produces — with no km/h unaccounted for between any two rungs.
5243
it('spells each band out as its km/h range, the last one open-ended', () => {
5344
expect(STANDING_LABEL).toBe('0')
5445
expect(SPEED_BANDS.map(speedBandLabel)).toEqual([
@@ -101,13 +92,12 @@ describe('standingSvgMarkup', () => {
10192
})
10293

10394
describe('marker stacking', () => {
104-
// Zoomed out, a ride is a handful of pixels: whatever sits lowest here is what gets buried.
10595
it('puts the ride bookends over every ping, and the smaller pings over the bigger ones', () => {
10696
const bands = SPEED_BANDS.map(bearingZIndex)
10797

10898
expect(BOOKEND_Z_INDEX).toBeGreaterThan(STANDING_Z_INDEX)
10999
expect(STANDING_Z_INDEX).toBeGreaterThan(Math.max(...bands))
110-
// strictly descending: band 0 is the smallest arrow and stays on top of the rest
100+
// strictly descending: band 0 is the smallest arrow and stays on top
111101
expect(bands).toEqual([...bands].sort((a, b) => b - a))
112102
expect(new Set(bands).size).toBe(bands.length)
113103
})

0 commit comments

Comments
 (0)