/** * 分类占比图(plan.md「5.2 图表与可视化」)。 * 采用卡片化布局与磨砂感水平胶囊进度条。 */ import React, { useMemo } from 'react'; import { StyleSheet, Text, View } from 'react-native'; import { useTheme } from '../../theme'; import { useT } from '../../i18n'; import { groupByCategory } from '../../domain/chartStats'; import type { Transaction } from '../../domain/types'; export function CategoryPie({ transactions }: { transactions: Transaction[] }) { const { theme } = useTheme(); const t = useT(); const data = useMemo(() => groupByCategory(transactions), [transactions]); const maxAmount = Math.max(...data.map(d => d.amount), 1); return ( {t('report.categoryTitle')} {data.map(d => ( {d.category.replace('Expenses:', '').replace('Income:', '')} {d.percentage}% ))} {data.length === 0 && ( {t('common.noData')} )} ); } const styles = StyleSheet.create({ container: { gap: 10 }, list: { gap: 8 }, row: { flexDirection: 'row', alignItems: 'center', gap: 10 }, barWrap: { width: 120, height: 8, borderRadius: 4, overflow: 'hidden' }, bar: { height: '100%', borderRadius: 4 }, });