rveciana - congressional-representatives-dataset

Congressional representatives dataset

Open raw page in new tab

Based on this data, contains a Shapefile and two topojson with the US congressional Districts.

The atlas-make project has a better maintained version of this data.

The difference from the data is based on, is that the American Samoa, Guam and Northern Marianas are included from the Natural Earth dataset. The Congress Representative data is included too.

get_areas.py is a script to calculate the area paoperties for the new objects. The name of the Congressional Representatives in the added territories has been taken from the Wikipedia.

The topojson has been calculated using the command: topojson -o us_congressional_district.json cgd114p010g.shp -p

The topojson data can be used with d3 and the d3-composite-projections library, as seen in the example.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
#tooltip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10;
  margin: 0;
  padding: 10px;
  width: 200px;
  height: 70px;
  color: white;
  font-family: sans-serif;
  font-size: 0.9em;
  font-weight: bold;
  text-align: center;
  background-color: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  border-radius:5px;
  transition: .2s;
}
</style>
<body>
  <div id="container"/>
  <div id="tooltip"/>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3-composite-projections/1.0.1/d3-composite-projections.min.js"></script>
<script>
var width = 960,
    height = 500;

var projection = d3.geoAlbersUsaTerritories();
var path = d3.geoPath()
    .projection(projection);

var svg = d3.select("#container").append("svg")
    .attr("width", width)
    .attr("height", height);

    var t = d3.transition();
d3.json("us_congressional_districts.json", function(error, us) {
  var us = topojson.feature(us, us.objects.us_congressional_districts);
  svg.selectAll(".region")
      .data(us.features)
      .enter()
      .append("path")
      .attr("class", "region")
      .attr("d", path)
      .style("fill", function(d){
        if(d.properties.PARTY_AFF=="Democrat")
          return "#4a86e8";
        else
          return "#e84a4a";})
      .style("stroke", "#000")
      .style("stroke-width", "0.5px")
      .on("mouseover", function(d){
        //Show the tooltip
        var x = d3.event.pageX;
        var y = d3.event.pageY - 40;

        d3.select("#tooltip")
          .style("left", x + "px")
          .style("top", y + "px")
          .style("opacity", 1)
          .html( d.properties.STATE + " dist: " + d.properties.CONG_DIST + "<br/>" +d.properties.CONG_REP + "<br/>" + d.properties.PARTY_AFF );
        })
        .on("mouseout", function(){
          //Hide the tooltip
          d3.select("#tooltip")
            .style("opacity", 0);
        });;

  svg
    .append("path")
      .style("fill","none")
      .style("stroke","#000")
      .style("stroke-dasharray","5,5")
      .attr("d", projection.getCompositionBorders());

});

</script>