-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex-first.html
162 lines (142 loc) · 5.9 KB
/
index-first.html
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
157
158
159
160
161
162
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BTAA GIN Member Institutions</title>
<style>
/* Add any additional CSS styles here */
body, html {
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<script src="https://d3js.org/d3.v6.min.js"></script>
<script src='https://unpkg.com/@turf/turf@6/turf.min.js'></script>
<script src="https://unpkg.com/@popperjs/core@2"></script>
<script src="https://unpkg.com/tippy.js@6"></script>
<script>
// Set up the dimensions of the SVG container
const width = window.innerWidth,
height = window.innerHeight;
// Create an SVG container
const svg = d3.create("svg")
.attr("viewBox", [0, -30, width, height]);
// Define a projection (you can choose a different projection as needed)
const projection = d3.geoMercator()
.center([-85.5,42.7]) // Center the map
.scale(2000) // Zoom level
.translate([width / 2, height / 2]);
//const projection = d3.geoAlbersUsa().scale(3000).translate([50, 550]);
// Create a path generator
const path = d3.geoPath().projection(projection);
// Load GeoJSON files
Promise.all([
d3.json('data/all-states.json'),
d3.json('data/btaa-states.json'),
d3.json('data/na-lakes.json'),
d3.json('data/ocean.json'),
d3.json('data/btaa-universities.json')
]).then(([allStates, uniStates, naLakes, ocean, unis]) => {
// Rewind with Turf
validUniStates = uniStates.features.map(d=>turf.rewind(d,{reverse:true}));
validLakes = naLakes.features.map(d=>turf.rewind(d,{reverse:true}));
validOcean = ocean.features.map(d=>turf.rewind(d,{reverse:true}));
// Append a new SVG path element for each state
svg.selectAll(".uni-state-path")
.data(validUniStates)
.enter().append("path")
.attr("fill", "#0088CE")
.attr("fill-opacity", 0.90)
.attr("stroke", "black")
.attr("stroke-linejoin", "round")
.attr("stroke-width", 1.0)
.attr("d", path);
// Append a new SVG path element for each state
svg.selectAll(".state-path")
.data(allStates.features)
.enter().append("path")
.attr("fill", "none")
.attr("fill-opacity", 0.0)
.attr("stroke", "gray")
.attr("stroke-linejoin", "round")
.attr("stroke-width", 0.75)
.attr("d", path);
// Append a new SVG path element for each state
svg.selectAll(".na-lakes-path")
.data(validLakes)
.enter().append("path")
.attr("fill", "#0088CE")
.attr("fill-opacity", 0.20)
.attr("stroke", "gray")
.attr("stroke-linejoin", "round")
.attr("stroke-width", 0.0)
.attr("d", path);
// Append a new SVG path element for each state
svg.selectAll(".oceans-path")
.data(validOcean)
.enter().append("path")
.attr("fill", "#0088CE")
.attr("fill-opacity", 0.20)
.attr("stroke", "gray")
.attr("stroke-linejoin", "round")
.attr("stroke-width", 0.0)
.attr("d", path);
// Create a force simulation
const simulation = d3.forceSimulation(unis.features)
.force("x", d3.forceX(d => projection(d.geometry.coordinates)[0]).strength(0.1))
.force("y", d3.forceY(d => projection(d.geometry.coordinates)[1]).strength(0.1))
.force("collide", d3.forceCollide().radius(12).strength(1)) // Adjust radius and strength as needed
.stop(); // Stop the simulation to manually set initial positions
// Run the simulation for a few ticks to resolve collisions and finalize positions
for (let i = 0; i < 300; ++i) simulation.tick();
// Bind data and create circle elements
svg.selectAll("circle")
.data(unis.features)
.enter().append("circle")
.attr("cx", d => d.x)
.attr("cy", d => d.y)
.attr("r", 12)
.attr("stroke", "#163b58")
.attr("stroke-width", 0.5)
.attr("fill-opacity", 0.75)
.attr("fill", "white") // Change the fill color as needed
// Define hover effects for circles
.on("mouseover", function() {
d3.select(this)
.attr("stroke", "yellow") // Change stroke to yellow
.attr("stroke-width", 1.0); // Widen stroke
})
.on("mouseout", function() {
d3.select(this)
.attr("stroke", "#163b58") // Change stroke back to gray
.attr("stroke-width", 0.5); // Change stroke back to 0.5
})
// For each state...
.each(function (d) {
// Set the tooltip content as follows...
tippy(this, {
content: `${d.properties.name}`,
allowHTML: true,
theme: "light",
});
});
// Bind data and create text elements associated with circles
svg.selectAll("text")
.data(unis.features)
.enter().append("text")
.attr("x", d => d.x)
.attr("y", d => d.y)
.text(d => d.properties.id)
.attr("text-anchor", "middle")
.attr("dy", 5) // Adjust the vertical position of the label as needed
.style("fill", "black") // Change the text color as needed
.style("pointer-events", "none"); // Prevent the text from triggering pointer events
// Append the SVG to the body
document.body.appendChild(svg.node());
});
</script>
</body>
</html>