diff --git a/src/components/MaintainersMap.tsx b/src/components/MaintainersMap.tsx index 6a179e495..687be2351 100644 --- a/src/components/MaintainersMap.tsx +++ b/src/components/MaintainersMap.tsx @@ -23,14 +23,13 @@ import { categoryOf } from '~/libraries/categories' import { Tooltip } from '~/ui/Tooltip' import { MaintainerAvatarImage } from './MaintainerAvatarImage' import { getVisitorLocation } from '~/utils/visitor-location.functions' -import { createChartsGlobe } from './maintainersChartsGlobe' +import { createChartsGlobe, globeHaloScale } from './maintainersChartsGlobe' import { initialMaintainersView, initialView } from './maintainersGlobeView' const zoomStep = 1.5 -const maxZoom = 128 const initialScale = initialView.scale * zoomStep -const mobileViewport = '(max-width: 639px)' -const mobileZoomFade = 48 +const mobileMaxZoom = initialScale * 1.2 +const mobileViewport = '(width < 40rem)' // Allow for rounding in rAF timestamps at 60 Hz and cap redraws on faster displays. const frameInterval = 1000 / 60 - 1 const markerElevation = 0.015 @@ -38,7 +37,10 @@ const profileClearance = 12 const viewportGutter = 16 const offscreenBadgeMinRemaining = 96 const globeRadius = 0.4 -const globeGlowDiameter = 0.9 +const globeAtmosphereDiameter = 2 * globeRadius * globeHaloScale +const desktopProjectionDiameter = 0.9 +const desktopMaxZoom = + (initialScale * desktopProjectionDiameter) / globeAtmosphereDiameter const zoomControls = { width: 46, height: 171 } type View = typeof initialView @@ -687,6 +689,7 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { > | null>(null) const [reducedMotion, setReducedMotion] = useState(false) const [scale, setScale] = useState(initialView.scale) + const [maxZoom, setMaxZoom] = useState(desktopMaxZoom) const [selectedId, setSelectedId] = useState('') const [paused, setPaused] = useState(false) const [behavior] = useState(() => zoom()) @@ -768,16 +771,20 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { useLayoutEffect(() => { if (!host || !surface) return - const readBounds = () => { + const mobile = window.matchMedia(mobileViewport) + const updateBounds = () => { const width = host.clientWidth const contentWidth = host.parentElement?.clientWidth ?? width const paintWidth = surface.clientWidth const height = host.clientHeight const paintHeight = surface.clientHeight - // The mobile surface is taller than the viewport-wide SVG's width so - // the globe fills its height and extends past its side edges. - const projectionHeight = paintHeight / (initialScale * globeGlowDiameter) - return { + const limit = mobile.matches ? mobileMaxZoom : desktopMaxZoom + // Keep the desktop starting diameter. On mobile, fit to the smaller edge. + const projectionHeight = mobile.matches + ? (Math.min(paintWidth, paintHeight) - 2 * viewportGutter) / + (globeAtmosphereDiameter * mobileMaxZoom) + : paintHeight / (initialScale * desktopProjectionDiameter) + hostSize.current = { width, height, centerY: height / 2, @@ -787,14 +794,16 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { paintTop: (height - paintHeight) / 2, projectionHeight, } + behavior.scaleExtent([1, limit]) + setMaxZoom(limit) + view.current.scale = Math.min(view.current.scale, limit) + if (target.current.scale > limit) + select(host).call(behavior.scaleTo, limit) + invalidate() } - hostSize.current = readBounds() + updateBounds() const instance = createChartsGlobe(surface) setGlobe(instance) - const updateBounds = () => { - hostSize.current = readBounds() - invalidate() - } const resize = new ResizeObserver(updateBounds) resize.observe(host) resize.observe(surface) @@ -817,7 +826,7 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { instance.destroy() surface.replaceChildren() } - }, [host, surface, invalidate]) + }, [host, surface, behavior, invalidate]) useLayoutEffect(() => { groupsRef.current = groups @@ -845,10 +854,9 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { }, []) useEffect(() => { - if (!host || !globe || !surface) return + if (!host || !globe) return const container = host const instance = globe - const canvasSurface = surface const section = container.closest('section') const help = section?.querySelector('#maintainers-globe-help') const intro = section?.parentElement?.querySelector(':scope > header') @@ -870,15 +878,12 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { } wakeGlobe.current = requestFrame const visualViewport = window.visualViewport - let fadeOffset: number | undefined - let fadedScale: number | undefined - let fadedBounds: GlobeBounds | undefined const updateViewport = () => { const { top, height } = container.getBoundingClientRect() const contentTop = (intro?.getBoundingClientRect().bottom ?? top) - top + viewportGutter const helpBounds = help?.getBoundingClientRect() - // Keep the zoomed paint and floating profiles clear of the next section. + // Keep floating profiles clear of the next section. const nextContent = help?.nextElementSibling ?? section?.nextElementSibling const contentBottom = @@ -887,14 +892,6 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { top + height) - top - viewportGutter - const nextFadeOffset = contentBottom - height / 2 - if (fadeOffset !== nextFadeOffset) { - fadeOffset = nextFadeOffset - canvasSurface.style.setProperty( - '--globe-fade-offset', - `${fadeOffset}px`, - ) - } const screenTop = visualViewport?.offsetTop ?? 0 const screenHeight = visualViewport?.height ?? document.documentElement.clientHeight @@ -1021,29 +1018,6 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { } wasIdle = idle if (redraw && paintHeight > 0) { - if ( - mobile.matches && - (current.scale !== fadedScale || bounds !== fadedBounds) - ) { - fadedScale = current.scale - fadedBounds = bounds - const fade = Math.min( - mobileZoomFade, - mobileZoomFade * - Math.max(0, (current.scale - initialScale) / (zoomStep - 1)), - ) - const drawRadius = projectionHeight * current.scale * globeRadius - const fadeAt = (overflow: number) => - `${Math.max(0, Math.min(fade, overflow))}px` - canvasSurface.style.setProperty( - '--globe-fade-vertical', - fadeAt(drawRadius - paintHeight / 2), - ) - canvasSurface.style.setProperty( - '--globe-fade-side', - fadeAt(drawRadius - paintWidth / 2), - ) - } const paintView = { ...current, scale: (current.scale * projectionHeight) / paintHeight, @@ -1068,14 +1042,13 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { cancelAnimationFrame(frame) wakeGlobe.current = undefined } - }, [host, globe, surface, reducedMotion, profilePositions, invalidate]) + }, [host, globe, reducedMotion, profilePositions, invalidate]) useEffect(() => { if (!host) return const selection = select(host) let previous = zoomIdentity behavior - .scaleExtent([1, maxZoom]) .extent((): [[number, number], [number, number]] => [ [0, 0], [host.clientWidth, host.clientHeight], @@ -1149,33 +1122,6 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) { className="relative space-y-4 [&_:focus-visible]:outline-2 [&_:focus-visible]:outline-offset-2 [&_:focus-visible]:outline-border-strong" >