Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ The map behind the dashboard, the layout editor, the offline view, the HV batter

### Dashboard cards

Cards are shown or hidden automatically based on vehicle type (HEV / PHEV / BEV). You can also reorder and toggle individual cards in the dashboard's edit mode.
Cards are shown or hidden automatically based on vehicle type (HEV / PHEV / BEV). You can also reorder and toggle individual cards in the dashboard's edit mode. On a phone, where the car overview and the location map stand one above the other, the edit mode shows magnifier buttons (**+** and **-**) over each of them: make the overview smaller (in three steps) and the map taller (in two). Making the overview smaller shrinks the car drawing and the readings over it together (the text a little less, to stay legible), so the map can have the room. Both are kept per device, and the standard size is the layout the dashboard has always had.

| Card | Description | Vehicle types |
| ---- | ----------- | ------------- |
Expand Down
26 changes: 15 additions & 11 deletions frontend/src/assets/carDiagram.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
position: absolute;
top: 0;
right: 0;
width: 80px;
width: calc(80px * var(--car-scale, 1));
pointer-events: auto;
user-select: none;
z-index: 1;
Expand Down Expand Up @@ -161,11 +161,13 @@
justify-content: center;
}

/* SVG viewBox is 420×480 (widened for 3-lane road); max-width keeps it on small screens */
/* SVG viewBox is 420×480 (widened for 3-lane road); max-width keeps it on small screens. The
dashboard's --car-scale (a phone's smaller overview, see dashboard.css) shrinks the drawing, and
with it everything laid over it by percentage. */
.tyre-car-wrap {
position: relative;
display: inline-block;
width: 300px;
width: calc(300px * var(--car-scale, 1));
max-width: 100%;
}

Expand Down Expand Up @@ -203,12 +205,14 @@
pointer-events: none;
}

/* What is written over the drawing shrinks with it by --car-text-scale, which falls more slowly than
--car-scale so the readings stay legible. */
.tyre-label {
position: absolute;
font-size: 0.68rem;
font-size: calc(0.68rem * var(--car-text-scale, 1));
font-weight: 600;
font-variant-numeric: tabular-nums;
padding: 2px 5px;
padding: calc(2px * var(--car-text-scale, 1)) calc(5px * var(--car-text-scale, 1));
border-radius: 4px;
background: var(--color-surface);
border: 1px solid var(--color-border);
Expand Down Expand Up @@ -297,14 +301,14 @@
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 0.35rem;
font-size: 0.85rem;
gap: calc(0.35rem * var(--car-text-scale, 1));
font-size: calc(0.85rem * var(--car-text-scale, 1));
font-weight: 700;
color: var(--color-text);
background: var(--color-surface);
border: 1px solid currentcolor;
border-radius: 20px;
padding: 3px 10px;
padding: calc(3px * var(--car-text-scale, 1)) calc(10px * var(--car-text-scale, 1));
white-space: nowrap;
pointer-events: auto;
user-select: none;
Expand Down Expand Up @@ -474,15 +478,15 @@

.car-badge {
position: absolute;
width: 26px;
height: 26px;
width: calc(26px * var(--car-text-scale, 1));
height: calc(26px * var(--car-text-scale, 1));
border-radius: 50%;
background: var(--color-warning);
color: #000;
display: flex;
align-items: center;
justify-content: center;
font-size: 0.65rem;
font-size: calc(0.65rem * var(--car-text-scale, 1));
pointer-events: auto;
user-select: none;
border: 2px solid var(--color-surface);
Expand Down
39 changes: 38 additions & 1 deletion frontend/src/assets/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,43 @@
.overview-row__map {
max-width: none;
}

/* The car's flex-basis is a width beside the map, but on a phone's column it is a height, a floor
of 320px that would keep a shrunk card's box that tall with the room left empty. A smaller
car lets go of it; standard keeps it, so the standard layout is as it was. */
.dashboard--car-small .overview-row__car,
.dashboard--car-smaller .overview-row__car,
.dashboard--car-smallest .overview-row__car {
flex-basis: auto;
}

/* The overview's two cards stand one above the other on a phone, so a phone can trade height
between them (the magnifier buttons over each card in the layout editor): a smaller car
drawing, and with it the readings over it, makes room for a taller map. --car-text-scale
falls more slowly than --car-scale so the pressures and badges stay legible. Standard is no
class at all. */
.dashboard--car-small {
--car-scale: 0.8;
--car-text-scale: 0.94;
}

.dashboard--car-smaller {
--car-scale: 0.62;
--car-text-scale: 0.86;
}

.dashboard--car-smallest {
--car-scale: 0.48;
--car-text-scale: 0.8;
}

.dashboard--map-tall {
--map-min-height: 240px;
}

.dashboard--map-taller {
--map-min-height: 300px;
}
}

/* Edit mode wraps each slot in extra card-slot/card-slot__content layers, which
Expand Down Expand Up @@ -82,7 +119,7 @@
.location-map-card__map {
position: relative;
flex: 1;
min-height: 180px;
min-height: var(--map-min-height, 180px);
border-radius: var(--radius);
overflow: hidden;
cursor: pointer;
Expand Down
38 changes: 38 additions & 0 deletions frontend/src/assets/editMode.css
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,44 @@
color: var(--color-on-success);
}

/* The magnifier buttons that make a card larger or smaller (CardSizeControl.vue), in the card's
bottom corner. Inside the card rather than over its edge, so they never cover the card below. */
.card-slot__size {
position: absolute;
right: 0.5rem;
bottom: 0.5rem;
display: flex;
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: calc(var(--touch-target) / 2);
box-shadow: 0 2px 8px var(--shadow-pop);
z-index: 2;
}

.card-slot__size-btn {
display: flex;
align-items: center;
justify-content: center;
width: var(--touch-target);
height: var(--touch-target);
border: 0;
border-radius: 50%;
background: transparent;
color: var(--color-text);
font-size: 1rem;
cursor: pointer;
}

.card-slot__size-btn:hover:not([aria-disabled='true']) {
background: var(--color-surface-2);
}

.card-slot__size-btn[aria-disabled='true'] {
color: var(--color-text-muted);
opacity: 0.4;
cursor: default;
}

/* Placeholder for hidden or data-less cards in edit mode */
.card-slot__placeholder {
background: var(--color-surface);
Expand Down
50 changes: 50 additions & 0 deletions frontend/src/components/CardSizeControl.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<script setup lang="ts">
import '@/assets/editMode.css'
import { useI18n } from 'vue-i18n'

const { t } = useI18n()

// The two magnifier buttons laid over a card in edit mode, to make it larger or smaller. What a
// step does, and where it stops, is up to the card: a button at its end is only dimmed. It is
// aria-disabled rather than disabled, so a finger or a key that has just taken the last step does
// not lose its focus to the page as the button it was on switches off.
const props = defineProps<{
/** What the buttons resize, for a screen reader. */
label: string
canLarger: boolean
canSmaller: boolean
}>()

const emit = defineEmits<{ larger: []; smaller: [] }>()

function larger() {
if (props.canLarger) emit('larger')
}

function smaller() {
if (props.canSmaller) emit('smaller')
}
</script>

<template>
<div class="card-slot__size" role="group" :aria-label="label">
<button
type="button"
class="card-slot__size-btn"
:aria-disabled="!canSmaller"
:aria-label="t('dashboard.cardSmaller')"
@click.stop="smaller"
>
<font-awesome-icon icon="magnifying-glass-minus" />
</button>
<button
type="button"
class="card-slot__size-btn"
:aria-disabled="!canLarger"
:aria-label="t('dashboard.cardLarger')"
@click.stop="larger"
>
<font-awesome-icon icon="magnifying-glass-plus" />
</button>
</div>
</template>
9 changes: 8 additions & 1 deletion frontend/src/components/EditableCardGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ defineProps<{

defineEmits<{ 'toggle-visible': [item: T] }>()

defineSlots<{ default(props: { item: T }): unknown }>()
defineSlots<{
default(props: { item: T }): unknown
/** Buttons over the card, for what only some grids offer (the dashboard's sizes). */
controls?(props: { item: T }): unknown
}>()
</script>

<template>
Expand All @@ -35,6 +39,9 @@ defineSlots<{ default(props: { item: T }): unknown }>()
@toggle-visible="$emit('toggle-visible', item)"
>
<slot :item="item" />
<template #controls>
<slot name="controls" :item="item" />
</template>
</EditableCardSlot>
</VueDraggable>
</template>
2 changes: 2 additions & 0 deletions frontend/src/components/EditableCardSlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ defineEmits<{ 'toggle-visible': [] }>()
<div class="card-slot__content">
<slot />
</div>
<!-- What a card offers to do to itself while editing, beside the badge (CardSizeControl). -->
<slot name="controls" />
<button
class="card-slot__badge"
:class="visible ? 'card-slot__badge--hide' : 'card-slot__badge--show'"
Expand Down
48 changes: 48 additions & 0 deletions frontend/src/components/__tests__/CardSizeControl.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { describe, it, expect } from 'vitest'
import { mount } from '@vue/test-utils'
import { createI18n } from 'vue-i18n'
import en from '@/locales/en.json'
import CardSizeControl from '../CardSizeControl.vue'

const i18n = createI18n({ legacy: false, locale: 'en', messages: { en } })

function mountControl(props: { canLarger: boolean; canSmaller: boolean }) {
return mount(CardSizeControl, {
props: { label: 'Overview', ...props },
global: { plugins: [i18n], stubs: { FontAwesomeIcon: true } },
})
}

describe('CardSizeControl', () => {
it('is a group named for what it resizes, with a button for each way', () => {
const wrapper = mountControl({ canLarger: true, canSmaller: true })

expect(wrapper.get('[role="group"]').attributes('aria-label')).toBe('Overview')
expect(wrapper.findAll('button').map((b) => b.attributes('aria-label'))).toEqual([
en.dashboard.cardSmaller,
en.dashboard.cardLarger,
])
})

it('says which way the finger asked, smaller or larger', async () => {
const wrapper = mountControl({ canLarger: true, canSmaller: true })
const [smaller, larger] = wrapper.findAll('button')

await larger!.trigger('click')
await smaller!.trigger('click')

expect(Object.keys(wrapper.emitted())).toEqual(expect.arrayContaining(['larger', 'smaller']))
expect(wrapper.emitted('larger')).toHaveLength(1)
expect(wrapper.emitted('smaller')).toHaveLength(1)
})

it('dims a button that has nowhere further to go, keeps its focus, and asks for nothing', async () => {
const wrapper = mountControl({ canLarger: false, canSmaller: true })
const [smaller, larger] = wrapper.findAll('button')

expect(larger!.attributes('aria-disabled')).toBe('true')
expect(smaller!.attributes('aria-disabled')).toBe('false')
await larger!.trigger('click')
expect(wrapper.emitted('larger')).toBeUndefined()
})
})
2 changes: 2 additions & 0 deletions frontend/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
"resetLayoutShort": "Reset",
"hideCard": "Hide card",
"showCard": "Show card",
"cardSmaller": "Make smaller",
"cardLarger": "Make larger",
"cardInfoBtn": "Card information",
"openFullMap": "Open full map",
"cardDesc": {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
"resetLayoutShort": "Restablecer",
"hideCard": "Ocultar tarjeta",
"showCard": "Mostrar tarjeta",
"cardSmaller": "Hacer más pequeño",
"cardLarger": "Hacer más grande",
"cardInfoBtn": "Información de la tarjeta",
"openFullMap": "Abrir mapa completo",
"cardDesc": {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
"resetLayoutShort": "Herstellen",
"hideCard": "Kaart verbergen",
"showCard": "Kaart tonen",
"cardSmaller": "Kleiner maken",
"cardLarger": "Groter maken",
"cardInfoBtn": "Kaartinformatie",
"openFullMap": "Volledige kaart openen",
"cardDesc": {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/locales/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
"resetLayoutShort": "Repor",
"hideCard": "Ocultar cartão",
"showCard": "Mostrar cartão",
"cardSmaller": "Diminuir",
"cardLarger": "Aumentar",
"cardInfoBtn": "Informações do cartão",
"openFullMap": "Abrir mapa completo",
"cardDesc": {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
"resetLayoutShort": "Restaurar",
"hideCard": "Ocultar cartão",
"showCard": "Mostrar cartão",
"cardSmaller": "Diminuir",
"cardLarger": "Aumentar",
"cardInfoBtn": "Informações do cartão",
"openFullMap": "Abrir mapa completo",
"cardDesc": {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/plugins/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export {
faLocationDot,
faLock,
faLockOpen,
faMagnifyingGlassMinus,
faMagnifyingGlassPlus,
faMap,
faMessage,
faMobileScreen,
Expand Down
Loading
Loading