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


Babel includes JSX processing.

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


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <script src=""></script>

<div id="headers">
  <h1 id="title">United States Educational Attainment</h1>
  <h4 id="description">Percentage of adults age 25 and older with a bachelor's degree or higher (2010-2014)</h4>


                @import url(;

body {
  min-width: 960px;
  font-family: "Open Sans", sans-serif;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  scroll-snap-type: x mandatory;

#headers {
  max-width: 280px;
  scroll-snap-align: center;

@media (min-width: 425px) {
  #headers {
    max-width: 400px;

@media (min-width: 768px) {
  #headers {
    max-width: 100%;

#title {
  text-align: center;

#description {
  text-align: center;

#canvas {
  display: flex;

#legend {
  font-size: 12px;

.county:hover {
  stroke: black;
  stroke-width: 2px;

.states {
  fill: none;
  stroke: #fff;
  stroke-linejoin: round;

#tooltip {
  display: flex;
  position: absolute;
  text-align: center;
  padding: 2px 4px;
  background: white;
  border: 1px solid;
  border-radius: 2px;



  .then((files) => {
    render(files[0], files[1]);
  .catch((err) => {
    console.log("Encountered an error");

// Scroll Header info into view for mobile
function scroll(){
  const headers = document.getElementById('headers');
    block: "center",
    inline: "center"

// D3 Rendering
function render(geoData, educationData) {
  // Create object to store education data
  const educationDataMap = {};
  educationData.forEach((county) => {
    educationDataMap[county.fips] = {
      area_name: county.area_name,
      bachelorsOrHigher: county.bachelorsOrHigher,
      state: county.state

  // Canvas Size
  const w = 960;
  const h = 600;

  // Render Canvas
  const svg = d3
    .attr("width", w)
    .attr("height", h)
    .attr("id", "canvas");
  const colorInterpolator = d3
    .interpolate("rgb(229, 255, 224)", "rgb(0, 68, 27)");

  // Color scale
  const fill = d3
      d3.min(educationData, (d) => d.bachelorsOrHigher),
      d3.max(educationData, (d) => d.bachelorsOrHigher)
    .range(d3.quantize(colorInterpolator, 6));
  // Path
  const path = d3.geoPath();
  const toolTip = d3
    .attr("id", "tooltip")
    .style("opacity", 0);

    .data(topojson.feature(geoData, geoData.objects.counties).features)
    .attr("d", path)
    .attr("class", "county")
    .attr("data-education", (d) => educationDataMap[].bachelorsOrHigher)
    .attr("data-fips", (d) =>
    .attr("fill", (d) => fill(educationDataMap[].bachelorsOrHigher))
    .on("mouseover", (d) => {
      const countyInfo = educationDataMap[];
      toolTip.transition().duration(200).style("opacity", 100);
          countyInfo.area_name +
            ", " +
            countyInfo.state +
            ": " +
            countyInfo.bachelorsOrHigher +
        .style("left", d3.event.pageX + 28 + "px")
        .style("top", d3.event.pageY - 28 + "px")
        .attr("data-education", countyInfo.bachelorsOrHigher)
    .on("mouseout", (d) =>
      toolTip.transition().duration(500).style("opacity", 0)

  // Render State Lines
      topojson.mesh(geoData, geoData.objects.states, (a, b) => !==
    .attr("class", "states")
    .attr("d", path);
  const legendLinear = d3
  const legend = svg
    .attr("class", "legendLinear")
    .attr("id", "legend")
    .attr("transform", "translate(" + 237 + ",5)")