|
1 <!DOCTYPE html> |
|
2 <html> |
|
3 <head> |
|
4 <title>Great Arc</title> |
|
5 <script type="text/javascript" src="../../d3.js"></script> |
|
6 <script type="text/javascript" src="../../d3.geo.js"></script> |
|
7 <style type="text/css"> |
|
8 |
|
9 #states path { |
|
10 fill: #ddd; |
|
11 stroke: #fff; |
|
12 } |
|
13 |
|
14 #arcs path { |
|
15 fill: none; |
|
16 stroke: #000; |
|
17 stroke-width: .5px; |
|
18 stroke-opacity: .2; |
|
19 } |
|
20 |
|
21 </style> |
|
22 </head> |
|
23 <body> |
|
24 <script type="text/javascript"> |
|
25 |
|
26 var w = 960, |
|
27 h = 500; |
|
28 |
|
29 var projection = d3.geo.azimuthal() |
|
30 .origin([-115, 50]) |
|
31 .scale(500); |
|
32 |
|
33 var path = d3.geo.path() |
|
34 .projection(projection); |
|
35 |
|
36 var arc = d3.geo.greatArc(); |
|
37 |
|
38 var svg = d3.select("body").append("svg:svg") |
|
39 .attr("width", w) |
|
40 .attr("height", h); |
|
41 |
|
42 var states = svg.append("svg:g") |
|
43 .attr("id", "states"); |
|
44 |
|
45 var arcs = svg.append("svg:g") |
|
46 .attr("id", "arcs"); |
|
47 |
|
48 d3.json("../data/us-states.json", function(collection) { |
|
49 states.selectAll("path") |
|
50 .data(collection.features) |
|
51 .enter().append("svg:path") |
|
52 .attr("d", path); |
|
53 }); |
|
54 |
|
55 d3.json("../data/us-state-centroids.json", function(collection) { |
|
56 var links = []; |
|
57 |
|
58 // Create a link between each state centroid. |
|
59 collection.features.forEach(function(a) { |
|
60 collection.features.forEach(function(b) { |
|
61 if (a !== b) { |
|
62 links.push({ |
|
63 source: a.geometry.coordinates, |
|
64 target: b.geometry.coordinates |
|
65 }); |
|
66 } |
|
67 }); |
|
68 }); |
|
69 |
|
70 arcs.selectAll("path") |
|
71 .data(links) |
|
72 .enter().append("svg:path") |
|
73 .attr("d", function(d) { return path(arc(d)); }); |
|
74 }); |
|
75 |
|
76 </script> |
|
77 </body> |
|
78 </html> |