Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <script src=""></script>
<script src=""></script>
<script src=""></script>
<link href="" rel="stylesheet">
<div id="content">
  <h1>Gross Rent as a Percentage of Household Income</h1>
  <h2>Data from the <a href="">American Community Survey</a>, Circa 2016</h2>
  <svg id="canvas"></svg>

  width: 900px;
  height: auto;
  margin-left: auto;
  margin-right: auto;
  font-family: 'Muli', san serif;

  font-size: 24px;
   text-align: center;
    font-size: 14px;
  transition: fill 0.5s;
  fill: #C9C9C9;
  stroke: #FFF;
  stroke-width: 2px;

.tooltip {
  position: absolute;
  text-align: center;
  padding: 8px;
  margin-top: -20px;
  border:2px solid #333;
  font: 12px sans-serif;
  background: #F7F4F3;
  pointer-events: none;
                1px 1px #FFC15E,
                2px 2px #FFC15E,
                3px 3px #FFC15E;
  transition: all ease;

              var width = 900
var height = 680

var path = d3.geoPath()

var colors = d3.scaleSequential(d3.interpolate("#F2CC8F","#E07A5F"));

var svg ="#canvas")
  .attr("width", width)
  .attr("height", height)

var g = svg.append("g")

var data = {};
var names ={};

 var tooltip ="body").append("div")
  .style("opacity", 0);
//Load in map data and household income data
//Tell d3 to queue data and then execute when it's all loaded
//This avoids ansynchroneous loading affecting our output
//Especially when dealing with large JSON files like topojson data
  .defer(d3.json , "")
 .defer(d3.csv, "")
function mapLoad(error, us, rent) {  
  //Write FIPS data and percentages into new array
  //Makes accessing percentages easier after feeding in the JSON coordinate data
  rent.forEach(function(d){ data[d.FIPS] = +d.percentage});
  rent.forEach(function(d){ names[d.FIPS] = d.county});

 var colorMin = d3.min(rent, function(d){return +d.percentage;});
 var colorMax = d3.max(rent, function(d){return +d.percentage;});

  .data(topojson.feature(us, us.objects.counties).features)
    .attr("class", "asdf")
    .attr("fill", function(d){ return colors(data[]);})
    .attr("d", path)
    .on("mousemove", function(d){
            .style("opacity", 1)
            .style("width", "100px");
            tooltip.html("<b>" + names[] + 
                         "</b></br> Median: " + data[] + "%")
              .style("left", (d3.event.pageX + 20)+"px")
              .style("top", (d3.event.pageY + 20)+"px");
    .on("mouseout", function(d){
            .style("opacity", 0)
            .style("width", "0px")});
  .datum(topojson.mesh(us, us.objects.states, function(a, b){return a !== b;}))
  .attr("d", path)
  .attr("fill", "none")
  .attr("stroke" , "#F9EDCC")
  .attr("stroke-width", 1);
 var x = d3.scaleLinear()
  .domain([colorMin, colorMax])
    .attr("height", 20)
    .attr("x", function(d,i){ return (i*4)+300})
    .attr("width", 5)
    .attr("fill", colors);
    .attr("class", "caption")
    .attr("x", function(d,i){ return (i*4)+300})
    .attr("y", -6)
    .attr("fill", "#000")
    .attr("text-anchor", "start")
    .attr("font-size", "12px")
    .tickFormat(function(x, i) { return i ? x : x + "%"; })
} ;

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.