update this code:'use client'; import React from 'react'; import { Dialog,…
- User
update this code:'use client';
import React from 'react'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, } from "@/components/ui/dialog"; import { AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, ReferenceLine, } from 'recharts'; import { Trade, DayStats } from '@/types/trade';
interface ChartDataPoint { name: string; value: number; }
const CustomTooltip = ({ active, payload }: any) => { if (active && payload && payload.length) { const isNegative = payload[0].value < 0; return ( {payload[0].payload.name} <p className={
text-sm font-semibold ${isNegative ? 'text-red-600' : 'text-green-600'}}> ${payload[0].value.toFixed(2)} ); } return null; };interface DayTradesModalProps { isOpen: boolean; onClose: () => void; selectedDay: { day: number; trades: Trade[]; stats: DayStats | null; } | null; currentDate: Date; }
export const DayTradesModal: React.FC = ({ isOpen, onClose, selectedDay, currentDate, }) => { if (!selectedDay) return null;
// Sort trades by exit_date ascending const sortedTrades = [...selectedDay.trades].sort( (a, b) => new Date(a.exit_date).getTime() - new Date(b.exit_date).getTime() );
// Build cumulative PnL data const chartData: ChartDataPoint[] = [{ name: 'Start', value: 0 }]; let runningTotal = 0; sortedTrades.forEach((trade, index) => { runningTotal += trade.pnl; chartData.push({ name:
Trade ${index + 1}, value: runningTotal, }); });// Calculate min and max for y-axis with padding const values = chartData.map((point) => point.value); const minY = Math.min(...values); const maxY = Math.max(...values); const padding = Math.abs(maxY - minY) * 0.1; const yMin = minY - padding; const yMax = maxY + padding; const zeroY = 0; // Calculate the normalized position for gradient split const totalRange = yMax - yMin; const zeroPosition = (0 - yMin) / totalRange;
const splitPoint = ((zeroY - yMin) / (yMax - yMin) * 100); // Calculate the exact y1 position for zero line const y1 = yMax / (yMax - yMin);
// Adjust gradient stops to ensure complete fill const negativeGradientStops = [ { offset: '0%', stopColor: 'rgb(239, 68, 68)', stopOpacity: 1 }, { offset:
${splitPoint}%, stopColor: 'rgb(239, 68, 68)', stopOpacity: 1 } ];const positiveGradientStops = [ { offset:
${splitPoint}%, stopColor: 'rgb(34, 197, 94)', stopOpacity: 1 }, { offset: '100%', stopColor: 'rgb(34, 197, 94)', stopOpacity: 1 } ];return ( Trading Activity Summary for {currentDate.toLocaleDateString()}
<div className="space-y-6"> {/* Stats Cards */} <div className="grid grid-cols-1 md:grid-cols-3 gap-4"> <div className="bg-gray-50 dark:bg-gray-800 rounded-lg p-4"> <p className="text-sm text-gray-500">Net P&L</p> <p className={`text-2xl font-bold ${selectedDay.stats?.pnl !== undefined && selectedDay.stats.pnl >= 0 ? 'text-green-600' : 'text-red-600'}`}> ${selectedDay.stats?.pnl.toFixed(2)} </p> </div> <div className="bg-gray-50 dark:bg-gray-800 rounded-lg p-4"> <p className="text-sm text-gray-500">Win Rate</p> <p className="text-2xl font-bold">{selectedDay.stats?.winRatePercent.toFixed(1)}%</p> </div> <div className="bg-gray-50 dark:bg-gray-800 rounded-lg p-4"> <p className="text-sm text-gray-500">Total Trades</p> <p className="text-2xl font-bold">{selectedDay.trades.length}</p> </div> </div> {/* Chart */} <div className="w-full h-[300px] border border-blue-400 rounded-lg p-4 bg-white dark:bg-gray-900"> <ResponsiveContainer width="100%" height="100%"> <AreaChart data={chartData} margin={{ top: 10, right: 30, left: 0, bottom: 0 }} > <defs> - Assistant