mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-11 12:30:25 +08:00
Replaced recoil with react-query for GraphContour, GraphParallelCoordinate, GraphSlice
This commit is contained in:
@@ -15,8 +15,9 @@ import blue from "@mui/material/colors/blue"
|
||||
import { plotlyDarkTemplate } from "./PlotlyDarkMode"
|
||||
import { useMergedUnionSearchSpace } from "../searchSpace"
|
||||
import { getAxisInfo } from "../graphUtil"
|
||||
import { getPlotAPI, PlotType } from "../apiClient"
|
||||
import { PlotType } from "../apiClient"
|
||||
import { useBackendRender } from "../state"
|
||||
import { usePlot } from "../hooks/usePlot"
|
||||
|
||||
const plotDomId = "graph-contour"
|
||||
|
||||
@@ -36,18 +37,23 @@ const ContourBackend: 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.Contour,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (studyId === undefined) {
|
||||
return
|
||||
if (data && layout) {
|
||||
plotly.react(plotDomId, data, layout)
|
||||
}
|
||||
getPlotAPI(studyId, PlotType.Contour)
|
||||
.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" }} />
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,9 @@ import {
|
||||
useParamTargets,
|
||||
} from "../trialFilter"
|
||||
import { useMergedUnionSearchSpace } from "../searchSpace"
|
||||
import { getPlotAPI, PlotType } from "../apiClient"
|
||||
import { PlotType } from "../apiClient"
|
||||
import { useBackendRender } from "../state"
|
||||
import { usePlot } from "../hooks/usePlot"
|
||||
|
||||
const plotDomId = "graph-parallel-coordinate"
|
||||
|
||||
@@ -102,18 +103,24 @@ const GraphParallelCoordinateBackend: 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.ParallelCoordinate,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (studyId === undefined) {
|
||||
return
|
||||
if (data && layout) {
|
||||
plotly.react(plotDomId, data, layout)
|
||||
}
|
||||
getPlotAPI(studyId, PlotType.ParallelCoordinate)
|
||||
.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" }} />
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,9 @@ import {
|
||||
useParamTargets,
|
||||
} from "../trialFilter"
|
||||
import { useMergedUnionSearchSpace } from "../searchSpace"
|
||||
import { getPlotAPI, PlotType } from "../apiClient"
|
||||
import { PlotType } from "../apiClient"
|
||||
import { useBackendRender } from "../state"
|
||||
import { usePlot } from "../hooks/usePlot"
|
||||
|
||||
const plotDomId = "graph-slice"
|
||||
|
||||
@@ -48,18 +49,24 @@ const GraphSliceBackend: 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.Slice,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (studyId === undefined) {
|
||||
return
|
||||
if (data && layout) {
|
||||
plotly.react(plotDomId, data, layout)
|
||||
}
|
||||
getPlotAPI(studyId, PlotType.Slice)
|
||||
.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" }} />
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ export const usePlot = ({
|
||||
AxiosError
|
||||
>({
|
||||
enabled: studyId !== undefined,
|
||||
queryKey: ["plot", studyId, numCompletedTrials],
|
||||
queryKey: ["plot", studyId, numCompletedTrials, plotType],
|
||||
queryFn: () => {
|
||||
if (studyId === undefined) {
|
||||
return Promise.reject(new Error("Invalid studyId"))
|
||||
|
||||
Reference in New Issue
Block a user