/** * 月度报告图表(plan.md「5.2 图表与可视化」)。 * 数据计算为纯函数,图表渲染用简单 RN 组件(避免重图表库依赖)。 */ import React from 'react'; import { StyleSheet, Text, View } from 'react-native'; import { useTheme } from '../../theme'; import { useT } from '../../i18n'; import { groupByMonth } from '../../domain/chartStats'; import type { Transaction } from '../../domain/types'; export function MonthlyReport({ transactions }: { transactions: Transaction[] }) { const { theme } = useTheme(); const t = useT(); const data = groupByMonth(transactions); const maxExpense = Math.max(...data.map(d => d.expense), 1); return ( {t('report.monthlyTitle')} {data.map(d => ( {d.month.slice(5)} {d.expense.toFixed(0)} ))} {data.length === 0 && ( {t('common.noData')} )} ); } const styles = StyleSheet.create({ container: { gap: 6 }, row: { flexDirection: 'row', alignItems: 'center', gap: 8 }, barWrap: { flex: 1, height: 12, borderRadius: 6, overflow: 'hidden' }, bar: { height: '100%', borderRadius: 6 }, });