import React, { useState } from 'react'; const GrowthComparisonWidget: React.FC = () => { const [linearRate, setLinearRate] = useState(10); // +10 per step const [expRate, setExpRate] = useState(10); // +10% per step const start = 100; const steps = 10; // Generate Data const data = Array.from({ length: steps + 1 }, (_, i) => { return { x: i, lin: start + linearRate * i, exp: start * Math.pow(1 + expRate/100, i) }; }); const maxY = Math.max(data[steps].lin, data[steps].exp); // Scales const width = 100; const height = 60; const getX = (i: number) => (i / steps) * width; const getY = (val: number) => height - (val / maxY) * height; // Inverted Y const linPath = `M ${data.map(d => `${getX(d.x)},${getY(d.lin)}`).join(' L ')}`; const expPath = `M ${data.map(d => `${getX(d.x)},${getY(d.exp)}`).join(' L ')}`; return (
setLinearRate(Number(e.target.value))} className="w-full h-2 bg-indigo-100 rounded-lg appearance-none cursor-pointer accent-indigo-600 mt-2" />
+{linearRate} / step
setExpRate(Number(e.target.value))} className="w-full h-2 bg-rose-100 rounded-lg appearance-none cursor-pointer accent-rose-600 mt-2" />
+{expRate}% / step
{/* Grid */} {/* Paths */} {/* Points */} {data.map((d, i) => ( ))} {/* Labels */}
Linear Final: {Math.round(data[steps].lin)}
Exp Final: {Math.round(data[steps].exp)}

Exponential growth eventually overtakes Linear growth, even if the linear rate seems larger at first!

); }; export default GrowthComparisonWidget;