add Decoration 12

This commit is contained in:
jiaming743 2020-09-09 17:12:42 +08:00
parent 654c461a1b
commit baeafe243f
3 changed files with 311 additions and 0 deletions

View File

@ -0,0 +1,5 @@
import Decoration12 from './src/main.vue'
export default function (Vue) {
Vue.component(Decoration12.name, Decoration12)
}

View File

@ -0,0 +1,304 @@
<template>
<div class="dv-decoration-12" :ref="ref">
<svg :width="width" :height="height">
<defs>
<g :id="gId">
<path
:stroke="pathColor[i]"
:stroke-width="width / 2"
fill="transparent"
v-for="(d, i) in pathD"
:key="d"
:d="d"
/>
</g>
<radialGradient
:id="gradientId"
cx="50%" cy="50%" r="50%"
>
<stop offset="0%" stop-color="transparent" stop-opacity="1" />
<stop offset="100%" :stop-color="fade(mergedColor[1] || defaultColor[1], 30)" stop-opacity="1" />
</radialGradient>
</defs>
<circle
v-for="r in circleR"
:key="r"
:r="r"
:cx="x"
:cy="y"
:stroke="mergedColor[1]"
:stroke-width="0.5"
fill="transparent"
/>
<circle
r="1"
:cx="x"
:cy="y"
stroke="transparent"
:fill="`url(#${gradientId})`"
>
<animate
attributeName="r"
:values="`1;${width / 2}`"
:dur="`${haloDur}s`"
repeatCount="indefinite"
/>
<animate
attributeName="opacity"
values="1;0"
:dur="`${haloDur}s`"
repeatCount="indefinite"
/>
</circle>
<circle
r="2"
:cx="x"
:cy="y"
:fill="mergedColor[1]"
/>
<g v-if="showSplitLine">
<polyline
v-for="p in splitLinePoints"
:key="p"
:points="p"
:stroke="mergedColor[1]"
:stroke-width="0.5"
opacity="0.5"
/>
</g>
<path
v-for="d in arcD"
:key="d"
:d="d"
:stroke="mergedColor[1]"
stroke-width="2"
fill="transparent"
/>
<use :xlink:href="`#${gId}`">
<animateTransform
attributeName="transform"
type="rotate"
:values="`0, ${x} ${y};360, ${x} ${y}`"
:dur="`${scanDur}s`"
repeatCount="indefinite"
/>
</use>
</svg>
<div class="decoration-content">
<slot></slot>
</div>
</div>
</template>
<script>
import autoResize from '../../../mixin/autoResize'
import { uuid } from '../../../util/index'
import { deepMerge } from '@jiaminghi/charts/lib/util/index'
import { deepClone, getCircleRadianPoint } from '@jiaminghi/c-render/lib/plugin/util'
import { fade } from '@jiaminghi/color'
export default {
name: 'DvDecoration12',
mixins: [autoResize],
props: {
color: {
type: Array,
default: () => ([])
},
/**
* @description Scan animation dur
*/
scanDur: {
type: Number,
default: 3
},
/**
* @description Halo animation dur
*/
haloDur: {
type: Number,
default: 2
}
},
data () {
const id = uuid()
return {
ref: 'decoration-12',
gId: `decoration-12-g-${id}`,
gradientId: `decoration-12-gradient-${id}`,
defaultColor: ['#2783ce', '#2cf7fe'],
mergedColor: [],
pathD: [],
pathColor: [],
circleR: [],
splitLinePoints: [],
arcD: [],
segment: 30,
sectorAngle: Math.PI / 3,
ringNum: 3,
ringWidth: 1,
showSplitLine: true
}
},
watch: {
color () {
const { mergeColor } = this
mergeColor()
}
},
computed: {
x () {
const { width } = this
return width / 2
},
y () {
const { height } = this
return height / 2
}
},
methods: {
init () {
const { mergeColor, calcPathD, calcPathColor, calcCircleR, calcSplitLinePoints, calcArcD } = this
mergeColor()
calcPathD()
calcPathColor()
calcCircleR()
calcSplitLinePoints()
calcArcD()
},
mergeColor () {
const { color, defaultColor } = this
this.mergedColor = deepMerge(deepClone(defaultColor, true), color || [])
},
calcPathD () {
const { x, y, width, segment, sectorAngle } = this
const startAngle = -Math.PI / 2
const angleGap = sectorAngle / segment
const r = width / 4
let lastEndPoints = getCircleRadianPoint(x, y, r, startAngle)
this.pathD = new Array(segment)
.fill('')
.map((_, i) => {
const endPoints = getCircleRadianPoint(x, y, r, startAngle - (i + 1) * angleGap).map(_ => _.toFixed(5))
const d = `M${lastEndPoints.join(',')} A${r}, ${r} 0 0 0 ${endPoints.join(',')}`
lastEndPoints = endPoints
return d
})
},
calcPathColor () {
const { mergedColor: [color], segment } = this
const colorGap = 100 / (segment - 1)
this.pathColor = new Array(segment)
.fill(color)
.map((_, i) => fade(color, 100 - i * colorGap))
},
calcCircleR () {
const { segment, ringNum, width, ringWidth } = this
const radiusGap = (width / 2 - ringWidth / 2) / ringNum
this.circleR = new Array(ringNum)
.fill(0)
.map((_, i) => radiusGap * (i + 1))
},
calcSplitLinePoints () {
const { x, y, width } = this
const angleGap = Math.PI / 6
const r = width / 2
this.splitLinePoints = new Array(6)
.fill('')
.map((_, i) => {
const startAngle = angleGap * (i + 1)
const endAngle = startAngle + Math.PI
const startPoint = getCircleRadianPoint(x, y, r, startAngle)
const endPoint = getCircleRadianPoint(x, y, r, endAngle)
return `${startPoint.join(',')} ${endPoint.join(',')}`
})
},
calcArcD () {
const { x, y, width } = this
const angleGap = Math.PI / 6
const r = width / 2 - 1
this.arcD = new Array(4)
.fill('')
.map((_, i) => {
const startAngle = angleGap * (3 * i + 1)
const endAngle = startAngle + angleGap
const startPoint = getCircleRadianPoint(x, y, r, startAngle)
const endPoint = getCircleRadianPoint(x, y, r, endAngle)
return `M${startPoint.join(',')} A${x}, ${y} 0 0 1 ${endPoint.join(',')}`
})
},
afterAutoResizeMixinInit () {
const { init } = this
init()
},
fade
}
}
</script>
<style lang="less">
.dv-decoration-12 {
position: relative;
width: 100%;
height: 100%;
display: flex;
.decoration-content {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
}
</style>

View File

@ -31,6 +31,7 @@ import decoration8 from './components/decoration8/index'
import decoration9 from './components/decoration9/index'
import decoration10 from './components/decoration10/index'
import decoration11 from './components/decoration11/index'
import decoration12 from './components/decoration12/index'
// charts
import charts from './components/charts/index'
@ -80,6 +81,7 @@ export default function (Vue) {
Vue.use(decoration9)
Vue.use(decoration10)
Vue.use(decoration11)
Vue.use(decoration12)
// charts
Vue.use(charts)