mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-12 12:40:33 +08:00
Introduce usePlot
This commit is contained in:
@@ -8,7 +8,8 @@ import {
|
||||
usePlotlyColorTheme,
|
||||
useBackendRender,
|
||||
} from "../state"
|
||||
import { getPlotAPI, PlotType } from "../apiClient"
|
||||
import { PlotType } from "../apiClient"
|
||||
import { usePlot } from "../hooks/usePlot"
|
||||
|
||||
const plotDomId = "graph-hyperparameter-importances"
|
||||
|
||||
@@ -43,18 +44,23 @@ const GraphHyperparameterImportanceBackend: FC<{
|
||||
}> = ({ studyId, study = null, graphHeight }) => {
|
||||
const numCompletedTrials =
|
||||
study?.trials.filter((t) => t.state === "Complete").length || 0
|
||||
const { data, layout, error } = usePlot({
|
||||
numCompletedTrials,
|
||||
studyId,
|
||||
plotType: PlotType.ParamImportances,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (studyId === undefined) {
|
||||
return
|
||||
if (data && layout) {
|
||||
plotly.react(plotDomId, data, layout)
|
||||
}
|
||||
getPlotAPI(studyId, PlotType.ParamImportances)
|
||||
.then(({ data, layout }) => {
|
||||
plotly.react(plotDomId, data, layout)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
}, [studyId, numCompletedTrials])
|
||||
}, [data, layout])
|
||||
useEffect(() => {
|
||||
if (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}, [error])
|
||||
|
||||
return <Box id={plotDomId} sx={{ height: graphHeight }} />
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,9 @@ import {
|
||||
import { makeHovertext } from "../graphUtil"
|
||||
import { usePlotlyColorTheme } from "../state"
|
||||
import { useNavigate } from "react-router-dom"
|
||||
import { getPlotAPI, PlotType } from "../apiClient"
|
||||
import { PlotType } from "../apiClient"
|
||||
import { useBackendRender } from "../state"
|
||||
import { usePlot } from "../hooks/usePlot"
|
||||
|
||||
const plotDomId = "graph-pareto-front"
|
||||
|
||||
@@ -35,18 +36,23 @@ const GraphParetoFrontBackend: FC<{
|
||||
const studyId = study?.id
|
||||
const numCompletedTrials =
|
||||
study?.trials.filter((t) => t.state === "Complete").length || 0
|
||||
const { data, layout, error } = usePlot({
|
||||
numCompletedTrials,
|
||||
studyId,
|
||||
plotType: PlotType.ParetoFront,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (studyId === undefined) {
|
||||
return
|
||||
if (data && layout) {
|
||||
plotly.react(plotDomId, data, layout)
|
||||
}
|
||||
getPlotAPI(studyId, PlotType.ParetoFront)
|
||||
.then(({ data, layout }) => {
|
||||
plotly.react(plotDomId, data, layout)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
}, [studyId, numCompletedTrials])
|
||||
}, [data, layout])
|
||||
useEffect(() => {
|
||||
if (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}, [error])
|
||||
|
||||
return <Box id={plotDomId} sx={{ height: "450px" }} />
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@ import React, { FC, useEffect } from "react"
|
||||
import { Card, CardContent, Grid, Typography, useTheme } from "@mui/material"
|
||||
import { makeHovertext } from "../graphUtil"
|
||||
import { usePlotlyColorTheme } from "../state"
|
||||
import { getPlotAPI, PlotType } from "../apiClient"
|
||||
import { PlotType } from "../apiClient"
|
||||
import { useBackendRender } from "../state"
|
||||
import { usePlot } from "../hooks/usePlot"
|
||||
|
||||
const plotDomId = "graph-timeline"
|
||||
const maxBars = 100
|
||||
@@ -25,18 +26,23 @@ const GraphTimelineBackend: FC<{
|
||||
const studyId = study?.id
|
||||
const numCompletedTrials =
|
||||
study?.trials.filter((t) => t.state === "Complete").length || 0
|
||||
const { data, layout, error } = usePlot({
|
||||
numCompletedTrials,
|
||||
studyId,
|
||||
plotType: PlotType.Timeline,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (studyId === undefined) {
|
||||
return
|
||||
if (data && layout) {
|
||||
plotly.react(plotDomId, data, layout)
|
||||
}
|
||||
getPlotAPI(studyId, PlotType.Timeline)
|
||||
.then(({ data, layout }) => {
|
||||
plotly.react(plotDomId, data, layout)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
}, [studyId, numCompletedTrials])
|
||||
}, [data, layout])
|
||||
useEffect(() => {
|
||||
if (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}, [error])
|
||||
|
||||
return (
|
||||
<Grid item xs={9}>
|
||||
{" "}
|
||||
|
||||
Reference in New Issue
Block a user