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 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 id="app">
      <year-graph 
      :graph-items="[{name: 'Design Projects', amount: [5,2,7,11,15,2,7,3,9,4,2,8]},
                     {name: 'Web pages', amount: [4,2,5,2,2,7,3,9,4,2,5,2]},
                     {name: '3d animations', amount: [2,5,2,7,11,4,2,5,15,8,7,3]}]"></year-graph>
</div>
              
            
!

CSS

              
                * 
  margin 0
  padding 0

button:focus 
  outline: none

body 
  display flex
  justify-content center
  align-items center
  height 100vh
  font-family sans-serif
  color rgb(255, 255, 255)
  background rgb(15, 15, 15)
  



.graph
  &__canvas 
    width 360px
    height 200px
    transform rotateX(180deg)
    border-bottom 1px solid  rgba(244, 65, 190, .2)
    background linear-gradient(rgba(244, 65, 190, .2) 1px , transparent 0) repeat-y top / 100% 40px 
    &-wrapper 
      margin-top 20px
      position relative
  &__navigation 
    display flex
    justify-content center
  &__button 
    margin 20px 10px
    width 85px
    padding 0 10px
    height @width
    border-radius 50%
    border none
    background transparent 
    color rgb(255, 255, 255)
    position relative
    background rgb(15, 15, 15)
    transition .4s ease
    box-shadow 0px 5px 5px rgb(65, 244, 106)
    &:after 
      content ''
      position absolute
      transition .4s ease
      top 0
      right 0
      bottom 0
      left 0
      border-radius 50%
      transform scale(1.1)
      background linear-gradient(rgb(244, 66, 104), rgb(65, 139, 244))
      opacity .4
      z-index -1
    &--active
      box-shadow 0px -4px 5px rgb(65, 244, 106)
    &:hover 
      &::after 
        transform scale(1.1) rotate(180deg)
      
      
  &__info 
    position absolute
    left: -75px
    &--amount 
      top -20px
      height 220px
      display flex 
      flex-direction column 
      justify-content space-between
    &--months
      display flex
      justify-content space-between
      bottom -40px
      width 425px
      padding 5px 15px 5px 0px
  &__text
    &--amount  
      display flex
      flex-direction column-reverse
    &--number
      margin-top 0px
      display flex
      justify-content center 
      align-items center
      height 40px
    &--month 
      display inline-block
      width 20px
      padding-left 9.5px
              
            
!

JS

              
                Vue.component('year-graph', {
  template: 
  `
  <secction class="graph"> 
  <div class="graph__navigation">
  <button class="graph__button graph__button--navigation"
  v-for="(item, index) of graphItems"
  @click="changeInformation(graphItems[index])"
  :class="{'graph__button--active' : currentName == item.name}"
  >{{item.name}}</button>
  </div>
  <div class="graph__canvas-wrapper">
  <canvas id="graph-canvas" class="graph__canvas" width="360" height="200"></canvas>
  <div class="graph__info graph__info--amount">
    <p class="graph__text">Amount</p>
    <p class="graph__text graph__text--amount">
      <span class="graph__text--number"
       v-for="item of 5">{{item * 5}}</span>
    </p>
  </div>
  <div class="graph__info graph__info--months">
  <p class="graph__text">Month</p>
  <p class="graph__text graph__text--months">
    <span
     class="graph__text graph__text--month"
     v-for="item of 12">{{item}}</span>
  </p>
 
  </div>
  </secction>

  `,
  props: {
    graphItems: {
      type: Array,
      require: true
    }
  },
  data() {
    return {
      currentName: '',
      currentAmount: '',
      context: '',
      currentY: []
    }
  },
  methods: {
    lineDraw(startX, startY,  finishY, ctx) {
      let y = startY || 0;
      function draw(startX,  finishY) {
        let requestAnimation;
        let ctxGradiend = ctx.createLinearGradient(0, 0, 0, 100);
        ctxGradiend.addColorStop(0, "#f44268");
        ctxGradiend.addColorStop(.25, "#ac41f4");
        ctxGradiend.addColorStop(.5, "#418bf4");
        ctxGradiend.addColorStop(1, "#41f46a");

        ctx.fillStyle = ctxGradiend;

        ctx.fillRect(startX, 0, 20, y);
        
        requestAnimation = requestAnimationFrame(()=> {       
          // ctx.fillStyle = `hsl(${y},90%,30%)`;
          y < finishY ?  y+=2 : y > finishY ? y-=2 : cancelAnimationFrame(requestAnimation);
          ctx.clearRect(startX,0,20,200);
          draw(startX,  finishY)
        });
      }
      draw(startX,  finishY);
    },


    changeInformation(data) {
      this.currentName = data.name,
      this.currentAmount  = data.amount
      let counter = 0;
      for(let i = 0; i < this.currentAmount.length; i++) {
        
        this.lineDraw(counter, this.currentY[i], this.currentAmount[i] * 10, this.context);
        counter += 30;
      }
      this.currentY = [];
      for(let i = 0; i < this.currentAmount.length; i++) {
         this.currentY.push(this.currentAmount[i] * 10);
      }
    }
  },
  mounted() {
    const graphCanvas = document.querySelector('#graph-canvas'),
    ctx = graphCanvas.getContext('2d');
    this.context = ctx;
    this.changeInformation(this.graphItems[0])
  }
})


new Vue({
  el: '#app'
})
              
            
!
999px

Console