From b2a9b3bb50429268e361f0750383dee6f3ea8c24 Mon Sep 17 00:00:00 2001 From: Kenshin Abe Date: Fri, 2 Feb 2024 19:28:00 +0900 Subject: [PATCH] Implement GraphEdfBackend --- optuna_dashboard/ts/apiClient.ts | 14 +++++++++ optuna_dashboard/ts/components/GraphEdf.tsx | 33 +++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/optuna_dashboard/ts/apiClient.ts b/optuna_dashboard/ts/apiClient.ts index 46fe3d0e..5339ff21 100644 --- a/optuna_dashboard/ts/apiClient.ts +++ b/optuna_dashboard/ts/apiClient.ts @@ -461,3 +461,17 @@ export const getPlotAPI = ( .get(`/api/studies/${studyId}/plot/${plotType}`) .then((res) => res.data) } + +export enum CompareStudiesPlotType { + EDF = "edf", +} +export const getCompareStudiesPlotAPI = ( + studyIds: number[], + plotType: CompareStudiesPlotType, +): Promise => { + return axiosInstance + .get(`/api/compare-studies/plot/${plotType}`, { + params: { study_ids: studyIds }, + }) + .then((res) => res.data) +} diff --git a/optuna_dashboard/ts/components/GraphEdf.tsx b/optuna_dashboard/ts/components/GraphEdf.tsx index ca85ee54..6bb65bdc 100644 --- a/optuna_dashboard/ts/components/GraphEdf.tsx +++ b/optuna_dashboard/ts/components/GraphEdf.tsx @@ -3,6 +3,8 @@ import React, { FC, useEffect, useMemo } from "react" import { Typography, useTheme, Box } from "@mui/material" import { plotlyDarkTemplate } from "./PlotlyDarkMode" import { Target, useFilteredTrialsFromStudies } from "../trialFilter" +import { getCompareStudiesPlotAPI, CompareStudiesPlotType } from "../apiClient" +import { useBackendRender } from "../state" const getPlotDomId = (objectiveId: number) => `graph-edf-${objectiveId}` @@ -14,6 +16,37 @@ interface EdfPlotInfo { export const GraphEdf: FC<{ studies: StudyDetail[] objectiveId: number +}> = ({ studies, objectiveId }) => { + if (useBackendRender()) { + return + } else { + return + } +} + +const GraphEdfBackend: FC<{ + studies: StudyDetail[] +}> = ({ studies }) => { + const studyIds = studies.map((s) => s.id) + const domId = getPlotDomId(-1) + useEffect(() => { + if (studyIds.length === 0) { + return + } + getCompareStudiesPlotAPI(studyIds, CompareStudiesPlotType.EDF) + .then(({ data, layout }) => { + plotly.react(domId, data, layout) + }) + .catch((err) => { + console.error(err) + }) + }, [studyIds]) + return +} + +const GraphEdfFrontend: FC<{ + studies: StudyDetail[] + objectiveId: number }> = ({ studies, objectiveId }) => { const theme = useTheme() const domId = getPlotDomId(objectiveId)