Skip to content

Instantly share code, notes, and snippets.

@rogerfischer
Last active October 18, 2016 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogerfischer/15ef631812c56e3ef85af8191ef0de75 to your computer and use it in GitHub Desktop.
Save rogerfischer/15ef631812c56e3ef85af8191ef0de75 to your computer and use it in GitHub Desktop.
Electoral College Hexagon State Map
license: mit

Hexagon Map as TopoJSON

This is a state hex map as topoJSON. The topoJSON uses GeoIDs (840 for the US, FIPS codes for state names). E.g. California is 84006. We added a REF or reference file for GeoIDs with full state names.

If you use it, it would be nice (but not necessary) if you can link back to Datamap

--

Hexagon Map designed with Tilegram by Pitch Interactive: https://pitchinteractiveinc.github.io/tilegrams/

Uploaded to blockbuilder.org

<!DOCTYPE html>
<meta charset="utf-8">
<head>
<title>Electoral College Hexagon Map: US States</title>
<style>
.land {
fill: #f23b17;
}
.bg {
border-color: #ffffff;
}
.stateBorder {
fill: #f23b17;
stroke: #ffffff;
stroke-width: 2px;
}
</style>
<body>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
const width = 960;
const height = 500;
const svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height)
.attr("class", "bg");
d3.queue()
.defer(d3.json, 'us_ec2016_state_hexagon.topojson')
.defer(d3.csv, 'REF_us_state_2015.csv')
.await(function(error, MAP, DATA) {
if (error) throw error;
/** Hex Projection
* See: http://bl.ocks.org/mbostock/5663666
* See 2D Affine Transformations: https://en.wikipedia.org/wiki/Transformation_matrix#Affine_transformations
*/
function matrix(a, b, c, d, tx, ty) {
return d3.geoTransform({
point: function(x, y) { this.stream.point(a * x + b * y + tx, c * x + d * y + ty); }
});
}
const path = d3.geoPath()
.projection(matrix(0.44, 0, 0, -0.44, -50, 500));
// State Hexagons
const hex = topojson.feature(MAP, MAP.objects.us_ec2016_hexagon).features;
svg.append("g")
.attr("class", "stateBorder")
.selectAll("path")
.data(hex)
.enter()
.append("path")
.attr("d", path)
.append('svg:title').text(function(d) {
return ("GeoID: " + d.properties.id); });
});
d3.select(self.frameElement).style("height", height + "px");
</script>
id state_fips state_code state_name gnisid
84001 01 AL Alabama 01779775
84002 02 AK Alaska 01785533
84004 04 AZ Arizona 01779777
84005 05 AR Arkansas 00068085
84006 06 CA California 01779778
84008 08 CO Colorado 01779779
84009 09 CT Connecticut 01779780
84010 10 DE Delaware 01779781
84011 11 DC District of Columbia 01702382
84012 12 FL Florida 00294478
84013 13 GA Georgia 01705317
84015 15 HI Hawaii 01779782
84016 16 ID Idaho 01779783
84017 17 IL Illinois 01779784
84018 18 IN Indiana 00448508
84019 19 IA Iowa 01779785
84020 20 KS Kansas 00481813
84021 21 KY Kentucky 01779786
84022 22 LA Louisiana 01629543
84023 23 ME Maine 01779787
84024 24 MD Maryland 01714934
84025 25 MA Massachusetts 00606926
84026 26 MI Michigan 01779789
84027 27 MN Minnesota 00662849
84028 28 MS Mississippi 01779790
84029 29 MO Missouri 01779791
84030 30 MT Montana 00767982
84031 31 NE Nebraska 01779792
84032 32 NV Nevada 01779793
84033 33 NH New Hampshire 01779794
84034 34 NJ New Jersey 01779795
84035 35 NM New Mexico 00897535
84036 36 NY New York 01779796
84037 37 NC North Carolina 01027616
84038 38 ND North Dakota 01779797
84039 39 OH Ohio 01085497
84040 40 OK Oklahoma 01102857
84041 41 OR Oregon 01155107
84042 42 PA Pennsylvania 01779798
84044 44 RI Rhode Island 01219835
84045 45 SC South Carolina 01779799
84046 46 SD South Dakota 01785534
84047 47 TN Tennessee 01325873
84048 48 TX Texas 01779801
84049 49 UT Utah 01455989
84050 50 VT Vermont 01779802
84051 51 VA Virginia 01779803
84053 53 WA Washington 01779804
84054 54 WV West Virginia 01779805
84055 55 WI Wisconsin 01779806
84056 56 WY Wyoming 01779807
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment