Skip to content
LIBRARYChartsUpdated

DonutChart ​

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.

Web preview
Open example ↗
vue
<MDonutChart v-model="selected" :segments="segments" label="Hours" animateNumber />
PropTypeDefaultContract
segmentsreadonly DonutSegment[]requiredUnique id, label, nonnegative finite value, optional six-digit HEX color. Up to 24.
modelValuestring or nullnullSelected segment ID; selecting again clears it.
size / strokeWidthnumber220 / 12Diameter 100–800px/DIP, stroke 1–20 in the 100-unit view box.
animated / animateNumber / disabledbooleantrue / false / falseJolt arcs, optional numeric presentation and selection lock.
formatValue / totalLabel / emptyLabelfunction / string / stringdefault / Total / No dataApp-controlled number formatting and localized text.

Legend buttons expose exact values and rounded percentages immediately; the decorative ring interpolates with Jolt. Stable IDs preserve segment identity. All-zero input shows an empty track, never an invalid division. Empty arrays are valid. The center shows the previewed or selected value, or the total. SVG SSR remains readable before enhancement; native rendering uses Jolt shape layers. Reduced motion settles immediately.

Motion ​

The first time the chart is on screen, the ring closes around in one continuous sweep, each discipline picking up where the previous one ends. It plays once; new data morphs the arcs instead. Pointing at a slice, or focusing its legend button, brings it forward, quiets the rest and shows its value in the center, without changing the selection. Clicking or tapping a slice on the ring selects it like its legend button, and the selected slice pulls out slightly from the ring. Rounded ends leave a hairline between slices. Under reduced motion the ring is drawn complete and the center changes at once.

update:modelValue → string | null.

vue
<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 selected = ref<string | null>(null),
  alternate = ref(false),
  animated = ref(true),
  empty = ref(false)
const segments = computed(() => [
  {
    id: 'design',
    label: t('Design', 'Design'),
    value: empty.value ? 0 : alternate.value ? 36 : 54,
    color: '#9C5270',
  },
  {
    id: 'research',
    label: t('Research', 'Pesquisa'),
    value: empty.value ? 0 : alternate.value ? 42 : 28,
    color: '#51847B',
  },
  {
    id: 'strategy',
    label: t('Strategy', 'Estratégia'),
    value: empty.value ? 0 : alternate.value ? 22 : 18,
    color: '#BF733E',
  },
])
</script>
<template>
  <MColumn gap="lg"
    ><MText text="FORMA STUDIO / TIME WELL SPENT" variant="overline" tone="primary" /><MCard
      padding="lg"
      ><MStack
        direction="column"
        :responsive="{ at: 720, direction: 'row' }"
        gap="lg"
        align="center"
        ><MColumn :grow="1" gap="md"
          ><MText
            :text="t('A week, in balance.', 'Uma semana, em equilíbrio.')"
            variant="title" /><MText
            :text="
              t(
                'Every hour has a purpose. Select a discipline to look closer.',
                'Cada hora tem um propósito. Escolha uma disciplina para olhar de perto.',
              )
            "
            tone="muted" /><MButton
            :text="t('Another week', 'Outra semana')"
            @click="alternate = !alternate" /></MColumn
        ><MDonutChart
          id="studio-donut"
          v-model="selected"
          :segments="segments"
          :label="t('Hours by discipline', 'Horas por disciplina')"
          :totalLabel="t('Hours', 'Horas')"
          :emptyLabel="t('A fresh start', 'Um novo começo')"
          :animated="animated"
          animateNumber /></MStack></MCard
    ><MRow gap="md" wrap
      ><MSwitch v-model="animated" :label="t('Animate arcs', 'Animar arcos')" /><MSwitch
        v-model="empty"
        :label="t('Empty week', 'Semana vazia')" /></MRow
    ><MText id="donut-selection" :text="selected ?? 'none'" variant="caption"
  /></MColumn>
</template>

On Web, iOS and Android, removing a segment by ID closes its arc before the drawing is released. Its legend entry can fade out at the same time. Reduced motion updates the chart immediately.

Desktop ​

The ring is drawn with native arcs: the chosen segment is pulled out and thickened, the others fade, and the legend buttons select a segment from the keyboard. Pointing at the ring neither previews nor selects a segment on desktop, and animateNumber has no effect: the number in the middle changes at once; see Desktop components.

A removed segment closes its arc where the surviving segments meet. Reduced motion removes it immediately.

Components for NativeScript and Web. Starting with Vue.