RightRail.tsx
12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
import { useMemo, useState } from 'react';
import { Segmented } from 'antd';
import { placeRoster, streetRoster, districtRoster, roadRoster } from '@/features/heatmap/spotlight/spotlightView';
import { TimeExtraBlocks } from '@/features/heatmap/panels/StatsPanel';
import { DayTrend } from '@/features/heatmap/panels/DayTrend';
import { MapLink } from '@/features/heatmap/panels/MapLink';
import { useHeatmapStore, type StatsBoard } from '@/store/useHeatmapStore';
import { districtNameOf, fmtCompact, fmtInt, fmtPercent, placeLabelOf, streetNameOf } from '@/utils/format';
/**
* 右栏:归因。
*
* 四块内容按「领导站在这张图前会追问什么」排序,不是按数据的多少:
* ① **哪个区 / 哪条街 / 哪条路最多** —— 第一句一定是「哪儿最多」,而且接着就要「带我去看看」;
* ② **最近是涨还是跌** —— 第二句是走势;
* ③ **什么时候多** —— 时段形状;
* ④ **老在哪儿** —— 反复出险的点位。
*
* 2026-11-02 这一栏补回了两块东西:
* · 三张排名榜(区 / 街道 / 道路)连同「在地图上看」「查看全部」一起 —— 它们在改版里
* 只剩深潜抽屉这一个入口,而深潜默认是关的,等于把最常用的三张榜锁进了二级页;
* `openStatsBoard` 当时甚至一个调用点都没有,榜单抽屉根本打不开。
* · 近 30 天走势从底栏挪进来(底栏取消,132px 还给地图)。
*
* 刻意没放的:车种构成(VehicleBoard 是六个低基数维 + 新能源 + 完整性,深潜一整页的体量,
* 塞进 360px 会把真正该常驻的几块挤走)、区×车种矩阵(9–10 列,半栏必横向溢出)。
* 归因栏不是「把所有归因都摆出来」,是「摆出最常被问的那几条」。
*/
export function RightRail() {
return (
<div className="hm-rail__scroll">
<section className="hm-rail__sec">
<h3 className="hm-rail__h">区 / 街道 / 道路 排名</h3>
<GeoRanking />
</section>
<section className="hm-rail__sec">
<h3 className="hm-rail__h">近 30 天走势</h3>
<DayTrend compact />
</section>
<section className="hm-rail__sec">
<h3 className="hm-rail__h">夜间与时段</h3>
<TimeExtraBlocks />
</section>
<section className="hm-rail__sec">
<h3 className="hm-rail__h">反复出险点位</h3>
<RecurringPlaces />
</section>
</div>
);
}
/* ------------------------------- 三张地理排名榜 ------------------------------- */
type GeoKind = 'districts' | 'streets' | 'roads';
/** 三张榜各自「一行怎么拼」的差别集中在这一张表里,组件里不再写第二套 if */
const GEO_LABEL: Record<GeoKind, { tab: string; note: string; unit: string }> = {
districts: {
tab: '区域',
note: '按行政区归集。点一行:地图飞到这一区,并列出它的案件(不动筛选)。',
unit: '个区',
},
streets: {
tab: '街道',
note: '按地址里的街道名归集,同名街道分属不同区是两条。点一行:地图框到这条街,并列出它的案件。',
unit: '条街道',
},
roads: {
tab: '道路',
note: '路名读自地址里明写的道路字样,一段地址只认第一个。点一行:地图框到这条路,并列出它的案件。',
unit: '条道路',
},
};
interface GeoRow {
key: string;
idx: number;
name: string;
parent: string;
count: number;
}
/**
* 区 / 街道 / 道路 三张排名榜(右栏常驻版)。
*
* 为什么这一块必须常驻:这三张榜是这套界面被问得最多的内容(「哪个区最多」「哪条街最多」),
* 而改版之后它们只在深潜抽屉里 —— 深潜默认是关的,等于每次都要先拉开一个 70% 屏宽的抽屉
* 才能念出一个数。这一块把「前三名 + 榜首占比」放回常驻位置,完整的榜仍旧走抽屉。
*
* 一次只显示一张榜(用页签切),不并排:360px 里并排三张表,每张只剩一格数字的宽度。
* 选中哪一张,标题右侧那颗「在地图上看」就跟着切到这一维(`kind`),
* 于是「看榜 → 看形状」永远只差一次点击,且不会铺错维度。
*/
function GeoRanking() {
const meta = useHeatmapStore((s) => s.meta);
const stats = useHeatmapStore((s) => s.stats);
const openRoster = useHeatmapStore((s) => s.openRoster);
const openStatsBoard = useHeatmapStore((s) => s.openStatsBoard);
const [kind, setKind] = useState<GeoKind>('districts');
/**
* 榜的行只在这三样真换了时才算一遍。
* 「位置」一栏要取字典、拆区名,而这张栏挂在很多与榜单无关的状态上(翻页、开关聚焦、
* 进度回报都会重渲染),放在 render 里就是每次重渲染把几百条重铺一遍。
*/
const rows = useMemo<GeoRow[]>(() => {
if (!meta) return [];
if (kind === 'districts') {
return (stats?.districtCounts ?? []).map(([idx, n]) => ({
key: `d${idx}`,
idx,
name: meta.dict.districts[idx] ?? '—',
parent: '',
count: n,
}));
}
if (kind === 'streets') {
return (stats?.topStreets ?? []).map(([idx, n]) => {
const raw = meta.dict.streets[idx] ?? '';
return {
key: `s${idx}`,
idx,
name: streetNameOf(raw),
parent: districtNameOf(raw),
count: n,
};
});
}
return (stats?.road?.counts ?? []).map(([idx, n]) => ({
key: `r${idx}`,
idx,
name: stats?.road?.names[idx] || '—',
parent: '',
count: n,
}));
}, [kind, meta, stats]);
const matched = stats?.matched ?? 0;
const cfg = GEO_LABEL[kind];
/**
* 一行点开:先把地图挪过去,再出清单 —— 与风险指数榜、新能源表同一套两步动作。
*
* 三种维度的「挪」不一样,所以不在这里手写取景,一律交给 spotlightView 的构造器:
* 区给的是区界范围、街道给的是这条街的轮廓、道路给的是这条路 —— ;各写一遍就会出现
* 「榜上点了飞到别处」这种最难查的错。分派规则因此只在这一处。
*/
const openRow = (r: GeoRow) => {
if (!meta) return;
if (kind === 'districts') {
openRoster(districtRoster(meta, r.idx));
return;
}
if (kind === 'streets') {
openRoster(streetRoster(meta, r.idx));
return;
}
openRoster(roadRoster(stats?.road?.names ?? [], r.idx));
};
if (!meta || !stats) return null;
return (
<>
<div className="hm-geo__tabs">
<Segmented
size="small"
value={kind}
onChange={(v) => setKind(v as GeoKind)}
options={(Object.keys(GEO_LABEL) as GeoKind[]).map((k) => ({
label: GEO_LABEL[k].tab,
value: k,
}))}
/>
<MapLink kind={kind} subject={`${cfg.tab}排名`} label="在地图上看" />
</div>
{rows.length === 0 ? (
<div className="hm-rail__empty">当前筛选里没有可读出的{cfg.tab}记录。</div>
) : (
<ol className="hm-geo">
{rows.slice(0, 6).map((r, i) => (
<li key={r.key}>
<button
type="button"
className="hm-geo__row"
onClick={() => openRow(r)}
title={`${r.parent ? `${r.parent} ` : ''}${r.name}:${fmtInt(r.count)} 起,占本批 ${fmtPercent(r.count, matched)}。点开:地图挪过去 + 案件清单`}
>
<span className={`hm-geo__no${i < 3 ? ' is-top' : ''}`}>{i + 1}</span>
<span className="hm-geo__name">
{r.name}
{r.parent && <i className="hm-geo__parent">{r.parent}</i>}
</span>
<span className="hm-geo__n">{fmtCompact(r.count)}</span>
<span className="hm-geo__pct">{fmtPercent(r.count, matched)}</span>
</button>
</li>
))}
</ol>
)}
<p className="hm-rail__note">{cfg.note}</p>
{/* 「查看全部」是这张栏里唯一通向完整榜的路 —— 它调的是榜单抽屉,
那里才是分页、未标注行、排序依据齐全的地方(榜单抽屉此前没有任何入口,见文件头注释) */}
<button
type="button"
className="hm-rail__more"
onClick={() => openStatsBoard(kind as StatsBoard)}
title={`打开「${cfg.tab}」的完整榜单(全部 ${fmtInt(rows.length)} ${cfg.unit},可翻页)`}
>
查看全部 {fmtInt(rows.length)} {cfg.unit} ›
</button>
</>
);
}
/* ------------------------------- 反复出险点位 ------------------------------- */
/**
* 反复出险的位置:常驻摘要,不是抽屉里那张全量表。
*
* 为什么另写一份而不直接搬 `PlaceBoard`:那张表是给「一屏看完该动手的位置有哪几处」用的,
* 带区/街道/位置/起数/天数/跨度/最近一次六七列,40 行不分页 —— 它需要 500px 以上才铺得开。
* 栏里只有 360px,搬过来就是一条横向滚动的窄缝,读的人得左右拖着看一行。
*
* 这里只留判断「要不要加派」所需的三样:位置、出险天数、起数。天数在前是因为这一维的
* 意义就是「同一个地方反复出事」,天数相同再看起数(与 PlaceStats.top 的排序一致)。
* 想看全部、想按别的列比,点标题旁的「更多」去榜单抽屉,那边是同一份数据的完整视图。
*/
function RecurringPlaces() {
const meta = useHeatmapStore((s) => s.meta);
const stats = useHeatmapStore((s) => s.stats);
const openDeepDive = useHeatmapStore((s) => s.openDeepDive);
const openRoster = useHeatmapStore((s) => s.openRoster);
const place = stats?.place;
const rows = place?.top ?? [];
if (!meta || rows.length === 0) {
return (
<div className="hm-rail__empty">
当前筛选里没有两天以上反复出案的方位。
<br />
案件集中的位置请看地图上的黑点清单。
</div>
);
}
const cellM = place?.cellM ?? 100;
const recentDays = place?.recentDays ?? 30;
return (
<>
<div className="hm-rail__note">
同一处约 {cellM} 米见方的位置,在筛选时段里有几个自然日出过案。按出险天数排。
</div>
<ol className="hm-place">
{rows.slice(0, 8).map((p, i) => {
const label = placeLabelOf(meta.dict, p) || '这一处';
return (
<li key={`${p.minLng}:${p.minLat}`}>
<button
type="button"
className="hm-place__row"
// 点一行 = 看这一处的案件清单。取数口径统一交给 placeRoster:
// 它管着「切哪个方格、清单标题怎么说」,面板与抽屉点进来的必须是同一份名单
onClick={() => openRoster(placeRoster(meta, p, cellM))}
title={`点开这一处约 ${cellM} 米见方位置内的案件清单`}
>
<span className="hm-place__no">{i + 1}</span>
<span className="hm-place__body">
<span className="hm-place__name">{label}</span>
<span className="hm-place__meta">
{p.days} 天出案 · {p.spanDays} 天跨度 · 最近一次{' '}
{p.idleDays === 0 ? '就在期末' : `${p.idleDays} 天前`}
</span>
</span>
<span className="hm-place__n">
{fmtInt(p.count)}
<i>起</i>
</span>
</button>
</li>
);
})}
</ol>
<button
type="button"
className="hm-rail__more"
onClick={() => openDeepDive('region')}
title="在深潜的区域风险页看完整的反复出险位置表"
>
全部位置与近 {recentDays} 天变化 · 深潜
</button>
</>
);
}