From 00d69e282d2addc4405537d27bdc37c566c18d08 Mon Sep 17 00:00:00 2001 From: Startklar Date: Tue, 7 Jul 2026 03:00:28 +0200 Subject: [PATCH] Fix comparison mode result cards --- src/App.jsx | 70 ++++++++++++++++++++++++++++++++++++++++++-------- src/styles.css | 34 ++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 11 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 578ca51..5e531ac 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -54,6 +54,24 @@ const getAlgorithmLabel = (value) => const clampArraySize = (size) => Math.min(Math.max(size, ARRAY_MIN), ARRAY_MAX); +const comparisonMetricLabels = [ + { key: 'comparisons', label: 'Vergleiche' }, + { key: 'moves', label: 'Bewegungen' }, + { key: 'steps', label: 'Schritte' }, + { key: 'generationTimeMs', label: 'Zeit' } +]; + +const createComparisonPlaceholder = (key) => ({ + key, + label: getAlgorithmLabel(key), + comparisons: '-', + moves: '-', + steps: '-', + generationTimeMs: '-' +}); + +const getNumericMetric = (row, key) => (typeof row[key] === 'number' ? row[key] : 0); + function App() { const initialArray = useMemo(() => createRandomArray(DEFAULT_SIZE), []); const [activeTab, setActiveTab] = useState('visualizer'); @@ -158,6 +176,20 @@ function App() { : currentStep > 0 && steps.length > 0 ? 'Bereit zum Fortsetzen' : 'Bereit'; + const comparisonDisplayRows = useMemo( + () => [compareLeftAlgorithm, compareRightAlgorithm].map((algorithmKey) => ( + comparisonRows.find((row) => row.key === algorithmKey) ?? createComparisonPlaceholder(algorithmKey) + )), + [compareLeftAlgorithm, compareRightAlgorithm, comparisonRows] + ); + const hasComparisonResult = comparisonRows.length > 0; + const comparisonMaxValues = useMemo(() => comparisonMetricLabels.reduce((maxValues, metric) => ({ + ...maxValues, + [metric.key]: Math.max( + ...comparisonDisplayRows.map((row) => getNumericMetric(row, metric.key)), + 1 + ) + }), {}), [comparisonDisplayRows]); const resetPlaybackState = () => { if (timeoutRef.current) { @@ -531,7 +563,10 @@ function App() { setCompareRightAlgorithm(event.target.value)} + onChange={(event) => { + setCompareRightAlgorithm(event.target.value); + setComparisonRows([]); + }} > {algorithmOptions.map((option) => (