/
MorSergey
/
diff-equations
Обзор
Документация
Войти
/
MorSergey
/
diff-equations
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/shared/ui/Chart.tsx
102 строки
3 KB
admin
init
22 окт 2025, 15:18
22 окт 2025, 15:18
412f98f
Код
Авторство
О чём код?
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts'; interface ChartProps { data: { x: number; y: number }[]; title: string; isLoading?: boolean; } export const Chart = ({ data, title, isLoading = false }: ChartProps) => { if (isLoading) { return ( <div className="bg-white rounded-lg shadow-lg p-6"> <h3 className="text-xl font-semibold mb-4 text-gray-800"> {title} </h3> <div className="flex justify-center items-center h-96"> <div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"></div> <span className="ml-3 text-gray-600">Построение графика...</span> </div> </div> ); } const CustomTooltip = ({ active, payload }: any) => { if (active && payload && payload.length) { const data = payload[0].payload; return ( <div className="bg-white p-3 border border-gray-300 rounded-lg shadow-lg"> <p className="text-sm text-blue-600">{`x = ${data.x.toFixed(3)}`}</p> <p className="text-sm text-red-600">{`y = ${data.y.toFixed(4)}`}</p> </div> ); } return null; }; return ( <div className="bg-white rounded-lg shadow-lg p-6"> <div className="mb-4"> <h3 className="text-xl font-semibold text-gray-800"> {title} </h3> </div> <div className="h-96 w-full"> <ResponsiveContainer width="100%" height="100%"> <LineChart data={data} margin={{ top: 20, right: 30, left: 20, bottom: 20, }} > <CartesianGrid strokeDasharray="3 3" stroke="#f0f0f0" /> <XAxis dataKey="x" type="number" scale="linear" domain={['dataMin', 'dataMax']} tickFormatter={(value) => value.toFixed(2)} stroke="#6b7280" fontSize={12} /> <YAxis type="number" domain={['dataMin - 0.1', 'dataMax + 0.1']} tickFormatter={(value) => value.toFixed(3)} stroke="#6b7280" fontSize={12} /> <Tooltip content={<CustomTooltip />} /> <Legend /> <Line type="monotone" dataKey="y" stroke="#2563eb" strokeWidth={2} dot={{ fill: '#2563eb', strokeWidth: 2, r: 3 }} activeDot={{ r: 5, stroke: '#2563eb', strokeWidth: 2 }} name="y(x)" /> </LineChart> </ResponsiveContainer> </div> <div className="mt-4 text-sm text-gray-500"> Всего точек: {data.length} </div> </div> ); };