Home / File/ svg.js — vue Source File

svg.js — vue Source File

Architecture documentation for svg.js, a javascript file in the vue codebase.

File javascript VueCore VDom 1 functions

Entity Profile

Relationship Graph

Source Code

// The raw data to observe
var globalStats = [
  { label: 'A', value: 100 },
  { label: 'B', value: 100 },
  { label: 'C', value: 100 },
  { label: 'D', value: 100 },
  { label: 'E', value: 100 },
  { label: 'F', value: 100 }
]

// A reusable polygon graph component
Vue.component('polygraph', {
  props: ['stats'],
  template: '#polygraph-template',
  computed: {
    // a computed property for the polygon's points
    points: function () {
      var total = this.stats.length
      return this.stats
        .map(function (stat, i) {
          var point = valueToPoint(stat.value, i, total)
          return point.x + ',' + point.y
        })
        .join(' ')
    }
  },
  components: {
    // a sub component for the labels
    'axis-label': {
      props: {
        stat: Object,
        index: Number,
        total: Number
      },
      template: '#axis-label-template',
      computed: {
        point: function () {
          return valueToPoint(+this.stat.value + 10, this.index, this.total)
        }
      }
    }
  }
})

// math helper...
function valueToPoint(value, index, total) {
  var x = 0
  var y = -value * 0.8
  var angle = ((Math.PI * 2) / total) * index
  var cos = Math.cos(angle)
  var sin = Math.sin(angle)
  var tx = x * cos - y * sin + 100
  var ty = x * sin + y * cos + 100
  return {
    x: tx,
    y: ty
  }
}

// bootstrap the demo
new Vue({
  el: '#demo',
  data: {
    newLabel: '',
    stats: globalStats
  },
  methods: {
    add: function (e) {
      e.preventDefault()
      if (!this.newLabel) return
      this.stats.push({
        label: this.newLabel,
        value: 100
      })
      this.newLabel = ''
    },
    remove: function (stat) {
      if (this.stats.length > 3) {
        this.stats.splice(this.stats.indexOf(stat), 1)
      } else {
        alert("Can't delete more!")
      }
    }
  }
})

Domain

Subdomains

Functions

Frequently Asked Questions

What does svg.js do?
svg.js is a source file in the vue codebase, written in javascript. It belongs to the VueCore domain, VDom subdomain.
What functions are defined in svg.js?
svg.js defines 1 function(s): valueToPoint.
Where is svg.js in the architecture?
svg.js is located at examples/classic/svg/svg.js (domain: VueCore, subdomain: VDom, directory: examples/classic/svg).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free