|
| 1 | +import React from 'react'; |
| 2 | +import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts'; |
| 3 | + |
| 4 | +// Generate data points for f(AGE) = 1 + mod(AGE - 18) functions |
| 5 | +const generateData = (modBase) => { |
| 6 | + const data = []; |
| 7 | + |
| 8 | + for (let age = 1; age <= 100; age++) { |
| 9 | + // Calculate different mod variations |
| 10 | + const standardMod = Math.abs(age - 18); |
| 11 | + const moduloTenMod = (age - 18) % 10; |
| 12 | + const moduloFiveMod = (age - 18) % 5; |
| 13 | + |
| 14 | + const standardBenefit = 1 / (1 + standardMod); |
| 15 | + const moduloTenBenefit = 1 / (1 + Math.abs(moduloTenMod)); |
| 16 | + const moduloFiveBenefit = 1 / (1 + Math.abs(moduloFiveMod)); |
| 17 | + |
| 18 | + data.push({ |
| 19 | + age: age, |
| 20 | + standardMod: standardMod, |
| 21 | + moduloTenMod: moduloTenMod, |
| 22 | + moduloFiveMod: moduloFiveMod, |
| 23 | + standardBenefit: Number(standardBenefit.toFixed(4)), |
| 24 | + moduloTenBenefit: Number(moduloTenBenefit.toFixed(4)), |
| 25 | + moduloFiveBenefit: Number(moduloFiveBenefit.toFixed(4)) |
| 26 | + }); |
| 27 | + } |
| 28 | + return data; |
| 29 | +}; |
| 30 | + |
| 31 | +export default function ModFunctionChart() { |
| 32 | + const data = generateData(); |
| 33 | + |
| 34 | + return ( |
| 35 | + <div className="w-full h-[800px] p-4"> |
| 36 | + <h2 className="text-center text-xl font-bold mb-4">Funkcje MOD różnych typów</h2> |
| 37 | + |
| 38 | + <ResponsiveContainer width="100%" height="30%"> |
| 39 | + <LineChart |
| 40 | + data={data} |
| 41 | + margin={{ top: 5, right: 30, left: 20, bottom: 5 }} |
| 42 | + > |
| 43 | + <CartesianGrid strokeDasharray="3 3" /> |
| 44 | + <XAxis |
| 45 | + dataKey="age" |
| 46 | + label={{ value: 'Wiek', position: 'insideBottomRight', offset: -10 }} |
| 47 | + /> |
| 48 | + <YAxis |
| 49 | + label={{ value: 'Wartość MOD', angle: -90, position: 'insideLeft' }} |
| 50 | + /> |
| 51 | + <Tooltip /> |
| 52 | + <Legend /> |
| 53 | + <Line |
| 54 | + type="monotone" |
| 55 | + dataKey="standardMod" |
| 56 | + stroke="#8884d8" |
| 57 | + name="Wartość bezwzględna |AGE - 18|" |
| 58 | + /> |
| 59 | + <Line |
| 60 | + type="monotone" |
| 61 | + dataKey="moduloTenMod" |
| 62 | + stroke="#82ca9d" |
| 63 | + name="MOD(AGE - 18, 10)" |
| 64 | + /> |
| 65 | + <Line |
| 66 | + type="monotone" |
| 67 | + dataKey="moduloFiveMod" |
| 68 | + stroke="#ff7300" |
| 69 | + name="MOD(AGE - 18, 5)" |
| 70 | + /> |
| 71 | + </LineChart> |
| 72 | + </ResponsiveContainer> |
| 73 | + |
| 74 | + <ResponsiveContainer width="100%" height="30%"> |
| 75 | + <LineChart |
| 76 | + data={data} |
| 77 | + margin={{ top: 5, right: 30, left: 20, bottom: 5 }} |
| 78 | + > |
| 79 | + <CartesianGrid strokeDasharray="3 3" /> |
| 80 | + <XAxis |
| 81 | + dataKey="age" |
| 82 | + label={{ value: 'Wiek', position: 'insideBottomRight', offset: -10 }} |
| 83 | + /> |
| 84 | + <YAxis |
| 85 | + label={{ value: 'Korzyść', angle: -90, position: 'insideLeft' }} |
| 86 | + /> |
| 87 | + <Tooltip /> |
| 88 | + <Legend /> |
| 89 | + <Line |
| 90 | + type="monotone" |
| 91 | + dataKey="standardBenefit" |
| 92 | + stroke="#8884d8" |
| 93 | + name="Korzyść (standardowa)" |
| 94 | + /> |
| 95 | + <Line |
| 96 | + type="monotone" |
| 97 | + dataKey="moduloTenBenefit" |
| 98 | + stroke="#82ca9d" |
| 99 | + name="Korzyść (MOD 10)" |
| 100 | + /> |
| 101 | + <Line |
| 102 | + type="monotone" |
| 103 | + dataKey="moduloFiveBenefit" |
| 104 | + stroke="#ff7300" |
| 105 | + name="Korzyść (MOD 5)" |
| 106 | + /> |
| 107 | + </LineChart> |
| 108 | + </ResponsiveContainer> |
| 109 | + |
| 110 | + <div className="text-center mt-4"> |
| 111 | + <h3 className="font-bold">Wzory funkcji MOD</h3> |
| 112 | + <ul className="list-disc list-inside text-left inline-block"> |
| 113 | + <li>f(x) = 1 + |x - 18|</li> |
| 114 | + <li>f(x) = 1 + mod(x - 18, 10)</li> |
| 115 | + <li>f(x) = 1 + mod(x - 18, 5)</li> |
| 116 | + </ul> |
| 117 | + <p className="mt-2">Różne sposoby obliczania MOD:</p> |
| 118 | + <ul className="list-disc list-inside text-left inline-block"> |
| 119 | + <li>Wartość bezwzględna: |x - 18|</li> |
| 120 | + <li>Modulo 10: reszta z dzielenia przez 10</li> |
| 121 | + <li>Modulo 5: reszta z dzielenia przez 5</li> |
| 122 | + </ul> |
| 123 | + </div> |
| 124 | + </div> |
| 125 | + ); |
| 126 | +} |
0 commit comments