Skip to content

Commit 0a5d264

Browse files
authored
Benchmarking Data Popup (#41)
* working popup * separate into 2 components * formatting * add comments
1 parent fadf99b commit 0a5d264

File tree

2 files changed

+188
-233
lines changed

2 files changed

+188
-233
lines changed
Lines changed: 71 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
import React, { useState, useEffect } from "react";
22
import DeckGL from "@deck.gl/react";
3-
import { LineLayer } from "@deck.gl/layers";
4-
import { GeoJsonLayer } from "deck.gl";
53
import { Map } from "react-map-gl";
6-
import mapbox_token from "./mapbox_token.js";
74
import { IconLayer } from "@deck.gl/layers";
85
import axios from "axios";
9-
import { Button } from "@mui/material";
10-
11-
import { useNavigate } from "react-router-dom";
6+
import mapbox_token from "./mapbox_token.js";
7+
import BenchmarkingData from "./BenchmarkingData.js";
128

139
const MAPBOX_ACCESS_TOKEN = mapbox_token;
1410
const MAP_STYLE =
1511
"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json";
1612

17-
// Viewport settings
1813
const INITIAL_VIEW_STATE = {
1914
longitude: -111,
2015
latitude: 33,
@@ -24,7 +19,6 @@ const INITIAL_VIEW_STATE = {
2419
bearing: 0,
2520
};
2621

27-
// retrieve benchmarking collection data from database
2822
const getBenchmarkingCollection = async () => {
2923
try {
3024
const response = await axios.get(
@@ -44,10 +38,12 @@ const getBenchmarkingCollection = async () => {
4438
};
4539

4640
// https://deck.gl/docs/api-reference/layers/icon-layer
47-
export default function Benchmarking() {
48-
let navigate = useNavigate(); // navigate to diff pages
4941

50-
const [benchmarkingData, setBenchmarkingData] = useState();
42+
export default function Benchmarking() {
43+
const [benchmarkingData, setBenchmarkingData] = useState([]);
44+
const [selectedSite, setSelectedSite] = useState(null);
45+
const [isPanelOpen, setIsPanelOpen] = useState(false);
46+
const [model, setModel] = useState("regressionBaseline");
5147

5248
useEffect(() => {
5349
getBenchmarkingCollection().then((data) => {
@@ -57,12 +53,15 @@ export default function Benchmarking() {
5753

5854
const onClick = (info) => {
5955
if (info.object) {
60-
const siteID = info.object.siteID;
61-
// Use the navigate function to go to a new page with the siteID parameter
62-
navigate(`/benchmarking/${siteID}`);
56+
setSelectedSite(info.object);
57+
setIsPanelOpen(true);
6358
}
6459
};
6560

61+
const chooseModel = (event) => {
62+
setModel(event.target.value);
63+
};
64+
6665
const ICON_MAPPING = {
6766
marker: { x: 0, y: 0, width: 120, height: 120, mask: true },
6867
};
@@ -71,34 +70,74 @@ export default function Benchmarking() {
7170
id: "icon-layer",
7271
data: benchmarkingData,
7372
pickable: true,
74-
// iconAtlas and iconMapping are required
75-
// getIcon: return a string
7673
iconAtlas:
7774
"https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/icon-atlas.png",
7875
iconMapping: ICON_MAPPING,
76+
// iconAtlas and iconMapping are required
77+
// getIcon: return a string
7978
getIcon: (d) => "marker",
80-
8179
sizeScale: 6,
8280
getPosition: (d) => d.coordinates,
8381
getSize: (d) => 5,
8482
getColor: (d) => [Math.sqrt(d.exits), 140, 0],
8583
});
8684

8785
return (
88-
<DeckGL
89-
initialViewState={INITIAL_VIEW_STATE}
90-
controller={true}
91-
layers={[layers]}
92-
getTooltip={({ object }) =>
93-
object &&
94-
`${object.siteInfo.city}, ${object.siteInfo.state} \
95-
\nSite ID: ${object.siteID} \
96-
\nDOE Climate Zone: ${object.siteInfo.doe_climate_zone}
97-
\n Click for detailed information`
98-
}
99-
onClick={onClick}
100-
>
101-
<Map mapStyle={MAP_STYLE} mapboxAccessToken={MAPBOX_ACCESS_TOKEN} />
102-
</DeckGL>
86+
<div style={{ position: "relative", height: "100vh", width: "100%" }}>
87+
<DeckGL
88+
initialViewState={INITIAL_VIEW_STATE}
89+
controller={true}
90+
layers={[layers]}
91+
getTooltip={({ object }) =>
92+
object &&
93+
`${object.siteInfo.city}, ${object.siteInfo.state}
94+
\nSite ID: ${object.siteID}
95+
\nDOE Climate Zone: ${object.siteInfo.doe_climate_zone}
96+
\n Click for detailed information`
97+
}
98+
onClick={onClick}
99+
>
100+
<Map mapStyle={MAP_STYLE} mapboxAccessToken={MAPBOX_ACCESS_TOKEN} />
101+
</DeckGL>
102+
103+
{isPanelOpen && selectedSite && (
104+
<div
105+
style={{
106+
position: "absolute",
107+
bottom: 0,
108+
left: 0,
109+
right: 0,
110+
height: "60%", // popup window height
111+
backgroundColor: "white",
112+
padding: "20px",
113+
boxShadow: "0 -2px 10px rgba(0, 0, 0, 0.1)",
114+
overflowY: "auto",
115+
transition: "transform 0.3s ease-out",
116+
transform: isPanelOpen ? "translateY(0)" : "translateY(100%)",
117+
}}
118+
>
119+
<button
120+
onClick={() => setIsPanelOpen(false)}
121+
style={{
122+
position: "absolute",
123+
top: "10px",
124+
right: "10px",
125+
background: "none",
126+
border: "none",
127+
fontSize: "1.5em",
128+
cursor: "pointer",
129+
}}
130+
>
131+
&times;
132+
</button>
133+
134+
<BenchmarkingData
135+
selectedSite={selectedSite}
136+
model={model}
137+
chooseModel={chooseModel}
138+
/>
139+
</div>
140+
)}
141+
</div>
103142
);
104143
}

0 commit comments

Comments
 (0)