'use client'; import { useMemo } from 'react'; import { Box } from '@chakra-ui/react'; import { Chart, useChart } from '@chakra-ui/charts'; import { LineChart, CartesianGrid, Line, YAxis, Tooltip, ReferenceLine, ResponsiveContainer, } from 'recharts'; import { useBacktest, useTestsCompare } from '#store'; import { useTestContext } from '../context'; import { TestCompareList } from '@tradejs/types'; import { mapOrderLogToChartData, getChartData } from './utils'; import { getFormatted, getTimeline } from '@tradejs/core/backtest'; import { formatTimeSeriesTooltipTimestamp } from '#app/lib/timeSeriesChart'; import { TimeSeriesXAxis } from '#shared/Charts/TimeSeriesXAxis'; import { buildBacktestTradeOutcomePoints, TradeOutcomeMarkers, } from '#shared/Charts/TradeOutcomeMarkers'; interface TestCardChartProps { height?: string | number; } export const TestCardChart = ({ height = '350px' }: TestCardChartProps) => { const { testResult } = useTestContext(); const { test, stat } = testResult; const { compareList } = useTestsCompare(); const { backtest } = useBacktest(test.name); const chartData = useMemo(() => { if (!compareList.length) { return mapOrderLogToChartData(testResult); } const timeline = getTimeline(test.options.start, test.options.end); const testList: TestCompareList = [ ...compareList.filter( ({ testResult }) => testResult.test.testId !== test.testId, ), { testResult, color: 'teal', }, ]; return getChartData(testList, timeline); }, [ compareList, test.options.end, test.options.start, test.testId, testResult, ]); const chart = useChart(chartData as any); const tradeOutcomePoints = useMemo( () => buildBacktestTradeOutcomePoints(backtest), [backtest], ); const { formatted: maxAmount } = getFormatted(stat, 'maxAmount'); const { formatted: minAmount } = getFormatted(stat, 'minAmount'); const startTimestamp = test.options.start ?? testResult.orderLog[0]?.[0] ?? 0; const endTimestamp = test.options.end ?? testResult.orderLog.at(-1)?.[0] ?? startTimestamp; return ( } /> {chart.series.map((item) => ( ))} ); };