2021-06-25 21:03:06 +02:00
|
|
|
<template>
|
2021-07-27 19:47:13 +02:00
|
|
|
<div ref="wrap" class="wrap" :style="wrapStyle">
|
2021-06-25 21:03:06 +02:00
|
|
|
<div class="hp-bar-big" :style="barStyle">
|
2021-06-29 10:06:20 +02:00
|
|
|
<div
|
2021-07-27 19:47:13 +02:00
|
|
|
v-for="(beat, index) in shortBeatList"
|
|
|
|
:key="index"
|
2021-06-29 10:06:20 +02:00
|
|
|
class="beat"
|
2021-07-19 18:23:06 +02:00
|
|
|
:class="{ 'empty' : (beat === 0), 'down' : (beat.status === 0), 'pending' : (beat.status === 2) }"
|
2021-06-29 10:06:20 +02:00
|
|
|
:style="beatStyle"
|
2021-08-18 05:40:20 +02:00
|
|
|
:title="getBeatTitle(beat)"
|
2021-07-27 19:47:13 +02:00
|
|
|
/>
|
2021-06-25 21:03:06 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
export default {
|
2021-06-27 10:10:55 +02:00
|
|
|
props: {
|
|
|
|
size: {
|
|
|
|
type: String,
|
2021-07-27 19:47:13 +02:00
|
|
|
default: "big",
|
2021-06-27 10:10:55 +02:00
|
|
|
},
|
2021-08-18 05:40:20 +02:00
|
|
|
monitorId: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-09-11 17:43:07 +02:00
|
|
|
heartbeatList: {
|
|
|
|
type: Array,
|
|
|
|
default: null,
|
|
|
|
}
|
2021-06-27 10:10:55 +02:00
|
|
|
},
|
2021-06-25 21:03:06 +02:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
beatWidth: 10,
|
|
|
|
beatHeight: 30,
|
|
|
|
hoverScale: 1.5,
|
2021-09-04 18:08:24 +02:00
|
|
|
beatMargin: 4,
|
2021-06-25 21:03:06 +02:00
|
|
|
move: false,
|
2021-06-26 08:32:12 +02:00
|
|
|
maxBeat: -1,
|
2021-10-07 15:47:11 +02:00
|
|
|
}
|
2021-06-25 21:03:06 +02:00
|
|
|
},
|
|
|
|
computed: {
|
2021-06-26 08:32:12 +02:00
|
|
|
|
2021-09-11 17:43:07 +02:00
|
|
|
/**
|
|
|
|
* If heartbeatList is null, get it from $root.heartbeatList
|
|
|
|
*/
|
2021-06-27 10:10:55 +02:00
|
|
|
beatList() {
|
2021-09-11 17:43:07 +02:00
|
|
|
if (this.heartbeatList === null) {
|
|
|
|
return this.$root.heartbeatList[this.monitorId];
|
|
|
|
} else {
|
|
|
|
return this.heartbeatList;
|
|
|
|
}
|
2021-06-27 10:10:55 +02:00
|
|
|
},
|
|
|
|
|
2021-06-26 08:32:12 +02:00
|
|
|
shortBeatList() {
|
2021-08-19 12:41:31 +02:00
|
|
|
if (! this.beatList) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
let placeholders = [];
|
2021-06-27 10:10:55 +02:00
|
|
|
|
2021-06-26 08:32:12 +02:00
|
|
|
let start = this.beatList.length - this.maxBeat;
|
|
|
|
|
|
|
|
if (this.move) {
|
|
|
|
start = start - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start < 0) {
|
2021-06-27 10:10:55 +02:00
|
|
|
// Add empty placeholder
|
|
|
|
for (let i = start; i < 0; i++) {
|
2021-10-07 15:47:11 +02:00
|
|
|
placeholders.push(0)
|
2021-06-27 10:10:55 +02:00
|
|
|
}
|
2021-06-26 08:32:12 +02:00
|
|
|
start = 0;
|
|
|
|
}
|
|
|
|
|
2021-10-07 15:47:11 +02:00
|
|
|
return placeholders.concat(this.beatList.slice(start))
|
2021-06-26 08:32:12 +02:00
|
|
|
},
|
|
|
|
|
2021-06-25 21:03:06 +02:00
|
|
|
wrapStyle() {
|
|
|
|
let topBottom = (((this.beatHeight * this.hoverScale) - this.beatHeight) / 2);
|
|
|
|
let leftRight = (((this.beatWidth * this.hoverScale) - this.beatWidth) / 2);
|
|
|
|
|
|
|
|
return {
|
|
|
|
padding: `${topBottom}px ${leftRight}px`,
|
2021-07-28 17:03:37 +02:00
|
|
|
width: "100%",
|
2021-10-07 15:47:11 +02:00
|
|
|
}
|
2021-06-25 21:03:06 +02:00
|
|
|
},
|
2021-06-26 08:32:12 +02:00
|
|
|
|
2021-06-25 21:03:06 +02:00
|
|
|
barStyle() {
|
2021-06-26 08:32:12 +02:00
|
|
|
if (this.move && this.shortBeatList.length > this.maxBeat) {
|
2021-06-25 21:03:06 +02:00
|
|
|
let width = -(this.beatWidth + this.beatMargin * 2);
|
|
|
|
|
2021-06-26 08:32:12 +02:00
|
|
|
return {
|
2021-06-25 21:03:06 +02:00
|
|
|
transition: "all ease-in-out 0.25s",
|
|
|
|
transform: `translateX(${width}px)`,
|
2021-10-07 15:47:11 +02:00
|
|
|
}
|
2021-06-26 08:32:12 +02:00
|
|
|
|
2021-06-25 21:03:06 +02:00
|
|
|
}
|
2021-07-27 19:47:13 +02:00
|
|
|
return {
|
|
|
|
transform: "translateX(0)",
|
2021-10-07 15:47:11 +02:00
|
|
|
}
|
2021-07-27 19:47:13 +02:00
|
|
|
|
2021-06-25 21:03:06 +02:00
|
|
|
},
|
2021-06-26 08:32:12 +02:00
|
|
|
|
2021-06-25 21:03:06 +02:00
|
|
|
beatStyle() {
|
|
|
|
return {
|
|
|
|
width: this.beatWidth + "px",
|
|
|
|
height: this.beatHeight + "px",
|
|
|
|
margin: this.beatMargin + "px",
|
|
|
|
"--hover-scale": this.hoverScale,
|
2021-10-07 15:47:11 +02:00
|
|
|
}
|
2021-07-27 19:47:13 +02:00
|
|
|
},
|
2021-06-26 08:32:12 +02:00
|
|
|
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
beatList: {
|
|
|
|
handler(val, oldVal) {
|
|
|
|
this.move = true;
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
this.move = false;
|
2021-10-07 15:47:11 +02:00
|
|
|
}, 300)
|
2021-06-26 08:32:12 +02:00
|
|
|
},
|
|
|
|
deep: true,
|
2021-07-27 19:47:13 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
unmounted() {
|
|
|
|
window.removeEventListener("resize", this.resize);
|
|
|
|
},
|
2021-08-18 05:40:20 +02:00
|
|
|
beforeMount() {
|
2021-09-11 17:43:07 +02:00
|
|
|
if (this.heartbeatList === null) {
|
|
|
|
if (! (this.monitorId in this.$root.heartbeatList)) {
|
|
|
|
this.$root.heartbeatList[this.monitorId] = [];
|
|
|
|
}
|
2021-08-18 05:40:20 +02:00
|
|
|
}
|
|
|
|
},
|
2021-09-04 18:08:24 +02:00
|
|
|
|
2021-07-27 19:47:13 +02:00
|
|
|
mounted() {
|
|
|
|
if (this.size === "small") {
|
2021-09-04 18:08:24 +02:00
|
|
|
this.beatWidth = 5;
|
2021-09-04 17:32:46 +02:00
|
|
|
this.beatHeight = 16;
|
2021-09-04 18:08:24 +02:00
|
|
|
this.beatMargin = 2;
|
|
|
|
}
|
2021-09-04 17:32:46 +02:00
|
|
|
|
2021-09-04 18:08:24 +02:00
|
|
|
// Suddenly, have an idea how to handle it universally.
|
|
|
|
// If the pixel * ratio != Integer, then it causes render issue, round it to solve it!!
|
|
|
|
const actualWidth = this.beatWidth * window.devicePixelRatio;
|
|
|
|
const actualMargin = this.beatMargin * window.devicePixelRatio;
|
2021-09-04 17:32:46 +02:00
|
|
|
|
2021-09-04 18:08:24 +02:00
|
|
|
if (! Number.isInteger(actualWidth)) {
|
|
|
|
this.beatWidth = Math.round(actualWidth) / window.devicePixelRatio;
|
|
|
|
}
|
2021-09-04 17:32:46 +02:00
|
|
|
|
2021-09-04 18:08:24 +02:00
|
|
|
if (! Number.isInteger(actualMargin)) {
|
|
|
|
this.beatMargin = Math.round(actualMargin) / window.devicePixelRatio;
|
2021-06-26 08:32:12 +02:00
|
|
|
}
|
2021-07-27 19:47:13 +02:00
|
|
|
|
|
|
|
window.addEventListener("resize", this.resize);
|
|
|
|
this.resize();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
resize() {
|
|
|
|
if (this.$refs.wrap) {
|
2021-10-07 15:47:11 +02:00
|
|
|
this.maxBeat = Math.floor(this.$refs.wrap.clientWidth / (this.beatWidth + this.beatMargin * 2))
|
2021-07-27 19:47:13 +02:00
|
|
|
}
|
|
|
|
},
|
2021-08-18 05:40:20 +02:00
|
|
|
|
|
|
|
getBeatTitle(beat) {
|
2021-10-22 11:59:53 +02:00
|
|
|
return `${this.$root.datetime(beat.time)}` + ((beat.msg) ? ` - ${beat.msg}` : ``);
|
2021-08-18 05:40:20 +02:00
|
|
|
}
|
2021-07-27 19:47:13 +02:00
|
|
|
},
|
2021-10-07 15:47:11 +02:00
|
|
|
}
|
2021-06-25 21:03:06 +02:00
|
|
|
</script>
|
|
|
|
|
2021-08-08 07:47:29 +02:00
|
|
|
<style lang="scss" scoped>
|
2021-06-25 21:03:06 +02:00
|
|
|
@import "../assets/vars.scss";
|
|
|
|
|
|
|
|
.wrap {
|
|
|
|
overflow: hidden;
|
2021-06-26 08:32:12 +02:00
|
|
|
width: 100%;
|
2021-06-25 21:03:06 +02:00
|
|
|
white-space: nowrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
.hp-bar-big {
|
|
|
|
.beat {
|
|
|
|
display: inline-block;
|
|
|
|
background-color: $primary;
|
2021-10-02 16:48:27 +02:00
|
|
|
border-radius: $border-radius;
|
2021-06-25 21:03:06 +02:00
|
|
|
|
2021-06-27 10:10:55 +02:00
|
|
|
&.empty {
|
2021-07-13 06:16:11 +02:00
|
|
|
background-color: aliceblue;
|
2021-06-26 08:32:12 +02:00
|
|
|
}
|
|
|
|
|
2021-06-27 10:10:55 +02:00
|
|
|
&.down {
|
|
|
|
background-color: $danger;
|
|
|
|
}
|
2021-06-25 21:03:06 +02:00
|
|
|
|
2021-07-19 18:23:06 +02:00
|
|
|
&.pending {
|
|
|
|
background-color: $warning;
|
|
|
|
}
|
|
|
|
|
2021-06-27 10:10:55 +02:00
|
|
|
&:not(.empty):hover {
|
|
|
|
transition: all ease-in-out 0.15s;
|
2021-06-25 21:03:06 +02:00
|
|
|
opacity: 0.8;
|
|
|
|
transform: scale(var(--hover-scale));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-08 07:47:29 +02:00
|
|
|
.dark {
|
2021-08-24 17:38:25 +02:00
|
|
|
.hp-bar-big .beat.empty {
|
2021-08-08 07:47:29 +02:00
|
|
|
background-color: #848484;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-25 21:03:06 +02:00
|
|
|
</style>
|