fix: 客户饼图按城市显示时按省份(区域)分组排序
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

同省城市相邻显示:华东(嘉兴/宁波/金华)→华南(佛山/广州)→华中(开封)→...
组内按数量降序。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
kkfluous
2026-03-29 09:13:28 +08:00
parent 16f5ef8741
commit db1e37b8bf

View File

@@ -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<string, number> = {};
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<string, number> = {};
const cityToRegion: Record<string, string> = {};
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]);