Replaced recoil with react-query for GraphContour, GraphParallelCoordinate, GraphSlice

This commit is contained in:
porink0424
2024-02-09 15:28:51 +09:00
parent 99177b98c6
commit a40fc7f76d
4 changed files with 54 additions and 34 deletions
+17 -11
View File
@@ -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" }} />
}
+18 -11
View File
@@ -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" }} />
}
+1 -1
View File
@@ -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"))