Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                %header
  .wrapper
    %div.logo
      %h1 
        Gross Domestic 
        %strong Product
    %nav
      %ul
        %li 
          %a.active{:href => '#timeline'}
            Chart
        %li 
          %a{:href => '#about'}
            About GDP
.wrapper 
  %aside.feature#chartfeature 
    %h4#timeline
    %h3#charttitle 
    .table-responsive 
      .chart 
%main
  .wrapper
    %section#about
      %h2 About the GDP
      %p.lead Gross domestic product (GDP) is a monetary measure of the market value of all final goods and services produced in a period (quarterly or yearly) of time. Nominal GDP estimates are commonly used to determine the economic performance of a whole country or region, and to make international comparisons. Nominal GDP per capita does not, however, reflect differences in the cost of living and the inflation rates of the countries; therefore using a basis of GDP per capita at purchasing power parity (PPP) is arguably more useful when comparing differences in living standards between different nations.
      <small>—Wikipedia</small> 
      
%footer 
  %p 
    Made with &hearts; by 
    %a{:href => 'https://satinflame.com', :target=> '_blank'}
      satinflame design  

      
        
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}
body,
html {
  padding: 0;
  margin: 0;
}
$base-font-size: 18px;
$heading-scale: 8;
$color-primary: #009688;
$color-primary-light: #52c7b8;
$color-primary-dark: #00675b;
$color-secondary: #8e24aa;
$color-secondary-light: #c158dc;
$color-secondary-dark: #5c007a;
* {
  font-family: "Open Sans", sans-serif;
}
@for $i from 1 through 6 {
  h#{$i} {
    font-size: $base-font-size + $heading-scale * (4 - $i);
    font-family: "Oswald", sans-serif;
    color: $color-primary;
    font-weight: 400;
  }
}

h1 {
  border: 1px solid $color-primary-dark;
  display: inline-block;
  padding-left: 0.5rem;
  margin: 0;
  font-size: 2rem;
  background: #fff;
  strong {
    font-family: inherit;
    margin-left: 10px;
    background: $color-primary;
    color: #fff;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    float: right;
  }
}

header {
  background: #f6f6f6;
  padding: 8px;
  .wrapper {
    display: flex;
  }
  div.logo,
  nav {
    flex: 1;
  }
}
.wrapper {
  max-width: 900px;
  margin: 0 auto;
}
div.logo {
  padding: 15px;
}
nav {
  margin: 0;
  padding-right: 15px;
  ul {
    float: right;
    padding: 0;
  }
  ul,
  li {
    display: inline;
  }
  a {
    color: $color-secondary;
    cursor: pointer;
    padding: 8px;
    display: inline-block;
    text-decoration: none;
    &:hover {
      background: $color-secondary-dark;
      color: #fff;
    }
  }
  a.active {
    border-bottom: 3px solid $color-secondary-light;
  }
}

@media (max-width: 767px) {
  header .wrapper {
    flex-direction: column;
    text-align: center;
    padding: 8px 15px;
  }
  nav {
    padding-top: 15px;
  }
  nav ul {
    float: none;
  }
}

main {
  h2 {
    display: inline-block;
    &:after {
      border-bottom: solid 0.1em $color-secondary-light;
      display: block;
      margin-left: 1rem;
      margin-right: -1rem;
      content: "";
    }
  }
}

main {
  .wrapper {
    display: flex;
    flex-direction: row;
    section,
    aside {
      flex: 1;
      padding: 1rem;
    }
  }
}

.chart {
  border: 1px solid $color-primary;
  padding: 5px 5px 0;
  margin: 0;
}
.chart div  { 
  background-color: $color-secondary-light;
  padding: 0.5px;
  cursor: pointer;
  display: inline-block; // magic for vert chart
  &:hover {
    background-color: $color-secondary;
  }
}
.tag { display:none; position: absolute; font-size: .8rem; padding: 3px 8px; background:rgba(98, 23, 117, 0.8);   }
.tag strong { font-size: .9rem;}
.tag strong:after { content: ""; display:block; clear:both;}
.chart div:hover .tag { display:block;}

aside.feature {
  margin-top: 1rem;
  background: $color-primary-dark;
  color: #fff;
  padding: 1rem;
  h2,
  h3 {
    margin: 0;
    color: #fff;
  }
  h4 {
    text-align: right;
    margin: 0;
    color: $color-primary-light;
  }
  small {
    font-size: 0.9rem;
    line-height: 1.3;
    display: block;
    padding: 3px 0 8px 0;
  }
}

footer {
  text-align: center;
  padding: 10px 20px;
  margin-top: 1rem;
  background: $color-secondary-dark;
  color: #fff;
  font-size: 0.8rem;
  a {
    color: lighten($color-secondary-light, 20);
  }
}
 

// Thanks to https://codepen.io/jasonadelia/pen/DnrAe
.chart {
  background-image: linear-gradient(0deg, transparent 24%, rgba(255, 255, 255, .05) 25%, rgba(255, 255, 255, .05) 26%, transparent 27%, transparent 74%, rgba(255, 255, 255, .05) 75%, rgba(255, 255, 255, .05) 76%, transparent 77%, transparent), linear-gradient(90deg, transparent 24%, rgba(255, 255, 255, .05) 25%, rgba(255, 255, 255, .05) 26%, transparent 27%, transparent 74%, rgba(255, 255, 255, .05) 75%, rgba(255, 255, 255, .05) 76%, transparent 77%, transparent);
  height:100%;
  background-size:50px 50px;
}
              
            
!

JS

              
                let model = {
  i: 0,
  chartMax: 0
};

let controller = {
  init: function() {
    let d = {};
    this.getData(); 
  },
  getData: function() {
    var myD;
    var XHR = new XMLHttpRequest();
    XHR.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        myData = JSON.parse(this.responseText);
        controller.loadChart(myData);
      }
    };
    XHR.open(
      "GET",
      "https://raw.githubusercontent.com/FreeCodeCamp/ProjectReferenceData/master/GDP-data.json"
    );
    XHR.send();
  },
  loadChart: function(obj) {
    let i = model.i;
    this.setMax(this.findMax(obj.data));

    let chartScale = d3
      .scaleLinear()
      .domain([0, model.chartMax])
      .range([0, 300]); // second # controls height

    document.getElementById("charttitle").innerHTML = `${obj.name} <small>${
      obj.description
    }</small>`;
    document.getElementById("timeline").innerHTML = `${showMonth(
      obj.from_date
    )} - ${showMonth(obj.to_date)}`;

    let barH = 100 / obj.data.length;
    d3
      .select(".chart")
      .selectAll("div")
      .data(obj.data)
      .enter()
      .append("div")
      .style("height", d => chartScale(Math.floor(d[1])) + "px")
      .style("width", barH + "%")
      // .attr("title", function(d) {
      //   return `${showMonth(d[0])} (${d[1]})`;
      // })
      .html(function(d) {
       return `<span class="tag"><strong>${getAmount(d[1])}</strong> ${showMonth(d[0])}</span>`
       })
    ;

    // this.incrementChart(); // for multi charts
  },
  findMax: function(arr) {
    let max = model.chartMax;
    let m = arr.forEach(e => {
      if (e[1] > max) {
        max = e[1];
      }
    });
    return max;
  },
  setMax: function(num) {
    model.chartMax = num;
  },
  incrementChart: function() {
    model.i++;
  }
};

controller.init();

function showMonth(timestamp) {
  let time = new Date(timestamp);
  return getMonthLabel(time.getUTCMonth()) + " " + time.getUTCFullYear();
}

function getMonthLabel(num) {
  var month = new Array();
  month[0] = "Jan";
  month[1] = "Feb";
  month[2] = "Mar";
  month[3] = "Apr";
  month[4] = "May";
  month[5] = "June";
  month[6] = "July";
  month[7] = "Aug";
  month[8] = "Sept";
  month[9] = "Oct";
  month[10] = "Nov";
  month[11] = "Dec";
  return month[num];
}
function getAmount(val) {
  return "$"+val.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,') + " billion";
}
              
            
!
999px

Console