use Eslint formatter code

This commit is contained in:
jiaming743 2019-06-27 19:28:07 +08:00
parent 3cde8e553a
commit 16a31ed68f
15 changed files with 537 additions and 29 deletions

View File

@ -128,7 +128,7 @@ export default {
return mergedConfig.data[activeIndex].name
},
fontSize () {
const { mergedConfig, activeIndex } = this
const { mergedConfig } = this
if (!mergedConfig) return ''
@ -178,7 +178,7 @@ export default {
ringAnimation()
},
getRingOption () {
const { mergedConfig, getRealRadius, chart } = this
const { mergedConfig, getRealRadius } = this
const radius = getRealRadius()
@ -217,7 +217,7 @@ export default {
return [insideRadius, outSideRadius]
},
ringAnimation () {
let { animation, activeIndex, getRingOption, chart, getRealRadius } = this
let { activeIndex, getRingOption, chart, getRealRadius } = this
const radius = getRealRadius()
const active = getRealRadius(true)

View File

@ -34,7 +34,7 @@
</defs>
<use
stroke="#235fa7"
stroke="#235fa7"
stroke-width="1"
:xlink:href="`#${path}`"
/>

View File

@ -19,7 +19,7 @@ export default {
props: {
option: {
type: Object,
default: {}
default: () => ({})
}
},
data () {
@ -42,7 +42,7 @@ export default {
methods: {
afterAutoResizeMixinInit () {
const { initChart } = this
initChart()
},
initChart () {

View File

@ -0,0 +1,221 @@
<template>
<div class="dv-conical-column-chart" :ref="ref">
<svg :width="width" :height="height">
<g
v-for="(item, i) in column"
:key="i"
>
<path
:d="item.d"
:fill="mergedConfig.columnColor"
/>
<text
:style="`fontSize:${mergedConfig.fontSize}px`"
:fill="mergedConfig.textColor"
:x="item.x"
:y="height - 4"
>
{{ item.name }}
</text>
<image
v-if="mergedConfig.img.length"
:xlink:href="mergedConfig.img[i % mergedConfig.img.length]"
:width="mergedConfig.imgSideLength"
:height="mergedConfig.imgSideLength"
:x="item.x - mergedConfig.imgSideLength / 2"
:y="item.y - mergedConfig.imgSideLength"
/>
<text
v-if="mergedConfig.showValue"
:style="`fontSize:${mergedConfig.fontSize}px`"
:fill="mergedConfig.textColor"
:x="item.x"
:y="item.textY"
>
{{ item.value }}
</text>
</g>
</svg>
</div>
</template>
<script>
import autoResize from '../../mixins/autoResize.js'
import { deepMerge } from '@jiaminghi/charts/lib/util/index'
import { deepClone } from '@jiaminghi/c-render/lib/plugin/util'
export default {
name: 'ConicalColumnChart',
mixins: [autoResize],
props: {
config: {
type: Object,
default: () => ({})
}
},
data () {
return {
ref: 'conical-column-chart',
defaultConfig: {
/**
* @description Chart data
* @type {Array<Object>}
* @default data = []
*/
data: [],
/**
* @description Chart img
* @type {Array<String>}
* @default img = []
*/
img: [],
/**
* @description Chart font size
* @type {Number}
* @default fontSize = 12
*/
fontSize: 12,
/**
* @description Img side length
* @type {Number}
* @default imgSideLength = 30
*/
imgSideLength: 30,
/**
* @description Column color
* @type {String}
* @default columnColor = 'rgba(0, 194, 255, 0.4)'
*/
columnColor: 'rgba(0, 194, 255, 0.4)',
/**
* @description Text color
* @type {String}
* @default textColor = '#fff'
*/
textColor: '#fff',
/**
* @description Show value
* @type {Boolean}
* @default showValue = false
*/
showValue: false
},
mergedConfig: null,
column: []
}
},
watch: {
config () {
const { calcData } = this
calcData()
}
},
methods: {
afterAutoResizeMixinInit () {
const { calcData } = this
calcData()
},
onResize () {
const { calcData } = this
calcData()
},
calcData () {
const { mergeConfig, initData, calcSVGPath } = this
mergeConfig()
initData()
calcSVGPath()
},
mergeConfig () {
const { defaultConfig, config } = this
this.mergedConfig = deepMerge(deepClone(defaultConfig, true), config || {})
},
initData () {
const { mergedConfig } = this
let { data } = mergedConfig
data = deepClone(data, true)
data.sort(({ value: a }, { value: b }) => {
if (a > b) return -1
if (a < b) return 1
if (a === b) return 0
})
const max = data[0] ? data[0].value : 10
data = data.map(item => ({
...item,
percent: item.value / max
}))
mergedConfig.data = data
},
calcSVGPath () {
const { mergedConfig, width, height } = this
const { imgSideLength, fontSize, data } = mergedConfig
const itemNum = data.length
const gap = width / (itemNum + 1)
const useAbleHeight = height - imgSideLength - fontSize - 5
const svgBottom = height - fontSize - 5
this.column = data.map((item, i) => {
const { percent } = item
const middleXPos = gap * (i + 1)
const leftXPos = gap * i
const rightXpos = gap * (i + 2)
const middleYPos = svgBottom - useAbleHeight * percent
const controlYPos = useAbleHeight * percent * 0.6 + middleYPos
const d = `
M${leftXPos}, ${svgBottom}
Q${middleXPos}, ${controlYPos} ${middleXPos},${middleYPos}
M${middleXPos},${middleYPos}
Q${middleXPos}, ${controlYPos} ${rightXpos},${svgBottom}
L${leftXPos}, ${svgBottom}
Z
`
const textY = (svgBottom + middleYPos) / 2 + fontSize / 2
return {
...item,
d,
x: middleXPos,
y: middleYPos,
textY
}
})
console.warn(this.column)
}
}
}
</script>
<style lang="less">
.dv-conical-column-chart {
width: 100%;
height: 100%;
text {
text-anchor: middle;
}
}
</style>

View File

@ -114,7 +114,7 @@ export default {
methods: {
afterAutoResizeMixinInit () {
const { calcSVGData } = this
calcSVGData()
},
calcSVGData () {
@ -158,7 +158,7 @@ export default {
},
onResize () {
const { calcSVGData } = this
calcSVGData()
}
}

View File

@ -55,7 +55,7 @@ export default {
methods: {
afterAutoResizeMixinInit () {
const { calcSVGData } = this
calcSVGData()
},
calcSVGData () {
@ -89,7 +89,7 @@ export default {
},
onResize () {
const { calcSVGData } = this
calcSVGData()
}
}

View File

@ -59,13 +59,13 @@ export default {
line2Points: '',
line1Length: 0,
line2Length: 0,
line2Length: 0
}
},
methods: {
afterAutoResizeMixinInit () {
const { calcSVGData } = this
calcSVGData()
},
calcSVGData () {
@ -95,7 +95,7 @@ export default {
},
onResize () {
const { calcSVGData } = this
calcSVGData()
}
}

View File

@ -71,7 +71,7 @@ export default {
methods: {
afterAutoResizeMixinInit () {
const { calcSVGData } = this
calcSVGData()
},
calcSVGData () {
@ -114,7 +114,7 @@ export default {
},
onResize () {
const { calcSVGData } = this
calcSVGData()
}
}

View File

@ -39,7 +39,7 @@ export default {
},
data () {
return {
ref: 'decoration-8',
ref: 'decoration-8'
}
},
methods: {

View File

@ -163,7 +163,7 @@ export default {
props: {
config: {
type: Object,
default: {}
default: () => ({})
},
dev: {
type: Boolean,
@ -239,7 +239,7 @@ export default {
/**
* @description Relative points position
* @type {Boolean}
* @default relative = true
* @default relative = true
*/
relative: true,
/**
@ -375,7 +375,6 @@ export default {
const { calcData } = this
calcData()
},
onResize () {
const { calcData } = this

View File

@ -24,7 +24,7 @@
<div
class="row-item"
v-for="(row, ri) in rows"
:key="row.toString() + row.rowIndex"
:key="row.toString() + row.scroll"
:style="`
height: ${heights[ri]}px;
line-height: ${heights[ri]}px;
@ -78,7 +78,6 @@ export default {
* @description Board data
* @type {Array<Array>}
* @default data = []
* @example header = [['column1Row1', 'column2Row1', 'column3Row1']]
*/
data: [],
/**
@ -232,7 +231,7 @@ export default {
this.header = header
},
calcRowsData () {
let { data, index, headerBGC } = this.mergedConfig
let { data, index, headerBGC, rowNum } = this.mergedConfig
if (index) {
data = data.map((row, i) => {
@ -248,6 +247,14 @@ export default {
data = data.map((ceils, i) => ({ ceils, rowIndex: i }))
const rowLength = data.length
if (rowLength > rowNum && rowLength < 2 * rowNum) {
data = [...data, ...data]
}
data = data.map((d, i) => ({ ...d, scroll: i }))
this.rowsData = data
this.rows = data
},

View File

@ -0,0 +1,283 @@
<template>
<div class="dv-scroll-ranking-board" :ref="ref">
<div
class="row-item"
v-for="(item, i) in rows"
:key="item.toString() + item.scroll"
:style="`height: ${heights[i]}px;`"
>
<div class="ranking-info">
<div class="rank">No.{{ item.ranking }}</div>
<div class="info-name">{{ item.name }}</div>
<div class="ranking-value">{{ item.value }}</div>
</div>
<div class="ranking-column">
<div
class="inside-column"
:style="`width: ${item.percent}%;`"
>
<div class="shine" />
</div>
</div>
</div>
</div>
</template>
<script>
import autoResize from '../../mixins/autoResize.js'
import { deepMerge } from '@jiaminghi/charts/lib/util/index'
import { deepClone } from '@jiaminghi/c-render/lib/plugin/util'
export default {
name: 'ScrollRankingBoard',
mixins: [autoResize],
props: {
config: {
type: Object,
default: () => ({})
}
},
data () {
return {
ref: 'scroll-ranking-board',
defaultConfig: {
/**
* @description Board data
* @type {Array<Object>}
* @default data = []
*/
data: [],
/**
* @description Row num
* @type {Number}
* @default rowNum = 5
*/
rowNum: 5,
/**
* @description Scroll wait time
* @type {Number}
* @default waitTime = 2000
*/
waitTime: 2000,
/**
* @description Carousel type
* @type {String}
* @default carousel = 'single'
* @example carousel = 'single' | 'page'
*/
carousel: 'single'
},
mergedConfig: null,
rowsData: [],
rows: [],
heights: [],
animationIndex: 0,
animationHandler: ''
}
},
watch: {
config () {
const { stopAnimation, calcData } = this
stopAnimation()
calcData()
}
},
methods: {
afterAutoResizeMixinInit () {
const { calcData } = this
calcData()
},
onResize () {
const { mergedConfig, calcHeights } = this
if (!mergedConfig) return
calcHeights(true)
},
calcData () {
const { mergeConfig, calcRowsData } = this
mergeConfig()
calcRowsData()
const { calcHeights } = this
calcHeights()
const { animation } = this
animation(true)
},
mergeConfig () {
let { config, defaultConfig } = this
this.mergedConfig = deepMerge(deepClone(defaultConfig, true), config || {})
},
calcRowsData () {
let { data, rowNum } = this.mergedConfig
data.sort(({ value: a }, { value: b }) => {
if (a > b) return -1
if (a < b) return 1
if (a === b) return 0
})
const value = data.map(({ value }) => value)
const max = Math.max(...value) || 0
data = data.map((row, i) => ({ ...row, ranking: i + 1, percent: row.value / max * 100 }))
const rowLength = data.length
if (rowLength > rowNum && rowLength < 2 * rowNum) {
data = [...data, ...data]
}
data = data.map((d, i) => ({ ...d, scroll: i }))
this.rowsData = data
this.rows = data
},
calcHeights (onresize = false) {
const { height, mergedConfig } = this
const { rowNum, data } = mergedConfig
const avgHeight = height / rowNum
this.avgHeight = avgHeight
if (!onresize) this.heights = new Array(data.length).fill(avgHeight)
},
async animation (start = false) {
let { avgHeight, animationIndex, mergedConfig, rowsData, animation } = this
const { waitTime, carousel, rowNum } = mergedConfig
const rowLength = rowsData.length
if (rowNum >= rowLength) return
if (start) await new Promise(resolve => setTimeout(resolve, waitTime))
const animationNum = carousel === 'single' ? 1 : rowNum
let rows = rowsData.slice(animationIndex)
rows.push(...rowsData.slice(0, animationIndex))
this.rows = rows
this.heights = new Array(rowLength).fill(avgHeight)
await new Promise(resolve => setTimeout(resolve, 300))
this.heights.splice(0, animationNum, ...new Array(animationNum).fill(0))
animationIndex += animationNum
const back = animationIndex - rowLength
if (back >= 0) animationIndex = back
this.animationIndex = animationIndex
this.animationHandler = setTimeout(animation, waitTime - 300)
},
stopAnimation () {
const { animationHandler } = this
if (!animationHandler) return
clearTimeout(animationHandler)
}
},
destroyed () {
const { stopAnimation } = this
stopAnimation()
}
}
</script>
<style lang="less">
@color: #1370fb;
.dv-scroll-ranking-board {
width: 100%;
height: 100%;
color: #fff;
overflow: hidden;
.row-item {
transition: all 0.3s;
display: flex;
flex-direction: column;
justify-content: center;
overflow: hidden;
}
.ranking-info {
display: flex;
width: 100%;
font-size: 13px;
.rank {
width: 40px;
color: @color;
}
.info-name {
flex: 1;
}
}
.ranking-column {
border-bottom: 2px solid fade(@color, 50);
margin-top: 5px;
.inside-column {
position: relative;
height: 6px;
background-color: @color;
margin-bottom: 2px;
border-radius: 1px;
overflow: hidden;
}
.shine {
position: absolute;
left: 0%;
top: 2px;
height: 2px;
width: 50px;
transform: translateX(-100%);
background: radial-gradient(rgb(40, 248, 255) 5%, transparent 80%);
animation: shine 3s ease-in-out infinite;
}
}
}
@keyframes shine {
85% {
left: 0%;
transform: translateX(-100%);
}
100% {
left: 100%;
transform: translateX(0%);
}
}
</style>

View File

@ -266,7 +266,7 @@ export default {
const firstPoint = points[0]
const lastPoint = points.slice(-1)[0]
const [w, h] = area
const h = area[1]
ctx.lineTo(lastPoint[0], h)
ctx.lineTo(firstPoint[0], h)
@ -285,8 +285,6 @@ export default {
const w = render.area[0]
waves.forEach(graph => {
const reset = repeat % 2 === 0
graph.attr('style', { translate: [0, 0] })
graph.animation('style', {
@ -309,7 +307,7 @@ export default {
init()
},
beforeDestroy () {
const { calcData, render } = this
const { render } = this
render.delAllGraph()

View File

@ -54,7 +54,7 @@ export default {
window.addEventListener('resize', debounceInitWHFun)
},
unbindDomResizeCallback () {
const { domObserver, debounceInitWHFun } = this
let { domObserver, debounceInitWHFun } = this
domObserver.disconnect()
domObserver.takeRecords()
@ -73,4 +73,4 @@ export default {
unbindDomResizeCallback()
}
}
}

View File

@ -36,4 +36,4 @@ export function getPointDistance (pointOne, pointTwo) {
const minusY = Math.abs(pointOne[1] - pointTwo[1])
return Math.sqrt(minusX * minusX + minusY * minusY)
}
}