From db1e37b8bfe76f5710244a39aa322335cacedcb8 Mon Sep 17 00:00:00 2001 From: kkfluous Date: Sun, 29 Mar 2026 09:13:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=A2=E6=88=B7=E9=A5=BC=E5=9B=BE?= =?UTF-8?q?=E6=8C=89=E5=9F=8E=E5=B8=82=E6=98=BE=E7=A4=BA=E6=97=B6=E6=8C=89?= =?UTF-8?q?=E7=9C=81=E4=BB=BD(=E5=8C=BA=E5=9F=9F)=E5=88=86=E7=BB=84?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 同省城市相邻显示:华东(嘉兴/宁波/金华)→华南(佛山/广州)→华中(开封)→... 组内按数量降序。 Co-Authored-By: Claude Opus 4.6 (1M context) --- src/App.tsx | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 53c41b1..7de7a1b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -512,17 +512,28 @@ export default function App() { customerData.forEach(item => { map[item.region] = (map[item.region] || 0) + item.total; }); data = Object.entries(map).map(([name, value]) => ({ name, value })).sort((a, b) => b.value - a.value); } else { - const map: Record = {}; - customerData.forEach(item => { map[item.city] = (map[item.city] || 0) + item.total; }); - const tot = Object.values(map).reduce((a, b) => a + b, 0); + const cityMap: Record = {}; + const cityToRegion: Record = {}; + customerData.forEach(item => { + cityMap[item.city] = (cityMap[item.city] || 0) + item.total; + if (!cityToRegion[item.city]) cityToRegion[item.city] = item.region; + }); + const tot = Object.values(cityMap).reduce((a, b) => a + b, 0); const threshold = tot * 0.05; let other = 0; - Object.entries(map).forEach(([name, value]) => { + Object.entries(cityMap).forEach(([name, value]) => { if (value >= threshold) data.push({ name, value }); else other += value; }); if (other > 0) data.push({ name: '其他', value: other }); - data.sort((a, b) => b.value - a.value); + // Sort by region group, then by value within group + const regionOrder = ['华东', '华南', '华中', '华北', '西北', '西南', '其他']; + data.sort((a, b) => { + const ra = regionOrder.indexOf(cityToRegion[a.name] || '其他'); + const rb = regionOrder.indexOf(cityToRegion[b.name] || '其他'); + if (ra !== rb) return ra - rb; + return b.value - a.value; + }); } return data; }, [customerData, customerChartView]);