Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                  <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<script src="https://d3js.org/d3-geo.v1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3-legend/2.25.6/d3-legend.js"></script>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/topojson.v2.min.js"></script> 
              
            
!

CSS

              
                
.county-borders {
  fill: none;
  stroke: #fff;
  stroke-width: 0.2px;
  stroke-linejoin: round;
  stroke-linecap: round;
  pointer-events: none;
}
.counties {
  fill: none;
  text-align: center;
  margin: 0 auto;
}

.county {
  fill: none;
}
 
 
  .dot:hover {
    fill: lightslategray;
  }
  .dot{box-shadow: 1px 2px 1px 10px black;}
  div.tooltip {	
    position: absolute;			
    text-align: center;			
    width: 100px;					
    height: 50px;					
    padding: 2px;				
    font: 12px sans-serif;		
    background: rgb(143, 143, 143);	
    border: 0px;		
    border-radius: 8px;			
    pointer-events: none;	
    line-height: 150%	;
    color: whitesmoke;
    box-shadow: 0px 0px 25px 5px rgba(241, 239, 239, 0.75);
  
}
#title,
#leftlegend,
#description{
  text-shadow: 1px 2px 3px black;
}
#leftlegend {color: midnightblue ;font-size: 22px;text-anchor:'middle';
}
.legend{font-size: 15px;

}
#title{
  text-anchor: middle;
  font-size: 25px;
}
#description{
  text-anchor: middle;
  font-size: 15px;
}



a:visited{
  text-decoration: none;
  text-decoration-color: inherit;
  color: inherit;
}
              
            
!

JS

              
                var USEducationDataUrl = "https://raw.githubusercontent.com/no-stack-dub-sack/testable-projects-fcc/master/src/data/choropleth_map/for_user_education.json";
var USCountyDataUrl = "https://raw.githubusercontent.com/no-stack-dub-sack/testable-projects-fcc/master/src/data/choropleth_map/counties.json";
var padding = 50;
var width = window.innerWidth;
var height = window.innerHeight / 10 * 9;



const svg = d3.select("body")
    .append("svg").attr("width", width)
    .attr("height", height);
svg.append('text')
    .attr("id", "title")
    .attr("transform", "translate(" + (width / 2) + "," + padding / 3 + ")")
    .text("United States Educational Attainment    ");
svg.append('text')
    .attr("id", "description")
    .attr("transform", "translate(" + (width / 2) + "," + (padding / 3 + 22) + ")")
    .text(" Percentage of adults age 25 and older with a bachelor's degree or higher (2010-2014)");

d3.selectAll('body').append('a')
    .attr("id", "link")
    .attr("target", "_blank")
    .attr("href", "https://www.ers.usda.gov/data-products/county-level-data-sets/download-data.aspx")
    .attr("transform", "translate(" + (width / 2) + "," + (padding / 2 + 22) + ")")
    .html(function () {
        return (
            "Source: <a href='https://www.ers.usda.gov/data-products/county-level-data-sets/'>USDA Economic Research Service</a>"
        );
    });




//https://github.com/d3/d3-geo-projection..geoAlbers().projection(projection);

   

var path = d3.geoPath();



queue()
    .defer(d3.json, USCountyDataUrl)
    .defer(d3.json, USEducationDataUrl)
    .await(makeMyMap);


function makeMyMap(error, states, data) {
     //tooltip declarations
     var div = d3.select("body").append("div")
     .attr("class", "tooltip")
     .attr("id", "tooltip")
     .style("opacity", 0);
    colors = ["#f21e1e", "#1e37f2" ];
    var rateById = {};
    var areaId= {};
    var stateId= {};
var features = topojson.feature(states, states.objects.counties).features;

for (const d of data) {
          rateById[d.fips] = +d.bachelorsOrHigher;
        areaId[d.fips]= d.area_name;
       stateId[d.fips]= d.state;
 }
       
    var hhh = Object.values(rateById);
    var maxr = d3.max(hhh);

    var color = d3.scaleLinear()
        // 
        .domain([0, maxr])
        .range(colors);

    svg.append("g")  
        .attr("class", "counties")
      .selectAll("path")
        .data(features )
        .enter().append("path")
        .attr('class', 'county')
        .attr('data-fips', 
        (d) => d.id)
        .attr('data-education', (d) => rateById[d.id])
        .style("fill", (d) =>
            color(rateById[d.id]))
        .attr("stroke", "#FFF")
        .attr("stroke-width", "0.5px")
        .attr('d', path).on("mouseover", function (d) {
            div.transition()
                .duration(100)
                .style("opacity", 0.9);
            div.attr('data-education', rateById[d.id]);
            div.html( areaId[d.id]  + "\t/ " + stateId[d.id]  + 
                  "<br/>" +rateById[d.id]+" %"
                )
                .style("left", (d3.event.pageX) + "px")
                .style("top", (d3.event.pageY - 28) + "px");
        }).on("mouseout", function (d) {
            div.transition()
                .duration(500)
                .style("opacity", 0);
        });
  svg.append("path")
        
        .attr("class", "county-borders")
        .attr("d", path(topojson.mesh(states, states.objects.counties, function (a, b) {
            return a.id !== b.id; })));

   

   


            var colorp = d3.scaleLinear()
            // 
            .domain([0, maxr/100])
            .range(colors);
   

   

    svg.append("g")
        .attr("class", "legendLinear").attr("id", "legend")
        .attr("transform", "translate(" + (width-200) + "," + ( +padding) + ")");

    var legendLinear = d3.legendColor()
        .shapeWidth(90)
        .cells(10)
        .orient('vertical')
        .labelFormat(d3.format(".1%"))
        .scale(colorp);

    svg.select(".legendLinear")
        .call(legendLinear);
}
              
            
!
999px

Console