Add plotly color theme to PlotSlice

This commit is contained in:
keisuke-umezawa
2024-08-10 14:05:15 +09:00
parent f859230bed
commit 89c87c14c6
2 changed files with 13 additions and 7 deletions
@@ -1,3 +1,4 @@
import { useTheme } from "@mui/material"
import {
GraphContainer,
PlotSlice,
@@ -8,7 +9,7 @@ import React, { FC, useEffect } from "react"
import { StudyDetail } from "ts/types/optuna"
import { PlotType } from "../apiClient"
import { usePlot } from "../hooks/usePlot"
import { useBackendRender } from "../state"
import { useBackendRender, usePlotlyColorTheme } from "../state"
export const GraphSlice: FC<{
study: StudyDetail | null
@@ -16,7 +17,9 @@ export const GraphSlice: FC<{
if (useBackendRender()) {
return <GraphSliceBackend study={study} />
} else {
return <PlotSlice study={study} />
const theme = useTheme()
const colorTheme = usePlotlyColorTheme(theme.palette.mode)
return <PlotSlice study={study} colorTheme={colorTheme} />
}
}
+8 -5
View File
@@ -34,10 +34,13 @@ const domId = "plot-slice"
export const PlotSlice: FC<{
study: Optuna.Study | null
}> = ({ study = null }) => {
colorTheme?: Partial<Plotly.Template>
}> = ({ study = null, colorTheme }) => {
const { graphComponentState, notifyGraphDidRender } = useGraphComponentState()
const theme = useTheme()
const colorThemeUsed =
colorTheme ?? (theme.palette.mode === "dark" ? plotlyDarkTemplate : {})
const [objectiveTargets, selectedObjective, setObjectiveTarget] =
useObjectiveAndUserAttrTargets(study)
@@ -63,7 +66,7 @@ export const PlotSlice: FC<{
selectedParamTarget,
searchSpace.find((s) => s.name === selectedParamTarget?.key) || null,
logYScale,
theme.palette.mode
colorThemeUsed
)?.then(notifyGraphDidRender)
}
}, [
@@ -72,7 +75,7 @@ export const PlotSlice: FC<{
searchSpace,
selectedParamTarget,
logYScale,
theme.palette.mode,
colorThemeUsed,
graphComponentState,
])
@@ -160,7 +163,7 @@ const plotSlice = (
selectedParamTarget: Target | null,
selectedParamSpace: Optuna.SearchSpaceItem | null,
logYScale: boolean,
mode: string
colorTheme: Partial<Plotly.Template>
) => {
if (document.getElementById(domId) === null) {
return
@@ -190,7 +193,7 @@ const plotSlice = (
},
showlegend: false,
uirevision: "true",
template: mode === "dark" ? plotlyDarkTemplate : {},
template: colorTheme,
}
if (
selectedParamSpace === null ||