Skip to content

Commit 67a628d

Browse files
committed
fix some bugs
1 parent 361211c commit 67a628d

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

usa_map/NY/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ <h1>Welcome to New York</h1>
2222
<div id="stateInfo"></div>
2323
</div>
2424

25+
<div id="tooltip" class="tooltip"></div>
26+
2527
<script type="module" src="usa_ny.js"> </script>
2628
</body>
2729
</html>

usa_map/NY/usa_ny.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ svgObject.addEventListener('load', () => {
7777

7878
regions.forEach(region => {
7979
if (region.id && !region.id.includes("path")) {
80-
region.addEventListener('mouseover', () => {
80+
region.addEventListener('mouseover', (e) => {
8181
region.style.fill = '#FF0000';
82-
8382

8483
const stateInfo = document.getElementById('stateInfo');
8584
stateInfo.style.display = 'block';
@@ -105,9 +104,30 @@ svgObject.addEventListener('load', () => {
105104
if (Array.from(countyData.entries()).find(([key]) => key.endsWith(processedId))) {
106105
Create_County_Chart('tempChart', getRandomPattern(test_data_pattern1, test_data_pattern2), 'County Alert Trend');
107106
}
107+
// const tooltip = document.getElementById('tooltip');
108+
// console.log("get tooltip", tooltip);
109+
// tooltip.style.display = 'block';
110+
// tooltip.style.left = e.pageX + 10 + 'px';
111+
// tooltip.style.top = e.pageY + 10 + 'px';
112+
// tooltip.innerHTML = `
113+
// <h3>${processedId}</h3>
114+
// ${(() => {
115+
// const match = Array.from(countyData.entries()).find(([key]) => key.endsWith(processedId));
116+
// if (match) {
117+
// const [_, value] = match;
118+
// return `
119+
// <p>Climate Zone: ${value.BA_zone}</p>
120+
// <p>State: ${value.state_name}</p>
121+
// `;
122+
// }
123+
// return 'Data not match';
124+
// })()}
125+
// `;
126+
108127
});
109128
region.addEventListener('mouseout', () => {
110129
region.style.fill = '';
130+
// document.getElementById('tooltip').style.display = 'none';
111131
});
112132
region.addEventListener('click', () => {
113133
const targetUrl = `https://danielchen3.github.io/usa_map/${region.id}`;
@@ -143,7 +163,7 @@ svgObject.addEventListener('load', () => {
143163
})()}
144164
`;
145165
if (Array.from(countyData.entries()).find(([key]) => key.endsWith(processedId))) {
146-
Create_County_Chart('tempChart', test_data, 'County Alert Trend');
166+
Create_County_Chart('tempChart', getRandomPattern(test_data_pattern1, test_data_pattern2), 'County Alert Trend');
147167
}
148168
});
149169
path.addEventListener('mouseout', () => {

usa_map/sty.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ p {
2525
gap: 20px;
2626
}
2727

28+
.tooltip {
29+
position: fixed;
30+
background: rgba(0, 0, 0, 0.5);
31+
color: white;
32+
padding: 10px;
33+
border-radius: 4px;
34+
font-size: 14px;
35+
pointer-events: none;
36+
z-index: 1000;
37+
display: none;
38+
border: 1px solid rgba(255, 255, 255, 0.2);
39+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
40+
}
41+
2842
button {
2943
background-color: #4CAF50;
3044
color: white;

0 commit comments

Comments
 (0)