fix: 客户饼图按城市显示时按省份(区域)分组排序
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
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:
21
src/App.tsx
21
src/App.tsx
@@ -512,17 +512,28 @@ export default function App() {
|
|||||||
customerData.forEach(item => { map[item.region] = (map[item.region] || 0) + item.total; });
|
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);
|
data = Object.entries(map).map(([name, value]) => ({ name, value })).sort((a, b) => b.value - a.value);
|
||||||
} else {
|
} else {
|
||||||
const map: Record<string, number> = {};
|
const cityMap: Record<string, number> = {};
|
||||||
customerData.forEach(item => { map[item.city] = (map[item.city] || 0) + item.total; });
|
const cityToRegion: Record<string, string> = {};
|
||||||
const tot = Object.values(map).reduce((a, b) => a + b, 0);
|
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;
|
const threshold = tot * 0.05;
|
||||||
let other = 0;
|
let other = 0;
|
||||||
Object.entries(map).forEach(([name, value]) => {
|
Object.entries(cityMap).forEach(([name, value]) => {
|
||||||
if (value >= threshold) data.push({ name, value });
|
if (value >= threshold) data.push({ name, value });
|
||||||
else other += value;
|
else other += value;
|
||||||
});
|
});
|
||||||
if (other > 0) data.push({ name: '其他', value: other });
|
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;
|
return data;
|
||||||
}, [customerData, customerChartView]);
|
}, [customerData, customerChartView]);
|
||||||
|
|||||||
Reference in New Issue
Block a user