From e4fa3e6e87351c324fa00461de7a81acef7f80c4 Mon Sep 17 00:00:00 2001 From: c-bata Date: Sat, 5 Mar 2022 02:35:04 +0900 Subject: [PATCH] Move 'Reload Interval' to preference panel --- .../static/components/StudyDetail.tsx | 186 +++++++----------- .../static/components/StudyList.tsx | 6 +- 2 files changed, 67 insertions(+), 125 deletions(-) diff --git a/optuna_dashboard/static/components/StudyDetail.tsx b/optuna_dashboard/static/components/StudyDetail.tsx index 91a4b3d6..cc7015d5 100644 --- a/optuna_dashboard/static/components/StudyDetail.tsx +++ b/optuna_dashboard/static/components/StudyDetail.tsx @@ -17,14 +17,12 @@ import { Select, MenuItem, FormGroup, - useTheme, + useTheme, FormLabel, FormControl } from "@mui/material" -import { Home, Cached, Settings } from "@mui/icons-material" -import { alpha } from '@mui/material/styles'; +import { Home, Settings } from "@mui/icons-material" import FormControlLabel from "@mui/material/FormControlLabel" import MuiDialogTitle from "@mui/material/DialogTitle" import MuiDialogContent from "@mui/material/DialogContent" -import {styled} from "@mui/system"; import CloseIcon from "@mui/icons-material/Close" import { DataGridColumn, DataGrid } from "./DataGrid" @@ -57,39 +55,40 @@ export const StudyDetail: FC = () => { const { studyId } = useParams() const studyIdNumber = parseInt(studyId, 10) const studyDetail = useStudyDetailValue(studyIdNumber) - const [openReloadIntervalSelect, setPrefOpenReloadIntervalSelect] = - useState(false) - const [reloadInterval, setReloadInterval] = useState(10) - const savedPref = localStorage.getItem("savedPref") - const graphsChecked = - savedPref !== null - ? JSON.parse(savedPref) - : { - graphHistoryChecked: true, - graphParetoFrontChecked: true, - graphParallelCoordinateChecked: true, - graphIntermediateValuesChecked: true, - edfChecked: true, - graphHyperparameterImportancesChecked: true, - graphSliceChecked: true, - } - const [prefOpen, setPrefOpen] = React.useState(false) + const [preferences, setPreferences] = useState({ + graphHistoryChecked: true, + graphParetoFrontChecked: true, + graphParallelCoordinateChecked: true, + graphIntermediateValuesChecked: true, + edfChecked: true, + graphHyperparameterImportancesChecked: true, + graphSliceChecked: true, + reloadInterval: 10, + }) + useEffect(() => { + const localStoragePreferences = localStorage.getItem("savedPref") + if (localStoragePreferences !== null) { + const merged = {...preferences, ...JSON.parse(localStoragePreferences)} + setPreferences(merged) + } + }, []) + useEffect(() => { + localStorage.setItem("savedPref", JSON.stringify(preferences)) + }, [preferences]) + + const [prefOpen, setPrefOpen] = useState(false) const handleClickOpen = () => { setPrefOpen(true) } const handleClose = () => { setPrefOpen(false) } - const [chartsShown, setChartsShown] = React.useState(graphsChecked) - useEffect(() => { - localStorage.setItem("savedPref", JSON.stringify(chartsShown)) - }, [chartsShown]) const handleChartShownChange = ( event: React.ChangeEvent ) => { - setChartsShown({ - ...chartsShown, + setPreferences({ + ...preferences, [event.target.name]: event.target.checked, }) } @@ -99,45 +98,19 @@ export const StudyDetail: FC = () => { }, []) useEffect(() => { - if (reloadInterval < 0) { + if (preferences.reloadInterval < 0) { return } const intervalId = setInterval(function () { action.updateStudyDetail(studyIdNumber) - }, reloadInterval * 1000) + }, preferences.reloadInterval * 1000) return () => clearInterval(intervalId) - }, [reloadInterval, studyDetail]) + }, [preferences.reloadInterval, studyDetail]) // TODO(chenghuzi): Reduce the number of calls to setInterval and clearInterval. const title = studyDetail !== null ? studyDetail.name : `Study #${studyId}` const trials: Trial[] = studyDetail !== null ? studyDetail.trials : [] - const ReloadDiv = styled('div')({ - position: "relative", - borderRadius: theme.shape.borderRadius, - backgroundColor: alpha(theme.palette.common.white, 0.15), - "&:hover": { - backgroundColor: alpha(theme.palette.common.white, 0.25), - }, - marginLeft: 0, - width: "100%", - [theme.breakpoints.up("sm")]: { - marginLeft: theme.spacing(1), - width: "auto", - }, - }) - const ReloadIconDiv = styled('div')({ - padding: theme.spacing(0, 2), - height: "100%", - position: "absolute", - pointerEvents: "none", - display: "flex", - alignItems: "center", - justifyContent: "center", - }) - const GrowDiv = styled('div')({ - flexGrow: 1, - }) return (
@@ -146,10 +119,7 @@ export const StudyDetail: FC = () => { padding: theme.spacing(2), minWidth: 300, }}> -
- Visualization Preference -
- + Preferences { - + Charts @@ -182,7 +152,7 @@ export const StudyDetail: FC = () => { } control={ @@ -192,7 +162,7 @@ export const StudyDetail: FC = () => { @@ -205,7 +175,7 @@ export const StudyDetail: FC = () => { } control={ @@ -215,17 +185,17 @@ export const StudyDetail: FC = () => { } - label="Edf" + label="EDF" /> @@ -235,7 +205,7 @@ export const StudyDetail: FC = () => { @@ -243,6 +213,25 @@ export const StudyDetail: FC = () => { label="Slice" /> + Reload Interval + + +
@@ -253,50 +242,7 @@ export const StudyDetail: FC = () => { }}> {APP_BAR_TITLE} - - { - setPrefOpenReloadIntervalSelect(!openReloadIntervalSelect) - }} - > - - - - - - + @@ -324,7 +270,7 @@ export const StudyDetail: FC = () => { }}> {title} - {chartsShown.graphHistoryChecked ? ( + {preferences.graphHistoryChecked ? ( @@ -336,14 +282,14 @@ export const StudyDetail: FC = () => { {studyDetail !== null && !isSingleObjectiveStudy(studyDetail) && - chartsShown.graphParetoFrontChecked ? ( + preferences.graphParetoFrontChecked ? ( ) : null} - {chartsShown.graphParallelCoordinateChecked ? ( + {preferences.graphParallelCoordinateChecked ? ( @@ -353,21 +299,21 @@ export const StudyDetail: FC = () => { {studyDetail !== null && isSingleObjectiveStudy(studyDetail) && - chartsShown.graphIntermediateValuesChecked ? ( + preferences.graphIntermediateValuesChecked ? ( ) : null} - {chartsShown.edfChecked ? ( + {preferences.edfChecked ? ( ) : null} - {chartsShown.graphHyperparameterImportancesChecked ? ( + {preferences.graphHyperparameterImportancesChecked ? ( { ) : null} - {studyDetail !== null && chartsShown.graphSliceChecked ? ( + {studyDetail !== null && preferences.graphSliceChecked ? ( diff --git a/optuna_dashboard/static/components/StudyList.tsx b/optuna_dashboard/static/components/StudyList.tsx index e2fffaf3..47a259d2 100644 --- a/optuna_dashboard/static/components/StudyList.tsx +++ b/optuna_dashboard/static/components/StudyList.tsx @@ -31,7 +31,6 @@ import { Add, AddBox, Delete, Refresh, Remove } from "@mui/icons-material" import { actionCreator } from "../action" import { DataGrid, DataGridColumn } from "./DataGrid" import { studySummariesState } from "../state" -import {styled} from "@mui/system"; export const StudyList: FC = () => { const theme = useTheme() @@ -200,9 +199,6 @@ export const StudyList: FC = () => { ) } - const GrowDiv = styled('div')({ - flexGrow: 1 - }) return (
@@ -213,7 +209,7 @@ export const StudyList: FC = () => { }}> {APP_BAR_TITLE} - +