Implement backend rendering of timeline plot

This commit is contained in:
Kenshin Abe
2024-02-09 18:32:55 +09:00
parent 8124ca5eeb
commit 18e01d4d37
3 changed files with 36 additions and 0 deletions
+2
View File
@@ -283,6 +283,8 @@ def create_app(
fig = optuna.visualization.plot_rank(study)
elif plot_type == "edf":
fig = optuna.visualization.plot_edf(study)
elif plot_type == "timeline":
fig = optuna.visualization.plot_timeline(study)
else:
response.status = 404 # Not found
return {"reason": f"plot_type={plot_type} is not supported."}
+1
View File
@@ -452,6 +452,7 @@ export enum PlotType {
ParallelCoordinate = "parallel_coordinate",
Rank = "rank",
EDF = "edf",
Timeline = "timeline",
}
export const getPlotAPI = (
studyId: number,
@@ -3,12 +3,45 @@ 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 { useBackendRender } from "../state"
const plotDomId = "graph-timeline"
const maxBars = 100
export const GraphTimeline: FC<{
study: StudyDetail | null
}> = ({ study }) => {
if (useBackendRender()) {
return <GraphTimelineBackend study={study} />
} else {
return <GraphTimelineFrontend study={study} />
}
}
const GraphTimelineBackend: FC<{
study: StudyDetail | null
}> = ({ study }) => {
const studyId = study?.id
const numCompletedTrials =
study?.trials.filter((t) => t.state === "Complete").length || 0
useEffect(() => {
if (studyId === undefined) {
return
}
getPlotAPI(studyId, PlotType.Timeline)
.then(({ data, layout }) => {
plotly.react(plotDomId, data, layout)
})
.catch((err) => {
console.error(err)
})
}, [studyId, numCompletedTrials])
return <Grid item xs={9}> <div id={plotDomId} /> </Grid>
}
const GraphTimelineFrontend: FC<{
study: StudyDetail | null
}> = ({ study }) => {
const theme = useTheme()
const colorTheme = usePlotlyColorTheme(theme.palette.mode)