1.0.3 • Published 4 years ago

v-justgage v1.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

vue-justgage

A Vue plugin of JustGage

中文文档

Reference and Thanks

justgage

Install

npm install vue-justgage --save-dev

or use dist/vueJustgage.js without webpack

<script src="vue.min.js"></script>
<!-- must place this line after vue.js -->
<script src="dist/vueJustgage.js"></script>

Usage

You can import it in main.js

import vueJustgage from 'vue-justgage';
Vue.use(vueJustgage);

or import it in your own component.

<script>
import Vue from 'vue';
import vueJustgage from 'vue-justgage';
Vue.use(vueJustgage);
export default {
  ...
}
</script>

Sample

Please use methods after mounted hook.

<template>
  <vue-justgage ref="g1" id="g1" class="gauge"></vue-justgage>
  <button type="button" id="gauge_refresh" @click="refresh">Refresh Gauges</button>
</template>

<script>
export default {
  data() {
    return {
      dflt: {
        min: 0,
        max: 200,
        donut: true,
        gaugeWidthScale: 0.6,
        counter: true,
        hideInnerShadow: true
      }
    }
  },
  mounted() {
    var g1 = this.$refs.g1.draw({
      id: 'g1',
      value: 125,
      title: 'javascript call',
      defaults: this.dflt
    });
  },
  methods: {
    refresh() {
      this.g1.refresh(this.getRandomInt(0, 100));
    }
  }
}
</script>

Options

options about container

optiontypedefaultdescription
idstringcontainer element id
parentNodenode objectnullcontainer element
widthintnullgauge width
heightintnullgauge height
defaultsboolfalsedefaults parameter to use

options about gauge

optiontypedefaultdescription
valuefloat0value gauge is showing
gaugeWidthScalefloat1width of the gauge element
gaugeColorstring'#edebeb'background color of gauge element
levelColorsstring[] "#a9d70b", "#f9c802", "#ff0000" colors of indicator, from lower to upper, in RGB format
customSectors of objects number of digits after floating point, available option:{color, lo, hi}
noGradientboolfalsewhether to use gradual color change for value, or sector-based
donutboolfalseshow full donut gauge
donutStartAngleint90angle to start from when in donut mode
hideInnerShadowboolfalsehide inner shadow
shadowOpacityint0.2shadow opacity, values 0 ~ 1
shadowSizeint5inner shadow size
shadowVerticalOffsetint3how much shadow is offset from top
reverseboolfalsereverse min and max
relativeGaugeSizeboolfalsewhether gauge size should follow changes in container element size
pointerboolfalseshow value pointer
pointerOptionsobject of objectsdefine pointer look, available option:{toplength, bottomlength, bottomwidth, color, stroke, stroke_width, stroke_linecap}

options about text

optiontypedefaultdescription
titlestring' 'gauge title
minfloat0min value
maxfloat100max value
hideMinMaxboolfalsehide min and max values
counterboolfalseanimate level number change
labelstring' 'text to show below value
decimalsint0number of digits after floating point
textRendererfuncnullfunction applied before rendering text
titleFontColorstring'#999999'color of gauge title
titleFontFamilystring'sans-serif'font family of gauge title
titlePositionstring'above'position of gauge title,'above' or 'below'
valueFontColorstring'#010101'color of label showing current value
valueFontFamilystring'Arial'font family of label showing current value
symbolstring' 'special symbol to show next to value
humanFriendlystringfalsefont family of label showing current value
labelFontColorstring'#b3b3b3'color of label showing label under value
valueMinFontSizeint16absolute minimum font size for the value
titleMinFontSizeint10absolute minimum font size for the title
labelMinFontSizeint10absolute minimum font size for the label
minLabelMinFontSizeint10absolute minimum font size for the minimum label
maxLabelMinFontSizeint10absolute minimum font size for the maximum label
hideValueboolfalsehide value text
humanFriendlyDecimalint0number of decimal places for our human friendly number to contain
formatNumberboolfalseformats numbers with commas where appropriate

options about animation

optiontypedefaultdescription
startAnimationTimeint700length of initial animation
startAnimationTypestring'>'type of initial animation (linear, >, <, <>, bounce)
refreshAnimationTimeint700length of refresh animation
refreshAnimationTypestring'>'type of refresh animation (linear, >, <, <>, bounce)

Methods

<vue-justgage ref="g1" id="g1" class="gauge"></vue-justgage>
  • draw: new a JustGage instance
this.$refs.g1.draw(options)
  • refresh:refresh gauge
this.$refs.g1.refresh(this.getRandomInt(0, 100));

PS: the method getRandomInt can be used directly as this.getRandomInt()


For detailed explanation on how things work, consult the docs for vue-justgage.