From 8ca38f1806ffd52573b443330c7fb16d9b21c974 Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Fri, 23 Oct 2026 08:54:07 +0900 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20=EB=8B=A8=ED=92=8D=20=EC=A7=80?= =?UTF-8?q?=EB=8F=84=EB=A5=BC=20=EC=A0=90=EC=9C=BC=EB=A1=9C=20=E2=80=94=20?= =?UTF-8?q?=EB=8B=A8=EA=B3=84=EB=B3=84=20=EC=A0=90=20=EC=83=89,=20?= =?UTF-8?q?=EC=A0=88=EC=A0=95=20=EB=8B=A8=ED=92=8D=EC=9D=80=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=ED=91=9C(=EA=B2=B9=EC=B9=98=EB=A9=B4=20=EC=83=9D?= =?UTF-8?q?=EB=9E=B5),=20=EC=A7=80=EB=8F=84=20=EC=83=89=20=EC=98=85?= =?UTF-8?q?=EA=B2=8C,=20=EC=A0=88=EC=A0=95=207=EC=9D=BC=20=EB=92=A4?= =?UTF-8?q?=EB=B6=80=ED=84=B0=EB=8A=94=20=ED=9A=8C=EC=83=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/b/foliageMap.tsx | 149 ++++++++++++++++++++++++---------- 1 file changed, 108 insertions(+), 41 deletions(-) diff --git a/frontend/src/b/foliageMap.tsx b/frontend/src/b/foliageMap.tsx index 290e61a..7ffa7fd 100644 --- a/frontend/src/b/foliageMap.tsx +++ b/frontend/src/b/foliageMap.tsx @@ -1,102 +1,169 @@ -import { useState } from 'react' +import { useLayoutEffect, useMemo, useRef, useState } from 'react' import data from '../../seo/foliage_2026.json' import { cx } from '../lib/utils' import { kst } from './lib' import { PostFrame } from './Post' -import { Ic } from './ui' type Kind = 'maple' | 'ginkgo' type Spot = { name: string; kind: Kind; region: string; lat: number; lon: number; peak: string; basis: string } -type Stage = 'before' | 'first' | 'peak' +type Stage = 'before' | 'first' | 'peak' | 'gone' // 지도 그림(public/foliage/korea-map.webp, 정사각형)의 위경도 → 그림 위 위치. generated-images/foliage-map/south_outline.json 과 같은 값 const MAP = { lon0: 124.5, lat1: 38.75, k: 0.809017, s: 153.5327, ox: 40, oy: 62.92, size: 1024 } -// 발표에 시작일이 없어 절정 FIRST_DAYS 일 전부터 첫 단풍, PEAK_DAYS 일 전부터 절정으로 본다 +// 발표에 시작일이 없어 절정 FIRST_DAYS 일 전부터 첫 단풍, PEAK_DAYS 일 전부터 PEAK_AFTER 일 뒤까지 절정으로 본다 const FIRST_DAYS = 14 const PEAK_DAYS = 3 +const PEAK_AFTER = 7 const SEASON = { from: '09-20', to: '11-25' } const SEOUL = { lat: 37.566, lon: 126.978 } +// 이름표가 피해 갈 점 반지름(px) +const DOT_R = 7 -const STAGE: Record = { - before: { label: '단풍 전', icon: 'size-3 opacity-60 grayscale' }, - first: { label: '첫 단풍', icon: 'size-3.5' }, - peak: { label: '절정', icon: 'size-[18px]' }, -} -const KIND: Record = { - maple: { label: '단풍', icon: 'maple' }, - ginkgo: { label: '은행', icon: 'ginkgo' }, +const STAGE: Record = { before: '단풍 전', first: '첫 단풍', peak: '절정', gone: '' } +const KIND: Record = { maple: '단풍', ginkgo: '은행' } +const DOT: Record = { + before: 'size-2 bg-[#b9bcc6]', + first: 'size-2.5 bg-[#f39a3d]', + peak: 'size-[13px] bg-[#e0442e]', + gone: 'size-2 bg-[#b9bcc6]', } +const LEGEND = [ + { label: '단풍 전', color: 'bg-[#b9bcc6]' }, + { label: '첫 단풍', color: 'bg-[#f39a3d]' }, + { label: '절정 단풍', color: 'bg-[#e0442e]' }, + { label: '절정 은행', color: 'bg-[#f2c230]' }, +] -const pos = (m: Spot) => ({ - left: `${((MAP.ox + (m.lon - MAP.lon0) * MAP.k * MAP.s) / MAP.size) * 100}%`, - top: `${((MAP.oy + (MAP.lat1 - m.lat) * MAP.s) / MAP.size) * 100}%`, -}) +const xy = (m: Spot) => [(MAP.ox + (m.lon - MAP.lon0) * MAP.k * MAP.s) / MAP.size, (MAP.oy + (MAP.lat1 - m.lat) * MAP.s) / MAP.size] const DAY = 86_400_000 const days = (from: string, to: string) => Math.round((Date.parse(to) - Date.parse(from)) / DAY) function stage(m: Spot, today: string): Stage { const d = days(today, m.peak) + if (d < -PEAK_AFTER) return 'gone' if (d <= PEAK_DAYS) return 'peak' return d <= FIRST_DAYS ? 'first' : 'before' } const md = (iso: string) => `${Number(iso.slice(5, 7))}/${Number(iso.slice(8, 10))}` -/** 단풍철에만 나오는 단풍 지도 카드. 산마다 절정 예측일로 지금 절정·곧·아직·지남을 점으로 */ +type Box = { l: number; t: number; r: number; b: number } +const overlaps = (a: Box, b: Box) => a.l < b.r && b.l < a.r && a.t < b.b && b.t < a.b + +/** 단풍철에만 나오는 단풍 지도 카드. 명소마다 절정 예측일로 단풍 전·첫 단풍·절정을 점 색으로, 절정 단풍은 이름까지 */ export function FoliageCard() { const [now] = useState(() => new Date()) const t = kst(now) const today = `${t.y}-${String(t.mo).padStart(2, '0')}-${String(t.d).padStart(2, '0')}` const [picked, setPicked] = useState(null) + const spots = useMemo(() => (data.spots as Spot[]).map((m) => ({ ...m, stage: stage(m, today) })), [today]) + const named = useMemo(() => spots.filter((m) => m.kind === 'maple' && m.stage === 'peak').sort((a, b) => b.lat - a.lat), [spots]) + const mapRef = useRef(null) + const [labelAt, setLabelAt] = useState>({}) + + // 이름표를 점 오른쪽·왼쪽·위·아래 순으로 놓아 보고, 다른 절정 점·이름표와 겹치면 그 이름은 뺀다 + useLayoutEffect(() => { + const box = mapRef.current + if (!box) return + const place = () => { + const W = box.clientWidth + const taken: Box[] = named.map((m) => { + const [x, y] = xy(m) + return { l: x * W - DOT_R, t: y * W - DOT_R, r: x * W + DOT_R, b: y * W + DOT_R } + }) + const out: Record = {} + box.querySelectorAll('[data-label]').forEach((el) => { + const m = named.find((n) => n.name === el.dataset.label) + if (!m) return + const [x, y] = xy(m) + const w = el.offsetWidth + const h = el.offsetHeight + const own = { l: x * W - DOT_R, t: y * W - DOT_R, r: x * W + DOT_R, b: y * W + DOT_R } + const tries = [ + [DOT_R + 1, -h / 2], + [-w - DOT_R - 1, -h / 2], + [-w / 2, -h - DOT_R], + [-w / 2, DOT_R], + ] + for (const [dx, dy] of tries) { + const r = { l: x * W + dx, t: y * W + dy, r: x * W + dx + w, b: y * W + dy + h } + if (r.l < 0 || r.t < 0 || r.r > W || r.b > W) continue + if (taken.some((o) => !(o.l === own.l && o.t === own.t) && overlaps(r, o))) continue + taken.push(r) + out[m.name] = { left: r.l, top: r.t } + break + } + }) + setLabelAt(out) + } + place() + const ro = new ResizeObserver(place) + ro.observe(box) + return () => ro.disconnect() + }, [named]) + const mmdd = today.slice(5) if (mmdd < SEASON.from || mmdd > SEASON.to) return null - const spots = (data.spots as Spot[]).map((m) => ({ ...m, stage: stage(m, today) })) const peakNow = spots.filter((m) => m.stage === 'peak').map((m) => m.name) // 발표 지도에 서울 안 산은 없어 서울 시청에서 가장 가까운 단풍 예측 산으로 const forecast = spots.filter((m) => m.kind === 'maple' && m.basis.startsWith('산림청')) const seoul = forecast.reduce((a, b) => (Math.hypot(b.lat - SEOUL.lat, b.lon - SEOUL.lon) < Math.hypot(a.lat - SEOUL.lat, a.lon - SEOUL.lon) ? b : a)) const sel = spots.find((m) => m.name === picked) + const order = [...spots].sort((a, b) => Number(a.stage === 'peak') - Number(b.stage === 'peak')) return ( 5 ? ' 외' : ''}` : undefined}>

단풍 지도 · {md(today)}

서울 근교 {seoul.name} 절정 예상 {md(seoul.peak)}

-
- 단풍 지도 - {spots.map((m) => ( - + {m.name} + ))} {sel && (

{sel.name} {sel.region}
- {KIND[sel.kind].label} {STAGE[sel.stage].label} · 절정 예상 {md(sel.peak)} + {KIND[sel.kind]} {STAGE[sel.stage] && `${STAGE[sel.stage]} · `}절정 예상 {md(sel.peak)} {!sel.basis.startsWith('산림청') && 가까운 예측 지점 날짜예요}

)}
- {(Object.keys(KIND) as Kind[]).map((k) => ( - - - {KIND[k].label} - - ))} - - {(Object.keys(STAGE) as Stage[]).map((st) => ( - - - {STAGE[st].label} + {LEGEND.map((l) => ( + + + {l.label} ))}
From 1306c437404e386e71a86b59d51bab70490718ec Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Fri, 23 Oct 2026 09:07:51 +0900 Subject: [PATCH 2/7] =?UTF-8?q?fix:=20=EB=8B=A8=ED=92=8D=20=EC=A7=80?= =?UTF-8?q?=EB=8F=84=20=EC=9D=B4=EB=A6=84=ED=91=9C=EB=A5=BC=20=EB=88=8C?= =?UTF-8?q?=EB=9F=AC=EB=8F=84=20=EB=AA=85=EC=86=8C=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=EA=B0=80=20=EB=82=98=EC=98=A4=EA=B2=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/b/foliageMap.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/src/b/foliageMap.tsx b/frontend/src/b/foliageMap.tsx index 7ffa7fd..28b9eba 100644 --- a/frontend/src/b/foliageMap.tsx +++ b/frontend/src/b/foliageMap.tsx @@ -137,18 +137,21 @@ export function FoliageCard() { ) })} {named.map((m) => ( - + ))} {sel && (

From 199e834227d7ba1e26ce80f4cf659484fd1deacb Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Fri, 23 Oct 2026 09:13:12 +0900 Subject: [PATCH 3/7] =?UTF-8?q?feat:=20=EB=8B=A8=ED=92=8D=20=EC=A7=80?= =?UTF-8?q?=EB=8F=84=20=EC=A0=9C=EB=AA=A9=EC=9D=84=20'=EC=A7=80=EA=B8=88?= =?UTF-8?q?=20=EC=A0=88=EC=A0=95:=20=EC=8B=9C=C2=B7=EB=8F=84'=EB=A1=9C,=20?= =?UTF-8?q?=EB=B3=B4=EC=97=AC=20=EC=A3=BC=EB=8A=94=20=EA=B8=B0=EA=B0=84?= =?UTF-8?q?=EC=9D=84=20=EB=AA=85=EC=86=8C=20=EC=A0=88=EC=A0=95=EC=9D=BC?= =?UTF-8?q?=EC=97=90=20=EB=A7=9E=EC=B6=B0(=EC=B2=AB=20=EB=8B=A8=ED=92=8D?= =?UTF-8?q?=20=EC=8B=9C=EC=9E=91~=EB=A7=88=EC=A7=80=EB=A7=89=20=EC=A0=88?= =?UTF-8?q?=EC=A0=95=207=EC=9D=BC=20=EB=92=A4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/b/foliageMap.tsx | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/frontend/src/b/foliageMap.tsx b/frontend/src/b/foliageMap.tsx index 28b9eba..9af1c24 100644 --- a/frontend/src/b/foliageMap.tsx +++ b/frontend/src/b/foliageMap.tsx @@ -14,8 +14,6 @@ const MAP = { lon0: 124.5, lat1: 38.75, k: 0.809017, s: 153.5327, ox: 40, oy: 62 const FIRST_DAYS = 14 const PEAK_DAYS = 3 const PEAK_AFTER = 7 -const SEASON = { from: '09-20', to: '11-25' } -const SEOUL = { lat: 37.566, lon: 126.978 } // 이름표가 피해 갈 점 반지름(px) const DOT_R = 7 @@ -47,6 +45,20 @@ function stage(m: Spot, today: string): Stage { } const md = (iso: string) => `${Number(iso.slice(5, 7))}/${Number(iso.slice(8, 10))}` +const province = (m: Spot) => m.region.split(' ')[0].split('·') + +/** 절정 명소가 많은 시·도 3곳, 절정이 없으면 가장 먼저 올 절정, 다 지났으면 지는 중 */ +function headline(spots: (Spot & { stage: Stage })[]) { + const peak = spots.filter((m) => m.stage === 'peak') + if (peak.length) { + const count = new Map() + for (const p of peak.flatMap(province)) count.set(p, (count.get(p) ?? 0) + 1) + return `지금 절정: ${[...count].sort((a, b) => b[1] - a[1]).slice(0, 3).map(([p]) => p).join('·')}` + } + if (spots.some((m) => m.stage === 'gone')) return '올해 단풍이 지고 있어요' + const first = spots.reduce((a, b) => (b.peak < a.peak ? b : a)) + return `첫 절정은 ${province(first)[0]}, ${md(first.peak)}쯤` +} type Box = { l: number; t: number; r: number; b: number } const overlaps = (a: Box, b: Box) => a.l < b.r && b.l < a.r && a.t < b.b && b.t < a.b @@ -103,19 +115,17 @@ export function FoliageCard() { return () => ro.disconnect() }, [named]) - const mmdd = today.slice(5) - if (mmdd < SEASON.from || mmdd > SEASON.to) return null + // 가장 이른 명소가 첫 단풍에 들 때부터 가장 늦은 명소의 절정이 끝날 때까지 + const peaks = spots.map((m) => m.peak).sort() + if (days(peaks[0], today) < -FIRST_DAYS || days(peaks[peaks.length - 1], today) > PEAK_AFTER) return null const peakNow = spots.filter((m) => m.stage === 'peak').map((m) => m.name) - // 발표 지도에 서울 안 산은 없어 서울 시청에서 가장 가까운 단풍 예측 산으로 - const forecast = spots.filter((m) => m.kind === 'maple' && m.basis.startsWith('산림청')) - const seoul = forecast.reduce((a, b) => (Math.hypot(b.lat - SEOUL.lat, b.lon - SEOUL.lon) < Math.hypot(a.lat - SEOUL.lat, a.lon - SEOUL.lon) ? b : a)) const sel = spots.find((m) => m.name === picked) const order = [...spots].sort((a, b) => Number(a.stage === 'peak') - Number(b.stage === 'peak')) return ( 5 ? ' 외' : ''}` : undefined}>

단풍 지도 · {md(today)}

-

서울 근교 {seoul.name} 절정 예상 {md(seoul.peak)}

+

{headline(spots)}

단풍 지도 {order.map((m) => { From 9a75b02d1ae5cc6aadf50607b57bc129fda6a78e Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Fri, 23 Oct 2026 09:16:53 +0900 Subject: [PATCH 4/7] =?UTF-8?q?fix:=20=EB=8B=A8=ED=92=8D=20=EC=A7=80?= =?UTF-8?q?=EB=8F=84=EC=97=90=EC=84=9C=20=EA=B2=B9=EC=B3=90=20=EC=95=88=20?= =?UTF-8?q?=EB=B3=B4=EC=9D=B4=EA=B3=A0=20=EB=AA=BB=20=EB=88=84=EB=A5=B4?= =?UTF-8?q?=EB=8D=98=20=EC=A0=90=20=E2=80=94=20=EA=B2=B9=EC=B9=9C=20?= =?UTF-8?q?=EC=A0=90=EC=9D=84=20=EC=84=9C=EB=A1=9C=20=EB=B0=80=EC=96=B4=20?= =?UTF-8?q?65=EA=B3=B3=20=EB=AA=A8=EB=91=90=20=EB=B3=B4=EC=9D=B4=EA=B3=A0?= =?UTF-8?q?=20=EB=88=8C=EB=A6=AC=EA=B2=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/b/foliageMap.tsx | 64 ++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/frontend/src/b/foliageMap.tsx b/frontend/src/b/foliageMap.tsx index 9af1c24..87bf8bf 100644 --- a/frontend/src/b/foliageMap.tsx +++ b/frontend/src/b/foliageMap.tsx @@ -14,8 +14,9 @@ const MAP = { lon0: 124.5, lat1: 38.75, k: 0.809017, s: 153.5327, ox: 40, oy: 62 const FIRST_DAYS = 14 const PEAK_DAYS = 3 const PEAK_AFTER = 7 -// 이름표가 피해 갈 점 반지름(px) -const DOT_R = 7 +// 점 반지름(테두리 포함, px)과 점 사이 최소 틈 +const DOT_R: Record = { before: 5.5, first: 6.5, peak: 8, gone: 5.5 } +const GAP = 1.5 const STAGE: Record = { before: '단풍 전', first: '첫 단풍', peak: '절정', gone: '' } const KIND: Record = { maple: '단풍', ginkgo: '은행' } @@ -72,48 +73,72 @@ export function FoliageCard() { const spots = useMemo(() => (data.spots as Spot[]).map((m) => ({ ...m, stage: stage(m, today) })), [today]) const named = useMemo(() => spots.filter((m) => m.kind === 'maple' && m.stage === 'peak').sort((a, b) => b.lat - a.lat), [spots]) const mapRef = useRef(null) + const [at, setAt] = useState>({}) const [labelAt, setLabelAt] = useState>({}) - // 이름표를 점 오른쪽·왼쪽·위·아래 순으로 놓아 보고, 다른 절정 점·이름표와 겹치면 그 이름은 뺀다 + // 겹친 점은 서로 밀어 떼어 놓고, 이름표는 점 오른쪽·왼쪽·위·아래 순으로 놓아 보다 다른 절정 점·이름표와 겹치면 뺀다 useLayoutEffect(() => { const box = mapRef.current if (!box) return const place = () => { const W = box.clientWidth - const taken: Box[] = named.map((m) => { + const pts = spots.map((m) => { const [x, y] = xy(m) - return { l: x * W - DOT_R, t: y * W - DOT_R, r: x * W + DOT_R, b: y * W + DOT_R } + return { m, x: x * W, y: y * W, r: DOT_R[m.stage] } }) + for (let it = 0; it < 80; it++) { + let moved = false + for (let i = 0; i < pts.length; i++) + for (let j = i + 1; j < pts.length; j++) { + const a = pts[i] + const b = pts[j] + let dx = b.x - a.x + let dy = b.y - a.y + let d = Math.hypot(dx, dy) + const need = a.r + b.r + GAP + if (d >= need) continue + if (d < 0.01) [dx, dy, d] = [Math.cos(i + j), Math.sin(i + j), 1] + const push = (need - d) / 2 + a.x -= (dx / d) * push + a.y -= (dy / d) * push + b.x += (dx / d) * push + b.y += (dy / d) * push + moved = true + } + if (!moved) break + } + const pos = Object.fromEntries(pts.map((p) => [p.m.name, { x: p.x, y: p.y }])) + const dot = (p: (typeof pts)[number]): Box => ({ l: p.x - p.r, t: p.y - p.r, r: p.x + p.r, b: p.y + p.r }) + const taken = pts.filter((p) => p.m.stage === 'peak').map((p) => ({ name: p.m.name, box: dot(p) })) const out: Record = {} box.querySelectorAll('[data-label]').forEach((el) => { - const m = named.find((n) => n.name === el.dataset.label) - if (!m) return - const [x, y] = xy(m) + const p = pts.find((q) => q.m.name === el.dataset.label) + if (!p) return const w = el.offsetWidth const h = el.offsetHeight - const own = { l: x * W - DOT_R, t: y * W - DOT_R, r: x * W + DOT_R, b: y * W + DOT_R } const tries = [ - [DOT_R + 1, -h / 2], - [-w - DOT_R - 1, -h / 2], - [-w / 2, -h - DOT_R], - [-w / 2, DOT_R], + [p.r + 2, -h / 2], + [-w - p.r - 2, -h / 2], + [-w / 2, -h - p.r - 1], + [-w / 2, p.r + 1], ] for (const [dx, dy] of tries) { - const r = { l: x * W + dx, t: y * W + dy, r: x * W + dx + w, b: y * W + dy + h } + const r = { l: p.x + dx, t: p.y + dy, r: p.x + dx + w, b: p.y + dy + h } if (r.l < 0 || r.t < 0 || r.r > W || r.b > W) continue - if (taken.some((o) => !(o.l === own.l && o.t === own.t) && overlaps(r, o))) continue - taken.push(r) - out[m.name] = { left: r.l, top: r.t } + if (taken.some((o) => o.name !== p.m.name && overlaps(r, o.box))) continue + taken.push({ name: '', box: r }) + out[p.m.name] = { left: r.l, top: r.t } break } }) + setAt(pos) setLabelAt(out) } place() const ro = new ResizeObserver(place) ro.observe(box) return () => ro.disconnect() - }, [named]) + }, [spots, named]) // 가장 이른 명소가 첫 단풍에 들 때부터 가장 늦은 명소의 절정이 끝날 때까지 const peaks = spots.map((m) => m.peak).sort() @@ -130,6 +155,7 @@ export function FoliageCard() { 단풍 지도 {order.map((m) => { const [x, y] = xy(m) + const p = at[m.name] return ( +
+

+ + 단풍 지도 · {md(today)} +

+

{headline(spots)}

+
+ +
+ {copied &&

링크를 복사했어요

} + +
+ 단풍 지도 + {[...pts].sort((a, b) => Number(a.m.stage === 'peak') - Number(b.m.stage === 'peak')).map((p) => ( + + ))} + {spots.map((m) => ( + + ))} +
+ {( + [ + ['+', '확대', 1.6], + ['−', '축소', 1 / 1.6], + ] as const + ).map(([t, label, f]) => ( + + ))} +
+ {chosen && ( +
+ +
+ {chosen.name} + + {chosen.region} · {KIND[chosen.kind]} + + {!chosen.own && 가까운 예측 지점 날짜예요} +
+
+ {STAGE[chosen.stage]} + 절정 예상 {md(chosen.peak)} +
+ +
+ )} +
+ +
+ + + 단풍 절정 + + + + 은행 절정 + + + 첫 단풍 + + + 단풍 전 + +
+ + +
+ {GROUPS.map(([g, title]) => { + const rows = shown.filter((m) => m.stage === g).sort((a, b) => a.peak.localeCompare(b.peak)) + if (!rows.length) return null + return ( +
+

+ {title} {rows.length} +

+
    + {rows.map((m) => ( +
  • + +
  • + ))} +
+
+ ) + })} +

+ 출처: 산림청 2026 단풍절정 예측 · 잎 절반이 물든 때를 절정으로, 그 2주 전부터 첫 단풍으로 봐요{peakCount ? ` · 지금 절정 ${peakCount}곳` : ''} +

+
+
+ ) +} diff --git a/frontend/src/b/foliage.ts b/frontend/src/b/foliage.ts new file mode 100644 index 0000000..19e20a7 --- /dev/null +++ b/frontend/src/b/foliage.ts @@ -0,0 +1,150 @@ +import { useLayoutEffect, useMemo, useState, type RefObject } from 'react' +import data from '../../seo/foliage_2026.json' +import { kst } from './lib' + +export type Kind = 'maple' | 'ginkgo' +export type Stage = 'before' | 'first' | 'peak' | 'gone' +type Raw = { name: string; kind: Kind; region: string; lat: number; lon: number; peak: string; basis: string } +/** x·y 는 지도 그림 안 위치(0~1), own 은 산림청 예측 지점 자기 날짜인지(아니면 가까운 지점에서 빌린 날짜) */ +export type Spot = Omit & { stage: Stage; d: number; x: number; y: number; own: boolean } + +// 지도 그림(public/foliage/korea-map.webp, 정사각형)의 위경도 → 그림 위 위치. generated-images/foliage-map/south_outline.json 과 같은 값 +const MAP = { lon0: 124.5, lat1: 38.75, k: 0.809017, s: 153.5327, ox: 40, oy: 62.92, size: 1024 } +export const MAP_SRC = '/foliage/korea-map.webp' +// 발표에 시작일이 없어 절정 FIRST_DAYS 일 전부터 첫 단풍, PEAK_DAYS 일 전부터 PEAK_AFTER 일 뒤까지 절정으로 본다 +const FIRST_DAYS = 14 +const PEAK_DAYS = 3 +const PEAK_AFTER = 7 + +export const STAGE: Record = { before: '단풍 전', first: '첫 단풍', peak: '절정', gone: '절정 지남' } +export const KIND: Record = { maple: '단풍', ginkgo: '은행' } + +const DAY = 86_400_000 +const days = (from: string, to: string) => Math.round((Date.parse(to) - Date.parse(from)) / DAY) + +function stage(peak: string, today: string): Stage { + const d = days(today, peak) + if (d < -PEAK_AFTER) return 'gone' + if (d <= PEAK_DAYS) return 'peak' + return d <= FIRST_DAYS ? 'first' : 'before' +} + +export const md = (iso: string) => `${Number(iso.slice(5, 7))}/${Number(iso.slice(8, 10))}` +const province = (m: Spot) => m.region.split(' ')[0].split('·') + +/** 오늘(한국 시각) 기준 명소 65곳과 단계. 단풍철이 아니면 inSeason 이 false */ +export function useFoliage() { + const [today] = useState(() => { + const t = kst(new Date()) + return `${t.y}-${String(t.mo).padStart(2, '0')}-${String(t.d).padStart(2, '0')}` + }) + return useMemo(() => { + const spots: Spot[] = (data.spots as Raw[]).map(({ basis, lat, lon, ...m }) => ({ + ...m, + stage: stage(m.peak, today), + d: days(today, m.peak), + x: (MAP.ox + (lon - MAP.lon0) * MAP.k * MAP.s) / MAP.size, + y: (MAP.oy + (MAP.lat1 - lat) * MAP.s) / MAP.size, + own: basis.startsWith('산림청'), + })) + // 가장 이른 명소가 첫 단풍에 들 때부터 가장 늦은 명소의 절정이 끝날 때까지 + const peaks = spots.map((m) => m.peak).sort() + const inSeason = days(peaks[0], today) >= -FIRST_DAYS && days(peaks[peaks.length - 1], today) <= PEAK_AFTER + return { today, spots, inSeason } + }, [today]) +} + +/** 절정 명소가 많은 시·도 3곳, 절정이 없으면 가장 먼저 올 절정, 다 지났으면 지는 중 */ +export function headline(spots: Spot[]) { + const peak = spots.filter((m) => m.stage === 'peak') + if (peak.length) { + const count = new Map() + for (const p of peak.flatMap(province)) count.set(p, (count.get(p) ?? 0) + 1) + return `지금 절정: ${[...count].sort((a, b) => b[1] - a[1]).slice(0, 3).map(([p]) => p).join('·')}` + } + if (spots.some((m) => m.stage === 'gone')) return '올해 단풍이 지고 있어요' + const first = spots.reduce((a, b) => (b.peak < a.peak ? b : a)) + return `첫 절정은 ${province(first)[0]}, ${md(first.peak)}쯤` +} + +export type Pt = { m: Spot; x: number; y: number; r: number } +export type Box = { l: number; t: number; r: number; b: number } +const overlaps = (a: Box, b: Box) => a.l < b.r && b.l < a.r && a.t < b.b && b.t < a.b + +/** 화면 위 점끼리 겹치면 서로 밀어 떼어 놓는다 (pts 를 고쳐서 돌려줌) */ +export function spread(pts: Pt[], gap = 1.5) { + for (let it = 0; it < 60; it++) { + let moved = false + for (let i = 0; i < pts.length; i++) + for (let j = i + 1; j < pts.length; j++) { + const a = pts[i] + const b = pts[j] + let dx = b.x - a.x + let dy = b.y - a.y + let d = Math.hypot(dx, dy) + const need = a.r + b.r + gap + if (d >= need) continue + if (d < 0.01) [dx, dy, d] = [Math.cos(i + j), Math.sin(i + j), 1] + const push = (need - d) / 2 + a.x -= (dx / d) * push + a.y -= (dy / d) * push + b.x += (dx / d) * push + b.y += (dy / d) * push + moved = true + } + if (!moved) break + } + return pts +} + +/** 이름표를 점 오른쪽·왼쪽·위·아래 순으로 놓아 보고, 점·다른 이름표·막힌 칸과 겹치거나 영역 밖이면 그 이름은 뺀다. 앞 순서가 먼저 자리를 잡는다 */ +export function placeLabels(order: Pt[], all: Pt[], size: Record, area: Box, blocked: Box[] = []) { + const dots = all.map((p) => ({ name: p.m.name, box: { l: p.x - p.r, t: p.y - p.r, r: p.x + p.r, b: p.y + p.r } })) + const taken = [...blocked.map((box) => ({ name: '', box })), ...dots] + const out: Record = {} + for (const p of order) { + const s = size[p.m.name] + if (!s || p.x < area.l || p.x > area.r || p.y < area.t || p.y > area.b) continue + const tries = [ + [p.r + 2, -s.h / 2], + [-s.w - p.r - 2, -s.h / 2], + [-s.w / 2, -s.h - p.r - 1], + [-s.w / 2, p.r + 1], + ] + for (const [dx, dy] of tries) { + const r = { l: p.x + dx, t: p.y + dy, r: p.x + dx + s.w, b: p.y + dy + s.h } + if (r.l < area.l || r.t < area.t || r.r > area.r || r.b > area.b) continue + if (taken.some((o) => o.name !== p.m.name && overlaps(r, o.box))) continue + taken.push({ name: '', box: r }) + out[p.m.name] = { left: r.l, top: r.t } + break + } + } + return out +} + +/** 이름표 크기를 재 둔다: host 안 data-label 이 붙은 요소의 폭·높이 (host 크기가 바뀌면 다시) */ +export function useLabelSize(host: RefObject, key: unknown) { + const [size, setSize] = useState>({}) + useLayoutEffect(() => { + const el = host.current + if (!el) return + const ro = new ResizeObserver(() => { + const out: Record = {} + el.querySelectorAll('[data-label]').forEach((l) => { + out[l.dataset.label ?? ''] = { w: l.offsetWidth, h: l.offsetHeight } + }) + setSize(out) + }) + ro.observe(el) + return () => ro.disconnect() + }, [host, key]) + return size +} + +export const LEAF_SHADOW = 'drop-shadow-[0_0_1.5px_#fff] drop-shadow-[0_1px_1px_rgb(40_48_74/0.45)]' +export const LABEL = 'absolute rounded-[7px] bg-white/92 px-[5px] py-px text-[11.5px] leading-[1.35] font-extrabold whitespace-nowrap shadow-[0_1px_3px_rgb(40_48_74/0.18)]' +export const LABEL_INK: Record = { maple: 'text-[#b5321f]', ginkgo: 'text-[#8a6508]' } +// 지도 그림 색을 빼서 단풍 아이콘이 묻히지 않게 +export const MAP_IMG = 'pointer-events-none absolute inset-0 size-full select-none mix-blend-multiply brightness-[1.08] saturate-[.3]' +export const ICON_R = 10 diff --git a/frontend/src/b/foliageMap.tsx b/frontend/src/b/foliageMap.tsx index 050c902..f61c0e5 100644 --- a/frontend/src/b/foliageMap.tsx +++ b/frontend/src/b/foliageMap.tsx @@ -1,239 +1,72 @@ import { useLayoutEffect, useMemo, useRef, useState } from 'react' -import data from '../../seo/foliage_2026.json' +import { useNavigate } from 'react-router' import { cx } from '../lib/utils' -import { kst } from './lib' +import { headline, ICON_R, LABEL, LABEL_INK, LEAF_SHADOW, MAP_IMG, MAP_SRC, md, placeLabels, spread, useFoliage, useLabelSize } from './foliage' import { PostFrame } from './Post' +import { Ic } from './ui' -type Kind = 'maple' | 'ginkgo' -type Spot = { name: string; kind: Kind; region: string; lat: number; lon: number; peak: string; basis: string } -type Stage = 'before' | 'first' | 'peak' | 'gone' - -// 지도 그림(public/foliage/korea-map.webp, 정사각형)의 위경도 → 그림 위 위치. generated-images/foliage-map/south_outline.json 과 같은 값 -const MAP = { lon0: 124.5, lat1: 38.75, k: 0.809017, s: 153.5327, ox: 40, oy: 62.92, size: 1024 } -// 발표에 시작일이 없어 절정 FIRST_DAYS 일 전부터 첫 단풍, PEAK_DAYS 일 전부터 PEAK_AFTER 일 뒤까지 절정으로 본다 -const FIRST_DAYS = 14 -const PEAK_DAYS = 3 -const PEAK_AFTER = 7 -// 점 반지름(테두리 포함, px)과 점 사이 최소 틈, 지도를 눌렀을 때 가장 가까운 명소를 고르는 거리 -const DOT_R: Record = { before: 2.5, first: 3, peak: 7.5, gone: 2.5 } -const GAP = 1.5 -const TAP_R = 22 - -const STAGE: Record = { before: '단풍 전', first: '첫 단풍', peak: '절정', gone: '' } -const KIND: Record = { maple: '단풍', ginkgo: '은행' } -// 절정만 테두리·그림자로 띄우고, 나머지는 테두리 없는 작은 점으로 지도 결에 묻는다 -const DOT: Record = { - before: 'size-[5px] bg-[#8f8a80]/55', - first: 'size-[6px] bg-[#d9772e]/80', - peak: 'size-[13px] border-2 border-white bg-[#e0442e] shadow-[0_1px_3px_rgb(40_48_74/0.35)]', - gone: 'size-[5px] bg-[#8f8a80]/55', -} -const LEGEND = [ - { label: '단풍 전', dot: DOT.before }, - { label: '첫 단풍', dot: DOT.first }, - { label: '절정 단풍', dot: DOT.peak }, - { label: '절정 은행', dot: cx(DOT.peak, 'bg-[#f2c230]') }, -] - -const xy = (m: Spot) => [(MAP.ox + (m.lon - MAP.lon0) * MAP.k * MAP.s) / MAP.size, (MAP.oy + (MAP.lat1 - m.lat) * MAP.s) / MAP.size] - -const DAY = 86_400_000 -const days = (from: string, to: string) => Math.round((Date.parse(to) - Date.parse(from)) / DAY) - -function stage(m: Spot, today: string): Stage { - const d = days(today, m.peak) - if (d < -PEAK_AFTER) return 'gone' - if (d <= PEAK_DAYS) return 'peak' - return d <= FIRST_DAYS ? 'first' : 'before' -} - -const md = (iso: string) => `${Number(iso.slice(5, 7))}/${Number(iso.slice(8, 10))}` -const province = (m: Spot) => m.region.split(' ')[0].split('·') - -/** 절정 명소가 많은 시·도 3곳, 절정이 없으면 가장 먼저 올 절정, 다 지났으면 지는 중 */ -function headline(spots: (Spot & { stage: Stage })[]) { - const peak = spots.filter((m) => m.stage === 'peak') - if (peak.length) { - const count = new Map() - for (const p of peak.flatMap(province)) count.set(p, (count.get(p) ?? 0) + 1) - return `지금 절정: ${[...count].sort((a, b) => b[1] - a[1]).slice(0, 3).map(([p]) => p).join('·')}` - } - if (spots.some((m) => m.stage === 'gone')) return '올해 단풍이 지고 있어요' - const first = spots.reduce((a, b) => (b.peak < a.peak ? b : a)) - return `첫 절정은 ${province(first)[0]}, ${md(first.peak)}쯤` -} - -type Box = { l: number; t: number; r: number; b: number } -const overlaps = (a: Box, b: Box) => a.l < b.r && b.l < a.r && a.t < b.b && b.t < a.b - -/** 단풍철에만 나오는 단풍 지도 카드. 명소마다 절정 예측일로 단풍 전·첫 단풍·절정을 점 색으로, 절정 단풍은 이름까지 */ +/** 피드의 단풍 지도 카드: 지금 절정인 곳만 단풍잎·은행잎으로. 누르면 단풍 지도 페이지, 이름을 누르면 그 명소로 */ export function FoliageCard() { - const [now] = useState(() => new Date()) - const t = kst(now) - const today = `${t.y}-${String(t.mo).padStart(2, '0')}-${String(t.d).padStart(2, '0')}` - const [picked, setPicked] = useState(null) - const spots = useMemo(() => (data.spots as Spot[]).map((m) => ({ ...m, stage: stage(m, today) })), [today]) - const named = useMemo(() => spots.filter((m) => m.kind === 'maple' && m.stage === 'peak').sort((a, b) => b.lat - a.lat), [spots]) + const navigate = useNavigate() + const { today, spots, inSeason } = useFoliage() + const peak = useMemo(() => spots.filter((m) => m.stage === 'peak').sort((a, b) => Number(a.kind === 'ginkgo') - Number(b.kind === 'ginkgo') || a.y - b.y), [spots]) const mapRef = useRef(null) - const [at, setAt] = useState>({}) - const [labelAt, setLabelAt] = useState>({}) + const size = useLabelSize(mapRef, peak) + const [W, setW] = useState(0) - // 겹친 점은 서로 밀어 떼어 놓고, 이름표는 점 오른쪽·왼쪽·위·아래 순으로 놓아 보다 다른 절정 점·이름표와 겹치면 뺀다 useLayoutEffect(() => { - const box = mapRef.current - if (!box) return - const place = () => { - const W = box.clientWidth - const pts = spots.map((m) => { - const [x, y] = xy(m) - return { m, x: x * W, y: y * W, r: DOT_R[m.stage] } - }) - for (let it = 0; it < 80; it++) { - let moved = false - for (let i = 0; i < pts.length; i++) - for (let j = i + 1; j < pts.length; j++) { - const a = pts[i] - const b = pts[j] - let dx = b.x - a.x - let dy = b.y - a.y - let d = Math.hypot(dx, dy) - const need = a.r + b.r + GAP - if (d >= need) continue - if (d < 0.01) [dx, dy, d] = [Math.cos(i + j), Math.sin(i + j), 1] - const push = (need - d) / 2 - a.x -= (dx / d) * push - a.y -= (dy / d) * push - b.x += (dx / d) * push - b.y += (dy / d) * push - moved = true - } - if (!moved) break - } - const pos = Object.fromEntries(pts.map((p) => [p.m.name, { x: p.x, y: p.y }])) - const dot = (p: (typeof pts)[number]): Box => ({ l: p.x - p.r, t: p.y - p.r, r: p.x + p.r, b: p.y + p.r }) - const taken = pts.filter((p) => p.m.stage === 'peak').map((p) => ({ name: p.m.name, box: dot(p) })) - const out: Record = {} - box.querySelectorAll('[data-label]').forEach((el) => { - const p = pts.find((q) => q.m.name === el.dataset.label) - if (!p) return - const w = el.offsetWidth - const h = el.offsetHeight - const tries = [ - [p.r + 2, -h / 2], - [-w - p.r - 2, -h / 2], - [-w / 2, -h - p.r - 1], - [-w / 2, p.r + 1], - ] - for (const [dx, dy] of tries) { - const r = { l: p.x + dx, t: p.y + dy, r: p.x + dx + w, b: p.y + dy + h } - if (r.l < 0 || r.t < 0 || r.r > W || r.b > W) continue - if (taken.some((o) => o.name !== p.m.name && overlaps(r, o.box))) continue - taken.push({ name: '', box: r }) - out[p.m.name] = { left: r.l, top: r.t } - break - } - }) - setAt(pos) - setLabelAt(out) - } - place() - const ro = new ResizeObserver(place) - ro.observe(box) + const el = mapRef.current + if (!el) return + const ro = new ResizeObserver(() => setW(el.clientWidth)) + ro.observe(el) return () => ro.disconnect() - }, [spots, named]) + }, [inSeason]) - // 가장 이른 명소가 첫 단풍에 들 때부터 가장 늦은 명소의 절정이 끝날 때까지 - const peaks = spots.map((m) => m.peak).sort() - if (days(peaks[0], today) < -FIRST_DAYS || days(peaks[peaks.length - 1], today) > PEAK_AFTER) return null - const peakNow = spots.filter((m) => m.stage === 'peak').map((m) => m.name) - const sel = spots.find((m) => m.name === picked) - // 작은 점도 손가락으로 고를 수 있게 누른 자리에서 가장 가까운 명소를 연다 - const tapNearest = (e: React.MouseEvent) => { - const r = e.currentTarget.getBoundingClientRect() - const x = e.clientX - r.left - const y = e.clientY - r.top - let best: string | null = null - let bestD = TAP_R - for (const m of spots) { - const [nx, ny] = xy(m) - const p = at[m.name] ?? { x: nx * r.width, y: ny * r.width } - const d = Math.hypot(p.x - x, p.y - y) - if (d < bestD) [best, bestD] = [m.name, d] - } - setPicked(best === picked ? null : best) - } - const order = [...spots].sort((a, b) => Number(a.stage === 'peak') - Number(b.stage === 'peak')) + const pts = useMemo(() => spread(peak.map((m) => ({ m, x: m.x * W, y: m.y * W, r: ICON_R }))), [peak, W]) + const labelAt = useMemo(() => placeLabels(pts, pts, size, { l: 0, t: 0, r: W, b: W }), [pts, size, W]) + + if (!inSeason) return null + const go = (name?: string) => navigate(name ? `/foliage?spot=${encodeURIComponent(name)}` : '/foliage') return ( - 5 ? ' 외' : ''}` : undefined}> -
+ m.name).join(' · ')}${peak.length > 5 ? ' 외' : ''}` : undefined}> +
go()} onKeyDown={(e) => e.key === 'Enter' && go()} aria-label="단풍 지도 크게 보기" className="relative cursor-pointer bg-[#fff6ea] px-4 pt-4 pb-3">

단풍 지도 · {md(today)}

{headline(spots)}

-
- 단풍 지도 - {order.map((m) => { - const [x, y] = xy(m) - const p = at[m.name] - return ( - ))} - {sel && ( -

- {sel.name} {sel.region} -
- {KIND[sel.kind]} {STAGE[sel.stage] && `${STAGE[sel.stage]} · `}절정 예상 {md(sel.peak)} - {!sel.basis.startsWith('산림청') && 가까운 예측 지점 날짜예요} -

- )}
-
- {LEGEND.map((l) => ( - - - - - {l.label} +
+ + + + 단풍 절정 - ))} + + + 은행 절정 + + + 지도 크게 보기 ›
-

- 출처: 산림청 2026 단풍절정 예측 · 잎 절반이 물든 때를 절정으로, 그 2주 전부터 첫 단풍으로 봐요 -

) From 1888dd6cf38da90daaed57c36a301737358afb87 Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Fri, 23 Oct 2026 10:44:01 +0900 Subject: [PATCH 7/7] =?UTF-8?q?feat:=20=EB=8B=A8=ED=92=8D=20=EC=A7=80?= =?UTF-8?q?=EB=8F=84=20=EB=94=94=EC=9E=90=EC=9D=B8=20=EA=B2=80=EC=88=98=20?= =?UTF-8?q?=EB=B0=98=EC=98=81=20=E2=80=94=20=EC=B9=B4=EB=93=9C=202?= =?UTF-8?q?=EC=9E=A5(=EC=A7=80=EB=8F=84=C2=B7=EC=88=9C=EC=9C=84),=20?= =?UTF-8?q?=EB=9D=BC=EB=B2=A8=20=EB=88=8C=EB=9F=AC=20=EA=B3=A0=EB=A5=B4?= =?UTF-8?q?=EA=B8=B0,=20=EC=97=91=EC=8A=A4=20=EC=97=86=EC=95=A4=20?= =?UTF-8?q?=EC=84=A0=ED=83=9D=20=EC=A4=84,=20=EB=AA=85=EC=86=8C=EB=A7=88?= =?UTF-8?q?=EB=8B=A4=20=EA=B3=B5=EC=9C=A0=20=EC=9D=B4=EB=AF=B8=EC=A7=80,?= =?UTF-8?q?=20=EC=8B=9C=C2=B7=EB=8F=84=20=EC=9D=B4=EB=A6=84,=20=EB=B0=A4?= =?UTF-8?q?=20=ED=99=94=EB=A9=B4=20=EA=B8=80=EC=9E=90,=20=ED=99=95?= =?UTF-8?q?=EB=8C=80=ED=95=A0=EC=88=98=EB=A1=9D=20=EC=9D=B4=EB=A6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PRODUCT.md | 25 ++++ frontend/src/b/BLayout.tsx | 13 +- frontend/src/b/FoliagePage.tsx | 239 ++++++++++++++++++++------------- frontend/src/b/b.css | 3 +- frontend/src/b/foliage.ts | 81 +++++++++-- frontend/src/b/foliageMap.tsx | 162 ++++++++++++++++------ frontend/src/b/shareCards.tsx | 71 ++++++++++ 7 files changed, 448 insertions(+), 146 deletions(-) create mode 100644 PRODUCT.md diff --git a/PRODUCT.md b/PRODUCT.md new file mode 100644 index 0000000..eb2913a --- /dev/null +++ b/PRODUCT.md @@ -0,0 +1,25 @@ +# Product + + + +## Platform + +web + +## Users + +휴대폰으로 오늘·내일 뭘 할지 정하려는 2040 일반인. 아침이나 외출 전에 잠깐 열어 봐요. + +## Product Purpose + +동네(구) 날씨를 '빨래각·소맥각' 같은 활동 점수로 바꿔 보여 줘요. 피드로 훑어보고 친구에게 보내요. + +## Positioning + +날씨 숫자가 아니라 '지금 ○○하기 좋은지'를 알려 주고, 귀엽고 공유하고 싶은 카드로 보여 줘요. + +## Constraints + +- 모바일 웹 우선(토스 미니앱, 홈 화면 추가). +- 로그인은 글쓰기에만 요구해요. +- 화면 문구는 반말 없는 '해요'체예요. diff --git a/frontend/src/b/BLayout.tsx b/frontend/src/b/BLayout.tsx index bcf19ab..a48b43d 100644 --- a/frontend/src/b/BLayout.tsx +++ b/frontend/src/b/BLayout.tsx @@ -220,15 +220,22 @@ function Shell() { window.scrollTo({ top: 0 }) return } - // 피드가 다시 그려져 그 높이가 될 때까지 몇 프레임 기다리며 맞춘다 + // 피드가 다시 그려져 그 높이가 될 때까지 최대 3초 맞추고, 그 사이 사람이 화면을 만지면 멈춘다 let tries = 0 let raf = 0 + const stop = () => cancelAnimationFrame(raf) const go = () => { window.scrollTo({ top }) - if (Math.abs(window.scrollY - top) > 2 && ++tries < 60) raf = requestAnimationFrame(go) + if (Math.abs(window.scrollY - top) > 2 && ++tries < 180) raf = requestAnimationFrame(go) } go() - return () => cancelAnimationFrame(raf) + window.addEventListener('touchstart', stop, { once: true, passive: true }) + window.addEventListener('wheel', stop, { once: true, passive: true }) + return () => { + stop() + window.removeEventListener('touchstart', stop) + window.removeEventListener('wheel', stop) + } }, [pathname, key, navType]) // 지금 보고 있는 탭을 다시 누르면 맨 위로 const toTopIfHere = (to: string) => () => { diff --git a/frontend/src/b/FoliagePage.tsx b/frontend/src/b/FoliagePage.tsx index 14f432d..e2eee97 100644 --- a/frontend/src/b/FoliagePage.tsx +++ b/frontend/src/b/FoliagePage.tsx @@ -1,8 +1,9 @@ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react' import { useNavigate, useSearchParams } from 'react-router' -import { SITE_URL } from '../api/setup' import { cx } from '../lib/utils' -import { ICON_R, KIND, LABEL, LABEL_INK, LEAF_SHADOW, MAP_IMG, MAP_SRC, STAGE, headline, md, placeLabels, spread, useFoliage, useLabelSize, type Box, type Kind, type Pt, type Spot, type Stage } from './foliage' +import { ICON_R, LABEL, LABEL_INK, LEAF_SHADOW, MAP_IMG, MAP_SRC, PROVINCE, PROVINCES, labelBoxes, placeProvinces, rankNow, STAGE, headline, md, placeLabels, spread, useFoliage, useLabelSize, type Box, type Kind, type Pt, type Spot, type Stage } from './foliage' +import { useSheet } from './sheetContext' +import { FoliageMapShare, FoliageSpotShare } from './shareCards' import { SendIcon } from './svg' import { Chips, Ic, TAP44 } from './ui' @@ -11,12 +12,16 @@ type Filter = 'all' | Kind const DOT_R: Record = { peak: ICON_R, first: 4, before: 3, gone: 3 } const MAX_ZOOM = 5 -// 고른 명소는 흰 동그라미로 크게 -const SEL_R = 18 +const FIT_TOP = 30 +const FIT_BOTTOM = 14 // 이름 우선순위(절정 단풍 > 절정 은행 > 첫 단풍 > 나머지)와 그 이름이 나오기 시작하는 배율(처음 화면 대비) const pri = (m: Spot) => (m.stage === 'peak' ? (m.kind === 'maple' ? 0 : 1) : m.stage === 'first' ? 2 : 3) -const LABEL_FROM = [1, 1.6, 1.6, 2.5] +const LABEL_FROM = [1, 1.6, 2.5, 3.5] +// 점이 나오기 시작하는 배율: 처음엔 절정 잎만 보여 차분하게 +const DOT_FROM: Record = { peak: 1, first: 1.6, before: 2.5, gone: 2.5 } const TAP_R = 24 +const SHARE_ICON = 'relative grid size-9 shrink-0 cursor-pointer place-items-center rounded-full [&_svg]:size-[19px] [&_svg]:fill-none [&_svg]:stroke-(--ink2) [&_svg]:stroke-[1.9]' +const SHARE_BTN = `${SHARE_ICON} bg-white/80` const GROUPS: [Stage, string][] = [ ['peak', '지금 절정'], ['first', '곧 절정'], @@ -28,18 +33,23 @@ const FILTERS: [Filter, string][] = [ ['maple', '단풍'], ['ginkgo', '은행'], ] -// 단계마다 잎 아이콘을 얼마나 흐리게: 절정만 또렷하게 -const LEAF_DIM: Record = { peak: '', first: 'opacity-80', before: 'opacity-45 grayscale', gone: 'opacity-45 grayscale' } + +// 단계 표시: 절정은 잎, 첫 단풍은 주황 점, 단풍 전·지남은 회색 점(고르면 점을 크게) +const DOT_CLASS: Record = { peak: '', first: 'bg-[#d9772e]/85', before: 'bg-[#8f8a80]/60', gone: 'bg-[#8f8a80]/60' } + +function StageMark({ m, big }: { m: Spot; big?: boolean }) { + if (m.stage === 'peak') return + return +} function Marker({ p, sel }: { p: Pt; sel: boolean }) { - const style = { left: p.x, top: p.y } - if (p.m.stage === 'peak' || sel) - return ( - - - - ) - return + return ( + + {/* 고른 명소는 속이 빈 고리만: 옆 명소를 가리지 않게 */} + {sel && } + + + ) } /** 단풍 지도 페이지: 명소 65곳을 지도에서 확대해 보고 목록으로 고른다. 한 손가락은 확대 전엔 페이지 스크롤, 확대 뒤엔 지도 이동 */ @@ -50,7 +60,11 @@ export function FoliagePage() { const [filter, setFilter] = useState('all') const [sel, setSel] = useState(params.get('spot')) const linked = useRef(params.get('spot')) - const [copied, setCopied] = useState(false) + const { open } = useSheet() + const [shareSpot, setShareSpot] = useState(null) + const [shareReq, setShareReq] = useState(0) + const spotShotRef = useRef(null) + const mapShotRef = useRef(null) const shown = useMemo(() => spots.filter((m) => filter === 'all' || m.kind === filter), [spots, filter]) const vpRef = useRef(null) @@ -69,8 +83,10 @@ export function FoliagePage() { const xs = spots.map((m) => m.x) const ys = spots.map((m) => m.y) const [x0, x1, y0, y1] = [Math.min(...xs), Math.max(...xs), Math.min(...ys), Math.max(...ys)] - const s = Math.min(W / ((x1 - x0 + 0.14) * W), H / ((y1 - y0 + 0.1) * W)) - return { s, tx: W / 2 - ((x0 + x1) / 2) * W * s, ty: H / 2 - ((y0 + y1) / 2) * W * s } + // 위쪽은 맨 북쪽 이름표가 잘리지 않게 FIT_TOP 만큼 띄우고, 아래는 제주까지만 + const h = H - FIT_TOP - FIT_BOTTOM + const s = Math.min(W / ((x1 - x0 + 0.14) * W), h / ((y1 - y0) * W)) + return { s, tx: W / 2 - ((x0 + x1) / 2) * W * s, ty: FIT_TOP + h / 2 - ((y0 + y1) / 2) * W * s } }, [box, spots]) const clamp = useCallback( @@ -149,7 +165,11 @@ export function FoliagePage() { if (m) focus(m) }, [box, fit, spots, set, clamp, focus]) - const pts = useMemo(() => spread(shown.map((m) => ({ m, x: view.tx + m.x * box.W * view.s, y: view.ty + m.y * box.W * view.s, r: m.name === sel ? SEL_R : DOT_R[m.stage] }))), [shown, view, box.W, sel]) + const pts = useMemo(() => { + const ratio = view.s / fit.s + const visible = shown.filter((m) => m.name === sel || ratio >= DOT_FROM[m.stage] - 0.01) + return spread(visible.map((m) => ({ m, x: view.tx + m.x * box.W * view.s, y: view.ty + m.y * box.W * view.s, r: DOT_R[m.stage] }))) + }, [shown, view, box.W, fit.s, sel]) const ptsRef = useRef(pts) useLayoutEffect(() => { ptsRef.current = pts @@ -159,9 +179,12 @@ export function FoliagePage() { const ratio = view.s / fit.s const order = pts.filter((p) => p.m.name === sel || ratio >= LABEL_FROM[pri(p.m)]).sort((a, b) => Number(b.m.name === sel) - Number(a.m.name === sel) || pri(a.m) - pri(b.m)) const blocked: Box[] = [{ l: box.W - 52, t: 0, r: box.W, b: 100 }] - if (sel) blocked.push({ l: 0, t: box.H - 110, r: box.W, b: box.H }) - return placeLabels(order, pts, size, { l: 4, t: 4, r: box.W - 4, b: box.H - 4 }, blocked) + return placeLabels(order, pts, size, { l: 4, t: 4, r: box.W - 4, b: box.H - 4 }, blocked, (p) => p.m.stage === 'peak' || p.m.name === sel) }, [pts, size, sel, view.s, fit.s, box]) + const provs = useMemo( + () => placeProvinces(PROVINCES.map((v) => ({ name: v.name, x: view.tx + v.x * box.W * view.s, y: view.ty + v.y * box.W * view.s })), pts, labelBoxes(labelAt, size)), + [view, box.W, pts, labelAt, size], + ) const pickAt = useCallback((x: number, y: number) => { let best: string | null = null @@ -170,7 +193,7 @@ export function FoliagePage() { const d = Math.hypot(p.x - x, p.y - y) if (d < bestD) [best, bestD] = [p.m.name, d] } - if (best) setSel(best) + setSel((cur) => (best && best !== cur ? best : null)) }, []) // 손가락: 두 손가락은 확대·이동, 한 손가락은 확대했을 때만 지도 이동(아니면 페이지 스크롤), 두 번 누르면 확대 @@ -178,7 +201,7 @@ export function FoliagePage() { const el = vpRef.current if (!el) return let pinch: { d: number; x: number; y: number } | null = null - let one: { x: number; y: number; moved: boolean } | null = null + let one: { x: number; y: number; moved: boolean; scroll: boolean } | null = null let lastTap = 0 const local = (t: { clientX: number; clientY: number }) => { const r = el.getBoundingClientRect() @@ -196,7 +219,7 @@ export function FoliagePage() { pinch = { d: Math.hypot(a.x - b.x, a.y - b.y), x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 } one = null } else if (e.touches.length === 1) { - one = { ...local(e.touches[0]), moved: false } + one = { ...local(e.touches[0]), moved: false, scroll: false } } } const onMove = (e: TouchEvent) => { @@ -215,12 +238,19 @@ export function FoliagePage() { } if (e.touches.length !== 1 || !one) return const p = local(e.touches[0]) + const first = !one.moved if (Math.hypot(p.x - one.x, p.y - one.y) > 6) one.moved = true - if (!zoomed()) return - e.preventDefault() + if (!zoomed() || one.scroll) return const v = viewRef.current - set(clamp({ s: v.s, tx: v.tx + p.x - one.x, ty: v.ty + p.y - one.y })) - one = { ...p, moved: one.moved } + const next = clamp({ s: v.s, tx: v.tx + p.x - one.x, ty: v.ty + p.y - one.y }) + // 첫 움직임이 세로인데 지도가 그쪽 끝에 닿아 더 못 가면 이번 손짓은 페이지 스크롤로 넘긴다 + if (first && Math.abs(p.y - one.y) > Math.abs(p.x - one.x) && next.ty === v.ty) { + one.scroll = true + return + } + e.preventDefault() + set(next) + one = { ...p, moved: one.moved, scroll: false } } const onEnd = (e: TouchEvent) => { if (e.touches.length < 2) pinch = null @@ -295,21 +325,20 @@ export function FoliagePage() { if (el) window.scrollTo({ top: window.scrollY + el.getBoundingClientRect().top - 120, behavior: 'smooth' }) focus(m) } - const share = () => { - const url = `${SITE_URL}/foliage` - if (navigator.share) { - navigator.share({ title: '단풍 지도 · 날씨각', text: headline(spots), url }).catch((e: unknown) => { - if (!(e instanceof DOMException && e.name === 'AbortError')) console.error('[foliage] share', e) - }) - return - } - navigator.clipboard.writeText(url).then( - () => setCopied(true), - (e: unknown) => console.error('[foliage] copy', e), - ) + // 보내기: 공유 창이 이미지(명소 하나면 그 명소 지도 조각, 아니면 전체 지도)와 링크를 같이 보낸다 + const share = (m?: Spot) => { + setShareSpot(m ?? null) + setShareReq((n) => n + 1) } + useEffect(() => { + if (!shareReq) return + const el = shareSpot ? spotShotRef.current : mapShotRef.current + if (el) open({ type: 'share', share: { title: shareSpot ? `${shareSpot.name} 단풍` : '단풍 지도', slides: [el] } }) + }, [shareReq, shareSpot, open]) const back = () => (window.history.state?.idx > 0 ? navigate(-1) : navigate('/')) - const peakCount = spots.filter((m) => m.stage === 'peak').length + const peakSpots = spots.filter((m) => m.stage === 'peak') + const peakCount = peakSpots.length + const ranked = rankNow(spots) return (
@@ -324,21 +353,33 @@ export function FoliagePage() {

{headline(spots)}

-
- {copied &&

링크를 복사했어요

} -
+
단풍 지도 + {provs.map((v) => ( + + ))} {[...pts].sort((a, b) => Number(a.m.stage === 'peak') - Number(b.m.stage === 'peak')).map((p) => ( ))} {spots.map((m) => ( -
-
- - - 단풍 절정 - - - - 은행 절정 - - - 첫 단풍 - - - 단풍 전 - -
+ {/* 고른 명소는 범례 자리에: 지도 위를 가리지 않고, 다시 누르거나 빈 곳을 누르면 풀린다 */} + {chosen ? ( +
+ + + +
+

+ {chosen.name} + {STAGE[chosen.stage]} +

+

+ {chosen.region} + · 절정 예상 {md(chosen.peak)} +

+
+ +
+ ) : ( +
+ + + 단풍 절정 + + + + 은행 절정 + + + 첫 단풍 + + + 단풍 전 + +
+ )} -
+
{GROUPS.map(([g, title]) => { const rows = shown.filter((m) => m.stage === g).sort((a, b) => a.peak.localeCompare(b.peak)) if (!rows.length) return null return ( -
-

- {title} {rows.length} +
+

+ {title} + {rows.length}곳

-
    +
      {rows.map((m) => ( -
    • - +
    • ))} @@ -422,6 +469,8 @@ export function FoliagePage() {
) })} + +

출처: 산림청 2026 단풍절정 예측 · 잎 절반이 물든 때를 절정으로, 그 2주 전부터 첫 단풍으로 봐요{peakCount ? ` · 지금 절정 ${peakCount}곳` : ''}

diff --git a/frontend/src/b/b.css b/frontend/src/b/b.css index b620123..46f67c9 100644 --- a/frontend/src/b/b.css +++ b/frontend/src/b/b.css @@ -611,7 +611,8 @@ html.b-sheet-open .b-app :is(.b-fall, .b-bob, .b-blob, .b-skystars i, .b-shoot, .b-app[data-t='night'] .bg-\(--ink\) .text-\[\#ffb3c4\] { color: #ffd0dc; } -.b-app[data-t='night'] .text-\[\#28304a\] { +/* b-keep-bg(밤에도 밝은 바탕 그대로) 안은 글자도 그대로 */ +.b-app[data-t='night'] .text-\[\#28304a\]:not(.b-keep-bg, .b-keep-bg *) { color: var(--ink); } .b-app[data-t='night'] :is(.text-\[\#1f9d62\], .text-\[\#1f7a4f\]) { diff --git a/frontend/src/b/foliage.ts b/frontend/src/b/foliage.ts index 19e20a7..20ed7ff 100644 --- a/frontend/src/b/foliage.ts +++ b/frontend/src/b/foliage.ts @@ -29,6 +29,24 @@ function stage(peak: string, today: string): Stage { return d <= FIRST_DAYS ? 'first' : 'before' } +const toXY = (lat: number, lon: number) => ({ x: (MAP.ox + (lon - MAP.lon0) * MAP.k * MAP.s) / MAP.size, y: (MAP.oy + (MAP.lat1 - lat) * MAP.s) / MAP.size }) + +// 지도 위 시·도 이름 자리(위경도). 서울·경기는 겹치지 않게 경기를 북쪽으로 조금 올림 +export const PROVINCES = ( + [ + ['서울', 37.56, 126.98], + ['경기', 37.95, 127.05], + ['강원', 37.65, 128.35], + ['충북', 36.8, 127.75], + ['충남', 36.45, 126.85], + ['전북', 35.72, 127.1], + ['전남', 34.85, 126.9], + ['경북', 36.3, 128.75], + ['경남', 35.3, 128.2], + ['제주', 33.38, 126.55], + ] as const +).map(([name, lat, lon]) => ({ name, ...toXY(lat, lon) })) + export const md = (iso: string) => `${Number(iso.slice(5, 7))}/${Number(iso.slice(8, 10))}` const province = (m: Spot) => m.region.split(' ')[0].split('·') @@ -43,8 +61,7 @@ export function useFoliage() { ...m, stage: stage(m.peak, today), d: days(today, m.peak), - x: (MAP.ox + (lon - MAP.lon0) * MAP.k * MAP.s) / MAP.size, - y: (MAP.oy + (MAP.lat1 - lat) * MAP.s) / MAP.size, + ...toXY(lat, lon), own: basis.startsWith('산림청'), })) // 가장 이른 명소가 첫 단풍에 들 때부터 가장 늦은 명소의 절정이 끝날 때까지 @@ -67,7 +84,42 @@ export function headline(spots: Spot[]) { return `첫 절정은 ${province(first)[0]}, ${md(first.peak)}쯤` } +/** 지금 가기 좋은 순: 절정인 곳 중 절정 예상일이 오늘과 가까운 순, 같으면 자기 예측 날짜 먼저, 그다음 이름 순 */ +export const rankNow = (spots: Spot[]) => + spots.filter((m) => m.stage === 'peak').sort((a, b) => Math.abs(a.d) - Math.abs(b.d) || Number(b.own) - Number(a.own) || a.name.localeCompare(b.name)) + +/** 시·도 이름 자리(명소 이름표를 먼저 놓은 뒤): 원래 자리가 잎·점·이름표에 덮이면 둘레를 돌며 가장 가까운 빈자리로 옮긴다(최대 반경 R, 바다 쪽도 됨) */ +export function placeProvinces(provs: { name: string; x: number; y: number }[], pts: Pt[], labels: Box[] = [], R = 90) { + // 앞에서 놓은 시·도 이름도 피한다(서울·경기처럼 붙은 곳) + const placed: Box[] = [] + const free = (x: number, y: number) => + pts.every((p) => Math.abs(p.x - x) > p.r + 17 || Math.abs(p.y - y) > p.r + 10) && [...labels, ...placed].every((b) => !overlaps(provinceBox(x, y), b)) + return provs.map((v) => { + const at = pick(v) + placed.push(provinceBox(at.x, at.y)) + return at + }) + function pick(v: { name: string; x: number; y: number }) { + if (free(v.x, v.y)) return v + for (let d = 5; d <= R; d += 5) + for (let a = 0; a < 24; a++) { + const x = v.x + Math.cos((a / 24) * 2 * Math.PI) * d + const y = v.y + Math.sin((a / 24) * 2 * Math.PI) * d + if (free(x, y)) return { ...v, x, y } + } + return v + } +} +export function provinceBox(x: number, y: number): Box { + return { l: x - 16, t: y - 9, r: x + 16, b: y + 9 } +} + +/** placeLabels 결과를 상자로: 시·도 이름이 피해 갈 자리 */ +export const labelBoxes = (at: Record, size: Record) => + Object.entries(at).map(([n, a]) => ({ l: a.left, t: a.top, r: a.left + (size[n]?.w ?? 0), b: a.top + (size[n]?.h ?? 0) })) + export type Pt = { m: Spot; x: number; y: number; r: number } +const LABEL_GAP = 4 export type Box = { l: number; t: number; r: number; b: number } const overlaps = (a: Box, b: Box) => a.l < b.r && b.l < a.r && a.t < b.b && b.t < a.b @@ -97,24 +149,31 @@ export function spread(pts: Pt[], gap = 1.5) { return pts } -/** 이름표를 점 오른쪽·왼쪽·위·아래 순으로 놓아 보고, 점·다른 이름표·막힌 칸과 겹치거나 영역 밖이면 그 이름은 뺀다. 앞 순서가 먼저 자리를 잡는다 */ -export function placeLabels(order: Pt[], all: Pt[], size: Record, area: Box, blocked: Box[] = []) { +/** 이름표를 점 오른쪽·왼쪽 순으로 놓아 보고(잎과 짝이 헷갈리지 않게 옆 먼저), 점·다른 이름표·막힌 칸과 겹치거나 영역 밖이면 그 이름은 뺀다. 앞 순서가 먼저 자리를 잡는다 */ +export function placeLabels(order: Pt[], all: Pt[], size: Record, area: Box, blocked: Box[] = [], vertical: (p: Pt) => boolean = () => false) { const dots = all.map((p) => ({ name: p.m.name, box: { l: p.x - p.r, t: p.y - p.r, r: p.x + p.r, b: p.y + p.r } })) const taken = [...blocked.map((box) => ({ name: '', box })), ...dots] const out: Record = {} for (const p of order) { const s = size[p.m.name] if (!s || p.x < area.l || p.x > area.r || p.y < area.t || p.y > area.b) continue + // 옆 자리가 없을 때 vertical 인 명소(절정)만 위·아래도 써 본다 const tries = [ [p.r + 2, -s.h / 2], [-s.w - p.r - 2, -s.h / 2], - [-s.w / 2, -s.h - p.r - 1], - [-s.w / 2, p.r + 1], + ...(vertical(p) ? [[-s.w / 2, -s.h - p.r - 1], [-s.w / 2, p.r + 1]] : []), ] for (const [dx, dy] of tries) { const r = { l: p.x + dx, t: p.y + dy, r: p.x + dx + s.w, b: p.y + dy + s.h } if (r.l < area.l || r.t < area.t || r.r > area.r || r.b > area.b) continue - if (taken.some((o) => o.name !== p.m.name && overlaps(r, o.box))) continue + // 이름표끼리는 LABEL_GAP 만큼 띄워 손가락으로 옆 이름을 잘못 누르지 않게 + const pad = { l: r.l - LABEL_GAP, t: r.t - LABEL_GAP, r: r.r + LABEL_GAP, b: r.b + LABEL_GAP } + if (taken.some((o) => o.name !== p.m.name && overlaps(o.name ? r : pad, o.box))) continue + // 위·아래 자리는 이름표에서 가장 가까운 표시가 자기 것일 때만: 아니면 다른 점의 이름처럼 읽힌다 + const cx = (r.l + r.r) / 2 + const cy = (r.t + r.b) / 2 + const mine = Math.hypot(cx - p.x, cy - p.y) + if (dy !== -s.h / 2 && all.some((q) => q.m.name !== p.m.name && Math.hypot(cx - q.x, cy - q.y) < mine)) continue taken.push({ name: '', box: r }) out[p.m.name] = { left: r.l, top: r.t } break @@ -143,8 +202,12 @@ export function useLabelSize(host: RefObject, key: unknown) } export const LEAF_SHADOW = 'drop-shadow-[0_0_1.5px_#fff] drop-shadow-[0_1px_1px_rgb(40_48_74/0.45)]' -export const LABEL = 'absolute rounded-[7px] bg-white/92 px-[5px] py-px text-[11.5px] leading-[1.35] font-extrabold whitespace-nowrap shadow-[0_1px_3px_rgb(40_48_74/0.18)]' -export const LABEL_INK: Record = { maple: 'text-[#b5321f]', ginkgo: 'text-[#8a6508]' } +// 밤 화면에서도 지도는 밝은 종이 그대로라 이름표도 흰 바탕 그대로(b-keep-bg) +export const LABEL = "b-keep-bg absolute rounded-[7px] before:absolute before:-inset-x-1 before:-inset-y-2 before:content-[''] px-[5px] py-px text-[11.5px] leading-[1.35] font-extrabold whitespace-nowrap shadow-[0_1px_3px_rgb(40_48_74/0.18)]" +export const LABEL_INK: Record = { maple: 'bg-[#ffffffeb] text-[#b5321f]', ginkgo: 'bg-[#ffffffeb] text-[#8a6508]' } // 지도 그림 색을 빼서 단풍 아이콘이 묻히지 않게 export const MAP_IMG = 'pointer-events-none absolute inset-0 size-full select-none mix-blend-multiply brightness-[1.08] saturate-[.3]' export const ICON_R = 10 +// 시·도 이름: 지도에 옅게 깔리는 글자 +// 어두운 산 무늬 위에서도 읽히게 종이색 테두리를 두른다 +export const PROVINCE = 'pointer-events-none absolute -translate-x-1/2 -translate-y-1/2 font-jua text-[13px] leading-none whitespace-nowrap text-[#5c4a36]/85 [text-shadow:0_0_2px_#fff6ea,0_0_4px_#fff6ea,0_0_6px_#fff6ea]' diff --git a/frontend/src/b/foliageMap.tsx b/frontend/src/b/foliageMap.tsx index f61c0e5..7a58ce7 100644 --- a/frontend/src/b/foliageMap.tsx +++ b/frontend/src/b/foliageMap.tsx @@ -1,11 +1,18 @@ -import { useLayoutEffect, useMemo, useRef, useState } from 'react' +import { useLayoutEffect, useMemo, useRef, useState, type MouseEvent } from 'react' import { useNavigate } from 'react-router' import { cx } from '../lib/utils' -import { headline, ICON_R, LABEL, LABEL_INK, LEAF_SHADOW, MAP_IMG, MAP_SRC, md, placeLabels, spread, useFoliage, useLabelSize } from './foliage' +import { useCarousel } from './carousel' +import { headline, ICON_R, LABEL, LABEL_INK, LEAF_SHADOW, MAP_IMG, MAP_SRC, md, placeLabels, PROVINCE, PROVINCES, labelBoxes, placeProvinces, rankNow, spread, useFoliage, useLabelSize } from './foliage' import { PostFrame } from './Post' +import { useSheet } from './sheetContext' +import { FoliageSpotShare } from './shareCards' +import { SendIcon } from './svg' import { Ic } from './ui' -/** 피드의 단풍 지도 카드: 지금 절정인 곳만 단풍잎·은행잎으로. 누르면 단풍 지도 페이지, 이름을 누르면 그 명소로 */ +const TAP_R = 24 +const RANK_N = 7 + +/** 피드의 단풍 지도 카드: 1장은 지금 절정인 곳만 잎 아이콘으로(누르면 카드 안에 정보), 2장은 지금 가기 좋은 순위. '지도 크게 보기'로 단풍 지도 페이지 */ export function FoliageCard() { const navigate = useNavigate() const { today, spots, inSeason } = useFoliage() @@ -13,6 +20,10 @@ export function FoliageCard() { const mapRef = useRef(null) const size = useLabelSize(mapRef, peak) const [W, setW] = useState(0) + const [picked, setPicked] = useState(null) + const { open } = useSheet() + const spotShotRef = useRef(null) + const { ref: sliderRef, index } = useCarousel({ align: 'start' }) useLayoutEffect(() => { const el = mapRef.current @@ -23,50 +34,125 @@ export function FoliageCard() { }, [inSeason]) const pts = useMemo(() => spread(peak.map((m) => ({ m, x: m.x * W, y: m.y * W, r: ICON_R }))), [peak, W]) - const labelAt = useMemo(() => placeLabels(pts, pts, size, { l: 0, t: 0, r: W, b: W }), [pts, size, W]) + const labelAt = useMemo(() => placeLabels(pts, pts, size, { l: 0, t: 0, r: W, b: W }, [], () => true), [pts, size, W]) + const provs = useMemo(() => placeProvinces(PROVINCES.map((v) => ({ name: v.name, x: v.x * W, y: v.y * W })), pts, labelBoxes(labelAt, size)), [pts, W, labelAt, size]) if (!inSeason) return null const go = (name?: string) => navigate(name ? `/foliage?spot=${encodeURIComponent(name)}` : '/foliage') + const toggle = (name: string) => setPicked(name === picked ? null : name) + // 잎이 작아 손가락으로 겨냥하기 어려우니 누른 자리에서 가까운 명소를 고른다 + const tapMap = (e: MouseEvent) => { + const r = e.currentTarget.getBoundingClientRect() + let best: string | null = null + let bestD = TAP_R + for (const p of pts) { + const d = Math.hypot(p.x - (e.clientX - r.left), p.y - (e.clientY - r.top)) + if (d < bestD) [best, bestD] = [p.m.name, d] + } + setPicked(best && best !== picked ? best : null) + } + const sel = peak.find((m) => m.name === picked) + // 2번째 장: 지금 절정인 곳을 절정 예상일이 오늘과 가까운 순서로 + const ranked = rankNow(spots).slice(0, RANK_N) return ( m.name).join(' · ')}${peak.length > 5 ? ' 외' : ''}` : undefined}> -
go()} onKeyDown={(e) => e.key === 'Enter' && go()} aria-label="단풍 지도 크게 보기" className="relative cursor-pointer bg-[#fff6ea] px-4 pt-4 pb-3"> +

단풍 지도 · {md(today)}

{headline(spots)}

-
- - {pts.map((p) => ( - - ))} - {peak.map((m) => ( - - ))} -
-
- - - - 단풍 절정 - - - - 은행 절정 - +
+ - 지도 크게 보기 › +
+
+
+
+ + {provs.map((v) => ( + + ))} + {pts.map((p) => ( + + {p.m.name === picked && } + + + ))} + {peak.map((m) => ( + + ))} +
+ {/* 고른 명소 정보는 지도 밖, 범례 자리에: 지도 위 잎을 가리지 않게 */} + {sel ? ( +
+ +
+ {sel.name} + + {sel.region.split(' ')[0]} + · 절정 예상 {md(sel.peak)} + +
+ + +
+ ) : ( + + + + 단풍 절정 + + + + 은행 절정 + + + )} +
+
+

지금 가기 좋은 곳

+

절정 예상일이 오늘과 가까운 순서예요

+
    + {ranked.map((m, i) => ( +
  1. + +
  2. + ))} +
+
+
+
+ +
) diff --git a/frontend/src/b/shareCards.tsx b/frontend/src/b/shareCards.tsx index 91fb9d0..b6d69e0 100644 --- a/frontend/src/b/shareCards.tsx +++ b/frontend/src/b/shareCards.tsx @@ -2,6 +2,7 @@ import type { Ref } from 'react' import { createPortal } from 'react-dom' import { cx } from '../lib/utils' import type { TopIndex } from '../api/client/types.gen' +import { LEAF_SHADOW, MAP_IMG, MAP_SRC, md, PROVINCE, PROVINCES, STAGE, type Spot } from './foliage' import { MEDALS, type TimeKind } from './lib' import { Ic } from './ui' @@ -114,3 +115,73 @@ export function GakShareCard({ items, title, ref }: { items: TopIndex[]; title: ) } + +/** 단풍 명소 하나 공유: 그 명소를 가운데 둔 지도 조각(둘레 시·도 이름과 다른 절정 잎) 위에 큰 잎, 아래에 이름·지역·절정 예상일 */ +export function FoliageSpotShare({ spot, peak, ref }: { spot: Spot | null; peak: Spot[]; ref: Ref }) { + if (!spot) return null + const near = peak.filter((m) => m.name !== spot.name) + return ( + +
+
+ {/* 명소가 가운데 오게 지도 그림을 3배로 키워 옮긴다 */} +
+ + {PROVINCES.map((v) => ( + + {v.name} + + ))} + {near.map((m) => ( + + ))} +
+ + + +
+
+

+ {spot.name} + {STAGE[spot.stage]} +

+

{spot.region}

+

절정 예상 {md(spot.peak)}

+
+
+
+ ) +} + +/** 단풍 지도 전체 공유: 지금 절정 제목, 절정 잎만 찍힌 지도, 가기 좋은 곳 1~3위 */ +export function FoliageMapShare({ title, peak, ranked, ref }: { title: string; peak: Spot[]; ranked: Spot[]; ref: Ref }) { + return ( + +
+

{title}

+
+ + {PROVINCES.map((v) => ( + + {v.name} + + ))} + {peak.map((m) => ( + + ))} +
+
    + {ranked.slice(0, 3).map((m, i) => ( +
  1. + + + {m.name} + {m.region.split(' ')[0]} + {md(m.peak)} +
  2. + ))} +
+
+
+ ) +}