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

              
                .wrapper
  h1 Answered Questions
  .pie-charts

    .pieID--micro-skills.pie-chart--wrapper
      h2 Micro-Skills
      .pie-chart
        .pie-chart__pie
        ul.pie-chart__legend
          li
            em Additive
            span 642
          li
            em Multiplicative
            span 358

    .pieID--categories.pie-chart--wrapper
      h2 Categories
      .pie-chart
        .pie-chart__pie
        ul.pie-chart__legend
          li
            em Horizontal
            span 768
          li
            em Vertical
            span 232

    .pieID--operations.pie-chart--wrapper
      h2 Operations
      .pie-chart
        .pie-chart__pie
        ul.pie-chart__legend
          li
            em Addition
            span 486
          li
            em Subtraction
            span 156
          li
            em Multiplication
            span 215
          li
            em Division
            span 143

              
            
!

CSS

              
                body
  font-family: "Open Sans", Arial
  background: #EEE
  
  text-align: center

  *
    font-weight: 300
    margin: 0
    padding: 0
  


@keyframes bake-pie
  from
    transform: rotate(0deg) translate3d(0,0,0)
  
.pie-chart
  font-family: "Open Sans", Arial
  &--wrapper
    width: 400px
    margin: 30px auto
    text-align: center

  &__pie, &__legend
    display: inline-block
    vertical-align: top

  &__pie
    position: relative
    height: 200px
    width: 200px
    margin: 10px auto 35px
    &::before
      content: ""
      display: block
      position: absolute
      z-index: 1
      width: 100px
      height: 100px
      background: #EEE
      border-radius: 50%
      top: 50px
      left: 50px
    &::after
      content: ""
      display: block
      width: 120px
      height: 2px
      background: rgba(0,0,0,0.1)
      border-radius: 50%
      box-shadow: 0 0 3px 4px rgba(0,0,0,0.1)
      margin: 220px auto

.slice
  position: absolute
  width: 200px
  height: 200px
  clip: rect(0px, 200px, 200px, 100px)
  animation: bake-pie 1s
  span
    display: block
    position: absolute
    top: 0
    left: 0
    background-color: black
    width: 200px
    height: 200px
    border-radius: 50%
    clip: rect(0px, 200px, 200px, 100px)


.pie-chart__legend
  display: block
  list-style-type: none
  padding: 0
  margin: 0 auto
  background: #FFF
  padding: 0.75em 0.75em 0.05em
  font-size: 13px
  box-shadow: 1px 1px 0 #DDD, 2px 2px 0 #BBB
  text-align: left
  width: 65%
  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

.pie-charts
  display: flex
  flex-direction: row
  @media (max-width: 500px)
    flex-direction: column

              
            
!

JS

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

function addSlice(id, sliceSize, pieElement, offset, sliceID, color) {
  $(pieElement).append("<div class='slice "+ sliceID + "'><span></span></div>");
  var offset = offset - 1;
  var sizeRotation = -179 + sliceSize;

  $(id + " ." + sliceID).css({
    "transform": "rotate(" + offset + "deg) translate3d(0,0,0)"
  });

  $(id + " ." + sliceID + " span").css({
    "transform"       : "rotate(" + sizeRotation + "deg) translate3d(0,0,0)",
    "background-color": color
  });
}

function iterateSlices(id, sliceSize, pieElement, offset, dataCount, sliceCount, color) {
  var
    maxSize = 179,
    sliceID = "s" + dataCount + "-" + sliceCount;

  if( sliceSize <= maxSize ) {
    addSlice(id, sliceSize, pieElement, offset, sliceID, color);
  } else {
    addSlice(id, maxSize, pieElement, offset, sliceID, color);
    iterateSlices(id, sliceSize-maxSize, pieElement, offset+maxSize, dataCount, sliceCount+1, color);
  }
}

function createPie(id) {
  var
    listData      = [],
    listTotal     = 0,
    offset        = 0,
    i             = 0,
    pieElement    = id + " .pie-chart__pie"
    dataElement   = id + " .pie-chart__legend"

    color         = [
      "cornflowerblue",
      "olivedrab",
      "orange",
      "tomato",
      "crimson",
      "purple",
      "turquoise",
      "forestgreen",
      "navy"
    ];

  color = shuffle( color );

  $(dataElement+" span").each(function() {
    listData.push(Number($(this).html()));
  });

  for(i = 0; i < listData.length; i++) {
    listTotal += listData[i];
  }

  for(i=0; i < listData.length; i++) {
    var size = sliceSize(listData[i], listTotal);
    iterateSlices(id, size, pieElement, offset, i, 0, color[i]);
    $(dataElement + " li:nth-child(" + (i + 1) + ")").css("border-color", color[i]);
    offset += size;
  }
}

function shuffle(a) {
    var j, x, i;
    for (i = a.length; i; i--) {
        j = Math.floor(Math.random() * i);
        x = a[i - 1];
        a[i - 1] = a[j];
        a[j] = x;
    }

    return a;
}

function createPieCharts() {
  createPie('.pieID--micro-skills' );
  createPie('.pieID--categories' );
  createPie('.pieID--operations' );
}

createPieCharts();

              
            
!
999px

Console