-
Notifications
You must be signed in to change notification settings - Fork 3
/
SurfacePlot.tsx
156 lines (147 loc) · 4.07 KB
/
SurfacePlot.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { Box, Typography, useTheme } from "@mui/material";
import React, { useState } from "react";
import ConditionalDialog from "../ConditionalDialog";
import Plotly from "react-plotly.js";
import { SurfacePlotProps } from "./SurfacePlot.types";
import { getConfig } from "../utils/plotlyConfig";
// The `SurfacePlot` component renders a 3D surface plot using Plotly.
const SurfacePlot = ({
fullscreenTitle = "",
xdata = [],
ydata = [],
zdata = [],
xlabel = "",
ylabel = "",
zlabel = "",
title = "",
showGrid = true
}: SurfacePlotProps) => {
// theme hook
const theme = useTheme();
// state for fullscreen
const [isFullscreen, setIsFullscreen] = useState(false);
// callback for fullscreen button
const handleClickFullscreen = () => {
setIsFullscreen(true);
};
// callback for closing fullscreen
const handleClose = () => {
setIsFullscreen(false);
};
// get config for plotly
const config = getConfig({ handleClickFullscreen, isFullscreen });
// determine whether to show title
const showTitle = title !== "";
return (
<ConditionalDialog
condition={isFullscreen}
onClose={handleClose}
title={fullscreenTitle}
>
<Box
display="flex"
flexDirection="column"
overflow="hidden"
height="100%"
width="100%"
>
{!isFullscreen && showTitle ? (
<Typography
align="center"
style={{ padding: "0 16px", wordWrap: "break-word" }}
>
{title || ""}
</Typography>
) : null}
<Plotly
data={[
{
colorbar: {
tickfont: {
color: theme.palette.mode === "light" ? "" : "white",
family: "Montserrat, sans-serif",
shadow: "none",
size: 12,
weight: 400
}
},
type: "surface",
x: xdata,
y: ydata,
z: zdata
}
]}
layout={{
autosize: true,
font: {
family: "Montserrat, sans-serif"
},
margin: {
b: 5,
l: 5,
r: 5,
t: 20
},
paper_bgcolor: "rgba(0,0,0,0)",
scene: {
camera: { eye: { x: 2 } },
xaxis: {
color: theme.palette.mode === "light" ? "" : "white",
exponentformat: "E",
gridcolor:
theme.palette.mode === "light"
? ""
: theme.palette.grey["500"],
showgrid: showGrid,
title: {
font: {
size: 12
},
text: xlabel || ""
}
},
yaxis: {
color: theme.palette.mode === "light" ? "" : "white",
exponentformat: "E",
gridcolor:
theme.palette.mode === "light"
? ""
: theme.palette.grey["500"],
showgrid: showGrid,
title: {
font: {
size: 12
},
text: ylabel || ""
}
},
zaxis: {
color: theme.palette.mode === "light" ? "" : "white",
exponentformat: "E",
gridcolor:
theme.palette.mode === "light"
? ""
: theme.palette.grey["500"],
showgrid: showGrid,
title: {
font: {
size: 12
},
text: zlabel || ""
}
}
}
}}
style={{
flexGrow: 1,
height: "100%",
width: "100%"
}}
useResizeHandler={true}
config={config}
/>
</Box>
</ConditionalDialog>
);
};
export default SurfacePlot;