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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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.


                <h1 id="title">United States Educational Attainment

<h3 id="description"> Percentage of adults age 25 and older with a bachelor's degree or higher (2010-2014) </h3>

<div id="container" class="container">
  <div id="tooltip" class="tooltip"></div>

<script src=''></script>


                body {
  background-image: radial-gradient( circle 879px at 10.4% 22.3%,  rgba(255,235,238,1) 0%, rgba(186,190,245,1) 93.6% );
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  flex-direction: column;
  font-family: sans-serif;

h1 {
  margin-top: -40px;
  margin-bottom: 0px;

svg {
  border: 2px solid black;
  box-shadow: 4px 4px 6px rgba(0, 0, 0, 0.4);
  background-color: #fff;

.container {
  position: relative;

.tooltip {
  background-color: #fff;
  display: none;
  box-shadow: 2px 2px 4px rgba(255, 255, 255, 0.4);
  position: absolute;
  z-index: 100;
  text-align: center;
  opacity: 0.8;
} {
  display: block;

.tooltip small {
  margin-bottom: 5px;

.legend {
  position: absolute;
  top: 20px;
  right: 110px;


                //const tooltip = document.getElementById('tooltip');

async function run() {
const eduResp = await fetch ('')
const educations = await eduResp.json()

const countiesResp = await fetch('')
const counties = await countiesResp.json()

// outer svg dynamics
  const width = 960;
  const height = 600;
  const padding = 60;
  //create Path (add map)
  const path = d3.geoPath();
  // add data
  const data = topojson.feature(counties, counties.objects.counties).features;
  const minEdu =  d3.min(educations, edu => edu.bachelorsOrHigher);
  const maxEdu =  d3.max(educations, edu => edu.bachelorsOrHigher);
  const step = (maxEdu - minEdu) / 8;
  const colorsScale = d3.scaleThreshold()
  .domain(d3.range(minEdu, maxEdu, step))
 const colors = [];
  for(let i=minEdu; i<=maxEdu; i+=step) {
// calling outer svg
  const svg ='#container').append('svg')
          .attr('width', width)
          .attr('height', height);
  // inner svg
    .attr('class', 'county')
  .attr('fill', d => colorsScale(educations.find(edu => edu.fips ===
  .attr('d', path)
  .attr('data-fips', d =>
  .attr('data-education', d => educations.find(edu => edu.fips === )
  .on('mouseover', (event, d) => {
  const {coordinates} = d.geometry;
    const [x, y] = coordinates[0][0];
    const education = educations.find(edu => edu.fips ===;
    tooltip.classList.add('show'); = x  - 50 + 'px'; = y - 50 + 'px';
    tooltip.setAttribute ('data-education', education.bachelorsOrHigher );
    tooltip.innerHTML = `
    <p>${education.area_name} - ${education.state}</p>
}).on('mouseout', () => {

  //create Legend
 const legendHeight = 30;
  const legendWidth= 200;
  const legendRectWidth = legendWidth / colors.length;
  const legend ='#container')
  .attr('id', 'legend')
  .attr('class', 'legend')
  .attr('height', legendHeight)
  .attr('width', legendWidth)
  .attr('x', (_, i) => i * legendRectWidth)
  .attr('y', 0)
  .attr('width', legendRectWidth)
  .attr('height', legendHeight)
  .attr('fill', c => c)


run ();