diff --git a/optuna_dashboard/ts/components/AppDrawer.tsx b/optuna_dashboard/ts/components/AppDrawer.tsx index 1d4d9c78..068dcff2 100644 --- a/optuna_dashboard/ts/components/AppDrawer.tsx +++ b/optuna_dashboard/ts/components/AppDrawer.tsx @@ -361,15 +361,16 @@ export const AppDrawer: FC<{ - + diff --git a/optuna_dashboard/ts/components/Settings.tsx b/optuna_dashboard/ts/components/Settings.tsx index 78ec883f..4e7a38dd 100644 --- a/optuna_dashboard/ts/components/Settings.tsx +++ b/optuna_dashboard/ts/components/Settings.tsx @@ -1,93 +1,147 @@ -import React, { FC, useState } from "react" - +import React from "react" import { Typography, Select, Switch, MenuItem, - Grid, SelectChangeEvent, + Stack, + useTheme, + IconButton, + Box, } from "@mui/material" +import ClearIcon from "@mui/icons-material/Clear" +import { useRecoilState } from "recoil" +import { plotlyColorThemeState, plotBackendRenderingState } from "../state" -import { useRecoilValue, useSetRecoilState, useRecoilState } from "recoil" -import { plotlyColorTheme, plotBackendRenderingState } from "../state" +interface SettingsProps { + handleClose: () => void +} -export const Settings: FC = () => { - const colorTheme = useRecoilValue(plotlyColorTheme) - const setPlotlyColorTheme = useSetRecoilState(plotlyColorTheme) - - const [darkModeColor, setDarkModeColor] = useState(colorTheme.dark) - const [lightModeColor, setLightModeColor] = useState(colorTheme.light) +export const Settings = ({ handleClose }: SettingsProps) => { + const theme = useTheme() + const [plotlyColorTheme, setPlotlyColorTheme] = useRecoilState( + plotlyColorThemeState + ) + const [plotBackendRendering, setPlotBackendRendering] = useRecoilState( + plotBackendRenderingState + ) const handleDarkModeColorChange = (event: SelectChangeEvent) => { - setDarkModeColor(event.target.value) - setPlotlyColorTheme({ dark: event.target.value, light: lightModeColor }) + const dark = event.target.value as PlotlyColorThemeDark + setPlotlyColorTheme((cur) => ({ ...cur, dark })) } const handleLightModeColorChange = (event: SelectChangeEvent) => { - setLightModeColor(event.target.value) - setPlotlyColorTheme({ dark: darkModeColor, light: event.target.value }) + const light = event.target.value as PlotlyColorThemeLight + setPlotlyColorTheme((cur) => ({ ...cur, light })) } - const [plotBackendRendering, setPlotBackendRendering] = - useRecoilState(plotBackendRenderingState) - const handleBackendRenderingChange = () => { - setPlotBackendRendering(!plotBackendRendering) + const togglePlotBackendRendering = () => { + setPlotBackendRendering((cur) => !cur) } return ( - - - + + + Settings - - - - Plotly Color Scales - - - - - Dark Mode - - - - - + + + Plotly Color Scales + + {theme.palette.mode === "dark" ? ( + <> + + Dark Mode + + + + Only the "Default" color scale is supported in dark mode + + + ) : ( + + Light Mode + + + )} + - - - Light Mode - - - - - + + + Use Plotlypy + + + + - - - Use Plotlypy - - - - - - + + + + ) } diff --git a/optuna_dashboard/ts/state.ts b/optuna_dashboard/ts/state.ts index 44c9341a..5828985f 100644 --- a/optuna_dashboard/ts/state.ts +++ b/optuna_dashboard/ts/state.ts @@ -42,8 +42,8 @@ export const artifactIsAvailable = atom({ default: false, }) -export const plotlyColorTheme = atom({ - key: "plotlyDarkColorScale", +export const plotlyColorThemeState = atom({ + key: "plotlyColorThemeState", default: { dark: "default", light: "default", @@ -110,7 +110,7 @@ export const useArtifacts = (studyId: number, trialId: number): Artifact[] => { } export const usePlotlyColorTheme = (mode: string): Partial => { - const theme = useRecoilValue(plotlyColorTheme) + const theme = useRecoilValue(plotlyColorThemeState) if (mode === "dark") { return DarkColorTemplates[theme.dark] } else { @@ -119,10 +119,8 @@ export const usePlotlyColorTheme = (mode: string): Partial => { } export const useBackendRender = (): boolean => { - const plotBackendRendering = useRecoilValue( - plotBackendRenderingState - ) - const plotlypyIsAvailable = useRecoilValue(plotlypyIsAvailableState) + const plotBackendRendering = useRecoilValue(plotBackendRenderingState) + const plotlypyIsAvailable = useRecoilValue(plotlypyIsAvailableState) if (plotBackendRendering) { if (plotlypyIsAvailable) { diff --git a/optuna_dashboard/ts/types/index.d.ts b/optuna_dashboard/ts/types/index.d.ts index 5127c22c..789dd5ff 100644 --- a/optuna_dashboard/ts/types/index.d.ts +++ b/optuna_dashboard/ts/types/index.d.ts @@ -236,7 +236,10 @@ type PreferenceHistory = { is_removed: boolean } +type PlotlyColorThemeDark = "default" +type PlotlyColorThemeLight = "default" | "seaborn" | "presentation" | "ggplot2" + type PlotlyColorTheme = { - dark: string - light: string + dark: PlotlyColorThemeDark + light: PlotlyColorThemeLight }