Add "use plotlypy" button

This commit is contained in:
Kenshin Abe
2024-02-09 19:04:12 +09:00
parent 8124ca5eeb
commit 16ee07d4d8
2 changed files with 28 additions and 4 deletions
+21 -2
View File
@@ -3,13 +3,14 @@ import React, { FC, useState } from "react"
import {
Typography,
Select,
Switch,
MenuItem,
Grid,
SelectChangeEvent,
} from "@mui/material"
import { useRecoilValue, useSetRecoilState } from "recoil"
import { plotlyColorTheme } from "../state"
import { useRecoilValue, useSetRecoilState, useRecoilState } from "recoil"
import { plotlyColorTheme, plotBackendRenderingState } from "../state"
export const Settings: FC = () => {
const colorTheme = useRecoilValue<PlotlyColorTheme>(plotlyColorTheme)
@@ -28,6 +29,11 @@ export const Settings: FC = () => {
setPlotlyColorTheme({ dark: darkModeColor, light: event.target.value })
}
const [plotBackendRendering, setPlotBackendRendering] = useRecoilState<boolean>(plotBackendRenderingState)
const handleBackendRenderingChange = () => {
setPlotBackendRendering(!plotBackendRendering)
}
return (
<Grid container spacing={4} sx={{ padding: "40px" }}>
<Grid item xs={12}>
@@ -68,6 +74,19 @@ export const Settings: FC = () => {
<MenuItem value={"ggplot2"}>GGPlot2</MenuItem>
</Select>
</Grid>
<Grid item xs={2}>
<Typography variant="h6" color="textSecondary">
Use Plotlypy
</Typography>
</Grid>
<Grid item xs={10} sx={{ display: "flex", alignItems: "center" }}>
<Switch
checked={plotBackendRendering}
onChange={handleBackendRenderingChange}
value="enable"
/>
</Grid>
</Grid>
)
}
+7 -2
View File
@@ -51,6 +51,11 @@ export const plotlyColorTheme = atom<PlotlyColorTheme>({
},
})
export const plotBackendRenderingState = atom<boolean>({
key: "plotBackendRendering",
default: false,
})
export const plotlypyIsAvailableState = atom<boolean>({
key: "plotlypyIsAvailable",
default: true,
@@ -115,10 +120,10 @@ export const usePlotlyColorTheme = (mode: string): Partial<Plotly.Template> => {
}
export const useBackendRender = (): boolean => {
const query = useQuery()
const plotBackendRendering = useRecoilValue<boolean>(plotBackendRenderingState)
const plotlypyIsAvailable = useRecoilValue<boolean>(plotlypyIsAvailableState)
if (query.get("plotlypy_rendering") === "true") {
if (plotBackendRendering) {
if (plotlypyIsAvailable) {
return true
}