-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
346 lines (338 loc) · 17.3 KB
/
index.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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<!DOCTYPE html>
<html>
<head>
<title>Metro Density</title>
<!-- https://github.com/mvs202/metro-density -->
<style>
html {
height: 100%;
}
body {
margin: 0px;
font-family: menlo;
font-size: 14px;
overflow: hidden;
}
svg {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
text {
text-transform: uppercase;
}
#controls {
position: absolute;
left: 8px;
top: 8px;
z-index: 2;
}
</style>
<script src="https://d3js.org/d3.v2.min.js"></script>
</head>
<body>
<div id=controls >
<input type=radio name=displayType id=geographic onchange="switchDisplay()" checked ><label for=geographic >geographic</label>
<input type=radio name=displayType id=linear onchange="switchDisplay()"><label for=linear >linear</label>
</div>
</body>
<script>
var red = [
{name: "Shady Grove", lat: 39.119990, lng: -77.164761, dist: 0.0000},
{name: "Rockville", lat: 39.085452, lng: -77.146689, dist: 2.5847},
{name: "Twinbrook", lat: 39.062389, lng: -77.120792, dist: 4.7091},
{name: "White Flint", lat: 39.047162, lng: -77.112782, dist: 5.8498},
{name: "Grosvenor-Strathmore", lat: 39.029243, lng: -77.103838, dist: 7.1824},
{name: "Medical Center", lat: 39.000062, lng: -77.096948, dist: 9.2366},
{name: "Bethesda", lat: 38.984431, lng: -77.094151, dist: 10.3286},
{name: "Friendship Heights", lat: 38.960997, lng: -77.085767, dist: 12.0140},
{name: "Tenleytown", lat: 38.947849, lng: -77.079299, dist: 12.9902},
{name: "Van Ness-UDC", lat: 38.944519, lng: -77.063716, dist: 13.8610},
{name: "Cleveland Park", lat: 38.935852, lng: -77.058624, dist: 14.5222},
{name: "Woodley Park", lat: 38.925000, lng: -77.052350, dist: 15.3477},
{name: "Dupont Circle", lat: 38.911129, lng: -77.044428, dist: 16.4008},
{name: "Farragut North", lat: 38.903297, lng: -77.039502, dist: 17.0059},
{name: "Metro Center", lat: 38.898327, lng: -77.027777, dist: 17.7271},
{name: "Gallery Place", lat: 38.898354, lng: -77.021527, dist: 18.0633},
{name: "Judiciary Square", lat: 38.896121, lng: -77.016312, dist: 18.3848},
{name: "Union Station", lat: 38.897770, lng: -77.006402, dist: 18.9286},
{name: "NoMa-Gallaudet U", lat: 38.907413, lng: -77.002981, dist: 19.6180},
{name: "Rhode Island Avenue", lat: 38.920778, lng: -76.995682, dist: 20.6176},
{name: "Brookland-CUA", lat: 38.933232, lng: -76.994474, dist: 21.4801},
{name: "Fort Totten", lat: 38.951808, lng: -77.001864, dist: 22.8282},
{name: "Takoma", lat: 38.975432, lng: -77.017421, dist: 24.6706},
{name: "Silver Spring", lat: 38.993658, lng: -77.032307, dist: 26.1699},
{name: "Forest Glen", lat: 39.015465, lng: -77.042667, dist: 27.7820},
{name: "Wheaton", lat: 39.038565, lng: -77.050776, dist: 29.4413},
{name: "Glenmont", lat: 39.061743, lng: -77.053097, dist: 31.0492}
];
var silver = [
{name: "Largo Town Center", lat: 38.900269, lng: -76.844540, dist: 0.0000},
{name: "Morgan Boulevard", lat: 38.893586, lng: -76.868498, dist: 1.3634},
{name: "Addison Road", lat: 38.886702, lng: -76.893290, dist: 2.7739},
{name: "Capitol Heights", lat: 38.889571, lng: -76.913313, dist: 3.8714},
{name: "Benning Road", lat: 38.890418, lng: -76.937662, dist: 5.1831},
{name: "Stadium-Armory", lat: 38.885982, lng: -76.977168, dist: 7.3269},
{name: "Potomac Avenue", lat: 38.880874, lng: -76.985397, dist: 7.8900},
{name: "Eastern Market", lat: 38.884148, lng: -76.995010, dist: 8.4566},
{name: "Capitol South", lat: 38.885669, lng: -77.005892, dist: 9.0525},
{name: "Federal Center SW", lat: 38.884981, lng: -77.015536, dist: 9.5729},
{name: "L'Enfant Plaza", lat: 38.884886, lng: -77.021600, dist: 9.8991},
{name: "Smithsonian", lat: 38.887587, lng: -77.028174, dist: 10.3008},
{name: "Federal Triangle", lat: 38.893789, lng: -77.027896, dist: 10.7294},
{name: "Metro Center", lat: 38.898327, lng: -77.027777, dist: 11.0430},
{name: "McPherson Square", lat: 38.901335, lng: -77.031958, dist: 11.3508},
{name: "Farragut West", lat: 38.901366, lng: -77.039482, dist: 11.7555},
{name: "Foggy Bottom", lat: 38.900705, lng: -77.050026, dist: 12.3239},
{name: "Rosslyn", lat: 38.895493, lng: -77.071954, dist: 13.5534},
{name: "Court House", lat: 38.891331, lng: -77.084823, dist: 14.3004},
{name: "Clarendon", lat: 38.887176, lng: -77.094987, dist: 14.9153},
{name: "Virginia Square", lat: 38.883074, lng: -77.103809, dist: 15.4657},
{name: "Ballston", lat: 38.882238, lng: -77.111550, dist: 15.8856},
{name: "East Falls Church", lat: 38.886042, lng: -77.156567, dist: 18.3242},
{name: "McLean", lat: 38.925069, lng: -77.208304, dist: 22.2170},
{name: "Tysons Corner", lat: 38.920304, lng: -77.221713, dist: 23.0070},
{name: "Greensboro", lat: 38.919564, lng: -77.232555, dist: 23.5917},
{name: "Spring Hill", lat: 38.928544, lng: -77.240880, dist: 24.3598},
{name: "Wiehle-Reston East", lat: 38.947134, lng: -77.337699, dist: 29.7307}
];
var orange = [
{name: "New Carrollton", lat: 38.946912, lng: -76.870445, dist: 0.0000},
{name: "Landover", lat: 38.933994, lng: -76.890005, dist: 1.3710},
{name: "Cheverly", lat: 38.916552, lng: -76.915104, dist: 3.1697},
{name: "Deanwood", lat: 38.907945, lng: -76.935569, dist: 4.4146},
{name: "Minnesota Avenue", lat: 38.898313, lng: -76.947716, dist: 5.3419},
{name: "Stadium-Armory", lat: 38.885982, lng: -76.977168, dist: 7.1322},
{name: "Potomac Avenue", lat: 38.880874, lng: -76.985397, dist: 7.6953},
{name: "Eastern Market", lat: 38.884148, lng: -76.995010, dist: 8.2619},
{name: "Capitol South", lat: 38.885669, lng: -77.005892, dist: 8.8578},
{name: "Federal Center SW", lat: 38.884981, lng: -77.015536, dist: 9.3782},
{name: "L'Enfant Plaza", lat: 38.884886, lng: -77.021600, dist: 9.7044},
{name: "Smithsonian", lat: 38.887587, lng: -77.028174, dist: 10.1061},
{name: "Federal Triangle", lat: 38.893789, lng: -77.027896, dist: 10.5347},
{name: "Metro Center", lat: 38.898327, lng: -77.027777, dist: 10.8483},
{name: "McPherson Square", lat: 38.901335, lng: -77.031958, dist: 11.1561},
{name: "Farragut West", lat: 38.901366, lng: -77.039482, dist: 11.5608},
{name: "Foggy Bottom", lat: 38.900705, lng: -77.050026, dist: 12.1292},
{name: "Rosslyn", lat: 38.895493, lng: -77.071954, dist: 13.3587},
{name: "Court House", lat: 38.891331, lng: -77.084823, dist: 14.1057},
{name: "Clarendon", lat: 38.887176, lng: -77.094987, dist: 14.7206},
{name: "Virginia Square", lat: 38.883074, lng: -77.103809, dist: 15.2710},
{name: "Ballston", lat: 38.882238, lng: -77.111550, dist: 15.6909},
{name: "East Falls Church", lat: 38.886042, lng: -77.156567, dist: 18.1295},
{name: "West Falls Church", lat: 38.900738, lng: -77.188871, dist: 20.1502},
{name: "Dunn Loring", lat: 38.883146, lng: -77.228654, dist: 22.6023},
{name: "Vienna", lat: 38.877881, lng: -77.271363, dist: 24.9258}
];
var yellow = [
{name: "Huntington", lat: 38.793895, lng: -77.074955, dist: 0.0000},
{name: "Eisenhower Ave", lat: 38.800345, lng: -77.070831, dist: 0.4960},
{name: "King St", lat: 38.806506, lng: -77.060796, dist: 1.1805},
{name: "Braddock Rd", lat: 38.814052, lng: -77.053434, dist: 1.8324},
{name: "National Airport", lat: 38.853003, lng: -77.043475, dist: 4.5720},
{name: "Crystal City", lat: 38.857817, lng: -77.050346, dist: 5.0720},
{name: "Pentagon City", lat: 38.862961, lng: -77.059142, dist: 5.6669},
{name: "Pentagon", lat: 38.869474, lng: -77.053777, dist: 6.1991},
{name: "L'Enfant Plaza", lat: 38.884886, lng: -77.021600, dist: 8.2222},
{name: "Archives-Navy Memorial", lat: 38.893907, lng: -77.021592, dist: 8.8456},
{name: "Gallery Place", lat: 38.898354, lng: -77.021527, dist: 9.1530},
{name: "Mount Vernon Square", lat: 38.905638, lng: -77.021905, dist: 9.6570},
{name: "Shaw", lat: 38.914546, lng: -77.021927, dist: 10.2727},
{name: "U Street", lat: 38.917015, lng: -77.029169, dist: 10.6994},
{name: "Columbia Heights", lat: 38.928711, lng: -77.032454, dist: 11.5286},
{name: "Georgia Ave-Petworth", lat: 38.936255, lng: -77.024252, dist: 12.2078},
{name: "Fort Totten", lat: 38.951808, lng: -77.001864, dist: 13.8127}
];
var green = [
{name: "Branch Ave", lat: 38.827022, lng: -76.911802, dist: 0.0000},
{name: "Suitland", lat: 38.843839, lng: -76.931610, dist: 1.5866},
{name: "Naylor Rd", lat: 38.851164, lng: -76.956314, dist: 3.0148},
{name: "Southern Ave", lat: 38.841047, lng: -76.975003, dist: 4.2333},
{name: "Congress Heights", lat: 38.845379, lng: -76.987860, dist: 4.9903},
{name: "Anacostia", lat: 38.862117, lng: -76.995325, dist: 6.2191},
{name: "Navy Yard", lat: 38.876517, lng: -77.004749, dist: 7.3411},
{name: "Waterfront", lat: 38.876478, lng: -77.017189, dist: 8.0104},
{name: "L'Enfant Plaza", lat: 38.884886, lng: -77.021600, dist: 8.6403},
{name: "Archives-Navy Memorial", lat: 38.893907, lng: -77.021592, dist: 9.2638},
{name: "Gallery Place", lat: 38.898354, lng: -77.021527, dist: 9.5712},
{name: "Mount Vernon Square", lat: 38.905638, lng: -77.021905, dist: 10.0752},
{name: "Shaw", lat: 38.914546, lng: -77.021927, dist: 10.6909},
{name: "U Street", lat: 38.917015, lng: -77.029169, dist: 11.1176},
{name: "Columbia Heights", lat: 38.928711, lng: -77.032454, dist: 11.9468},
{name: "Georgia Ave-Petworth", lat: 38.936255, lng: -77.024252, dist: 12.6259},
{name: "Fort Totten", lat: 38.951808, lng: -77.001864, dist: 14.2309},
{name: "West Hyattsville", lat: 38.955028, lng: -76.969522, dist: 15.9809},
{name: "Prince George's Plaza", lat: 38.965252, lng: -76.955988, dist: 16.9892},
{name: "College Park", lat: 38.978400, lng: -76.928197, dist: 18.7282},
{name: "Greenbelt", lat: 39.011067, lng: -76.911011, dist: 21.1574}
];
var blue = [
{name: "Largo Town Center", lat: 38.900269, lng: -76.844540, dist: 0.0000},
{name: "Morgan Boulevard", lat: 38.893586, lng: -76.868498, dist: 1.3634},
{name: "Addison Rd", lat: 38.886702, lng: -76.893290, dist: 2.7739},
{name: "Capitol Heights", lat: 38.889571, lng: -76.913313, dist: 3.8714},
{name: "Benning Rd", lat: 38.890418, lng: -76.937662, dist: 5.1831},
{name: "Stadium-Armory", lat: 38.885982, lng: -76.977168, dist: 7.3269},
{name: "Potomac Ave", lat: 38.880874, lng: -76.985397, dist: 7.8900},
{name: "Eastern Market", lat: 38.884148, lng: -76.995010, dist: 8.4566},
{name: "Capitol South", lat: 38.885669, lng: -77.005892, dist: 9.0525},
{name: "Federal Center SW", lat: 38.884981, lng: -77.015536, dist: 9.5729},
{name: "L'Enfant Plaza", lat: 38.884886, lng: -77.021600, dist: 9.8991},
{name: "Smithsonian", lat: 38.887587, lng: -77.028174, dist: 10.3008},
{name: "Federal Triangle", lat: 38.893789, lng: -77.027896, dist: 10.7294},
{name: "Metro Center", lat: 38.898327, lng: -77.027777, dist: 11.0430},
{name: "McPherson Square", lat: 38.901335, lng: -77.031958, dist: 11.3508},
{name: "Farragut West", lat: 38.901366, lng: -77.039482, dist: 11.7555},
{name: "Foggy Bottom", lat: 38.900705, lng: -77.050026, dist: 12.3239},
{name: "Rosslyn", lat: 38.895493, lng: -77.071954, dist: 13.5534},
{name: "Arlington Cemetery", lat: 38.884612, lng: -77.062795, dist: 14.4566},
{name: "Pentagon", lat: 38.869474, lng: -77.053777, dist: 15.6144},
{name: "Pentagon City", lat: 38.862961, lng: -77.059142, dist: 16.1466},
{name: "Crystal City", lat: 38.857817, lng: -77.050346, dist: 16.7415},
{name: "National Airport", lat: 38.853003, lng: -77.043475, dist: 17.2415},
{name: "Braddock Rd", lat: 38.814052, lng: -77.053434, dist: 19.9811},
{name: "King St", lat: 38.806506, lng: -77.060796, dist: 20.6330},
{name: "Van Dorn St", lat: 38.799263, lng: -77.129111, dist: 24.3415},
{name: "Franconia-Springfield", lat: 38.766196, lng: -77.168487, dist: 27.4453}
];
var stations = [];
var lines = [];
addLine(red, "#FF1C18", 5, "Red Line");
addLine(silver, "#CCCCD8", 4, "Silver Line");
addLine(orange, "#FC7D20", 3, "Orange Line");
addLine(green, "#008749", 2, "Green Line");
addLine(blue, "#075B99", 0, "Blue Line");
addLine(yellow, "#F3EC11", 1, "Yellow Line");
function addLine(line, color, order, name) {
// make sure line goes west-to-east
if (line[0].lng > line[line.length - 1].lng) {
line = reverseLine(line);
}
for (var i = 0; i < line.length; i++) {
line[i].parent = order;
stations.push(line[i]);
}
var distline = d3.svg.line() // Path Data Generator Function
.x(function(d) {return distScale(d.dist);})
.y(displayScaleFunction(order))
.interpolate("linear");
var lineLength = line[line.length - 1].dist;
var lineStops = line.length;
var density = Math.round(10*(lineStops - 1)/lineLength)/10;
var stats = name + ": " + Math.round(10*lineLength)/10 + " miles, " + lineStops + " stops. " + density + " stops per mile.";
lines.push({line: line, color: color, order: order, distline: distline, stats: stats});
}
function displayScaleFunction(order) {
return function(d) {return displayScale(order);}
}
function reverseLine(line) {
var reverse = [];
var dist = 0;
for (var i = line.length - 1; i >= 0; i--) {
reverse.push({name: line[i].name, lat: line[i].lat, lng: line[i].lng, dist: dist});
if (i > 0) {
dist += line[i].dist - line[i - 1].dist;
}
}
return reverse;
}
function switchDisplay() {
if (document.getElementById("geographic").checked) {showGeo( 800);}
else {showDist(800);}
}
function showDist(duration) {
metroStations.data(stations)
.transition()
.duration(duration)
.attr("transform", function(d, i) {return "translate(" + distScale(d.dist) + "," + displayScale(d.parent) + ")"});
for (var i = 0; i < lines.length; i++) {
lines[i].path.data(lines[i].line)
.transition()
.duration(duration)
.attr("d", lines[i].distline(lines[i].line)); // "d" is the Path Description
}
}
function showGeo(duration) {
metroStations.data(stations)
.transition()
.duration(duration)
.attr("transform", function(d) {return "translate(" + lngScale(d.lng) + "," + latScale(d.lat) + ")"});
for (var i = 0; i < lines.length; i++) {
lines[i].path.data(lines[i].line)
.transition()
.duration(duration)
.attr("d", geolineFunction(lines[i].line)); // "d" is the Path Description
lines[i].statLabel.data(lines[i].stats)
.transition()
.duration(duration)
.attr("x", 12)
.attr("y", 30 + 20*(lines.length - lines[i].order));
}
}
function geolineFunction(line) {
return function () {return geoline(line);}
}
var w = window.innerWidth,
h = window.innerHeight;
var margin = 20;
var lngScale = d3.scale.linear()
.domain([d3.min(stations, function (d) {return d.lng;}), d3.max(stations, function (d) {return d.lng;})])
.range([margin, w - margin]);
var latScale = d3.scale.linear()
.domain([d3.min(stations, function (d) {return d.lat;}), d3.max(stations, function (d) {return d.lat;})])
.range([h - margin, margin]);
var distScale = d3.scale.linear()
.domain([0, d3.max(stations, function (d) {return d.dist;})])
.range([margin, w - margin]);
var displayScale = d3.scale.linear()
.domain([0, lines.length + 1])
.range([h - margin, margin]);
var display = d3.select('body')
.append('svg:svg')
.attr('width', w)
.attr('height', h)
.attr('class', 'display');
var g = display.append('g')
var geoline = d3.svg.line()
.x(function(d) {return lngScale(d.lng);})
.y(function(d) {return latScale(d.lat);})
.interpolate("linear");
for (var i = 0; i < lines.length; i++) {
lines[i].path = g.append("path") // define new property
.style("stroke-width", 15)
.style("stroke", lines[i].color)
.style("fill", "none");
lines[i].statLabel = g.append("text")
.attr("fill", "black")
.text(lines[i].stats);
}
var metroStations = g.selectAll("MetroStations")
.data(stations)
.enter()
.append("g")
.on('mouseover', function(d) {
d3.select(this).select("text").transition().duration("400")
.attr("fill", "rgba(0, 0, 0, 1.0)")
.attr("transform", "translate(0,0) rotate(-30)");
})
.on('mouseout', function(d) {
d3.select(this).select("text").transition().delay("3200").duration("200")
.attr("fill", "rgba(0, 0, 0, 0.0)")
.attr("transform", "translate(0,0) rotate(0)");
});
metroStations.append("svg:circle")
.attr("r", 12)
.style("stroke-width", 3)
.style("stroke", "black")
.style("fill", "white");
metroStations.append("text")
.attr("dx", function(d){return 2})
.attr("dy", function(d){return 2})
.attr("fill", "rgba(0, 0, 0, 0.0)")
.attr("transform", "translate(0,0) rotate(0)")
.text(function(d) {return d.name;});
showGeo(0);
</script>
</html>