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

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

              
                <div class="team-treehouse">
    <h1>Achievements</h1>
    <h2><strong class='total'>0</strong> points have been earned</h2>

    <div class="pieChart group">
      <div class="pie"></div>
      <div class="legend"></div>
    </div>
  </a>
</div>


              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Open+Sans:400,700');

// properties
$color-background: #f9f9f9;
$color-primary: #222222;
$size-circle: 12.5em;
$size-thickness: 2.5em;
$size-inner: $size-circle - $size-thickness * 2;

// resets
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  color: $color-primary;
}

// clearfix
.group:after {content:"";display:table;clear:both;}

// general
body {
  font-family: "Open Sans", Arial;
  background: $color-background;

  a {
    text-decoration: none;
  }
  
  .team-treehouse {

    h1, h2 {
      text-align: center;
    }
    h2 {
      font-weight: normal;
    }
  }
}


// pie chart
.pieChart {
  width: $size-circle + 13em;
  margin: 0 auto;
  padding-top: 1em;
}

// pie
.pie {
  height: $size-circle;
  width: $size-circle;
  position: relative;
  float:left;

  &::before {
    content: "";
    display: block;
    position: absolute;
    z-index: 1;
    width: $size-inner;
    height: $size-inner;
    background: $color-background;
    border-radius: 50%;
    top: $size-thickness;
    left: $size-thickness;
  }
}

.slice {
  position: absolute;
  width: $size-circle;
  height: $size-circle;
  clip: rect(0px, $size-circle, $size-circle, $size-circle/2);
  animation: bake-pie 1s;

  span {
    display: block;
    position: absolute;
    top: 0;
    left: 0; 
    background-color: black;
    width: $size-circle;
    height: $size-circle;
    border-radius: 50%;
    clip: rect(0px, $size-circle, $size-circle, $size-circle/2);
  }
}

// legend
.legend {
  width: 13em;
  padding-left: 1em;
  float:left;
  
  ul {
    list-style-type: none;
    list-style-position: inside;
    font-size: 0.8em;
  }
  li {
    height: 1.25em;
    margin-bottom: 0.7em;
    padding-left: 0.5em;
    border-left: 1.25em solid black;
  }
  em {
    font-style: normal;
  }
  span {
    float: right;
    font-weight: bold;
  }
}

              
            
!

JS

              
                // edit username here
$.ajax('https://teamtreehouse.com/ethanneff.json')
  .done(function(data) {
 // pull was a success
  var items = [];
  $.each( data, function( key, val ) {
    if (key.toLowerCase() === 'points') {
      $.each(val, function( key2, val2 ) {
        if (val2 !== 0) {
          if (key2.toLowerCase() !== 'total') {
            items.push([key2,val2]);
          } else {
            $('strong.total').text(val2);
          } 
        }
      });
    }
  });

  // sort
  var sorted = [];
  if (items.length === 0) {
    sorted = items;
  } else {
    sorted = [items.shift()];
  }

  while (items.length > 0) {
    for (i = 0; i < sorted.length; i++) {
      if (items[0][1] > sorted[i][1]) {
        sorted.splice(i,0,items.shift());
        break;
      }
      if (i === sorted.length-1) {
        sorted.push(items.shift());
        break;
      }   
    }
  }
  // make into html
  html = [];
  html.push("<ul>");
  for (s in sorted) {
    html.push("<li>");
    html.push("<em>" + sorted[s][0] + "</em>");
    html.push("<span>" + sorted[s][1]  + "</span>");
    html.push("</li>");
  }
  html.push("</ul>");  
  
  // make legend
  $('.legend').append(html.join(""));
  
  // make pie
  createPie(".legend", ".pie");
  })
  .fail(function() {
    $('.team-treehouse > a > h2').text("Could not connect. Username my be incorrect.");
  })


function sliceSize(dataNum, dataTotal) {
  return (dataNum / dataTotal) * 360;
}

function addSlice(sliceSize, pieElement, offset, sliceID, color) {
  $(pieElement).append("<div class='slice "+sliceID+"'><span></span></div>");
  var offset = offset - 1;
  var sizeRotation = -179 + sliceSize;
  $("."+sliceID).css({
    "transform": "rotate("+offset+"deg) translate3d(0,0,0)"
  });
  $("."+sliceID+" span").css({
    "transform"       : "rotate("+sizeRotation+"deg) translate3d(0,0,0)",
    "background-color": color
  });
}

function iterateSlices(sliceSize, pieElement, offset, dataCount, sliceCount, color) {
  var sliceID = "s"+dataCount+"-"+sliceCount;
  var maxSize = 179;
  if(sliceSize<=maxSize) {
    addSlice(sliceSize, pieElement, offset, sliceID, color);
  } else {
    addSlice(maxSize, pieElement, offset, sliceID, color);
    iterateSlices(sliceSize-maxSize, pieElement, offset+maxSize, dataCount, sliceCount+1, color);
  }
}

function createPie(dataElement, pieElement) {
  var listNames = [];
  var listData = [];
  $(dataElement+" li").each(function() {
    listNames.push($(this).children('em').html());
    listData.push(Number($(this).children('span').html()));
  });
  
  var listTotal = 0;
  for(var i=0; i<listData.length; i++) {
    listTotal += listData[i];
  }

  var offset = 0;
  var colors = {};
  colors['Android'] = '#5cb860';
  colors['Business'] = '#f9845b';
  colors['CSS'] = '#3079ab';
  colors['Design'] = '#e59a13';
  colors['Development Tools'] = '#637a91';
  colors['HTML'] = '#39add1';
  colors['iOS'] = '#53bbb4';
  colors['Java'] = '#2c9676';
  colors['Javascript'] = '#c25975';
  colors['PHP'] = '#7d669e';
  colors['Python'] = '#f092b0';
  colors['Ruby'] = '#e15258';
  colors['WordPress'] = '#838cc7';
  colors['Digital Literacy'] = '#c38cd4';
  
  for(var i=0; i<listData.length; i++) {
    var size = sliceSize(listData[i], listTotal);
    var color = '#000000';
    for (var c in colors) {
      if (listNames[i].toLowerCase() === c.toLowerCase()) {
        color = colors[c];
      }
    }

    // make slices
    iterateSlices(size, pieElement, offset, i, 0, color);
    
    // set legend colors
    $(dataElement+" li:nth-child("+(i+1)+")").css("border-color", color);
    offset += size;
  }
}
              
            
!
999px

Console