From c0a63bbbbc2114239158d93f02773e79d76c9fd8 Mon Sep 17 00:00:00 2001 From: porink0424 Date: Wed, 14 Feb 2024 09:39:42 +0900 Subject: [PATCH 1/5] Improve modal position and size & add close button --- optuna_dashboard/ts/components/AppDrawer.tsx | 13 ++- optuna_dashboard/ts/components/Settings.tsx | 115 ++++++++++++------- optuna_dashboard/ts/types/index.d.ts | 7 +- 3 files changed, 88 insertions(+), 47 deletions(-) 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 328521c0..f3d5b2af 100644 --- a/optuna_dashboard/ts/components/Settings.tsx +++ b/optuna_dashboard/ts/components/Settings.tsx @@ -1,17 +1,25 @@ -import React, { FC, useState } from "react" +import React, { useState } from "react" import { Typography, Select, MenuItem, - Grid, SelectChangeEvent, + Stack, + useTheme, + IconButton, } from "@mui/material" +import ClearIcon from "@mui/icons-material/Clear" import { useRecoilValue, useSetRecoilState } from "recoil" import { plotlyColorTheme } from "../state" -export const Settings: FC = () => { +interface SettingsProps { + handleClose: () => void +} + +export const Settings = ({ handleClose }: SettingsProps) => { + const theme = useTheme() const colorTheme = useRecoilValue(plotlyColorTheme) const setPlotlyColorTheme = useSetRecoilState(plotlyColorTheme) @@ -29,45 +37,74 @@ export const Settings: FC = () => { } return ( - - - - Settings - - - - + + + + + + + Settings + + + + Plotly Color Scales - - - - - Dark Mode + + Dark Mode + + + + Only the "Default" color scale is supported in dark mode - - - - - - - Light Mode - - - - - - + + Light Mode + + + + ) } diff --git a/optuna_dashboard/ts/types/index.d.ts b/optuna_dashboard/ts/types/index.d.ts index 30d6708f..78ca0386 100644 --- a/optuna_dashboard/ts/types/index.d.ts +++ b/optuna_dashboard/ts/types/index.d.ts @@ -240,7 +240,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 } From 704a5900242550cc80b316e948eaa8a0840a833a Mon Sep 17 00:00:00 2001 From: porink0424 Date: Wed, 14 Feb 2024 09:53:28 +0900 Subject: [PATCH 2/5] Fix plotlyColorTheme state in Settings component --- optuna_dashboard/ts/components/Settings.tsx | 31 ++++++++++----------- optuna_dashboard/ts/state.ts | 6 ++-- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/optuna_dashboard/ts/components/Settings.tsx b/optuna_dashboard/ts/components/Settings.tsx index f3d5b2af..e8420094 100644 --- a/optuna_dashboard/ts/components/Settings.tsx +++ b/optuna_dashboard/ts/components/Settings.tsx @@ -1,5 +1,4 @@ -import React, { useState } from "react" - +import React from "react" import { Typography, Select, @@ -10,9 +9,8 @@ import { IconButton, } from "@mui/material" import ClearIcon from "@mui/icons-material/Clear" - -import { useRecoilValue, useSetRecoilState } from "recoil" -import { plotlyColorTheme } from "../state" +import { useRecoilState } from "recoil" +import { plotlyColorThemeState } from "../state" interface SettingsProps { handleClose: () => void @@ -20,20 +18,18 @@ interface SettingsProps { export const Settings = ({ handleClose }: SettingsProps) => { const theme = useTheme() - const colorTheme = useRecoilValue(plotlyColorTheme) - const setPlotlyColorTheme = useSetRecoilState(plotlyColorTheme) - - const [darkModeColor, setDarkModeColor] = useState(colorTheme.dark) - const [lightModeColor, setLightModeColor] = useState(colorTheme.light) + const [plotlyColorTheme, setPlotlyColorTheme] = useRecoilState( + plotlyColorThemeState + ) const handleDarkModeColorChange = (event: SelectChangeEvent) => { - setDarkModeColor(event.target.value) - setPlotlyColorTheme({ dark: event.target.value, light: lightModeColor }) + const dark = event.target.value as PlotlyColorThemeDark + setPlotlyColorTheme((prev) => ({ ...prev, dark })) } const handleLightModeColorChange = (event: SelectChangeEvent) => { - setLightModeColor(event.target.value) - setPlotlyColorTheme({ dark: darkModeColor, light: event.target.value }) + const light = event.target.value as PlotlyColorThemeLight + setPlotlyColorTheme((prev) => ({ ...prev, light })) } return ( @@ -75,7 +71,7 @@ export const Settings = ({ handleClose }: SettingsProps) => { Dark Mode + - - Default - - - - - Only the "Default" color scale is supported in dark mode - - - - Light Mode - - + {theme.palette.mode === "dark" ? ( + <> + + Dark Mode + + + + Only the "Default" color scale is supported in dark mode + + + ) : ( + + Light Mode + + + )} ) From 372f4fc64890984f10e3f4cf3933328bccdf989e Mon Sep 17 00:00:00 2001 From: porink0424 Date: Wed, 14 Feb 2024 10:12:07 +0900 Subject: [PATCH 4/5] Remove redundant repetitions --- optuna_dashboard/ts/components/Settings.tsx | 42 +++++++++++++-------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/optuna_dashboard/ts/components/Settings.tsx b/optuna_dashboard/ts/components/Settings.tsx index 50ad1213..6b58453d 100644 --- a/optuna_dashboard/ts/components/Settings.tsx +++ b/optuna_dashboard/ts/components/Settings.tsx @@ -55,7 +55,7 @@ export const Settings = ({ handleClose }: SettingsProps) => { Settings @@ -76,9 +76,16 @@ export const Settings = ({ handleClose }: SettingsProps) => { value={plotlyColorTheme.dark} onChange={handleDarkModeColorChange} > - - Default - + {( + [{ value: "default", label: "Default" }] as { + value: PlotlyColorThemeDark + label: string + }[] + ).map((v) => ( + + {v.label} + + ))} @@ -92,18 +99,21 @@ export const Settings = ({ handleClose }: SettingsProps) => { value={plotlyColorTheme.light} onChange={handleLightModeColorChange} > - - Default - - - Seaborn - - - Presentation - - - GGPlot2 - + {( + [ + { value: "default", label: "Default" }, + { value: "seaborn", label: "Seaborn" }, + { value: "presentation", label: "Presentation" }, + { value: "ggplot2", label: "GGPlot2" }, + ] as { + value: PlotlyColorThemeLight + label: string + }[] + ).map((v) => ( + + {v.label} + + ))} )} From e60967397938ab1a562b74a1d7f702ea1b65d52f Mon Sep 17 00:00:00 2001 From: porink0424 Date: Wed, 14 Feb 2024 11:45:59 +0900 Subject: [PATCH 5/5] Follow-up of #806 --- optuna_dashboard/ts/components/Settings.tsx | 186 ++++++++++---------- optuna_dashboard/ts/state.ts | 6 +- 2 files changed, 99 insertions(+), 93 deletions(-) diff --git a/optuna_dashboard/ts/components/Settings.tsx b/optuna_dashboard/ts/components/Settings.tsx index 23ac647e..4e7a38dd 100644 --- a/optuna_dashboard/ts/components/Settings.tsx +++ b/optuna_dashboard/ts/components/Settings.tsx @@ -8,6 +8,7 @@ import { Stack, useTheme, IconButton, + Box, } from "@mui/material" import ClearIcon from "@mui/icons-material/Clear" import { useRecoilState } from "recoil" @@ -22,31 +23,113 @@ export const Settings = ({ handleClose }: SettingsProps) => { const [plotlyColorTheme, setPlotlyColorTheme] = useRecoilState( plotlyColorThemeState ) + const [plotBackendRendering, setPlotBackendRendering] = useRecoilState( + plotBackendRenderingState + ) const handleDarkModeColorChange = (event: SelectChangeEvent) => { const dark = event.target.value as PlotlyColorThemeDark - setPlotlyColorTheme((prev) => ({ ...prev, dark })) + setPlotlyColorTheme((cur) => ({ ...cur, dark })) } const handleLightModeColorChange = (event: SelectChangeEvent) => { const light = event.target.value as PlotlyColorThemeLight - setPlotlyColorTheme((prev) => ({ ...prev, light })) + setPlotlyColorTheme((cur) => ({ ...cur, light })) } - const [plotBackendRendering, setPlotBackendRendering] = - useRecoilState(plotBackendRenderingState) - const handleBackendRenderingChange = () => { - setPlotBackendRendering(!plotBackendRendering) + const togglePlotBackendRendering = () => { + setPlotBackendRendering((cur) => !cur) } return ( - + + + + Settings + + + + + Plotly Color Scales + + {theme.palette.mode === "dark" ? ( + <> + + Dark Mode + + + + Only the "Default" color scale is supported in dark mode + + + ) : ( + + Light Mode + + + )} + + + + + Use Plotlypy + + + + + { > - - - Settings - - - - - Plotly Color Scales - - {theme.palette.mode === "dark" ? ( - <> - - Dark Mode - - - - Only the "Default" color scale is supported in dark mode - - - ) : ( - - Light Mode - - - )} - - - Use Plotlypy - - - - + ) } diff --git a/optuna_dashboard/ts/state.ts b/optuna_dashboard/ts/state.ts index f8d51e64..5828985f 100644 --- a/optuna_dashboard/ts/state.ts +++ b/optuna_dashboard/ts/state.ts @@ -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) {