1- import { useEffect , useState , useCallback } from "react" ;
1+ import { useEffect , useState , useCallback , useRef } from "react" ;
22import { Box , useTheme } from "@mui/material" ;
33import Plot from "react-plotly.js" ;
44import { JobsLoading } from "../data/JobsLoading" ;
@@ -16,6 +16,7 @@ import { useMMUXContext } from "../../context/MMUXContext";
1616export function MOGAPareto ( props : MogaParetoPropsType ) {
1717 const { loading, progress, jobProgress } = props ;
1818 const theme = useTheme ( ) ;
19+ const ref = useRef < Plot > ( null ) ;
1920 const { selectedFunction, inputVars, distribution, outputTargets } = useFunctionContext ( ) ;
2021 const { fetchedJobCollections, filterSelectedJobList, selectedJobUids } = useJobContext ( ) ;
2122 const { weights } = useMMUXContext ( ) ;
@@ -25,6 +26,7 @@ export function MOGAPareto(props: MogaParetoPropsType) {
2526 const [ outputVarSelection , setOutputVarSelection ] = useState < OutputVarSelection > ( { } ) ;
2627 const [ optVars , setOptVars ] = useState < Array < string > > ( [ ] ) ;
2728 const [ tableData , setTableData ] = useState < MogaDataType | undefined > ( undefined ) ;
29+ const [ hovered , setHovered ] = useState < number | null > ( null ) ;
2830
2931 const calculatePerformance = useCallback (
3032 ( row : { [ x : string ] : number } ) => {
@@ -144,6 +146,26 @@ export function MOGAPareto(props: MogaParetoPropsType) {
144146 // eslint-disable-next-line react-hooks/exhaustive-deps
145147 } , [ selectedFunction , outputTargets , weights , selectedJobUids ] ) ;
146148
149+ useEffect ( ( ) => {
150+ if ( hovered !== null && tableData ) {
151+ const hoveredRow = tableData . rows . find ( r => r . NDI === hovered ) ;
152+ console . log ( "hovered row:" , hoveredRow ) ;
153+ if ( hoveredRow && optVars . length >= 2 ) {
154+ const newPlotData = [ ...plotData ] ;
155+ newPlotData [ 3 ] = {
156+ name : "Hovered Sample" ,
157+ mode : "markers" ,
158+ type : "scatter" ,
159+ marker : { color : "red" , size : 10 , symbol : "circle" } ,
160+ x : [ hoveredRow [ optVars [ 0 ] ] ] ,
161+ y : [ hoveredRow [ optVars [ 1 ] ] ] ,
162+ } ;
163+ setPlotData ( newPlotData ) ;
164+ }
165+ }
166+ // eslint-disable-next-line react-hooks/exhaustive-deps
167+ } , [ hovered ] ) ;
168+
147169 const layout = {
148170 title : { text : "Pareto Front Diagram" } ,
149171 xaxis : { title : { text : optVars [ 0 ] } } ,
@@ -176,8 +198,8 @@ export function MOGAPareto(props: MogaParetoPropsType) {
176198 ) }
177199 { ! propagating && plotData . length !== 0 && (
178200 < >
179- < Plot data = { plotData } layout = { layout } style = { plotStyle } />
180- < MogaParetoTable tableData = { tableData } />
201+ < Plot ref = { ref } data = { plotData } layout = { layout } style = { plotStyle } />
202+ < MogaParetoTable tableData = { tableData } hovered = { hovered } setHovered = { setHovered } />
181203 </ >
182204 ) }
183205 </ Box >
0 commit comments