Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 29 additions & 83 deletions src/components/MaintainersMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,24 @@ 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
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
Expand Down Expand Up @@ -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<HTMLDivElement, unknown>())
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -817,7 +826,7 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) {
instance.destroy()
surface.replaceChildren()
}
}, [host, surface, invalidate])
}, [host, surface, behavior, invalidate])

useLayoutEffect(() => {
groupsRef.current = groups
Expand Down Expand Up @@ -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')
Expand All @@ -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 =
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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],
Expand Down Expand Up @@ -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"
>
<style>{`
[data-globe-surface] {
mask-image: linear-gradient(
to bottom,
black calc(50% + var(--globe-fade-offset) - 4rem),
transparent calc(50% + var(--globe-fade-offset))
);
}
@media ${mobileViewport} {
[data-globe-surface] {
mask-image:
linear-gradient(
to bottom,
transparent,
black var(--globe-fade-vertical, 0px),
black calc(100% - var(--globe-fade-vertical, 0px)),
transparent
),
linear-gradient(
to right,
transparent,
black var(--globe-fade-side, 0px),
black calc(100% - var(--globe-fade-side, 0px)),
transparent
);
mask-composite: intersect;
}
}
@keyframes maintainer-location-pulse {
0% { transform: scale(0.45); opacity: 0.7; }
80%, 100% { transform: scale(2); opacity: 0; }
Expand Down Expand Up @@ -1217,7 +1163,7 @@ export function MaintainersMap({ maintainers }: MaintainersMapProps) {
<div
ref={setSurface}
data-globe-surface
className="pointer-events-none absolute inset-x-0 top-0 -z-10 h-full sm:top-1/2 sm:h-(--globe-width) sm:-translate-y-1/2"
className="pointer-events-none absolute inset-0 -z-10"
/>
<div className="absolute inset-0">
<div className="absolute inset-0 touch-pan-y cursor-grab active:cursor-grabbing" />
Expand Down
2 changes: 1 addition & 1 deletion src/components/home/HomeCommunitySection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function HomeCommunitySection() {
return (
<section
aria-labelledby="maintainers"
className="@container isolate mx-auto flex w-full max-w-(--breakpoint-lg) flex-col gap-4 px-4 [--globe-width:calc(100cqw+2rem)] [--globe-height:calc(var(--globe-width)*1.25)] sm:[--globe-width:min(120cqw,calc(100vw-1rem))] sm:[--globe-height:calc(var(--globe-width)*0.875)]"
className="@container isolate mx-auto flex w-full max-w-(--breakpoint-lg) flex-col gap-4 px-4 [--globe-width:calc(100cqw+2rem)] [--globe-height:min(calc(var(--globe-width)*1.25),calc(100svh-var(--navbar-height)))] sm:[--globe-width:min(120cqw,calc(100vw-1rem))] sm:[--globe-height:var(--globe-width)]"
>
<header className="sm:mb-10 lg:-mt-6">
<h2
Expand Down
Loading