123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              .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

            
          
!
            
              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

            
          
!
            
              
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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console