|
| 1 | +import { Tooltip } from '~/components/Tooltip' |
| 2 | +import { formatDateLabel, formatPercent } from './format' |
| 3 | +import type { TimelinePoint } from './types' |
| 4 | + |
| 5 | +export const DailyPnLGrid = ({ timeline }: { timeline: TimelinePoint[] }) => { |
| 6 | + if (!timeline.length) return null |
| 7 | + const days = timeline.slice(1) |
| 8 | + if (!days.length) return null |
| 9 | + |
| 10 | + const displayDays = days.slice(-90) |
| 11 | + |
| 12 | + return ( |
| 13 | + <div className="overflow-hidden rounded-md border border-(--cards-border) bg-(--cards-bg) p-4"> |
| 14 | + <div className="mb-3 flex items-center justify-between gap-2"> |
| 15 | + <h3 className="text-base font-semibold">Daily Change Grid</h3> |
| 16 | + <span className="text-xs text-(--text-secondary)">{displayDays.length} days shown</span> |
| 17 | + </div> |
| 18 | + <div className="no-scrollbar flex max-w-full flex-wrap gap-1.5 pb-1"> |
| 19 | + {displayDays.map((day) => { |
| 20 | + const isPositive = day.percentChange > 0 |
| 21 | + const isZero = day.percentChange === 0 |
| 22 | + const alpha = Math.min(0.6, Math.max(0.22, Math.abs(day.percentChange) / 9)) |
| 23 | + const backgroundColor = isZero |
| 24 | + ? 'rgba(148, 163, 184, 0.22)' |
| 25 | + : isPositive |
| 26 | + ? `rgba(16, 185, 129, ${alpha})` // emerald-500 with controlled alpha |
| 27 | + : `rgba(239, 68, 68, ${alpha})` // red-500 with controlled alpha |
| 28 | + return ( |
| 29 | + <Tooltip |
| 30 | + key={day.timestamp} |
| 31 | + placement="top" |
| 32 | + content={`${formatPercent(day.percentChange)} • ${formatDateLabel(day.timestamp)}`} |
| 33 | + > |
| 34 | + <div |
| 35 | + className="flex h-8 w-8 shrink-0 items-end justify-center rounded-md border border-white/5 transition-transform duration-200 hover:scale-[0.99]" |
| 36 | + style={{ background: backgroundColor }} |
| 37 | + > |
| 38 | + <span className="sr-only">{`${formatPercent(day.percentChange)} on ${formatDateLabel(day.timestamp)}`}</span> |
| 39 | + </div> |
| 40 | + </Tooltip> |
| 41 | + ) |
| 42 | + })} |
| 43 | + </div> |
| 44 | + </div> |
| 45 | + ) |
| 46 | +} |
0 commit comments