Sparkline
Included in RC.12
Available in Mavis 0.1.0-rc.12 for Vue + Vite, Nuxt and NativeScript. Keep the Mavis packages at the same version.
<MSparkline :points="points" label="Conversations" :height="64" />| Prop | Type | Default | Contract |
|---|---|---|---|
points | readonly SparklinePoint[] | required | Unique id, label and finite value or null; at most 100. |
domain | readonly [number, number] | automatic | Shared chart domain, including zero by default; explicit bounds must contain every value. |
height / color | number / string | 64 / theme | 24–240px/DIP and line color. |
animated / showData | boolean | true / false | Jolt line presentation and permanently expanded data. |
marker | boolean | true | A dot on the latest reading. |
formatValue / dataLabel / emptyLabel | function / string / string | default / View data / No data | Custom numbers and localized disclosure/empty labels. |
Compact presentation reuses the chart domain and null conventions. Null creates a gap; it never becomes zero. Compatible paths interpolate, while changed point/gap topology settles to the new path. A summary and expandable data list remain canonical and accessible; neither requires a hover gesture. All-null and empty input show the empty summary. One point remains visible. No axes or heavy chart controls are added.
Motion
The first time a sparkline is on screen, the line draws itself to the latest reading and the marker pops in where it ends. It happens once: new readings move the line and the marker together, and a resize or a theme change redraws in place. Sparklines below the fold wait until they are scrolled into view. The marker is decoration placed on the client; the summary and the data list carry the values. Under reduced motion the line and marker appear complete.
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useCatalogLocale } from '../locale'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const t = (en: string, br: string) => ((props.lang ?? locale.value) === 'pt' ? br : en)
const alternate = ref(false),
gaps = ref(false),
animated = ref(true),
marker = ref(true)
const points = computed(() =>
(alternate.value ? [14, 26, 18, 40, 36, 58, 72] : [12, 8, 24, 19, 38, 29, 48]).map(
(value, i) => ({
id: String(i),
label: t('Day', 'Dia') + ' ' + (i + 1),
value: gaps.value && i === 3 ? null : value,
}),
),
)
const negative = computed(() =>
points.value.map((p) => ({ ...p, value: p.value === null ? null : p.value - 32 })),
)
</script>
<template>
<MColumn gap="lg"
><MText text="FORMA STUDIO / SMALL SIGNALS" variant="overline" tone="primary" /><MText
:text="t('The direction matters.', 'A direção importa.')"
variant="title" /><MStack
direction="column"
:responsive="{ at: 680, direction: 'row' }"
gap="md"
><MCard :grow="1" padding="lg" gap="md"
><MText :text="t('New conversations', 'Novas conversas')" variant="heading" /><MNumberFlow
:value="points[6]?.value ?? 0"
variant="display" /><MSparkline
id="studio-sparkline"
:label="t('Conversations', 'Conversas')"
:points="points"
:animated="animated"
:marker="marker"
:dataLabel="t('View data', 'Ver dados')" /></MCard
><MCard :grow="1" padding="lg" gap="md"
><MText :text="t('Above and below', 'Altos e baixos')" variant="heading" /><MText
text="± 32"
variant="display" /><MSparkline
:label="t('Daily variation', 'Variação diária')"
:points="negative"
color="#51847B"
:animated="animated"
:marker="marker"
:dataLabel="t('View data', 'Ver dados')" /></MCard></MStack
><MRow gap="sm" wrap
><MButton
:text="t('New readings', 'Novas leituras')"
@click="alternate = !alternate" /><MSwitch
v-model="gaps"
:label="t('Missing reading', 'Leitura ausente')" /><MSwitch
v-model="animated"
:label="t('Animate lines', 'Animar linhas')" /><MSwitch
v-model="marker"
:label="t('Mark the latest', 'Marcar a última')" /></MRow
></MColumn>
</template>Desktop
The line is a native shape across the width the layout gives it, with the latest reading marked, and the summary and the data list are the same text as on the other platforms. It fades in once; new readings are drawn at once; see Desktop components.