Circle prop:strokeColor support Array to support gradient ramp
This commit is contained in:
parent
64de8de933
commit
0264b7c4fd
3 changed files with 38 additions and 2 deletions
|
@ -15,6 +15,10 @@
|
||||||
<i-circle :percent="80" dashboard stroke-linecap="square">
|
<i-circle :percent="80" dashboard stroke-linecap="square">
|
||||||
<span class="demo-circle-inner" style="font-size:24px">80%</span>
|
<span class="demo-circle-inner" style="font-size:24px">80%</span>
|
||||||
</i-circle>
|
</i-circle>
|
||||||
|
<Divider></Divider>
|
||||||
|
<i-circle :percent="80" dashboard stroke-linecap="square" :stroke-color="['#108ee9', '#87d068']">
|
||||||
|
<span class="demo-circle-inner" style="font-size:24px">80%</span>
|
||||||
|
</i-circle>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
<template>
|
<template>
|
||||||
<div :style="circleSize" :class="wrapClasses">
|
<div :style="circleSize" :class="wrapClasses">
|
||||||
<svg viewBox="0 0 100 100">
|
<svg viewBox="0 0 100 100">
|
||||||
|
<defs v-if="showDefs">
|
||||||
|
<linearGradient :id="id" x1="100%" y1="0%" x2="0%" y2="0%">
|
||||||
|
<stop offset="0%" :stop-color="strokeColor[0]"></stop>
|
||||||
|
<stop offset="100%" :stop-color="strokeColor[1]"></stop>
|
||||||
|
</linearGradient>
|
||||||
|
</defs>
|
||||||
<path :d="pathString" :stroke="trailColor" :stroke-width="trailWidth" :fill-opacity="0" :style="trailStyle" :stroke-linecap="strokeLinecap" />
|
<path :d="pathString" :stroke="trailColor" :stroke-width="trailWidth" :fill-opacity="0" :style="trailStyle" :stroke-linecap="strokeLinecap" />
|
||||||
<path :d="pathString" :stroke-linecap="strokeLinecap" :stroke="strokeColor" :stroke-width="computedStrokeWidth" fill-opacity="0" :style="pathStyle" />
|
<path :d="pathString" :stroke-linecap="strokeLinecap" :stroke="strokeValue" :stroke-width="computedStrokeWidth" fill-opacity="0" :style="pathStyle" />
|
||||||
</svg>
|
</svg>
|
||||||
<div :class="innerClasses">
|
<div :class="innerClasses">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
|
@ -11,6 +17,7 @@
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { oneOf } from '../../utils/assist';
|
import { oneOf } from '../../utils/assist';
|
||||||
|
import random from '../../utils/random_str';
|
||||||
|
|
||||||
const prefixCls = 'ivu-chart-circle';
|
const prefixCls = 'ivu-chart-circle';
|
||||||
|
|
||||||
|
@ -30,7 +37,7 @@
|
||||||
default: 6
|
default: 6
|
||||||
},
|
},
|
||||||
strokeColor: {
|
strokeColor: {
|
||||||
type: String,
|
type: [String, Array],
|
||||||
default: '#2d8cf0'
|
default: '#2d8cf0'
|
||||||
},
|
},
|
||||||
strokeLinecap: {
|
strokeLinecap: {
|
||||||
|
@ -52,6 +59,11 @@
|
||||||
default: false
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
id: `ivu-chart-circle-${random(3)}`
|
||||||
|
};
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
circleSize () {
|
circleSize () {
|
||||||
return {
|
return {
|
||||||
|
@ -112,6 +124,16 @@
|
||||||
},
|
},
|
||||||
innerClasses () {
|
innerClasses () {
|
||||||
return `${prefixCls}-inner`;
|
return `${prefixCls}-inner`;
|
||||||
|
},
|
||||||
|
strokeValue () {
|
||||||
|
let color = this.strokeColor;
|
||||||
|
if (typeof this.strokeColor !== 'string') {
|
||||||
|
color = `url(#${this.id})`;
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
},
|
||||||
|
showDefs () {
|
||||||
|
return typeof this.strokeColor !== 'string';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
10
src/utils/random_str.js
Normal file
10
src/utils/random_str.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
// 生成随机字符串
|
||||||
|
export default function (len = 32) {
|
||||||
|
const $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
|
||||||
|
const maxPos = $chars.length;
|
||||||
|
let str = '';
|
||||||
|
for (let i = 0; i < len; i++) {
|
||||||
|
str += $chars.charAt(Math.floor(Math.random() * maxPos));
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue