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>

<script src=""></script>

  <h1 id="title">United States Educational Attainment</h1>
    <h3 id="description">Percentage of adults aged 25+ with a bachelor's degree or higher (2010-2014)</h3>
    <div id="svg-container"></div>


                 body {
    font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif

#svg-container {
  padding-left: 50px;

  h1, h3{
    text-align: center;
  #tooltip {
    font-size: 1em;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    text-align: center;
    width: 150px;
    height: 100px;
    padding: 2px;
    background:rgb(251, 251, 252);
    box-shadow: 0px 0px 6px 2px #A9A5AA;
    border-radius: 2px;

  .county-border {
    fill: none;
    stroke: rgba(23, 10, 58, 0.432);
    stroke-width: 0.5px;
    stroke-linejoin: round;
    stroke-linecap: round;
    pointer-events: none;
  .counties :hover {
    fill: black;


                // set up svg area
    const width = 1200;
    const height = 600;
    const svgContainer ='#svg-container')
      .attr('width', width )
      .attr('height', height);

    const path = d3.geoPath();

    // tooltip
    let tooltip ="#svg-container")
        .style("opacity", 0) 
        .attr("class", "tooltip")
        .attr("id", "tooltip");
      // when mouse is moved away from bar, tooltip is hidden.
      let mouseleave = function(d) {
        .style("opacity", 0)

    ]).then(([educationData, mapData])=> {
      let counties = topojson.feature(mapData, mapData.objects.counties).features;

      counties.sort(function(a, b){
        return -;

      // assign objects from ed info json to US object
      for (let i = 0; i < counties.length; i++) {
        if (educationData.find(item => item.fips == counties[i].id )) {
          Object.assign(counties[i].properties, educationData[i]);

      // legend
      const colors = d3.scaleThreshold()
        .domain([0, 10, 20, 30, 40, 50, 60, 70, 80]);

      const colorX = d3.scaleLinear()
        .domain([0, 10, 20, 30, 40, 50, 60, 70, 80])
        .range([0, 40]);

      const legendAxis = d3.axisBottom(colorX)
      const legend = svgContainer.append("g")
        .attr("id", "legend")
        .attr("transform", "translate(500, 20)");

        .data(colors.range().map(function (d) {
          d = colors.invertExtent(d);
          if (d[0] == null) d[0] = colorX.domain()[0];
          if (d[1] == null) d[1] = colorX.domain()[1];
          return d;
        .attr("height", 8)
        .attr("x", function(d) { return colorX(d[0]); })
        .attr("width", function(d) { return colorX(d[1]) - colorX(d[0]); })
        .attr("fill", function(d) { return colors(d[0]); });

        // Draw map
          .attr("d", path)
          .attr("class", "county")
          .attr("data-fips", d =>
          .attr("data-education", d =>
          .attr("fill", d => colors(
          // MOUSEOVER
          .on("mouseover", function(d, i){
            .style('opacity', 0.9);
          tooltip.html( + ", State: " + + "<br>" 
          + "Bachelors degree or higher: " + + "%")
            .style("left", (d3.event.pageX+ 10) + "px")
            .style("top", (d3.event.pageY + 10) + "px")
            // MOUSELEAVE
          .on("mouseleave", mouseleave);
        // draw county borders
          .attr("class", "county-border")
          .attr("d", path(topojson.mesh(mapData, mapData.objects.counties, function(a,b){
            return a !== b;