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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Marni Duffy</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav ml-auto">
      <li class="nav-item">
        <a class="nav-link" href="#">Site/Resume</a>
      </li>
    </ul>
  </div>
</nav>
<div class="container text-center">
  <div class="card" >
    <div class="card-body">
      <h2 class="card-title">Monthly Global Land-Surface Temperature</h2>
      <h3 class="card-text">1753-2015</h3>
      <p>Temperatures are in Celcius and reported as anomolies relative to the Jan 1951 - Dec 1980 average.</p><p>Estimated Jan 1951-Dec 1980 absolute temperature °C 8.66 +/- 0.07.</p>
      <div id="chart"></div>
      <div id="legend"></div>
    </div>
  </div>
</div>


              
            
!

CSS

              
                $teal: rgba(#65CCCC, 0.2);

svg rect.bordered {
  stroke: white;
  stroke-width: 0.5px;
}
body, .navbar {
  background-color: $teal; 
}
.card {
  width: 75rem;
  height: 75rem; 
}
text.label {
  font-size: 9pt;
  font-family: sans-serif;
  fill: #795548;
}

.yLabel, .xLabel, .legend {
  font-size: 1.1em; 
}
.card {
  margin-top: 20px; 
  
}
              
            
!

JS

              
                var months = ["JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"];

var years = [];
function createYears(min,max){
  for(var i=min; i<=max; i++){
    years.push(i);
  }
  return years; 
}

var colors = ['#F8F87C',
              '#FFFF00',
              '#ECF91A',
              '#D9F233',
              '#C6EC4D',
              '#B3E666',
              '#A0E080',
              '#8CD999',
              '#79D3B3',
              '#66CCCC',
              ];

function drawMap() {
  var margin = { top: 30, right: 10, bottom: 30, left: 30 },
    width = $(".card").innerWidth(),
    gridSize = Math.floor(width/60),
    height = $('.card').innerHeight(),
    legendElementWidth = gridSize*2;
  
  var svg = d3.select("#chart").append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
    .append("g") // an svg "group", similar to an html "div"
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
  
  var monthLabels = svg.selectAll(".month")
    .data(months)
    .enter().append("text")
        .text(function(d) { return d.substr(0,3); })
        .attr("x", -5)
        .attr("y", function(d,i){ return (i *3 * gridSize) +70 ; })
        .style("text-anchor", "end")
        .attr("transform", "translate(0," + gridSize   +")")
        .attr("class", "label");

  d3.json("https://raw.githubusercontent.com/FreeCodeCamp/ProjectReferenceData/master/global-temperature.json", 
        
  function(error, data) {
    if(error) { console.log(error)};
    data = data.monthlyVariance;
    var varianceExtent = d3.extent(data.map(function(each) { return each.variance; }));
    var colorRange = d3.scale.quantile().domain(varianceExtent).range(colors);
    var yearsExtent = d3.extent(data.map(function(each) { return each.year; }));
  
    createYears(yearsExtent[0], yearsExtent[1]); 
  
    var yearLabels = svg.selectAll(".year")
       .data(years)
        .enter().append("text")
          .text(function (d) {
            if (d % 10 == 0 && d != 2010) {
              return d;
            } else { 
              return ''; 
            }  })
          .attr("x", function(d, i) { return i/4.25 * gridSize; })
          .attr("y", 50)
          .style("text-anchor", "middle")
          .attr("transform", "translate(" + gridSize / 2  + ", -6)")
          .attr("class", "label");
  
    var heatMap = svg.selectAll(".grid")
      .data(data)
      .enter().append("rect")
        .attr("width", gridSize )
        .attr("height", height/14)
         .attr("x", function(d, i){ return (i/(width/425)) })
        .attr("y", function(d) { return (d.month *3 ) * gridSize; })
        .style("fill", function(d) { return colorRange(d.variance); });

    heatMap.append("title") // append and format title element
        .text(function(d) {
          var title = d.month + '/' + d.year +   ' Variance: ' + d.variance;
          return title;
        });
  
    //label axes:   
  svg.append("text")
      .attr("class", "xLabel")
      .attr("text-anchor", "end")
      .attr("x", gridSize * 30)
      .attr("y", 9)
      .text("YEAR")
  
  //legend:
  var legend = svg.selectAll(".legend")
    .data([0].concat(colorRange.quantiles()), function(d){ return d; });
  
  legend.enter().append("g")
    .attr("class", "legend");
  
  legend.append("rect")
    .attr("x", function(d,i){ return (legendElementWidth * i) + 50;})
    .attr("y", 820)
    .attr("width", legendElementWidth)
    .attr("height", gridSize/2)
    .style("fill", function(d,i) { return colors[i]});
  
  var widthOfChart = '35rem'; 
    legend.append("text")
    .attr("class", "mono")
    .text(function(d) { return "≥ " + Math.round(d); })
    .attr("x", function(d,i){ return ((legendElementWidth + 1.75 ) * i)  +50; })
    .attr("y", 835 + gridSize);
    
  legend.append("text")
    .text("LEGEND")
    .attr("x", 200)
    .attr("y", 805)
    .attr("class", "legend") 
  
  heatMap.exit().remove(); 
  legend.exit().remove();
  
});
}

drawMap();

              
            
!
999px

Console