SparklineInner.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use client';
  2. import { Area, AreaChart, ResponsiveContainer, YAxis } from 'recharts';
  3. import type { MoveDir } from '@/types/worldIndex';
  4. // recharts(d3 포함) 실제 렌더 본체 — Sparkline 이 next/dynamic({ssr:false})로 지연 로드.
  5. // 색은 래퍼의 dir 클래스(.spark--up/down/flat)가 지정하는 CSS color 를 currentColor 로 상속.
  6. // 호출부에서 data.length>=2 보장.
  7. type Props = {
  8. data: number[];
  9. dir: MoveDir;
  10. };
  11. export default function SparklineInner({ data, dir }: Props)
  12. {
  13. const chartData = data.map((v, i) => ({ i, v }));
  14. return (
  15. <div className={`spark spark--${dir}`} aria-hidden='true'>
  16. <ResponsiveContainer width='100%' height='100%'>
  17. <AreaChart data={chartData} margin={{ top: 2, right: 0, bottom: 2, left: 0 }}>
  18. <YAxis hide domain={['dataMin', 'dataMax']} />
  19. <Area
  20. type='monotone'
  21. dataKey='v'
  22. stroke='currentColor'
  23. strokeWidth={1.5}
  24. fill='currentColor'
  25. fillOpacity={0.12}
  26. dot={false}
  27. isAnimationActive={false}
  28. />
  29. </AreaChart>
  30. </ResponsiveContainer>
  31. </div>
  32. );
  33. }