Blame view

src/components/circle/circle.vue 4.05 KB
7fa943eb   梁灏   init
1
2
3
  <template>
      <div :style="circleSize" :class="wrapClasses">
          <svg viewBox="0 0 100 100">
b40e2e96   梁灏   Circle add prop d...
4
5
              <path :d="pathString" :stroke="trailColor" :stroke-width="trailWidth" :fill-opacity="0" :style="trailStyle" />
              <path :d="pathString" :stroke-linecap="strokeLinecap" :stroke="strokeColor" :stroke-width="computedStrokeWidth" fill-opacity="0" :style="pathStyle" />
7fa943eb   梁灏   init
6
7
8
9
10
11
12
13
14
15
16
17
          </svg>
          <div :class="innerClasses">
              <slot></slot>
          </div>
      </div>
  </template>
  <script>
      import { oneOf } from '../../utils/assist';
  
      const prefixCls = 'ivu-chart-circle';
  
      export default {
e6508e27   梁灏   update Circle & S...
18
          name: 'iCircle',
7fa943eb   梁灏   init
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
          props: {
              percent: {
                  type: Number,
                  default: 0
              },
              size: {
                  type: Number,
                  default: 120
              },
              strokeWidth: {
                  type: Number,
                  default: 6
              },
              strokeColor: {
                  type: String,
                  default: '#2db7f5'
              },
              strokeLinecap: {
                  validator (value) {
                      return oneOf(value, ['square', 'round']);
                  },
                  default: 'round'
              },
              trailWidth: {
                  type: Number,
                  default: 5
              },
              trailColor: {
                  type: String,
                  default: '#eaeef2'
b40e2e96   梁灏   Circle add prop d...
49
50
51
52
              },
              dashboard: {
                  type: Boolean,
                  default: false
7fa943eb   梁灏   init
53
54
55
56
57
58
59
60
61
              }
          },
          computed: {
              circleSize () {
                  return {
                      width: `${this.size}px`,
                      height: `${this.size}px`
                  };
              },
b40e2e96   梁灏   Circle add prop d...
62
63
64
              computedStrokeWidth () {
                  return this.percent === 0 && this.dashboard ? 0 : this.strokeWidth;
              },
7fa943eb   梁灏   init
65
66
67
68
              radius () {
                  return 50 - this.strokeWidth / 2;
              },
              pathString () {
b40e2e96   梁灏   Circle add prop d...
69
70
71
72
73
74
75
76
77
                  if (this.dashboard) {
                      return `M 50,50 m 0,${this.radius}
                      a ${this.radius},${this.radius} 0 1 1 0,-${2 * this.radius}
                      a ${this.radius},${this.radius} 0 1 1 0,${2 * this.radius}`;
                  } else {
                      return `M 50,50 m 0,-${this.radius}
                      a ${this.radius},${this.radius} 0 1 1 0,${2 * this.radius}
                      a ${this.radius},${this.radius} 0 1 1 0,-${2 * this.radius}`;
                  }
7fa943eb   梁灏   init
78
79
80
81
              },
              len () {
                  return Math.PI * 2 * this.radius;
              },
b40e2e96   梁灏   Circle add prop d...
82
83
84
85
86
87
88
89
90
91
92
              trailStyle () {
                  let style = {};
                  if (this.dashboard) {
                      style = {
                          'stroke-dasharray': `${this.len - 75}px ${this.len}px`,
                          'stroke-dashoffset': `-${75 / 2}px`,
                          'transition': 'stroke-dashoffset .3s ease 0s, stroke-dasharray .3s ease 0s, stroke .3s'
                      }
                  }
                  return style;
              },
7fa943eb   梁灏   init
93
              pathStyle () {
b40e2e96   梁灏   Circle add prop d...
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
                  let style = {};
                  if (this.dashboard) {
                      style = {
                          'stroke-dasharray': `${(this.percent / 100) * (this.len - 75)}px ${this.len}px`,
                          'stroke-dashoffset': `-${75 / 2}px`,
                          'transition': 'stroke-dashoffset .3s ease 0s, stroke-dasharray .3s ease 0s, stroke .3s, stroke-width .06s ease .3s'
                      };
                  } else {
                      style = {
                          'stroke-dasharray': `${this.len}px ${this.len}px`,
                          'stroke-dashoffset': `${((100 - this.percent) / 100 * this.len)}px`,
                          'transition': 'stroke-dashoffset 0.3s ease 0s, stroke 0.3s ease'
                      };
                  }
                  return style;
7fa943eb   梁灏   init
109
110
111
112
113
114
115
116
              },
              wrapClasses () {
                  return `${prefixCls}`;
              },
              innerClasses () {
                  return `${prefixCls}-inner`;
              }
          }
b0893113   jingsam   :art: add eslint
117
118
      };
  </script>