-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress.html
332 lines (325 loc) · 14.1 KB
/
progress.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<!DOCTYPE html>
<html lang="en">
<head>
<base target="_top">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>10,000 Small Businesses Program Alumni Map</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.css" integrity="sha512-Zcn6bjR/8RZbLEpLIeOwNtzREBAJnUKESxces60Mpoj+2okopSAcSUIUOseddDm0cxnGQzxIR7vJgsLZbdLE3w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.js" integrity="sha512-BwHfrr4c9kmRkLw6iXFdzcdWV/PGkVgiIyIWLLlTSXzWQzxuSg4DiQUCpauz/EWjgk5TYQqX/kvn9pG1NpYfqg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/MarkerCluster.css">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/MarkerCluster.Default.css">
<script src="https://unpkg.com/[email protected]/dist/leaflet.markercluster.js"></script>
<script src="https://unpkg.com/[email protected]/dist/leaflet.featuregroup.subgroup.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"/>
<link rel="stylesheet" href="./leaflet.zoomhome.css">
<script src="./leaflet.zoomhome.min.js"></script>
<link rel="stylesheet" href="./demo.css">
<script src="./leaflet-iconex.js"></script>
<script src="https://cdn.jsdelivr.net/npm/d3@7"></script>
<style>
html, body {
height: 100%;
margin: 0;
}
.leaflet-container {
height: 100vh;
width: 100vw;
max-width: 100%;
max-height: 100%;
}
div.leaflet-control-layers {
visibility: hidden;
}
div.legend {
background-color: white;
padding: 0 20px 20px;
border-radius: 5px;
box-shadow: 0 0 15px rgba(0,0,0,0.2);
}
div.legend h3 {
letter-spacing: .05em;
font-size: 1.3em;
max-width: 150px;
}
div.cluster div.progressGroup {
display: flex;
flex-direction: row;
justify-content: space-around;
}
div.cluster div.progressGroup div.progress {
width: 50px;
height: auto;
border-bottom: 1px solid black;
border-top: 1px solid black;
display: flex;
flex-direction: column;
gap: 0;
}
div.cluster div.progressGroup div.progress div.barTick {
width: 30px;
margin: auto;
background: #002D72;
flex-grow: 1;
}
div.cluster div.entry div.label {
padding-bottom: 5px;
pointer-events: none;
font-weight: 500;
font-size: .9em;
}
div.cluster p.bizSum {
font-size: 1.1em;
font-weight: 500;
text-align: center;
}
div.legend.transit h3 {
width: 120px;
}
div.legend div.toggles {
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
div.legend div.toggles span {
vertical-align: text-top;
line-height: .9em;
}
</style>
</head>
<body>
<div id="map" style="width: 100vw; height: 100vh;"></div>
<script>
const map = L.map('map', {zoomControl: false}).setView([38.47654, -76.71313], 8);
const zoomHome = L.Control.zoomHome();
zoomHome.addTo(map);
const Stadia_AlidadeSmooth = L.tileLayer('https://tiles.stadiamaps.com/tiles/alidade_smooth/{z}/{x}/{y}{r}.{ext}', {
minZoom: 0,
maxZoom: 20,
attribution: '© <a href="https://www.stadiamaps.com/" target="_blank">Stadia Maps</a> © <a href="https://openmaptiles.org/" target="_blank">OpenMapTiles</a> © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
ext: 'png'
}).addTo(map);
const locations = [
{
lat: 39.328888,
lon: -76.620277,
label: "The Johns Hopkins University - Homewood Campus"
},
{
lat: 39.3459,
lon: -76.5832,
label: "Morgan State University"
},
{
lat: 39.291,
lon: -76.61073,
label: "Baltimore City Hall"
},
{
lat: 39.254,
lon: -76.73406,
label: "The Community College of Baltimore County - Catonsville Campus"
},
{
lat: 39.2657,
lon: -76.51482,
label: "The Community College of Baltimore County - Dundalk Campus"
},
{
lat: 39.35452,
lon: -76.48061,
label: "The Community College of Baltimore County - Essex Campus"
}
]
const campuses = L.featureGroup();
const icon = new L.IconEx({
contentHtml: `<i class="fa fa-building"></i>`,
iconFill: "#002D72",
iconStroke: null,
backgroundFill: "#002D72",
contentColor: "#fff"
})
locations.forEach(c => {
L.marker([c.lat, c.lon], {icon: icon}).bindTooltip(c.label).addTo(campuses);
})
d3.csv("alumni.csv").then((data) => {
const alumni = L.markerClusterGroup();
const subgroups = [];
const gradDates = Array.from(new Set(data.map(d => d.end_date)));
const barScale = d3.scaleLinear().range([0,1])
gradDates.forEach(cohort => {
let endDate = cohort.split("/");
let gradDate = new Date(endDate[2],
endDate[0].length < 2 ? `0${endDate[0]}` : endDate[0],
endDate[1].length < 2 ? `0${endDate[1]}` : endDate[1]);
let dateStrings = gradDate.toDateString().split(" ");
let cohortLabel = `${dateStrings[1]} ${dateStrings[3]}`;
let cohortData = data.filter(d => d.end_date === cohort);
subgroups.push({
label: cohortLabel,
data: cohortData,
date: gradDate});
})
const subgroupsSorted = subgroups.slice().sort((a,b) => b.date - a.date)
const dateScale = d3.scaleTime().domain([1,0]).range(subgroupsSorted.map(m => m.date))
subgroupsSorted.forEach(group => {
let groupMarkers = [];
group.data.forEach(alum => {
groupMarkers.push(
L.circleMarker([alum.latitude, alum.longitude], {
radius: 8,
fillColor: "#db0505",
fillOpacity: .35,
stroke: true,
weight: 0.5,
color: "white"
}).bindTooltip(alum.business_name)
)
})
let cohortGroup = L.featureGroup.subGroup(alumni, groupMarkers)
cohortGroup.addTo(map);
group.layerGroup = cohortGroup;
})
alumni.addTo(map)
const overlays = {}
subgroupsSorted.forEach(g => overlays[g.label] = g.layerGroup)
const layerControl = L.control.layers(null, overlays, {collapsed: false});
const transitLayerControl = L.control({position: "bottomleft"})
const transit_subgroups = [];
Promise.all([d3.json("blue_jay_shuttle_area.json"),
d3.json("jhu_shuttle_routes.geojson"),
d3.json("Baltimore_Region_Public_Transit_(routes).geojson")
]).then(([bjarea, jhu_shuttle, transitData]) => {
let styles = {
color: "#ff9333",
weight: 1,
opacity: 0.65,
};
let eachLayer = (layer) => {
layer.bindTooltip(
`${layer.feature.properties.Operator} ${layer.feature.properties.Route_Shor}<br/>${layer.feature.properties.LINENAME}`,
{ sticky: true }
);
}
let labels = ['Bus', 'Commuter', 'Local Bus', 'Local Ferry', 'Intercity', 'MARC', 'Light Rail', 'Subway'];
labels.forEach((label) => {
let geoJsonLayer = L.geoJson();
geoJsonLayer.addData(transitData.features.filter(t => t.properties.TYPE === label))
.setStyle(styles)
.eachLayer(eachLayer)
transit_subgroups.push({
"layer": geoJsonLayer,
"label": label
})
})
let bjareaLayer = L.geoJson();
bjareaLayer.addData(bjarea).setStyle({
color: "#0d6efd",
opacity: 0.65,
fillOpacity: 0,
weight: 1,
})
transit_subgroups.push({
"layer": bjareaLayer,
"label": "Blue Jay Shuttle Area"
})
let jhuShuttleLayer = L.geoJson();
jhuShuttleLayer.addData(jhu_shuttle).setStyle({
color: "#0a58ca",
weight: 1,
opacity: 0.65
})
jhuShuttleLayer.eachLayer((layer) => {
layer.bindTooltip(
`${layer.feature.properties.Name}`,
{ sticky: true }
);
})
transit_subgroups.push({
"layer": jhuShuttleLayer,
"label": "JHU Shuttle Routes"
})
transit_subgroups.push({
layer: campuses,
label: "Partner Locations"
});
transitLayerControl.onAdd = function(map) {
let div = L.DomUtil.create("div", "legend transit");
let h3 = L.DomUtil.create("h3", null, div);
h3.textContent = "Baltimore Region Transit"
let toggles = L.DomUtil.create("div", "toggles", div);
transit_subgroups.forEach(({label}) => {
let entry = L.DomUtil.create("label", "entry", toggles);
let chckbx = L.DomUtil.create("input", null, entry);
chckbx.value = label;
chckbx.type = "checkbox";
let chckLabel = L.DomUtil.create("span", null, entry);
chckLabel.textContent = label;
})
return div;
}
transitLayerControl.addTo(map);
d3.selectAll("div.toggles input").on("change", (e)=>{
let selected = transit_subgroups.find(f => f.label === e.target.value);
if (e.target.checked) {
selected.layer.addTo(map);
} else {
selected.layer.removeFrom(map);
}
})
d3.selectAll("div.toggles label.entry span").on("click", (e) =>{
L.DomEvent.stopPropagation(e);
})
layerControl.addTo(map);
});
const clusterLegend = L.control({position: "bottomright"})
clusterLegend.onAdd = function(map) {
let div = L.DomUtil.create("div", 'legend cluster');
let h3 = L.DomUtil.create("h3", null, div);
h3.innerHTML = "Cohorts by Program End Date";
let sum = L.DomUtil.create("p", "bizSum", div);
sum.textContent = `${data.length} Businesses`;
let pGroup = L.DomUtil.create("div", "progressGroup", div);
let pBar = L.DomUtil.create("div", "progress", pGroup);
let pLabels = L.DomUtil.create("div", "labels", pGroup);
subgroupsSorted.forEach((group, i) => {
let entry = L.DomUtil.create("div", `entry`, pLabels);
entry.innerHTML = `<div class="label index-${i}">${group.label}</div>`
let bartick = L.DomUtil.create("div", `barTick index-${i}`, pBar)
})
return div;
}
clusterLegend.addTo(map);
function updateLegend(i) {
d3.selectAll(`div.barTick`).style("background",
(d,j) => j < i ? "transparent" : "#002D72"
);
d3.selectAll("div.labels div.entry div.label").style("font-weight",
(d,j) => j < i ? "300" : "500"
)
let chkbxs = document.querySelectorAll("div.leaflet-control-layers-overlays input.leaflet-control-layers-selector")
chkbxs.forEach((c,j) => {
if (j < i && c.checked) {
c.click();
} else if (j >= i && !c.checked) {
c.click();
}
})
let sum = subgroupsSorted.slice(i).flatMap(f => f.data.map(m => m.cohort)).length;
let sumP = document.querySelector("div.cluster.legend p.bizSum");
sumP.textContent = `${sum} Businesses`;
}
function handleClusterLegendClick(e) {
let i = e.target.classList.value.split("-")[1];
updateLegend(i);
}
d3.selectAll("div.legend.cluster div.progressGroup div.progress").on("click", handleClusterLegendClick)
function handleLegendLabelsClick(e) {
let i = e.target.querySelector(".label").classList.value.split("-")[1];
updateLegend(i);
}
d3.selectAll("div.legend.cluster div.progressGroup div.labels").on("click", handleLegendLabelsClick)
})
</script>
</body>
</html>