/** * Parallel Coordinates Plot - Enhanced Multi-Objective Visualization * Shows design variables → objectives → constraints in proper research format * Light theme with high visibility */ import { useState } from 'react'; interface ParetoTrial { trial_number: number; values: number[]; params: Record; user_attrs?: Record; constraint_satisfied?: boolean; } interface Objective { name: string; type: 'minimize' | 'maximize'; unit?: string; } interface DesignVariable { name: string; unit?: string; min: number; max: number; } interface Constraint { name: string; threshold: number; type: 'less_than' | 'greater_than'; unit?: string; } interface ParallelCoordinatesPlotProps { paretoData: ParetoTrial[]; objectives: Objective[]; designVariables: DesignVariable[]; constraints?: Constraint[]; } export function ParallelCoordinatesPlot({ paretoData, objectives, designVariables, constraints = [] }: ParallelCoordinatesPlotProps) { const [hoveredTrial, setHoveredTrial] = useState(null); const [selectedTrials, setSelectedTrials] = useState>(new Set()); // Safety checks if (!paretoData || paretoData.length === 0) { return (

Parallel Coordinates Plot

No Pareto front data available
); } if (!objectives || objectives.length === 0 || !designVariables || designVariables.length === 0) { return (

Parallel Coordinates Plot

Missing objectives or design variables metadata
); } // Structure axes: Design Variables → Objectives → Constraints const axes: Array<{ name: string; label: string; type: 'design_var' | 'objective' | 'constraint'; unit?: string; }> = []; // Add design variables designVariables.forEach(dv => { axes.push({ name: dv.name, label: dv.unit ? `${dv.name}\n(${dv.unit})` : dv.name, type: 'design_var', unit: dv.unit }); }); // Add objectives objectives.forEach((obj, i) => { axes.push({ name: `objective_${i}`, label: obj.unit ? `${obj.name}\n(${obj.unit})` : obj.name, type: 'objective', unit: obj.unit }); }); // Add constraints (extract from user_attrs) const constraintNames = new Set(); paretoData.forEach(trial => { if (trial.user_attrs) { // Common constraint metrics if (trial.user_attrs.max_stress !== undefined) constraintNames.add('max_stress'); if (trial.user_attrs.max_displacement !== undefined) constraintNames.add('max_displacement'); if (trial.user_attrs.frequency !== undefined && objectives.findIndex(obj => obj.name.toLowerCase().includes('freq')) === -1) { constraintNames.add('frequency'); } if (trial.user_attrs.mass !== undefined && objectives.findIndex(obj => obj.name.toLowerCase().includes('mass')) === -1) { constraintNames.add('mass'); } } }); constraintNames.forEach(name => { const unit = name.includes('stress') ? 'MPa' : name.includes('displacement') ? 'mm' : name.includes('frequency') ? 'Hz' : name.includes('mass') ? 'g' : ''; axes.push({ name: `constraint_${name}`, label: unit ? `${name}\n(${unit})` : name, type: 'constraint', unit }); }); // Extract values for each axis const trialData = paretoData.map(trial => { const values: number[] = []; // Design variables designVariables.forEach(dv => { values.push(trial.params[dv.name] ?? 0); }); // Objectives trial.values.forEach(val => { values.push(val); }); // Constraints constraintNames.forEach(name => { values.push(trial.user_attrs?.[name] ?? 0); }); return { trial_number: trial.trial_number, values, feasible: trial.constraint_satisfied !== false }; }); // Calculate min/max for normalization const ranges = axes.map((_, axisIdx) => { const values = trialData.map(d => d.values[axisIdx]); return { min: Math.min(...values), max: Math.max(...values) }; }); // Normalize to [0, 1] const normalize = (value: number, axisIdx: number): number => { const range = ranges[axisIdx]; if (range.max === range.min) return 0.5; return (value - range.min) / (range.max - range.min); }; // Chart dimensions const width = 1400; const height = 500; const margin = { top: 100, right: 50, bottom: 60, left: 50 }; const plotWidth = width - margin.left - margin.right; const plotHeight = height - margin.top - margin.bottom; const axisSpacing = plotWidth / (axes.length - 1); // Toggle trial selection const toggleTrial = (trialNum: number) => { const newSelected = new Set(selectedTrials); if (newSelected.has(trialNum)) { newSelected.delete(trialNum); } else { newSelected.add(trialNum); } setSelectedTrials(newSelected); }; // Color scheme - highly visible const getLineColor = (trial: typeof trialData[0], isHovered: boolean, isSelected: boolean) => { if (isSelected) return '#FF6B00'; // Bright orange for selected if (!trial.feasible) return '#DC2626'; // Red for infeasible if (isHovered) return '#2563EB'; // Blue for hover return '#10B981'; // Green for feasible }; return (

Parallel Coordinates Plot ({paretoData.length} solutions)

Design Variables → Objectives → Constraints

{selectedTrials.size > 0 && ( )}
{/* Draw axes */} {axes.map((axis, i) => { const x = i * axisSpacing; const bgColor = axis.type === 'design_var' ? '#EFF6FF' : axis.type === 'objective' ? '#F0FDF4' : '#FEF3C7'; return ( {/* Background highlight */} {/* Axis line */} {/* Axis label */} {(axis.label || '').split('\n').map((line, idx) => ( {line} ))} {/* Type badge */} {axis.type === 'design_var' ? 'DESIGN VAR' : axis.type === 'objective' ? 'OBJECTIVE' : 'CONSTRAINT'} {/* Min/max labels */} {ranges[i].min.toFixed(2)} {ranges[i].max.toFixed(2)} ); })} {/* Draw polylines for each trial */} {trialData.map(trial => { const isHovered = hoveredTrial === trial.trial_number; const isSelected = selectedTrials.has(trial.trial_number); const isHighlighted = isHovered || isSelected; // Build path const pathData = axes.map((_, i) => { const x = i * axisSpacing; const normalizedY = normalize(trial.values[i], i); const y = plotHeight * (1 - normalizedY); return i === 0 ? `M ${x} ${y}` : `L ${x} ${y}`; }).join(' '); return ( 0 ? (isSelected ? 0.95 : 0.1) : (isHighlighted ? 0.95 : 0.5) } strokeLinecap="round" strokeLinejoin="round" className="transition-all duration-150 cursor-pointer" style={{ filter: isHighlighted ? 'drop-shadow(0 2px 4px rgba(0,0,0,0.2))' : 'none' }} onMouseEnter={() => setHoveredTrial(trial.trial_number)} onMouseLeave={() => setHoveredTrial(null)} onClick={() => toggleTrial(trial.trial_number)} /> ); })} {/* Hover tooltip */} {hoveredTrial !== null && ( Trial #{hoveredTrial} Click to select/deselect {selectedTrials.has(hoveredTrial) ? '✓ Selected' : '○ Not selected'} )}
{/* Legend */}
Feasible
Infeasible
Selected
Hover
{/* Axis type legend */}
Design Variables
Objectives
Constraints
); }