탐색

v2.1.0
데이터 표시

게이지

측정값에 해당하는 지점까지 원호를 채워 눈금판에 값을 표시합니다.

이 페이지의 내용

게이지는 눈금판에 측정값을 표시합니다. 아래쪽이 열린 원호는 원의 3분의 2를 이루며, 측정값에 해당하는 지점까지 전경색으로 채워집니다. 가운데에 숫자가 표시되고, 그 아래 원호의 양 끝 사이에 단어 하나가 놓입니다. 요소에 role="meter"를 지정하고 사람이 읽을 수 있는 형태로 값을 적으면 스타일시트가 원호를 그립니다. 스크립트와 SVG는 사용하지 않습니다.

게이지

<div class="card max-w(480) mx-auto">  <div class="flex flex-wrap justify-around gap-md">    <div class="gauge" role="meter" aria-label="CPU" aria-valuenow="38" style="--gauge-value: 38">      <span class="gauge-value">38%</span>      <span class="gauge-label">CPU</span>    </div>    <div class="gauge" role="meter" aria-label="Memory" aria-valuenow="72" style="--gauge-value: 72">      <span class="gauge-value">72%</span>      <span class="gauge-label">Memory</span>    </div>    <div class="gauge" role="meter" aria-label="Disk" aria-valuenow="91" style="--gauge-value: 91">      <span class="gauge-value">91%</span>      <span class="gauge-label">Disk</span>    </div>  </div></div>
<div className="card max-w(480) mx-auto">  <div className="flex flex-wrap justify-around gap-md">    <div className="gauge" role="meter" aria-label="CPU" aria-valuenow={38} style={{ '--gauge-value': '38' } as React.CSSProperties}>      <span className="gauge-value">38%</span>      <span className="gauge-label">CPU</span>    </div>    <div className="gauge" role="meter" aria-label="Memory" aria-valuenow={72} style={{ '--gauge-value': '72' } as React.CSSProperties}>      <span className="gauge-value">72%</span>      <span className="gauge-label">Memory</span>    </div>    <div className="gauge" role="meter" aria-label="Disk" aria-valuenow={91} style={{ '--gauge-value': '91' } as React.CSSProperties}>      <span className="gauge-value">91%</span>      <span className="gauge-label">Disk</span>    </div>  </div></div>
<div class="card max-w(480) mx-auto">  <div class="flex flex-wrap justify-around gap-md">    <div class="gauge" role="meter" aria-label="CPU" aria-valuenow="38" style="--gauge-value: 38">      <span class="gauge-value">38%</span>      <span class="gauge-label">CPU</span>    </div>    <div class="gauge" role="meter" aria-label="Memory" aria-valuenow="72" style="--gauge-value: 72">      <span class="gauge-value">72%</span>      <span class="gauge-label">Memory</span>    </div>    <div class="gauge" role="meter" aria-label="Disk" aria-valuenow="91" style="--gauge-value: 91">      <span class="gauge-value">91%</span>      <span class="gauge-label">Disk</span>    </div>  </div></div>
<template>  <div class="card max-w(480) mx-auto">    <div class="flex flex-wrap justify-around gap-md">      <div class="gauge" role="meter" aria-label="CPU" aria-valuenow="38" style="--gauge-value: 38">        <span class="gauge-value">38%</span>        <span class="gauge-label">CPU</span>      </div>      <div class="gauge" role="meter" aria-label="Memory" aria-valuenow="72" style="--gauge-value: 72">        <span class="gauge-value">72%</span>        <span class="gauge-label">Memory</span>      </div>      <div class="gauge" role="meter" aria-label="Disk" aria-valuenow="91" style="--gauge-value: 91">        <span class="gauge-value">91%</span>        <span class="gauge-label">Disk</span>      </div>    </div>  </div></template>

#원호의 채움 길이 계산

측정값은 aria-valuenow에 지정하며, 범위는 aria-valuemin부터 aria-valuemax까지입니다. 범위를 생략하면 0부터 100까지입니다. 브라우저가 타입을 지정하는 attr()를 지원하면 게이지가 해당 속성을 직접 읽으므로 값은 한 번만 적으면 됩니다. 지원하지 않는 브라우저에서는 폴백으로 --gauge-value를 읽고, 범위가 다르면 --gauge-min과 --gauge-max도 읽습니다. 모든 브라우저 엔진이 타입을 지정하는 attr()를 지원할 때까지는 여기의 예제처럼 두 방식으로 모두 지정하세요.

트랙과 채움 부분의 양 끝은 각각 둥글게 처리되며, 값이 바뀌면 채움 길이가 부드럽게 변합니다. 채움 길이가 0이면 채움 부분의 둥근 끝에도 크기가 없어 빈 트랙만 보입니다.

사용자 지정 범위

<div class="gauge" role="meter" aria-label="Engine speed" aria-valuenow="4200" aria-valuemin="0" aria-valuemax="8000" style="--gauge-value: 4200; --gauge-max: 8000">  <span class="gauge-value">4,200</span>  <span class="gauge-label">rpm</span></div><div class="gauge" role="meter" aria-label="Rating" aria-valuenow="4.6" aria-valuemin="1" aria-valuemax="5" style="--gauge-value: 4.6; --gauge-min: 1; --gauge-max: 5">  <span class="gauge-value">4.6</span>  <span class="gauge-label">of 5</span></div><div class="gauge" role="meter" aria-label="Queue" aria-valuenow="0" style="--gauge-value: 0">  <span class="gauge-value">0</span>  <span class="gauge-label">Queued</span></div>
<>  <div className="gauge" role="meter" aria-label="Engine speed" aria-valuenow={4200} aria-valuemin={0} aria-valuemax={8000} style={{ '--gauge-value': '4200', '--gauge-max': '8000' } as React.CSSProperties}>    <span className="gauge-value">4,200</span>    <span className="gauge-label">rpm</span>  </div>  <div className="gauge" role="meter" aria-label="Rating" aria-valuenow={4.6} aria-valuemin={1} aria-valuemax={5} style={{ '--gauge-value': '4.6', '--gauge-min': '1', '--gauge-max': '5' } as React.CSSProperties}>    <span className="gauge-value">4.6</span>    <span className="gauge-label">of 5</span>  </div>  <div className="gauge" role="meter" aria-label="Queue" aria-valuenow={0} style={{ '--gauge-value': '0' } as React.CSSProperties}>    <span className="gauge-value">0</span>    <span className="gauge-label">Queued</span>  </div></>
<div class="gauge" role="meter" aria-label="Engine speed" aria-valuenow="4200" aria-valuemin="0" aria-valuemax="8000" style="--gauge-value: 4200; --gauge-max: 8000">  <span class="gauge-value">4,200</span>  <span class="gauge-label">rpm</span></div><div class="gauge" role="meter" aria-label="Rating" aria-valuenow="4.6" aria-valuemin="1" aria-valuemax="5" style="--gauge-value: 4.6; --gauge-min: 1; --gauge-max: 5">  <span class="gauge-value">4.6</span>  <span class="gauge-label">of 5</span></div><div class="gauge" role="meter" aria-label="Queue" aria-valuenow="0" style="--gauge-value: 0">  <span class="gauge-value">0</span>  <span class="gauge-label">Queued</span></div>
<template>  <div class="gauge" role="meter" aria-label="Engine speed" aria-valuenow="4200" aria-valuemin="0" aria-valuemax="8000" style="--gauge-value: 4200; --gauge-max: 8000">    <span class="gauge-value">4,200</span>    <span class="gauge-label">rpm</span>  </div>  <div class="gauge" role="meter" aria-label="Rating" aria-valuenow="4.6" aria-valuemin="1" aria-valuemax="5" style="--gauge-value: 4.6; --gauge-min: 1; --gauge-max: 5">    <span class="gauge-value">4.6</span>    <span class="gauge-label">of 5</span>  </div>  <div class="gauge" role="meter" aria-label="Queue" aria-valuenow="0" style="--gauge-value: 0">    <span class="gauge-value">0</span>    <span class="gauge-label">Queued</span>  </div></template>

#크기

게이지의 기본 너비는 120px입니다. gauge-sm은 88px로, 정보가 빽빽한 대시보드의 타일에 적합합니다. gauge-lg는 160px로, 화면에서 측정값 하나를 강조할 때 적합합니다. 선 두께는 너비의 15분의 1이며 숫자 크기도 너비에 비례합니다. gauge-label이 없으면 숫자는 눈금판 중앙에 놓입니다.

크기

<div class="gauge gauge-sm" role="meter" aria-label="Battery" aria-valuenow="64" style="--gauge-value: 64">  <span class="gauge-value">64%</span>  <span class="gauge-label">Battery</span></div><div class="gauge" role="meter" aria-label="Battery" aria-valuenow="64" style="--gauge-value: 64">  <span class="gauge-value">64%</span>  <span class="gauge-label">Battery</span></div><div class="gauge gauge-lg" role="meter" aria-label="Battery" aria-valuenow="64" style="--gauge-value: 64">  <span class="gauge-value">64%</span></div>
<>  <div className="gauge gauge-sm" role="meter" aria-label="Battery" aria-valuenow={64} style={{ '--gauge-value': '64' } as React.CSSProperties}>    <span className="gauge-value">64%</span>    <span className="gauge-label">Battery</span>  </div>  <div className="gauge" role="meter" aria-label="Battery" aria-valuenow={64} style={{ '--gauge-value': '64' } as React.CSSProperties}>    <span className="gauge-value">64%</span>    <span className="gauge-label">Battery</span>  </div>  <div className="gauge gauge-lg" role="meter" aria-label="Battery" aria-valuenow={64} style={{ '--gauge-value': '64' } as React.CSSProperties}>    <span className="gauge-value">64%</span>  </div></>
<div class="gauge gauge-sm" role="meter" aria-label="Battery" aria-valuenow="64" style="--gauge-value: 64">  <span class="gauge-value">64%</span>  <span class="gauge-label">Battery</span></div><div class="gauge" role="meter" aria-label="Battery" aria-valuenow="64" style="--gauge-value: 64">  <span class="gauge-value">64%</span>  <span class="gauge-label">Battery</span></div><div class="gauge gauge-lg" role="meter" aria-label="Battery" aria-valuenow="64" style="--gauge-value: 64">  <span class="gauge-value">64%</span></div>
<template>  <div class="gauge gauge-sm" role="meter" aria-label="Battery" aria-valuenow="64" style="--gauge-value: 64">    <span class="gauge-value">64%</span>    <span class="gauge-label">Battery</span>  </div>  <div class="gauge" role="meter" aria-label="Battery" aria-valuenow="64" style="--gauge-value: 64">    <span class="gauge-value">64%</span>    <span class="gauge-label">Battery</span>  </div>  <div class="gauge gauge-lg" role="meter" aria-label="Battery" aria-valuenow="64" style="--gauge-value: 64">    <span class="gauge-value">64%</span>  </div></template>

#측정값이 나타내는 상태

채움 부분에는 기본적으로 전경색을 사용합니다. 측정값 자체가 경고를 뜻하면 --gauge-color에 상태 색상을 지정하고 경고임을 텍스트로도 표시하세요. 색상만으로 의미를 전달해서는 안 됩니다. 트랙에는 같은 색을 옅게 적용하므로 채움 색을 바꾸면 트랙 색도 함께 바뀝니다.

상태

<div class="gauge" role="meter" aria-label="Storage" aria-valuenow="84" aria-valuetext="84%, nearly full" style="--gauge-value: 84; --gauge-color: var(--color-warning)">  <span class="gauge-value">84%</span>  <span class="gauge-label">Nearly full</span></div><div class="gauge" role="meter" aria-label="Error budget" aria-valuenow="97" aria-valuetext="97% spent, over budget soon" style="--gauge-value: 97; --gauge-color: var(--color-danger)">  <span class="gauge-value">97%</span>  <span class="gauge-label">Spent</span></div>
<>  <div className="gauge" role="meter" aria-label="Storage" aria-valuenow={84} aria-valuetext="84%, nearly full" style={{ '--gauge-value': '84', '--gauge-color': 'var(--color-warning)' } as React.CSSProperties}>    <span className="gauge-value">84%</span>    <span className="gauge-label">Nearly full</span>  </div>  <div className="gauge" role="meter" aria-label="Error budget" aria-valuenow={97} aria-valuetext="97% spent, over budget soon" style={{ '--gauge-value': '97', '--gauge-color': 'var(--color-danger)' } as React.CSSProperties}>    <span className="gauge-value">97%</span>    <span className="gauge-label">Spent</span>  </div></>
<div class="gauge" role="meter" aria-label="Storage" aria-valuenow="84" aria-valuetext="84%, nearly full" style="--gauge-value: 84; --gauge-color: var(--color-warning)">  <span class="gauge-value">84%</span>  <span class="gauge-label">Nearly full</span></div><div class="gauge" role="meter" aria-label="Error budget" aria-valuenow="97" aria-valuetext="97% spent, over budget soon" style="--gauge-value: 97; --gauge-color: var(--color-danger)">  <span class="gauge-value">97%</span>  <span class="gauge-label">Spent</span></div>
<template>  <div class="gauge" role="meter" aria-label="Storage" aria-valuenow="84" aria-valuetext="84%, nearly full" style="--gauge-value: 84; --gauge-color: var(--color-warning)">    <span class="gauge-value">84%</span>    <span class="gauge-label">Nearly full</span>  </div>  <div class="gauge" role="meter" aria-label="Error budget" aria-valuenow="97" aria-valuetext="97% spent, over budget soon" style="--gauge-value: 97; --gauge-color: var(--color-danger)">    <span class="gauge-value">97%</span>    <span class="gauge-label">Spent</span>  </div></template>

#게이지, 미터, 진행률

게이지와 미터는 모두 정해진 범위 안의 측정값을 표시합니다. 대시보드처럼 측정값이 핵심이고 값을 표시할 별도 공간이 있으면 게이지를 사용하세요. 폼의 한 줄이나 표의 한 행에는 미터를 사용하세요. 진행률은 완료되는 작업에 사용하며, 원형 표시에는 닫힌 고리를 사용합니다. 게이지의 원호는 항상 열린 상태입니다.

#접근성

  • 요소에 role="meter"를 지정하고, aria-label 또는 aria-labelledby로 접근 가능한 이름을 제공한 뒤 aria-valuenow에 측정값을 지정하세요. 범위가 0부터 100까지가 아니면 aria-valuemin과 aria-valuemax를 추가하세요.
  • gauge-value의 텍스트에도 측정값을 단위와 함께 적으세요. 숫자를 이해하는 데 설명이 필요하면 aria-valuetext를 추가하세요.
  • 스타일시트가 그린 원호는 스크린 리더가 읽지 않습니다. 강제 색상 모드에서는 채움 부분에 시스템 강조 색상을, 트랙에 시스템 회색을 적용합니다.

#클래스

클래스설명
gauge지름 120px의 다이얼입니다. 요소에 role="meter"와 접근 가능한 이름을 지정하고 aria-valuenow에 측정값을 넣으세요. 아래쪽이 열린 호는 원 둘레의 3분의 2를 차지하며, 측정값에 해당하는 지점까지 전경색으로 채워집니다.
gauge-sm지름 88px의 다이얼입니다. 기본값은 120px입니다.적용할 클래스는 gauge입니다
gauge-lg160px 다이얼입니다. 기본값은 120px입니다.적용할 클래스는 gauge입니다
gauge-value다이얼 중앙에 측정값을 너비가 일정한 큰 숫자로 표시합니다.
gauge-label호의 양 끝 사이에서 숫자 아래에 낮은 대비로 단어 하나를 표시합니다. 이 단어가 없으면 숫자가 중앙에 놓입니다

#사용자 지정 속성

속성기본값설명
--gauge-value측정값입니다. 타입을 지정하는 attr()을 지원하는 환경에서는 aria-valuenow에서 가져오며, 그 외에는 직접 설정하세요.
--gauge-min0범위의 최솟값입니다. 타입을 지정하는 attr()을 지원하는 환경에서는 aria-valuemin에서 가져옵니다.
--gauge-max100범위의 최댓값입니다. 타입을 지정하는 attr()을 지원하는 환경에서는 aria-valuemax에서 가져옵니다.
--gauge-size7.5rem다이얼의 지름
--gauge-widthcalc(var(--gauge-size) / 15)호의 두께
--gauge-colorvar(--color-surface-inverse)채움 색상입니다. 트랙에는 같은 색을 옅게 적용합니다. 측정값이 상태를 나타내면 상태 색상을 지정하고 해당 상태를 텍스트로도 표시하세요.

#소스

@master/ui/components/gauge.css
/* * Gauge: a reading on a dial, for one measurement a reader takes in at a glance. * An element with role="meter" draws two thirds of a ring, open at the foot, and fills it with ink as far as * the reading has come. The figure stands in the middle and one word under it, between the two ends of the arc. * Where the browser supports typed attr(), the gauge reads aria-valuenow, aria-valuemin and aria-valuemax * itself, so the reading is written once, for people and for the drawing; elsewhere set --gauge-value. * The track and the fill both have round ends, and the fill eases to each new reading. * A gauge is 120px across (88 small, 160 large) and its stroke is a fifteenth of that. */@property --gauge-value {  syntax: '<number>';  inherits: true;  initial-value: 0;}@layer components.ui {  .gauge {    --gauge-size: 7.5rem;    --gauge-width: calc(var(--gauge-size) / 15);    --gauge-color: var(--color-surface-inverse);    --gauge-min: 0;    --gauge-max: 100;    /* How far along the arc the reading is, from nothing to all of it. */    --gauge-share: clamp(0, calc((var(--gauge-value) - var(--gauge-min)) / (var(--gauge-max) - var(--gauge-min))), 1);    --gauge-radius: calc((var(--gauge-size) - var(--gauge-width)) / 2);    position: relative;    display: inline-grid;    flex: none;    align-content: end;    justify-items: center;    gap: calc(var(--gauge-size) * .05);    box-sizing: border-box;    width: var(--gauge-size);    /* The arc ends a quarter of the way below the middle, so the box stops there, and so does what it can scroll. */    height: calc(var(--gauge-size) * .75 + var(--gauge-width) / 4);    margin: 0;    overflow: clip;    /* The figure and the word rise over the drawings inside the gauge, not over what stands near it on the page. */    isolation: isolate;    color: var(--color-text-strong);    font: var(--font-weight-control) calc(var(--gauge-size) * .235)/1 var(--font-family-sans);    font-feature-settings: inherit;    font-variant-numeric: tabular-nums;    letter-spacing: -.02em;    text-align: center;    vertical-align: middle;    transition: --gauge-value var(--duration-base) var(--easing-glide);    @supports (x: attr(x type(*))) {      &[aria-valuenow] {        --gauge-value: attr(aria-valuenow type(<number>), 0);      }      &[aria-valuemin] {        --gauge-min: attr(aria-valuemin type(<number>), 0);      }      &[aria-valuemax] {        --gauge-max: attr(aria-valuemax type(<number>), 100);      }    }    /* Both drawings are a square as wide as the gauge, cut down to a ring; the box shows its upper three quarters. */    &::before, &::after {      content: '';      position: absolute;      inset: 0 0 auto;      height: var(--gauge-size);      border-radius: 999px;      mask: radial-gradient(farthest-side, transparent calc(100% - var(--gauge-width) - .5px), black calc(100% - var(--gauge-width)), black calc(100% - .5px), transparent);      pointer-events: none;    }    /*     * The track: the whole arc, from 240 to 480 degrees, with a dot at each end to round it. It is drawn in     * the fill's own color and stepped back as one layer, so the dots and the arc never add up.     */    &::before {      background:        radial-gradient(circle at calc(50% + var(--gauge-radius) * sin(240deg)) calc(50% - var(--gauge-radius) * cos(240deg)), var(--gauge-color) calc(var(--gauge-width) / 2 - .5px), transparent calc(var(--gauge-width) / 2)),        radial-gradient(circle at calc(50% + var(--gauge-radius) * sin(480deg)) calc(50% - var(--gauge-radius) * cos(480deg)), var(--gauge-color) calc(var(--gauge-width) / 2 - .5px), transparent calc(var(--gauge-width) / 2)),        conic-gradient(from 240deg, var(--gauge-color) 240deg, transparent 0);      opacity: .12;    }    /* The fill: the same arc as far as the reading. Its end dots have no radius at nothing, so an empty gauge is an empty track. */    &::after {      --gauge-end: calc(240deg + var(--gauge-share) * 240deg);      --gauge-cap: calc(var(--gauge-width) / 2 * min(1, var(--gauge-share) * 200));      background:        radial-gradient(circle at calc(50% + var(--gauge-radius) * sin(240deg)) calc(50% - var(--gauge-radius) * cos(240deg)), var(--gauge-color) calc(var(--gauge-cap) - .5px), transparent var(--gauge-cap)),        radial-gradient(circle at calc(50% + var(--gauge-radius) * sin(var(--gauge-end))) calc(50% - var(--gauge-radius) * cos(var(--gauge-end))), var(--gauge-color) calc(var(--gauge-cap) - .5px), transparent var(--gauge-cap)),        conic-gradient(from 240deg, var(--gauge-color) calc(var(--gauge-share) * 240deg), transparent 0);    }    /* Without a word under it, the figure stands at the middle of the dial. */    &:not(:has(.gauge-label)) {      align-content: center;      padding-block-start: calc(var(--gauge-size) * .2);    }    &.gauge-sm {      --gauge-size: 5.5rem;    }    &.gauge-lg {      --gauge-size: 10rem;    }    @media (prefers-reduced-motion: reduce) {      transition: none;    }    /* Only the drawings keep their colors: the figure and the word take the system's text. */    @media (forced-colors: active) {      --gauge-color: Highlight;      &::before, &::after {        forced-color-adjust: none;      }      &::before {        --gauge-color: GrayText;        opacity: 1;      }    }  }  /* The reading, in the gauge's own large figures. */  .gauge-value {    position: relative;    z-index: 1;    max-width: 100%;    margin: 0;  }  /* What is measured: one quiet word between the ends of the arc. */  .gauge-label {    position: relative;    z-index: 1;    max-width: 62%;    margin: 0;    overflow: hidden;    color: var(--color-text-muted);    font: 400 .75rem/1rem var(--font-family-sans);    font-feature-settings: inherit;    letter-spacing: 0;    text-overflow: ellipsis;    white-space: nowrap;  }  .gauge-sm .gauge-label {    font-size: .6875rem;    line-height: .875rem;  }  .gauge-lg .gauge-label {    font-size: .8125rem;    line-height: 1.125rem;  }}