|
|
|
|
@ -5,10 +5,11 @@
|
|
|
|
|
</div> |
|
|
|
|
<div> |
|
|
|
|
<div |
|
|
|
|
class="flex v-center bar-item between" |
|
|
|
|
class="flex v-center bar-item between wrap" |
|
|
|
|
v-for="item in data" |
|
|
|
|
:size="size" |
|
|
|
|
:style="{ '--label-width': `${labelWidth}px` }" |
|
|
|
|
:position="labelPosition" |
|
|
|
|
> |
|
|
|
|
<span class="bar-item-label mr-10"> |
|
|
|
|
{{ item.label }} |
|
|
|
|
@ -18,7 +19,7 @@
|
|
|
|
|
class="bar-item_content-bar" |
|
|
|
|
:style="{ |
|
|
|
|
width: `${(item.value / max) * 100}%`, |
|
|
|
|
background: getColor(item.value / max * 100), |
|
|
|
|
background: getColor((item.value / max) * 100), |
|
|
|
|
}" |
|
|
|
|
></div> |
|
|
|
|
</div> |
|
|
|
|
@ -61,20 +62,23 @@ const props = defineProps({
|
|
|
|
|
}, |
|
|
|
|
color: { |
|
|
|
|
type: Object, |
|
|
|
|
default: "linear-gradient(270deg, #63e700 0%, #19674c 100%)" |
|
|
|
|
default: "linear-gradient(270deg, #63e700 0%, #19674c 100%)", |
|
|
|
|
}, |
|
|
|
|
labelWidth: { |
|
|
|
|
type: Number, |
|
|
|
|
default: 80 |
|
|
|
|
} |
|
|
|
|
default: 80, |
|
|
|
|
}, |
|
|
|
|
labelPosition: { |
|
|
|
|
type: String, |
|
|
|
|
default: "left", |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const max = ref(100); |
|
|
|
|
watch( |
|
|
|
|
() => props.data, |
|
|
|
|
() => { |
|
|
|
|
getMax() |
|
|
|
|
|
|
|
|
|
getMax(); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
@ -85,16 +89,16 @@ function getMax() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onMounted(() => { |
|
|
|
|
getMax() |
|
|
|
|
}) |
|
|
|
|
getMax(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
function getColor(val) { |
|
|
|
|
if (props.color instanceof String) { |
|
|
|
|
return props.color; |
|
|
|
|
} |
|
|
|
|
if (props.color instanceof Array) { |
|
|
|
|
const colors = [...props.color] |
|
|
|
|
colors.sort((a, b) => b.percentage - a.percentage) |
|
|
|
|
const colors = [...props.color]; |
|
|
|
|
colors.sort((a, b) => b.percentage - a.percentage); |
|
|
|
|
for (let i = 0; i < colors.length; i++) { |
|
|
|
|
if (val > colors[0].percentage) { |
|
|
|
|
return colors[0].color; |
|
|
|
|
@ -118,9 +122,7 @@ function getColor(val) {
|
|
|
|
|
} |
|
|
|
|
.bar-item { |
|
|
|
|
font-size: 17px; |
|
|
|
|
height: 32px; |
|
|
|
|
&[size="large"] { |
|
|
|
|
height: 42px; |
|
|
|
|
.bar-item_content { |
|
|
|
|
.bar-item_content-bar { |
|
|
|
|
height: 13px; |
|
|
|
|
@ -128,7 +130,6 @@ function getColor(val) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
&[size="small"] { |
|
|
|
|
height: 25px; |
|
|
|
|
font-size: 12px; |
|
|
|
|
} |
|
|
|
|
.bar-item-label { |
|
|
|
|
@ -138,6 +139,20 @@ function getColor(val) {
|
|
|
|
|
white-space: nowrap; |
|
|
|
|
text-overflow: ellipsis; |
|
|
|
|
} |
|
|
|
|
&[position="left"] { |
|
|
|
|
height: 32px; |
|
|
|
|
line-height: 32px; |
|
|
|
|
} |
|
|
|
|
&[position="top"] { |
|
|
|
|
margin-bottom: 4px; |
|
|
|
|
.bar-item-label { |
|
|
|
|
width: 100%; |
|
|
|
|
text-align: left; |
|
|
|
|
} |
|
|
|
|
.bar-item_content { |
|
|
|
|
width: calc(100% - 80px); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.bar-item_content { |
|
|
|
|
width: calc(100% - var(--label-width) - 80px); |
|
|
|
|
.bar-item_content-bar { |
|
|
|
|
|