Compare commits

...

19 Commits

Author SHA1 Message Date
6ce83e1fd8 update dist and lib 2020-05-06 14:15:15 +08:00
8e5f279b6e update version to 2.8.3 2020-05-06 14:15:02 +08:00
22afc8e787 update change log 2020-05-06 14:14:52 +08:00
eb78915c93 add showValue configuration 2020-05-06 14:13:49 +08:00
22c88c4ea5 add showOriginValue configuration 2020-05-06 14:13:34 +08:00
c98ca00179 Merge branch 'pr/76' into dev 2020-05-06 13:47:47 +08:00
c257ca6d9c update dist and lib 2020-05-06 13:20:20 +08:00
ce4cf0d342 add reverse configuration 2020-05-06 13:20:15 +08:00
7df0c0247a update version to 2.8.2 2020-05-06 13:20:04 +08:00
df2369dfe4 update change log 2020-05-06 13:19:55 +08:00
db52e8cdc0 update change log 2020-05-03 20:26:37 +08:00
f8e438b0c4 update version to 2.8.1 2020-05-03 20:26:33 +08:00
1a13bc08c5 update dist and lib 2020-05-03 20:15:35 +08:00
ba90fb2faa add rowGap configuration 2020-05-03 20:15:28 +08:00
7799ef3dae capsule-item > div add position prop 2020-04-30 13:38:11 +08:00
33456176f7 update dist 2020-04-28 18:41:09 +08:00
dd37ba167a format code 2020-04-28 16:43:44 +08:00
fdd1e243a7 active-ring-chart add showOriginalValue 2020-04-28 16:15:12 +08:00
57b6c726eb 1.add showVal prop;
2.optimize unit-label child style;
2020-04-27 18:19:20 +08:00
13 changed files with 881 additions and 437 deletions

View File

@ -1,9 +1,22 @@
# 2.8.0-alpha (2020-04-25) # 2.8.3-alpha (2020-05-06)
### Perfect ### Perfect
- **borderBox:** Add backgroundColor configuration. - **activeRingChart:** add `showOriginValue` configuration.
- **capsuleChart:** Improve compatibility. - **capsuleChart:** add `showValue` configuration.
# 2.8.2-alpha (2020-05-06)
### Perfect
- **borderBox8:** add `reverse` configuration.
# 2.8.1-alpha (2020-05-03)
### Perfect
- **digitalFlop:** Use `\n` to start a newline.
- **digitalFlop:** `rowGap` configuration.
# 2.7.4-alpha (2020-04-15) # 2.7.4-alpha (2020-04-15)

782
dist/datav.map.vue.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -28,7 +28,7 @@ export default {
default: () => ({}) default: () => ({})
} }
}, },
data () { data() {
return { return {
defaultConfig: { defaultConfig: {
/** /**
@ -94,7 +94,13 @@ export default {
* @type {String} * @type {String}
* @default animationFrame = 50 * @default animationFrame = 50
*/ */
animationFrame: 50 animationFrame: 50,
/**
* @description showOriginValue
* @type {Boolean}
* @default showOriginValue = false
*/
showOriginValue: false
}, },
mergedConfig: null, mergedConfig: null,
@ -107,34 +113,47 @@ export default {
} }
}, },
computed: { computed: {
digitalFlop () { digitalFlop() {
const { mergedConfig, activeIndex } = this const { mergedConfig, activeIndex } = this
if (!mergedConfig) return {} if (!mergedConfig) return {}
const { digitalFlopStyle, digitalFlopToFixed, data } = mergedConfig const {
digitalFlopStyle,
digitalFlopToFixed,
data,
showOriginValue
} = mergedConfig
const value = data.map(({ value }) => value) const value = data.map(({ value }) => value)
let displayValue
if (showOriginValue) {
displayValue = value[activeIndex]
} else {
const sum = value.reduce((all, v) => all + v, 0) const sum = value.reduce((all, v) => all + v, 0)
const percent = parseFloat(value[activeIndex] / sum * 100) || 0 const percent = parseFloat((value[activeIndex] / sum) * 100) || 0
displayValue = percent
}
return { return {
content: '{nt}%', content: showOriginValue ? '{nt}' : '{nt}%',
number: [percent], number: [displayValue],
style: digitalFlopStyle, style: digitalFlopStyle,
toFixed: digitalFlopToFixed toFixed: digitalFlopToFixed
} }
}, },
ringName () { ringName() {
const { mergedConfig, activeIndex } = this const { mergedConfig, activeIndex } = this
if (!mergedConfig) return '' if (!mergedConfig) return ''
return mergedConfig.data[activeIndex].name return mergedConfig.data[activeIndex].name
}, },
fontSize () { fontSize() {
const { mergedConfig } = this const { mergedConfig } = this
if (!mergedConfig) return '' if (!mergedConfig) return ''
@ -143,7 +162,7 @@ export default {
} }
}, },
watch: { watch: {
config () { config() {
const { animationHandler, mergeConfig, setRingOption } = this const { animationHandler, mergeConfig, setRingOption } = this
clearTimeout(animationHandler) clearTimeout(animationHandler)
@ -156,7 +175,7 @@ export default {
} }
}, },
methods: { methods: {
init () { init() {
const { initChart, mergeConfig, setRingOption } = this const { initChart, mergeConfig, setRingOption } = this
initChart() initChart()
@ -165,17 +184,20 @@ export default {
setRingOption() setRingOption()
}, },
initChart () { initChart() {
const { $refs } = this const { $refs } = this
this.chart = new Charts($refs['active-ring-chart']) this.chart = new Charts($refs['active-ring-chart'])
}, },
mergeConfig () { mergeConfig() {
const { defaultConfig, config } = this const { defaultConfig, config } = this
this.mergedConfig = deepMerge(deepClone(defaultConfig, true), config || {}) this.mergedConfig = deepMerge(
deepClone(defaultConfig, true),
config || {}
)
}, },
setRingOption () { setRingOption() {
const { getRingOption, chart, ringAnimation } = this const { getRingOption, chart, ringAnimation } = this
const option = getRingOption() const option = getRingOption()
@ -184,7 +206,7 @@ export default {
ringAnimation() ringAnimation()
}, },
getRingOption () { getRingOption() {
const { mergedConfig, getRealRadius } = this const { mergedConfig, getRealRadius } = this
const radius = getRealRadius() const radius = getRealRadius()
@ -206,7 +228,7 @@ export default {
color: mergedConfig.color color: mergedConfig.color
} }
}, },
getRealRadius (active = false) { getRealRadius(active = false) {
const { mergedConfig, chart } = this const { mergedConfig, chart } = this
const { radius, activeRadius, lineWidth } = mergedConfig const { radius, activeRadius, lineWidth } = mergedConfig
@ -217,14 +239,15 @@ export default {
let realRadius = active ? activeRadius : radius let realRadius = active ? activeRadius : radius
if (typeof realRadius !== 'number') realRadius = parseInt(realRadius) / 100 * maxRadius if (typeof realRadius !== 'number')
realRadius = (parseInt(realRadius) / 100) * maxRadius
const insideRadius = realRadius - halfLineWidth const insideRadius = realRadius - halfLineWidth
const outSideRadius = realRadius + halfLineWidth const outSideRadius = realRadius + halfLineWidth
return [insideRadius, outSideRadius] return [insideRadius, outSideRadius]
}, },
ringAnimation () { ringAnimation() {
let { activeIndex, getRingOption, chart, getRealRadius } = this let { activeIndex, getRingOption, chart, getRealRadius } = this
const radius = getRealRadius() const radius = getRealRadius()
@ -257,12 +280,12 @@ export default {
}, activeTimeGap) }, activeTimeGap)
} }
}, },
mounted () { mounted() {
const { init } = this const { init } = this
init() init()
}, },
beforeDestroy () { beforeDestroy() {
const { animationHandler } = this const { animationHandler } = this
clearTimeout(animationHandler) clearTimeout(animationHandler)

View File

@ -4,7 +4,7 @@
<defs> <defs>
<path <path
:id="path" :id="path"
:d="`M2.5, 2.5 L${width - 2.5}, 2.5 L${width - 2.5}, ${height - 2.5} L2.5, ${height - 2.5} L2.5, 2.5`" :d="pathD"
fill="transparent" fill="transparent"
/> />
<radialGradient <radialGradient
@ -25,7 +25,7 @@
<circle cx="0" cy="0" r="150" :fill="`url(#${gradient})`"> <circle cx="0" cy="0" r="150" :fill="`url(#${gradient})`">
<animateMotion <animateMotion
:dur="`${dur}s`" :dur="`${dur}s`"
:path="`M2.5, 2.5 L${width - 2.5}, 2.5 L${width - 2.5}, ${height - 2.5} L2.5, ${height - 2.5} L2.5, 2.5`" :path="pathD"
rotate="auto" rotate="auto"
repeatCount="indefinite" repeatCount="indefinite"
/> />
@ -85,6 +85,10 @@ export default {
backgroundColor: { backgroundColor: {
type: String, type: String,
default: 'transparent' default: 'transparent'
},
reverse: {
type: Boolean,
default: false
} }
}, },
data () { data () {
@ -105,6 +109,13 @@ export default {
const { width, height } = this const { width, height } = this
return (width + height - 5) * 2 return (width + height - 5) * 2
},
pathD () {
const { reverse, width, height } = this
if (reverse) return `M 2.5, 2.5 L 2.5, ${height - 2.5} L ${width - 2.5}, ${height - 2.5} L ${width - 2.5}, 2.5 L 2.5, 2.5`
return `M2.5, 2.5 L${width - 2.5}, 2.5 L${width - 2.5}, ${height - 2.5} L2.5, ${height - 2.5} L2.5, 2.5`
} }
}, },
watch: { watch: {

View File

@ -31,19 +31,27 @@
margin: 5px 0px; margin: 5px 0px;
border-radius: 5px; border-radius: 5px;
} }
.dv-capsule-chart .capsule-item div { .dv-capsule-chart .capsule-item .capsule-item-column {
position: relative;
height: 8px; height: 8px;
margin-top: 1px; margin-top: 1px;
border-radius: 5px; border-radius: 5px;
transition: all 0.3s; transition: all 0.3s;
display: flex;
justify-content: flex-end;
align-items: center;
}
.dv-capsule-chart .capsule-item .capsule-item-column .capsule-item-value {
font-size: 12px;
transform: translateX(100%);
} }
.dv-capsule-chart .unit-label { .dv-capsule-chart .unit-label {
height: 20px; height: 20px;
font-size: 12px; font-size: 12px;
position: relative;
display: flex; display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between; justify-content: space-between;
align-items: center;
} }
.dv-capsule-chart .unit-text { .dv-capsule-chart .unit-text {
text-align: right; text-align: right;

View File

@ -7,16 +7,23 @@
</div> </div>
<div class="capsule-container"> <div class="capsule-container">
<div class="capsule-item" v-for="(capsule, index) in capsuleLength" :key="index">
<div <div
class="capsule-item" class="capsule-item-column"
v-for="(capsule, index) in capsuleLength" :style="`width: ${capsule * 100}%; background-color: ${mergedConfig.colors[index % mergedConfig.colors.length]};`"
:key="index"
> >
<div :style="`width: ${capsule * 100}%; background-color: ${mergedConfig.colors[index % mergedConfig.colors.length]};`"></div> <div
v-if="mergedConfig.showValue"
class="capsule-item-value"
>{{ capsuleValue[index] }}</div>
</div>
</div> </div>
<div class="unit-label"> <div class="unit-label">
<div v-for="(label, index) in labelData" :key="label + index">{{ label }}</div> <div
v-for="(label, index) in labelData"
:key="label + index"
>{{ label }}</div>
</div> </div>
</div> </div>
@ -38,7 +45,7 @@ export default {
default: () => ({}) default: () => ({})
} }
}, },
data () { data() {
return { return {
defaultConfig: { defaultConfig: {
/** /**
@ -54,42 +61,61 @@ export default {
* @default color = ['#37a2da', '#32c5e9', '#67e0e3', '#9fe6b8', '#ffdb5c', '#ff9f7f', '#fb7293'] * @default color = ['#37a2da', '#32c5e9', '#67e0e3', '#9fe6b8', '#ffdb5c', '#ff9f7f', '#fb7293']
* @example color = ['#000', 'rgb(0, 0, 0)', 'rgba(0, 0, 0, 1)', 'red'] * @example color = ['#000', 'rgb(0, 0, 0)', 'rgba(0, 0, 0, 1)', 'red']
*/ */
colors: ['#37a2da', '#32c5e9', '#67e0e3', '#9fe6b8', '#ffdb5c', '#ff9f7f', '#fb7293'], colors: [
'#37a2da',
'#32c5e9',
'#67e0e3',
'#9fe6b8',
'#ffdb5c',
'#ff9f7f',
'#fb7293'
],
/** /**
* @description Chart unit * @description Chart unit
* @type {String} * @type {String}
* @default unit = '' * @default unit = ''
*/ */
unit: '' unit: '',
/**
* @description Show item value
* @type {Boolean}
* @default showValue = false
*/
showValue: false
}, },
mergedConfig: null, mergedConfig: null,
capsuleLength: [], capsuleLength: [],
labelData: [] capsuleValue: [],
labelData: [],
labelDataLength: []
} }
}, },
watch: { watch: {
config () { config() {
const { calcData } = this const { calcData } = this
calcData() calcData()
} }
}, },
methods: { methods: {
calcData () { calcData() {
const { mergeConfig, calcCapsuleLengthAndLabelData } = this const { mergeConfig, calcCapsuleLengthAndLabelData } = this
mergeConfig() mergeConfig()
calcCapsuleLengthAndLabelData() calcCapsuleLengthAndLabelData()
}, },
mergeConfig () { mergeConfig() {
let { config, defaultConfig } = this let { config, defaultConfig } = this
this.mergedConfig = deepMerge(deepClone(defaultConfig, true), config || {}) this.mergedConfig = deepMerge(
deepClone(defaultConfig, true),
config || {}
)
}, },
calcCapsuleLengthAndLabelData () { calcCapsuleLengthAndLabelData() {
const { data } = this.mergedConfig const { data } = this.mergedConfig
if (!data.length) return if (!data.length) return
@ -98,14 +124,24 @@ export default {
const maxValue = Math.max(...capsuleValue) const maxValue = Math.max(...capsuleValue)
this.capsuleLength = capsuleValue.map(v => maxValue ? v / maxValue : 0) this.capsuleValue = capsuleValue
this.capsuleLength = capsuleValue.map(v => (maxValue ? v / maxValue : 0))
const oneFifth = maxValue / 5 const oneFifth = maxValue / 5
this.labelData = Array.from(new Set(new Array(6).fill(0).map((v, i) => Math.ceil(i * oneFifth)))) const labelData = Array.from(
new Set(new Array(6).fill(0).map((v, i) => Math.ceil(i * oneFifth)))
)
this.labelData = labelData
this.labelDataLength = Array.from(labelData).map(v =>
maxValue ? v / maxValue : 0
)
} }
}, },
mounted () { mounted() {
const { calcData } = this const { calcData } = this
calcData() calcData()

View File

@ -53,6 +53,12 @@ export default {
* @example textAlign = 'center' | 'left' | 'right' * @example textAlign = 'center' | 'left' | 'right'
*/ */
textAlign: 'center', textAlign: 'center',
/**
* @description rowGap
* @type {Number}
@default rowGap = 0
*/
rowGap: 0,
/** /**
* @description Text style configuration * @description Text style configuration
* @type {Object} {CRender Class Style} * @type {Object} {CRender Class Style}
@ -124,7 +130,7 @@ export default {
}) })
}, },
getShape () { getShape () {
const { number, content, toFixed, textAlign } = this.mergedConfig const { number, content, toFixed, textAlign, rowGap } = this.mergedConfig
const [w, h] = this.renderer.area const [w, h] = this.renderer.area
@ -137,7 +143,8 @@ export default {
number, number,
content, content,
toFixed, toFixed,
position position,
rowGap
} }
}, },
getStyle () { getStyle () {

View File

@ -1,6 +1,6 @@
{ {
"name": "@jiaminghi/data-view", "name": "@jiaminghi/data-view",
"version": "2.8.0", "version": "2.8.3",
"author": "JiaMing <743192023@qq.com>", "author": "JiaMing <743192023@qq.com>",
"description": "Vue Large screen data display component library", "description": "Vue Large screen data display component library",
"main": "lib/index.js", "main": "lib/index.js",

View File

@ -28,7 +28,7 @@ export default {
default: () => ({}) default: () => ({})
} }
}, },
data () { data() {
return { return {
defaultConfig: { defaultConfig: {
/** /**
@ -94,7 +94,13 @@ export default {
* @type {String} * @type {String}
* @default animationFrame = 50 * @default animationFrame = 50
*/ */
animationFrame: 50 animationFrame: 50,
/**
* @description showOriginValue
* @type {Boolean}
* @default showOriginValue = false
*/
showOriginValue: false
}, },
mergedConfig: null, mergedConfig: null,
@ -107,34 +113,47 @@ export default {
} }
}, },
computed: { computed: {
digitalFlop () { digitalFlop() {
const { mergedConfig, activeIndex } = this const { mergedConfig, activeIndex } = this
if (!mergedConfig) return {} if (!mergedConfig) return {}
const { digitalFlopStyle, digitalFlopToFixed, data } = mergedConfig const {
digitalFlopStyle,
digitalFlopToFixed,
data,
showOriginValue
} = mergedConfig
const value = data.map(({ value }) => value) const value = data.map(({ value }) => value)
let displayValue
if (showOriginValue) {
displayValue = value[activeIndex]
} else {
const sum = value.reduce((all, v) => all + v, 0) const sum = value.reduce((all, v) => all + v, 0)
const percent = parseFloat(value[activeIndex] / sum * 100) || 0 const percent = parseFloat((value[activeIndex] / sum) * 100) || 0
displayValue = percent
}
return { return {
content: '{nt}%', content: showOriginValue ? '{nt}' : '{nt}%',
number: [percent], number: [displayValue],
style: digitalFlopStyle, style: digitalFlopStyle,
toFixed: digitalFlopToFixed toFixed: digitalFlopToFixed
} }
}, },
ringName () { ringName() {
const { mergedConfig, activeIndex } = this const { mergedConfig, activeIndex } = this
if (!mergedConfig) return '' if (!mergedConfig) return ''
return mergedConfig.data[activeIndex].name return mergedConfig.data[activeIndex].name
}, },
fontSize () { fontSize() {
const { mergedConfig } = this const { mergedConfig } = this
if (!mergedConfig) return '' if (!mergedConfig) return ''
@ -143,7 +162,7 @@ export default {
} }
}, },
watch: { watch: {
config () { config() {
const { animationHandler, mergeConfig, setRingOption } = this const { animationHandler, mergeConfig, setRingOption } = this
clearTimeout(animationHandler) clearTimeout(animationHandler)
@ -156,7 +175,7 @@ export default {
} }
}, },
methods: { methods: {
init () { init() {
const { initChart, mergeConfig, setRingOption } = this const { initChart, mergeConfig, setRingOption } = this
initChart() initChart()
@ -165,17 +184,20 @@ export default {
setRingOption() setRingOption()
}, },
initChart () { initChart() {
const { $refs } = this const { $refs } = this
this.chart = new Charts($refs['active-ring-chart']) this.chart = new Charts($refs['active-ring-chart'])
}, },
mergeConfig () { mergeConfig() {
const { defaultConfig, config } = this const { defaultConfig, config } = this
this.mergedConfig = deepMerge(deepClone(defaultConfig, true), config || {}) this.mergedConfig = deepMerge(
deepClone(defaultConfig, true),
config || {}
)
}, },
setRingOption () { setRingOption() {
const { getRingOption, chart, ringAnimation } = this const { getRingOption, chart, ringAnimation } = this
const option = getRingOption() const option = getRingOption()
@ -184,7 +206,7 @@ export default {
ringAnimation() ringAnimation()
}, },
getRingOption () { getRingOption() {
const { mergedConfig, getRealRadius } = this const { mergedConfig, getRealRadius } = this
const radius = getRealRadius() const radius = getRealRadius()
@ -206,7 +228,7 @@ export default {
color: mergedConfig.color color: mergedConfig.color
} }
}, },
getRealRadius (active = false) { getRealRadius(active = false) {
const { mergedConfig, chart } = this const { mergedConfig, chart } = this
const { radius, activeRadius, lineWidth } = mergedConfig const { radius, activeRadius, lineWidth } = mergedConfig
@ -217,14 +239,15 @@ export default {
let realRadius = active ? activeRadius : radius let realRadius = active ? activeRadius : radius
if (typeof realRadius !== 'number') realRadius = parseInt(realRadius) / 100 * maxRadius if (typeof realRadius !== 'number')
realRadius = (parseInt(realRadius) / 100) * maxRadius
const insideRadius = realRadius - halfLineWidth const insideRadius = realRadius - halfLineWidth
const outSideRadius = realRadius + halfLineWidth const outSideRadius = realRadius + halfLineWidth
return [insideRadius, outSideRadius] return [insideRadius, outSideRadius]
}, },
ringAnimation () { ringAnimation() {
let { activeIndex, getRingOption, chart, getRealRadius } = this let { activeIndex, getRingOption, chart, getRealRadius } = this
const radius = getRealRadius() const radius = getRealRadius()
@ -257,12 +280,12 @@ export default {
}, activeTimeGap) }, activeTimeGap)
} }
}, },
mounted () { mounted() {
const { init } = this const { init } = this
init() init()
}, },
beforeDestroy () { beforeDestroy() {
const { animationHandler } = this const { animationHandler } = this
clearTimeout(animationHandler) clearTimeout(animationHandler)

View File

@ -4,7 +4,7 @@
<defs> <defs>
<path <path
:id="path" :id="path"
:d="`M2.5, 2.5 L${width - 2.5}, 2.5 L${width - 2.5}, ${height - 2.5} L2.5, ${height - 2.5} L2.5, 2.5`" :d="pathD"
fill="transparent" fill="transparent"
/> />
<radialGradient <radialGradient
@ -25,7 +25,7 @@
<circle cx="0" cy="0" r="150" :fill="`url(#${gradient})`"> <circle cx="0" cy="0" r="150" :fill="`url(#${gradient})`">
<animateMotion <animateMotion
:dur="`${dur}s`" :dur="`${dur}s`"
:path="`M2.5, 2.5 L${width - 2.5}, 2.5 L${width - 2.5}, ${height - 2.5} L2.5, ${height - 2.5} L2.5, 2.5`" :path="pathD"
rotate="auto" rotate="auto"
repeatCount="indefinite" repeatCount="indefinite"
/> />
@ -85,6 +85,10 @@ export default {
backgroundColor: { backgroundColor: {
type: String, type: String,
default: 'transparent' default: 'transparent'
},
reverse: {
type: Boolean,
default: false
} }
}, },
data () { data () {
@ -105,6 +109,13 @@ export default {
const { width, height } = this const { width, height } = this
return (width + height - 5) * 2 return (width + height - 5) * 2
},
pathD () {
const { reverse, width, height } = this
if (reverse) return `M 2.5, 2.5 L 2.5, ${height - 2.5} L ${width - 2.5}, ${height - 2.5} L ${width - 2.5}, 2.5 L 2.5, 2.5`
return `M2.5, 2.5 L${width - 2.5}, 2.5 L${width - 2.5}, ${height - 2.5} L2.5, ${height - 2.5} L2.5, 2.5`
} }
}, },
watch: { watch: {

View File

@ -7,16 +7,23 @@
</div> </div>
<div class="capsule-container"> <div class="capsule-container">
<div class="capsule-item" v-for="(capsule, index) in capsuleLength" :key="index">
<div <div
class="capsule-item" class="capsule-item-column"
v-for="(capsule, index) in capsuleLength" :style="`width: ${capsule * 100}%; background-color: ${mergedConfig.colors[index % mergedConfig.colors.length]};`"
:key="index"
> >
<div :style="`width: ${capsule * 100}%; background-color: ${mergedConfig.colors[index % mergedConfig.colors.length]};`"></div> <div
v-if="mergedConfig.showValue"
class="capsule-item-value"
>{{ capsuleValue[index] }}</div>
</div>
</div> </div>
<div class="unit-label"> <div class="unit-label">
<div v-for="(label, index) in labelData" :key="label + index">{{ label }}</div> <div
v-for="(label, index) in labelData"
:key="label + index"
>{{ label }}</div>
</div> </div>
</div> </div>
@ -38,7 +45,7 @@ export default {
default: () => ({}) default: () => ({})
} }
}, },
data () { data() {
return { return {
defaultConfig: { defaultConfig: {
/** /**
@ -54,42 +61,61 @@ export default {
* @default color = ['#37a2da', '#32c5e9', '#67e0e3', '#9fe6b8', '#ffdb5c', '#ff9f7f', '#fb7293'] * @default color = ['#37a2da', '#32c5e9', '#67e0e3', '#9fe6b8', '#ffdb5c', '#ff9f7f', '#fb7293']
* @example color = ['#000', 'rgb(0, 0, 0)', 'rgba(0, 0, 0, 1)', 'red'] * @example color = ['#000', 'rgb(0, 0, 0)', 'rgba(0, 0, 0, 1)', 'red']
*/ */
colors: ['#37a2da', '#32c5e9', '#67e0e3', '#9fe6b8', '#ffdb5c', '#ff9f7f', '#fb7293'], colors: [
'#37a2da',
'#32c5e9',
'#67e0e3',
'#9fe6b8',
'#ffdb5c',
'#ff9f7f',
'#fb7293'
],
/** /**
* @description Chart unit * @description Chart unit
* @type {String} * @type {String}
* @default unit = '' * @default unit = ''
*/ */
unit: '' unit: '',
/**
* @description Show item value
* @type {Boolean}
* @default showValue = false
*/
showValue: false
}, },
mergedConfig: null, mergedConfig: null,
capsuleLength: [], capsuleLength: [],
labelData: [] capsuleValue: [],
labelData: [],
labelDataLength: []
} }
}, },
watch: { watch: {
config () { config() {
const { calcData } = this const { calcData } = this
calcData() calcData()
} }
}, },
methods: { methods: {
calcData () { calcData() {
const { mergeConfig, calcCapsuleLengthAndLabelData } = this const { mergeConfig, calcCapsuleLengthAndLabelData } = this
mergeConfig() mergeConfig()
calcCapsuleLengthAndLabelData() calcCapsuleLengthAndLabelData()
}, },
mergeConfig () { mergeConfig() {
let { config, defaultConfig } = this let { config, defaultConfig } = this
this.mergedConfig = deepMerge(deepClone(defaultConfig, true), config || {}) this.mergedConfig = deepMerge(
deepClone(defaultConfig, true),
config || {}
)
}, },
calcCapsuleLengthAndLabelData () { calcCapsuleLengthAndLabelData() {
const { data } = this.mergedConfig const { data } = this.mergedConfig
if (!data.length) return if (!data.length) return
@ -98,14 +124,24 @@ export default {
const maxValue = Math.max(...capsuleValue) const maxValue = Math.max(...capsuleValue)
this.capsuleLength = capsuleValue.map(v => maxValue ? v / maxValue : 0) this.capsuleValue = capsuleValue
this.capsuleLength = capsuleValue.map(v => (maxValue ? v / maxValue : 0))
const oneFifth = maxValue / 5 const oneFifth = maxValue / 5
this.labelData = Array.from(new Set(new Array(6).fill(0).map((v, i) => Math.ceil(i * oneFifth)))) const labelData = Array.from(
new Set(new Array(6).fill(0).map((v, i) => Math.ceil(i * oneFifth)))
)
this.labelData = labelData
this.labelDataLength = Array.from(labelData).map(v =>
maxValue ? v / maxValue : 0
)
} }
}, },
mounted () { mounted() {
const { calcData } = this const { calcData } = this
calcData() calcData()
@ -150,21 +186,30 @@ export default {
margin: 5px 0px; margin: 5px 0px;
border-radius: 5px; border-radius: 5px;
div { .capsule-item-column {
position: relative;
height: 8px; height: 8px;
margin-top: 1px; margin-top: 1px;
border-radius: 5px; border-radius: 5px;
transition: all 0.3s; transition: all 0.3s;
display: flex;
justify-content: flex-end;
align-items: center;
.capsule-item-value {
font-size: 12px;
transform: translateX(100%);
}
} }
} }
.unit-label { .unit-label {
height: 20px; height: 20px;
font-size: 12px; font-size: 12px;
position: relative;
display: flex; display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between; justify-content: space-between;
align-items: center;
} }
.unit-text { .unit-text {

View File

@ -53,6 +53,12 @@ export default {
* @example textAlign = 'center' | 'left' | 'right' * @example textAlign = 'center' | 'left' | 'right'
*/ */
textAlign: 'center', textAlign: 'center',
/**
* @description rowGap
* @type {Number}
@default rowGap = 0
*/
rowGap: 0,
/** /**
* @description Text style configuration * @description Text style configuration
* @type {Object} {CRender Class Style} * @type {Object} {CRender Class Style}
@ -124,7 +130,7 @@ export default {
}) })
}, },
getShape () { getShape () {
const { number, content, toFixed, textAlign } = this.mergedConfig const { number, content, toFixed, textAlign, rowGap } = this.mergedConfig
const [w, h] = this.renderer.area const [w, h] = this.renderer.area
@ -137,7 +143,8 @@ export default {
number, number,
content, content,
toFixed, toFixed,
position position,
rowGap
} }
}, },
getStyle () { getStyle () {