File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import * as plotly from "plotly.js-dist-min"
1818import { ChangeEvent , FC , useEffect , useState } from "react"
1919
2020import { useGraphComponentState } from "../hooks/useGraphComponentState"
21+ import { makeHovertext } from "../utils/graph"
2122import {
2223 Target ,
2324 useFilteredTrialsFromStudies ,
@@ -332,6 +333,10 @@ const plotHistory = (
332333 infeasibleTrials . push ( t )
333334 }
334335 }
336+ const hovertemplate =
337+ infeasibleTrials . length === 0
338+ ? "%{text}<extra>Trial</extra>"
339+ : "%{text}<extra>Feasible Trial</extra>"
335340 plotData . push ( {
336341 x : feasibleTrials . map ( getAxisX ) ,
337342 y : feasibleTrials . map (
@@ -343,6 +348,8 @@ const plotHistory = (
343348 } ,
344349 mode : "markers" ,
345350 type : "scatter" ,
351+ text : feasibleTrials . map ( ( t ) => makeHovertext ( t ) ) ,
352+ hovertemplate : hovertemplate ,
346353 } )
347354
348355 const objectiveId = target . getObjectiveId ( )
@@ -411,6 +418,8 @@ const plotHistory = (
411418 } ,
412419 mode : "markers" ,
413420 type : "scatter" ,
421+ text : infeasibleTrials . map ( ( t ) => makeHovertext ( t ) ) ,
422+ hovertemplate : "%{text}<extra>Infeasible Trial</extra>" ,
414423 showlegend : false ,
415424 } )
416425 }
Original file line number Diff line number Diff line change 1+ import * as Optuna from "@optuna/types"
2+
3+ export const makeHovertext = ( trial : Optuna . Trial ) : string => {
4+ return JSON . stringify (
5+ {
6+ number : trial . number ,
7+ values : trial . values ,
8+ params : trial . params
9+ . map ( ( p ) => [ p . name , p . param_external_value ] )
10+ . reduce (
11+ ( obj , [ key , value ] ) => {
12+ obj [ key as string ] = value
13+ return obj
14+ } ,
15+ { } as Record < string , Optuna . CategoricalChoiceType >
16+ ) ,
17+ } ,
18+ undefined ,
19+ " "
20+ ) . replace ( / \n / g, "<br>" )
21+ }
You can’t perform that action at this time.
0 commit comments