2024-01-11 13:42:20 +00:00
|
|
|
<template>
|
|
|
|
<div :class="cx('root')" role="meter" :aria-valuemin="min" :aria-valuemax="max" :aria-valuenow="totalPercent" v-bind="ptm('root')" data-pc-name="metergroup">
|
2024-01-18 12:53:33 +00:00
|
|
|
<slot v-if="labelPosition === 'start'" name="label" :value="value" :totalPercent="totalPercent" :percentages="percentages">
|
|
|
|
<MeterGroupLabel :value="value" :labelPosition="labelPosition" :labelOrientation="labelOrientation" :unstyled="unstyled" :pt="pt" />
|
2024-01-11 13:42:20 +00:00
|
|
|
</slot>
|
2024-01-18 12:53:33 +00:00
|
|
|
<slot name="start" :value="value" :totalPercent="totalPercent" :percentages="percentages" />
|
2024-01-11 13:42:20 +00:00
|
|
|
<div :class="cx('metercontainer')" v-bind="ptm('metercontainer')">
|
|
|
|
<template v-for="(val, index) in value" :key="index">
|
2024-01-18 12:53:33 +00:00
|
|
|
<slot name="meter" :value="val" :index="index" :class="cx('meter')" :orientation="orientation" :size="percentValue(val.value)" :totalPercent="totalPercent">
|
|
|
|
<span :class="cx('meter')" :style="meterSize(val)" v-bind="getPTOptions('meter', val, index)" />
|
2024-01-11 13:42:20 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
|
|
|
</div>
|
2024-01-18 12:53:33 +00:00
|
|
|
<slot name="end" :value="value" :totalPercent="totalPercent" :percentages="percentages" />
|
|
|
|
<slot v-if="labelPosition === 'end'" name="label" :value="value" :totalPercent="totalPercent" :percentages="percentages">
|
|
|
|
<MeterGroupLabel :value="value" :labelPosition="labelPosition" :labelOrientation="labelOrientation" :unstyled="unstyled" :pt="pt" />
|
2024-01-11 13:42:20 +00:00
|
|
|
</slot>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import BaseMeterGroup from './BaseMeterGroup.vue';
|
2024-01-18 12:53:33 +00:00
|
|
|
import MeterGroupLabel from './MeterGroupLabel.vue';
|
2024-01-11 13:42:20 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'MeterGroup',
|
|
|
|
extends: BaseMeterGroup,
|
|
|
|
methods: {
|
|
|
|
getPTOptions(key, value, index) {
|
|
|
|
return this.ptm(key, {
|
|
|
|
context: {
|
|
|
|
value,
|
|
|
|
index
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2024-01-18 12:53:33 +00:00
|
|
|
percent(meter = 0) {
|
2024-01-11 13:42:20 +00:00
|
|
|
const percentOfItem = ((meter - this.min) / (this.max - this.min)) * 100;
|
|
|
|
|
2024-01-12 12:26:28 +00:00
|
|
|
return Math.round(Math.max(0, Math.min(100, percentOfItem)));
|
2024-01-11 13:42:20 +00:00
|
|
|
},
|
|
|
|
percentValue(meter) {
|
|
|
|
return this.percent(meter) + '%';
|
|
|
|
},
|
2024-01-18 12:53:33 +00:00
|
|
|
meterSize(val) {
|
|
|
|
return {
|
|
|
|
backgroundColor: val.color,
|
|
|
|
width: this.orientation === 'horizontal' && this.percentValue(val.value),
|
|
|
|
height: this.orientation === 'vertical' && this.percentValue(val.value)
|
|
|
|
};
|
2024-01-11 13:42:20 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
totalPercent() {
|
|
|
|
return this.percent(this.value.reduce((total, val) => total + val.value, 0));
|
2024-01-18 12:53:33 +00:00
|
|
|
},
|
|
|
|
percentages() {
|
|
|
|
let sum = 0;
|
|
|
|
const sumsArray = [];
|
|
|
|
|
|
|
|
this.value.forEach((item) => {
|
|
|
|
sum += item.value;
|
|
|
|
sumsArray.push(sum);
|
|
|
|
});
|
|
|
|
|
|
|
|
return sumsArray;
|
2024-01-11 13:42:20 +00:00
|
|
|
}
|
2024-01-18 12:53:33 +00:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
MeterGroupLabel
|
2024-01-11 13:42:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|