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

              
                // Point of entry for Vue
#app
  line-chart(:graph-data='graphData' :width='500' :height='150' :padding='50')

// Component Templates
template#lineChart
  .line-chart
    svg#svgChart(:width='width' :height='height + padding' @mouseleave='hoverLeave')
      defs: clipPath#graphClipPath: path(:d='clipPath')
      g.selectionBackground
        rect(v-for='i in points.length - 2' :width='rectWidth' :height='height + padding' :x='rectWidth * (i - 1)' v-show='hover === i')
      path.area(:d='area')
      g.selectionForeground
        rect(v-for='i in points.length - 2' :width='rectWidth' :height='height + padding' :x='rectWidth * (i - 1)' v-show='hover === i')
      path.line(:d='line')
      g.points
        circle(v-for='p in points' :cx='p[0]' :cy='p[1]' r='4.5')
      g.labels
        text(v-for='i in graphData.length - 2' :x='points[i][0]' :y='height + padding / 2' text-anchor='middle') {{graphData[i].label}}
      g.hoverArea
        rect(v-for='i in points.length - 2' :width='rectWidth' :height='height + padding' :x='rectWidth * (i - 1)' @mouseenter='hoverEnter(i)')

// Profile link styling for self-shilling
a.shill(href='https://codepen.io/milesmanners' target='_blank' title='Made by Miles Manners')
              
            
!

CSS

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

$clr-bg: #1C1F2B;
$clr-bg-light: lighten($clr-bg, 5%);
$clr-bg-lighter: lighten($clr-bg, 15%);
$clr-bg-dark: darken($clr-bg, 2.5%);
$clr-bg-darker: darken($clr-bg, 5%);
$clr-text: $clr-white;
$clr-text-hint: rgba($clr-text, .6);
$clr-primary: $clr-blue;
$clr-secondary: $clr-green;

$anim-dur: 200ms;

$border-radius: 4px;

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  primary: $clr-primary;
}

body {
  background: $clr-bg;
  color: $clr-text;
  margin: 0px;
  font-family: 'Open Sans', sans-serif;
  display: flex;
}

#app {
  margin: auto;
}

svg {
  .points circle {
    fill: $clr-primary;
    stroke: $clr-bg;
    stroke-width: 3;
  }
  
  .line {
    fill: none;
    stroke: $clr-primary;
    stroke-width: 6;
  }
  
  .area {
    fill: $clr-bg-light;
  }
  
  .selectionBackground rect {
    fill: $clr-bg-light;
  }
  
  .selectionForeground rect {
    fill: $clr-primary;
    clip-path: url(#graphClipPath);
  }
  
  .labels {
    fill: $clr-text;
  }
  
  .hoverArea rect {
    fill: transparent;
  }
}

// Profile link styling for self-shilling
.shill {
  position: fixed;
  background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/726875/profile/profile-512.jpg?100000');
  background-size: cover;
  width: 40px;
  height: 40px;
  bottom: 15px;
  right: 15px;
  border-radius: 20px;
  opacity: .4;
  filter: blur(.5px);
  transition: opacity $anim-dur, blur $anim-dur;
  
  &:hover {
    opacity: 1;
    filter: none;
  }
}
              
            
!

JS

              
                /* jshint esversion: 6, asi: true, boss: true */

let graphData = [
  {
    value: 1398283,
    label: 'Thu'
  },
  {
    value: 1450120,
    label: 'Fri'
  },
  {
    value: 1552182,
    label: 'Sat'
  },
  {
    value: 1463981,
    label: 'Sun'
  },
  {
    value: 1343399,
    label: 'Mon'
  },
  {
    value: 1024392,
    label: 'Tue'
  },
  {
    value: 1181991,
    label: 'Wed'
  },
  {
    value: 1372919,
    label: 'Thu'
  },
  {
    value: 1231992,
    label: 'Fri'
  }
]

// Component Definitions
Vue.component('line-chart', {
  template: '#lineChart',
  props: {
    graphData: Array,
    width: Number,
    height: Number,
    padding: Number
  },
  data () {
    return {
      hover: null
    }
  },
  computed: {
    rectWidth () {
      return this.width / (this.values.length - 2)
    },
    values () {
      return this.graphData.map(x => x.value)
    },
    points () {
      let min = Math.floor(Math.min(...this.values) * 0.95)
      let max = Math.ceil(Math.max(...this.values) * 1.05)

      let yRatio = (max - min) / this.height
      let xRatio = this.width / (this.values.length - 2)

      return this.values.map((value, i) => {
        let y = this.height - ((value - min) / yRatio)
        let x = (xRatio * i) - (xRatio / 2)
        return [x, y]
      })
    },
    line () {
      let lineGenerator = d3.line()
        .x(p => p[0])
        .y(p => p[1])
        .curve(d3.curveCardinal)

      return lineGenerator(this.points)
    },
    area () {
      return `${this.line} L${this.points[this.points.length - 1][0]},${this.height + this.padding} L${this.points[0][0]},${this.height + this.padding} z`
    },
    clipPath () {
      return this.line + ` L${this.points[this.points.length - 1][0]},${this.height + this.padding} L${this.points[0][0]},${this.height + this.padding} z`
    }
  },
  methods: {
    hoverEnter (i) {
      this.hover = i
    },
    hoverLeave () {
      this.hover = null
    }
  }
})

// Point of entry
new Vue({
  el: '#app',
  data () {
    return {
      graphData: graphData
    }
  }
})
              
            
!
999px

Console