Skip to content

Commit

Permalink
Phase UI: improve single-phase visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
naltatis committed Feb 5, 2025
1 parent 87e1c92 commit a06ab83
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
10 changes: 10 additions & 0 deletions assets/js/components/Phases.story.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,15 @@ const state = reactive({
:chargeCurrents="[0, 13, 0]"
/>
</Variant>
<Variant title="mainly third phase">
<Phases
v-bind="state"
:phasesActive="1"
:chargeCurrent="10"
:chargeCurrents="[0.007, 0.009, 5.945]"
:minCurrent="6"
:maxCurrent="20"
/>
</Variant>
</Story>
</template>
31 changes: 17 additions & 14 deletions assets/js/components/Phases.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<template>
<div :class="`phases phases--${numberOfVisiblePhases}p d-flex justify-content-between`">
<div v-for="num in [1, 2, 3]" :key="num" :class="`phase phase--${num} me-1`">
<div :class="`phases d-flex justify-content-between`">
<div
v-for="num in [1, 2, 3]"
:key="num"
class="phase me-1"
:class="{ 'phase-inactive': !isPhaseActive(num) }"
>
<div class="target" :style="{ width: `${targetWidth()}%` }"></div>
<div class="real" :style="{ width: `${realWidth(num)}%` }"></div>
</div>
Expand All @@ -20,14 +25,8 @@ export default {
maxCurrent: { type: Number },
},
computed: {
numberOfVisiblePhases() {
if (!this.chargeCurrents) {
return this.phasesActive;
}
const [L1, L2, L3] = this.chargeCurrents.map((c) => c >= MIN_ACTIVE_CURRENT);
if (L1 && !L2 && !L3) return 1;
if (L1 && L2 && !L3) return 2;
return 3;
chargeCurrentsActive() {
return this.chargeCurrents?.filter((c) => c >= MIN_ACTIVE_CURRENT).length > 0;
},
},
methods: {
Expand All @@ -45,6 +44,12 @@ export default {
}
return this.targetWidth();
},
isPhaseActive(num) {
if (this.chargeCurrentsActive) {
return this.chargeCurrents[num - 1] >= MIN_ACTIVE_CURRENT;
}
return num <= this.phasesActive;
},
},
};
</script>
Expand All @@ -69,14 +74,12 @@ export default {
html.dark .phase {
background-color: var(--bs-gray-bright);
}
.phases--1p .phase--2,
.phases--1p .phase--3,
.phases--2p .phase--3 {
.phase-inactive {
flex-basis: 0;
margin-right: 0 !important;
opacity: 0;
}
.target,
.real {
position: absolute;
Expand Down

0 comments on commit a06ab83

Please sign in to comment.