ai.chat/contrib/lnstyles/js/components/value.js

50 lines
1.1 KiB
JavaScript

var value = {
props: {
value: { default: 0, type: Number },
unit: { default: null, type: String },
ranges: {
type: Object, default: {
0: '',
3: 'k',
6: 'M',
9: 'G',
12: 'T',
15: 'P',
18: 'E',
}
},
},
data: function(){
return {};
},
emits: {
},
methods: {
},
computed: {
metricvalue(){
if (this.value == 0)
return "0 " + this.unit;
let e = Math.trunc(Math.log10(this.value));
let m = e - (e % 3);
let div = Math.pow(10, e -2);
let fdiv = Math.pow(10, 2 - (e % 3));
// return this.value + ":" + m + ':' + Math.round(this.value/div) + ':' + e + ":" + fdiv;
return (Math.round(this.value/div)/fdiv).toString() + ' ' + this.ranges[m] + this.unit;
},
},
template: `<div class="value" :tooltip="this.value + ' ' + this.unit"><slot>
{{ metricvalue }}
</slot></div>`,
}
export const components = {
value,
};