탐색

v2.1.0
데이터 표시

차트

어떤 너비에도 맞는 하나의 SVG에 꺾은선 차트부터 선버스트 차트까지 20가지가 넘는 형태로 수치를 그립니다.

이 페이지의 내용

차트는 독자가 확인하려는 내용에 맞춰 수치를 그립니다. 꺾은선 차트, 막대 차트, 도넛 차트, 히스토그램, 퍼널 차트 등 20가지가 넘는 형태를 지원합니다. 모든 형태는 주어진 너비에 맞는 하나의 SVG로 그립니다. 눈금을 따르는 요소는 백분율로 배치하고, 플롯이 아무리 늘어나도 선 두께와 텍스트 크기는 그대로 유지합니다. 계열이 하나면 진행률 표시줄의 채움과 같은 잉크 색상을 쓰고, 여러 계열에는 카테고리 색상을 씁니다. 각 데이터 점은 그 값을 문장으로 설명하는 목록 항목입니다.

차트

<div class="card max-w(560) mx-auto">  <div class="card-header">    <h3 class="card-title">Requests</h3>    <p class="card-description">Millions per month, by region</p>  </div>  <figure class="chart" id="requests"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('requests'), {  type: 'area',  label: 'Requests per month by region, in millions',  labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],  series: [    { name: 'Tokyo', values: [32, 36, 34, 41, 46, 44, 52, 56, 54, 61, 68, 72] },    { name: 'Frankfurt', values: [12, 14, 18, 17, 22, 26, 25, 30, 34, 33, 39, 42] }  ]})})</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { Chart } from './ui/chart'<div className="card max-w(560) mx-auto">  <div className="card-header">    <h3 className="card-title">Requests</h3>    <p className="card-description">Millions per month, by region</p>  </div>  <Chart    id="requests"    type="area"    label="Requests per month by region, in millions"    labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']}    series={[      { name: 'Tokyo', values: [32, 36, 34, 41, 46, 44, 52, 56, 54, 61, 68, 72] },      { name: 'Frankfurt', values: [12, 14, 18, 17, 22, 26, 25, 30, 34, 33, 39, 42] }    ]}  /></div>
<script>  import Chart from './ui/Chart.svelte'</script><div class="card max-w(560) mx-auto">  <div class="card-header">    <h3 class="card-title">Requests</h3>    <p class="card-description">Millions per month, by region</p>  </div>  <Chart    id="requests"    type="area"    label="Requests per month by region, in millions"    labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']}    series={[      { name: 'Tokyo', values: [32, 36, 34, 41, 46, 44, 52, 56, 54, 61, 68, 72] },      { name: 'Frankfurt', values: [12, 14, 18, 17, 22, 26, 25, 30, 34, 33, 39, 42] }    ]}  /></div>
<script setup>import Chart from './ui/Chart.vue'</script><template>  <div class="card max-w(560) mx-auto">    <div class="card-header">      <h3 class="card-title">Requests</h3>      <p class="card-description">Millions per month, by region</p>    </div>    <Chart      id="requests"      type="area"      label="Requests per month by region, in millions"      :labels="['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']"      :series="[        { name: 'Tokyo', values: [32, 36, 34, 41, 46, 44, 52, 56, 54, 61, 68, 72] },        { name: 'Frankfurt', values: [12, 14, 18, 17, 22, 26, 25, 30, 34, 33, 39, 42] }      ]"    />  </div></template>
원하는 월에 포인터를 올리거나 Tab으로 차트에 포커스를 옮긴 뒤 방향키를 눌러 값을 확인합니다. 범례 항목을 선택하면 해당 계열을 숨길 수 있습니다.

#렌더링 방식

플롯은 viewBox가 없는 <svg>입니다. 너비는 주어진 공간에 맞추고 높이는 --chart-height로 정합니다. 기본값은 14rem입니다. 가는 안내선, 눈금, 막대, 점은 플롯에 대한 백분율로 배치합니다. 따라서 x="42%"에 놓인 막대는 너비와 상관없이 42% 위치에 있고, 모서리 반지름과 텍스트 크기도 그대로 유지됩니다.

선, 영역, 조각처럼 경로가 필요한 요소만 chart-canvas에 그립니다. 이 중첩 SVG는 100×100 좌표 영역을 플롯 크기에 맞춰 늘립니다. 선 두께는 함께 늘어나지 않으므로 좁은 카드와 넓은 카드에서 모두 --chart-stroke로 지정한 두께를 유지합니다.

너비가 바뀌어도 크기를 다시 측정하거나 차트를 다시 그릴 필요가 없으므로 서버, 프레임워크 컴포넌트, 동작 코드가 모두 같은 마크업을 생성합니다. 차트는 주어진 너비를 채웁니다. 여러 요소를 가로로 배치할 때는 차트에 너비를 지정하거나 남은 공간을 채우도록 설정합니다.

#차트 그리기

동작 코드는 chart 클래스가 있는 요소에 차트를 생성합니다. label에는 차트가 보여 주는 내용과 단위를 적습니다. labels에는 눈금의 각 위치에 붙일 이름을 지정하고, 각 계열에는 위치마다 값 하나를 넣습니다.

app.js
import { chart } from '@master/ui/behaviors/chart.js'chart(document.querySelector('.chart'), {  type: 'line',  label: 'Latency by region, in milliseconds',  labels: ['Jan', 'Feb', 'Mar', 'Apr'],  series: [    { name: 'Tokyo', values: [42, 44, 41, 47] },    { name: 'Frankfurt', values: [61, 58, 63, 66] },  ],})

서버에서는 chartMarkup()이 텍스트를 모두 이스케이프해 동일한 차트를 문자열로 반환합니다. 이 문자열을 요소에 넣으면 스크립트가 실행되기 전에도 차트를 읽을 수 있습니다. chartLayout()은 눈금 범위와 눈금값, 계열별 경로, 그리고 각 데이터 점과 그 표시 요소 및 설명 문장을 데이터로 반환합니다.

server.js
import { chartMarkup } from '@master/ui/behaviors/chart.js'const html = `<figure class="chart">${chartMarkup({ type: 'bar', label, labels, series })}</figure>`

계열을 전달하지 않고 해당 요소에 chart()를 호출하면 기존 차트 마크업에 동작을 연결합니다. @master/ui/behaviors의 attach()는 페이지의 모든 차트에 같은 동작을 연결합니다.

#필요한 차트 형태만 불러오기

chart.js에는 모든 형태가 들어 있으며, 축소 후 gzip으로 압축하면 약 16 kB입니다. 한두 가지 형태만 그리는 페이지에서는 필요한 형태만 불러올 수 있습니다. chart-core.js에는 차트의 기본 기능만 들어 있으며 크기는 약 6 kB입니다. 각 형태는 chartForms()에 전달하는 모듈입니다. 꺾은선, 영역, 막대 차트는 같은 눈금 체계를 공유하므로 한 모듈에서 함께 제공하며, 이 모듈을 추가하면 약 2 kB가 늘어납니다. 나머지 형태는 각각 1 kB 미만입니다.

app.js
import { chartCore, chartForms } from '@master/ui/behaviors/chart-core.js'import { chartCartesian } from '@master/ui/behaviors/chart-cartesian.js'chartForms(chartCartesian)chartCore(document.querySelector('.chart'), { type: 'line', label, labels, series })
모듈지원 형태
chart-cartesian.jsline, area, bar
chart-scatter.jsscatter
chart-pie.jspie, donut
chart-rings.js, chart-radar.js, chart-sunburst.jsrings, radar, sunburst
chart-waterfall.js, chart-range.jswaterfall; range, dumbbell
chart-slope.js, chart-bump.jsslope, bump
chart-marimekko.js, chart-funnel.js, chart-waffle.js, chart-treemap.jsmarimekko, funnel, waffle, treemap
chart-histogram.js, chart-box.js, chart-heatmap.jshistogram, box, heatmap

등록된 모듈에서 지원하지 않는 유형을 지정하면 가져와야 할 모듈을 알려 주는 오류가 발생해 누락을 바로 확인할 수 있습니다.

#차트 형태

각 형태의 페이지에서 예제와 관련 옵션을 확인할 수 있습니다.

형태type용도
꺾은선 차트line이어지는 값을 점과 점 사이의 선으로 표시합니다.
영역 차트area선 아래를 같은 색으로 옅게 채웁니다. 계열 하나를 표시하거나 여러 계열을 쌓아 합계를 나타냅니다.
기울기 차트slope두 시점 사이의 상승, 하락, 역전을 선의 기울기와 교차로 보여 줍니다.
순위 변화 차트bump여러 항목의 순위 변화를 보여 주며, 순위가 역전되는 곳에서 선이 교차합니다.
막대 차트bar기준선에서 시작하는 막대로 수량을 비교합니다. 막대를 나란히 배치하거나 쌓거나 가로로 그릴 수 있습니다.
레이더 차트radar같은 지표로 여러 항목을 비교하며, 각 항목을 공통 중심을 둘러싼 윤곽선으로 표시합니다.
폭포 차트waterfall시작값이 최종값에 이르기까지의 증감을 계단식으로 보여 줍니다.
범위 차트range각 범위의 시작값과 끝값을 보여 줍니다.
덤벨 차트dumbbell항목마다 두 값을 선으로 연결해 값 사이의 차이를 보여 줍니다.
원형 차트pie전체를 구성하는 각 부분을 원의 조각으로 표시합니다.
도넛 차트donut가운데 수치 하나를 두고, 그 둘레에 전체를 구성하는 각 부분을 표시합니다.
링 차트rings각 측정값이 해당 전체에서 차지하는 비율만큼 별도의 링을 채웁니다.
마리메코 차트marimekko각 열의 너비를 합계에 비례하게 정하고 열을 구성 항목별로 나눕니다.
퍼널 차트funnel한 흐름의 각 단계를 보여 주며, 다음 단계로 갈수록 폭이 좁아집니다.
와플 차트waffle100개 칸으로 전체를 나타내며, 각 칸은 1%에 해당합니다.
트리맵treemap전체를 구성하는 여러 부분을 각 비중에 비례하는 크기의 타일로 표시합니다.
선버스트 차트sunburst전체의 구성 항목과 각 항목의 하위 항목을 두 겹의 링으로 표시합니다.
히스토그램histogram떨어지는 수를 경계로 측정값을 여러 구간에 나누고, 구간마다 측정값 개수를 높이로 표시해 분포를 보여 줍니다.
상자 수염 그림box그룹마다 요약값 다섯 개를 상자, 중앙값 선, 수염으로 표시해 분포를 비교합니다.
히트맵heatmap두 축에 걸친 패턴을 각 셀의 값에 따른 색 농도로 보여 줍니다.
산점도scatter항목 하나를 점 하나로 표시해 두 측정값의 관계를 보여 줍니다.

꺾은선, 영역, 막대는 같은 눈금 체계를 사용하므로 한 차트에 함께 그릴 수 있습니다. 계열에 별도의 type을 지정하면 그 형태로 그립니다. 예를 들어 막대 위에 꺾은선을 겹칠 수 있습니다.

#값 표시와 키보드 조작

chart-tip은 값 표시 팝오버입니다. 데이터 점의 이름을 먼저 표시하고, 그 아래에 계열마다 해당 색상의 선, 계열 이름, 값을 한 줄에 표시합니다. 공간이 더 넓은 쪽에 데이터 점을 기준으로 배치하고, 팝오버 자체 높이를 기준으로 세로 위치를 조정합니다. 이렇게 하면 플롯을 벗어나지 않고 스크립트로 위치를 계산할 필요도 없습니다. 동작 코드는 데이터 점을 나타내는 요소에서 내용을 가져와 팝오버를 채우고, 그 점의 위치를 --chart-x, --chart-y, --chart-reach로 전달합니다.

데이터 점의 개수와 관계없이 플롯은 Tab으로 한 번만 포커스를 받습니다. 방향키로 데이터 점 사이를 이동하며 각 점의 값을 확인할 수 있습니다. 터치 화면에서는 차트를 따라 손가락을 움직이면 같은 방식으로 값을 확인할 수 있습니다.

키동작
Tab플롯 영역에 들어가면 마지막으로 탐색한 지점에 포커스를 두고 값 표시창을 엽니다. 처음 들어가면 첫 지점에 포커스를 둡니다. 그다음에는 범례의 체크박스로 이동합니다.
ArrowRight, ArrowDown다음 지점으로 이동하고 해당 지점의 값 표시창을 표시합니다.
ArrowLeft, ArrowUp이전 지점으로 이동합니다.
Home, End첫 번째 또는 마지막 지점으로 이동합니다.
Escape값 표시창을 숨기고 포커스는 지점에 유지합니다.
Space범례의 체크박스에서 해당 계열을 표시하거나 숨깁니다.

#범례

계열이 두 개 이상이면 범례를 표시해 색상 외에도 이름으로 계열을 구분할 수 있게 합니다. 각 항목은 체크박스를 감싸는 라벨이므로 Tab으로 이동하고 스페이스바로 선택을 전환할 수 있습니다. 선택을 해제하면 해당 계열이 숨겨지고 나머지 계열에 맞춰 눈금 범위가 조정됩니다. 다른 계열의 색상은 그대로 유지됩니다. 계열이 하나인 차트는 제목에서 내용을 알 수 있으므로 범례를 표시하지 않습니다.

toggle: false를 지정하면 범례를 일반 목록으로 표시합니다. 차트 주변 텍스트에서 각 계열의 이름을 설명하는 경우 legend: false로 범례를 생략할 수 있습니다. 차트의 값은 숨긴 계열의 이름 목록입니다. chart()의 반환값에서 이 목록을 읽거나 외부에서 설정해 계열을 숨길 수 있습니다.

#색상

계열이 하나인 차트는 잉크 색상인 --chart-color로 그립니다. 계열이 여러 개인 차트와 전체를 부분으로 나누는 차트에는 파랑, 주황, 청록, 보라, 호박색, 분홍, 초록, 하늘색 순으로 카테고리 색상을 적용합니다. 두 색상 모드에서 모두 주요 유형의 색각 이상이 있는 사용자도 이 순서에서 이웃한 색을 구분할 수 있습니다. 8개를 넘으면 처음 색상부터 반복되므로, 나머지 항목은 “기타”로 묶거나 차트를 하나 더 그립니다.

같은 항목에 항상 같은 색을 쓰려면 계열에 category를 직접 지정합니다. 예를 들어 도쿄는 목록의 순서와 관계없이 차트, 배지, 표의 행에서 모두 파란색으로 표시할 수 있습니다. 상태 색상은 계열에 사용하지 않습니다. 실패 상태인 계열은 그 상태를 텍스트로 표시합니다.

#눈금과 숫자 표기

눈금 범위는 0에서 시작하되 음수가 있으면 0 아래에서 시작합니다. 끝값은 최댓값보다 크면서 눈금 단위로 딱 떨어지는 수로 정하고, 눈금은 약 네 단계로 나눕니다. min과 max로 범위의 양 끝을 지정하고 ticks로 눈금 단계 수를 조정합니다. 막대의 길이 자체가 값을 나타내므로 막대 차트의 눈금은 0에서 시작해야 합니다.

format은 팝오버와 막대 끝에 표시되는 값의 형식을 정하고, tickFormat은 눈금값의 형식을 정합니다. 기본적으로 눈금값은 10,000 미만이면 전체 숫자로, 10,000 이상이면 축약형으로 표시합니다. 두 함수 모두 숫자를 받아 문자열을 반환합니다. locale은 숫자 형식에 사용할 BCP 47 태그이며 기본값은 en-US입니다. 서버에서 차트를 생성할 때 이 옵션을 지정하면 서버와 클라이언트의 표기가 일치합니다.

옵션기본값
type'bar'차트 형태에 나열된 유형 중 하나
label없음차트의 내용과 단위를 설명하는 플롯의 접근 가능한 이름
labels[]눈금을 따라, 레이더 차트 둘레에, 또는 히트맵의 각 열 위에 표시할 이름
series[]각 계열에는 name과 해당 형태에 필요한 values, value, points, ranges, children 중 하나를 지정합니다. category, type, low와 high, 링의 max를 추가로 지정할 수 있습니다.
stackedfalse막대나 영역을 쌓습니다. 'percent'는 각 누적 묶음을 100%로 맞추고, 'stream'은 누적 영역을 중심선에 맞춰 배치합니다.
horizontalfalse막대, 범위, 덤벨, 상자를 가로로 그립니다.
mark'bar''lollipop'은 막대를 끝에 점이 달린 선으로 그립니다.
curve'smooth'smooth, linear 또는 step
min, max, ticks자동, 4눈금 범위의 양 끝과 대략적인 단계 수입니다. 산점도의 가로축에는 xMin, xMax, xTicks를 사용합니다.
axistrue눈금값 표시 여부입니다. 타일 안의 작은 차트에서 false를 지정하면 가는 안내선만 남습니다.
format, tickFormat로캘 기본 형식값과 눈금값의 표시 형식입니다. 산점도의 가로축에는 xFormat을 사용합니다.
dots, valuesfalse각각 꺾은선의 모든 데이터 점을 표시하고 각 막대의 값을 표시합니다.
current없음aria-current가 지정된 데이터 점의 인덱스
legend, toggle계열이 두 개 이상일 때, true각각 범례 표시 여부와 범례 항목을 체크박스로 표시할지 여부입니다.
hole, center.7, 없음각각 도넛의 구멍 크기와 도넛 차트 또는 링 차트의 가운데에 표시할 내용입니다.
total없음폭포 차트 마지막 막대의 이름
bins측정값 개수에 따라 결정히스토그램에서 측정값을 나눌 대략적인 구간 수
ascendingfalse순위 변화 차트에서 가장 작은 값을 1위로 표시합니다.
words영어상자 수염 그림의 요약값 다섯 개에 붙이는 이름입니다. min, q1, median, q3, max에 각각 지정합니다.
hidden[]숨긴 계열의 이름
locale'en-US'숫자 형식에 사용할 BCP 47 태그
draw없음차트를 직접 그리는 렌더러에 넘기는 함수입니다. 숨긴 계열의 이름을 인수로 받아 마크업 생성을 맡습니다.

#스크립트 없이 사용하기

서버가 생성한 마크업만으로 차트가 완성됩니다. 스크린 리더는 각 데이터 점의 값을 읽을 수 있고, 스타일시트만으로도 포인터에 반응해 가는 안내선과 점을 표시하고 나머지 막대를 흐리게 합니다. 스크립트는 값 표시 팝오버, 키보드 조작, 범례 전환 기능을 추가합니다.

마크업으로 작성

<figure class="chart max-w(400) mx-auto" style="--chart-height: 10rem">  <div class="chart-body" style="--chart-gutter: 2">    <svg class="chart-plot" role="list" aria-label="Deployments per day, Monday to Friday">      <g aria-hidden="true">        <line class="chart-grid chart-grid-base" x1="0" y1="100%" x2="100%" y2="100%" />        <line class="chart-grid" x1="0" y1="75%" x2="100%" y2="75%" />        <line class="chart-grid" x1="0" y1="50%" x2="100%" y2="50%" />        <line class="chart-grid" x1="0" y1="25%" x2="100%" y2="25%" />        <line class="chart-grid" x1="0" y1="0%" x2="100%" y2="0%" />        <text class="chart-tick chart-tick-y" x="0" y="100%">0</text>        <text class="chart-tick chart-tick-y" x="0" y="75%">20</text>        <text class="chart-tick chart-tick-y" x="0" y="50%">40</text>        <text class="chart-tick chart-tick-y" x="0" y="25%">60</text>        <text class="chart-tick chart-tick-y" x="0" y="0%">80</text>        <text class="chart-tick chart-tick-x" x="10%" y="100%">Mon</text>        <text class="chart-tick chart-tick-x" x="30%" y="100%">Tue</text>        <text class="chart-tick chart-tick-x" x="50%" y="100%">Wed</text>        <text class="chart-tick chart-tick-x" x="70%" y="100%">Thu</text>        <text class="chart-tick chart-tick-x" x="90%" y="100%">Fri</text>      </g>      <g class="chart-point" role="listitem" aria-label="Mon: 42">        <rect class="chart-hit" x="0%" y="0" width="20%" height="100%" />        <rect class="chart-bar" x="3.8%" y="47.5%" width="12.4%" height="52.5%" />      </g>      <g class="chart-point" role="listitem" aria-label="Tue: 58">        <rect class="chart-hit" x="20%" y="0" width="20%" height="100%" />        <rect class="chart-bar" x="23.8%" y="27.5%" width="12.4%" height="72.5%" />      </g>      <g class="chart-point" role="listitem" aria-label="Wed: 36">        <rect class="chart-hit" x="40%" y="0" width="20%" height="100%" />        <rect class="chart-bar" x="43.8%" y="55%" width="12.4%" height="45%" />      </g>      <g class="chart-point" role="listitem" aria-label="Thu: 71">        <rect class="chart-hit" x="60%" y="0" width="20%" height="100%" />        <rect class="chart-bar" x="63.8%" y="11.25%" width="12.4%" height="88.75%" />      </g>      <g class="chart-point" role="listitem" aria-label="Fri: 64">        <rect class="chart-hit" x="80%" y="0" width="20%" height="100%" />        <rect class="chart-bar" x="83.8%" y="20%" width="12.4%" height="80%" />      </g>    </svg>  </div></figure>
<figure className="chart max-w(400) mx-auto" style={{ '--chart-height': '10rem' } as React.CSSProperties}>  <div className="chart-body" style={{ '--chart-gutter': '2' } as React.CSSProperties}>    <svg className="chart-plot" role="list" aria-label="Deployments per day, Monday to Friday">      <g aria-hidden="true">        <line className="chart-grid chart-grid-base" x1="0" y1="100%" x2="100%" y2="100%" />        <line className="chart-grid" x1="0" y1="75%" x2="100%" y2="75%" />        <line className="chart-grid" x1="0" y1="50%" x2="100%" y2="50%" />        <line className="chart-grid" x1="0" y1="25%" x2="100%" y2="25%" />        <line className="chart-grid" x1="0" y1="0%" x2="100%" y2="0%" />        <text className="chart-tick chart-tick-y" x="0" y="100%">0</text>        <text className="chart-tick chart-tick-y" x="0" y="75%">20</text>        <text className="chart-tick chart-tick-y" x="0" y="50%">40</text>        <text className="chart-tick chart-tick-y" x="0" y="25%">60</text>        <text className="chart-tick chart-tick-y" x="0" y="0%">80</text>        <text className="chart-tick chart-tick-x" x="10%" y="100%">Mon</text>        <text className="chart-tick chart-tick-x" x="30%" y="100%">Tue</text>        <text className="chart-tick chart-tick-x" x="50%" y="100%">Wed</text>        <text className="chart-tick chart-tick-x" x="70%" y="100%">Thu</text>        <text className="chart-tick chart-tick-x" x="90%" y="100%">Fri</text>      </g>      <g className="chart-point" role="listitem" aria-label="Mon: 42">        <rect className="chart-hit" x="0%" y="0" width="20%" height="100%" />        <rect className="chart-bar" x="3.8%" y="47.5%" width="12.4%" height="52.5%" />      </g>      <g className="chart-point" role="listitem" aria-label="Tue: 58">        <rect className="chart-hit" x="20%" y="0" width="20%" height="100%" />        <rect className="chart-bar" x="23.8%" y="27.5%" width="12.4%" height="72.5%" />      </g>      <g className="chart-point" role="listitem" aria-label="Wed: 36">        <rect className="chart-hit" x="40%" y="0" width="20%" height="100%" />        <rect className="chart-bar" x="43.8%" y="55%" width="12.4%" height="45%" />      </g>      <g className="chart-point" role="listitem" aria-label="Thu: 71">        <rect className="chart-hit" x="60%" y="0" width="20%" height="100%" />        <rect className="chart-bar" x="63.8%" y="11.25%" width="12.4%" height="88.75%" />      </g>      <g className="chart-point" role="listitem" aria-label="Fri: 64">        <rect className="chart-hit" x="80%" y="0" width="20%" height="100%" />        <rect className="chart-bar" x="83.8%" y="20%" width="12.4%" height="80%" />      </g>    </svg>  </div></figure>
<figure class="chart max-w(400) mx-auto" style="--chart-height: 10rem">  <div class="chart-body" style="--chart-gutter: 2">    <svg class="chart-plot" role="list" aria-label="Deployments per day, Monday to Friday">      <g aria-hidden="true">        <line class="chart-grid chart-grid-base" x1="0" y1="100%" x2="100%" y2="100%" />        <line class="chart-grid" x1="0" y1="75%" x2="100%" y2="75%" />        <line class="chart-grid" x1="0" y1="50%" x2="100%" y2="50%" />        <line class="chart-grid" x1="0" y1="25%" x2="100%" y2="25%" />        <line class="chart-grid" x1="0" y1="0%" x2="100%" y2="0%" />        <text class="chart-tick chart-tick-y" x="0" y="100%">0</text>        <text class="chart-tick chart-tick-y" x="0" y="75%">20</text>        <text class="chart-tick chart-tick-y" x="0" y="50%">40</text>        <text class="chart-tick chart-tick-y" x="0" y="25%">60</text>        <text class="chart-tick chart-tick-y" x="0" y="0%">80</text>        <text class="chart-tick chart-tick-x" x="10%" y="100%">Mon</text>        <text class="chart-tick chart-tick-x" x="30%" y="100%">Tue</text>        <text class="chart-tick chart-tick-x" x="50%" y="100%">Wed</text>        <text class="chart-tick chart-tick-x" x="70%" y="100%">Thu</text>        <text class="chart-tick chart-tick-x" x="90%" y="100%">Fri</text>      </g>      <g class="chart-point" role="listitem" aria-label="Mon: 42">        <rect class="chart-hit" x="0%" y="0" width="20%" height="100%" />        <rect class="chart-bar" x="3.8%" y="47.5%" width="12.4%" height="52.5%" />      </g>      <g class="chart-point" role="listitem" aria-label="Tue: 58">        <rect class="chart-hit" x="20%" y="0" width="20%" height="100%" />        <rect class="chart-bar" x="23.8%" y="27.5%" width="12.4%" height="72.5%" />      </g>      <g class="chart-point" role="listitem" aria-label="Wed: 36">        <rect class="chart-hit" x="40%" y="0" width="20%" height="100%" />        <rect class="chart-bar" x="43.8%" y="55%" width="12.4%" height="45%" />      </g>      <g class="chart-point" role="listitem" aria-label="Thu: 71">        <rect class="chart-hit" x="60%" y="0" width="20%" height="100%" />        <rect class="chart-bar" x="63.8%" y="11.25%" width="12.4%" height="88.75%" />      </g>      <g class="chart-point" role="listitem" aria-label="Fri: 64">        <rect class="chart-hit" x="80%" y="0" width="20%" height="100%" />        <rect class="chart-bar" x="83.8%" y="20%" width="12.4%" height="80%" />      </g>    </svg>  </div></figure>
<template>  <figure class="chart max-w(400) mx-auto" style="--chart-height: 10rem">    <div class="chart-body" style="--chart-gutter: 2">      <svg class="chart-plot" role="list" aria-label="Deployments per day, Monday to Friday">        <g aria-hidden="true">          <line class="chart-grid chart-grid-base" x1="0" y1="100%" x2="100%" y2="100%" />          <line class="chart-grid" x1="0" y1="75%" x2="100%" y2="75%" />          <line class="chart-grid" x1="0" y1="50%" x2="100%" y2="50%" />          <line class="chart-grid" x1="0" y1="25%" x2="100%" y2="25%" />          <line class="chart-grid" x1="0" y1="0%" x2="100%" y2="0%" />          <text class="chart-tick chart-tick-y" x="0" y="100%">0</text>          <text class="chart-tick chart-tick-y" x="0" y="75%">20</text>          <text class="chart-tick chart-tick-y" x="0" y="50%">40</text>          <text class="chart-tick chart-tick-y" x="0" y="25%">60</text>          <text class="chart-tick chart-tick-y" x="0" y="0%">80</text>          <text class="chart-tick chart-tick-x" x="10%" y="100%">Mon</text>          <text class="chart-tick chart-tick-x" x="30%" y="100%">Tue</text>          <text class="chart-tick chart-tick-x" x="50%" y="100%">Wed</text>          <text class="chart-tick chart-tick-x" x="70%" y="100%">Thu</text>          <text class="chart-tick chart-tick-x" x="90%" y="100%">Fri</text>        </g>        <g class="chart-point" role="listitem" aria-label="Mon: 42">          <rect class="chart-hit" x="0%" y="0" width="20%" height="100%" />          <rect class="chart-bar" x="3.8%" y="47.5%" width="12.4%" height="52.5%" />        </g>        <g class="chart-point" role="listitem" aria-label="Tue: 58">          <rect class="chart-hit" x="20%" y="0" width="20%" height="100%" />          <rect class="chart-bar" x="23.8%" y="27.5%" width="12.4%" height="72.5%" />        </g>        <g class="chart-point" role="listitem" aria-label="Wed: 36">          <rect class="chart-hit" x="40%" y="0" width="20%" height="100%" />          <rect class="chart-bar" x="43.8%" y="55%" width="12.4%" height="45%" />        </g>        <g class="chart-point" role="listitem" aria-label="Thu: 71">          <rect class="chart-hit" x="60%" y="0" width="20%" height="100%" />          <rect class="chart-bar" x="63.8%" y="11.25%" width="12.4%" height="88.75%" />        </g>        <g class="chart-point" role="listitem" aria-label="Fri: 64">          <rect class="chart-hit" x="80%" y="0" width="20%" height="100%" />          <rect class="chart-bar" x="83.8%" y="20%" width="12.4%" height="80%" />        </g>      </svg>    </div>  </figure></template>
스크립트 없이 동작합니다. 막대는 백분율로 배치하며, 한 막대에 포인터를 올리면 나머지 막대는 흐려집니다.

#모션

차트의 표시 요소는 처음 나타날 때 그려지는 애니메이션을 재생합니다. 막대는 기준선에서 차례로 올라오고, 선은 시작점부터 뻗어 나갑니다. 원형 조각과 레이더 차트의 도형은 중심에서 펼쳐지고, 링은 둘레를 따라 채워집니다. 팝오버는 데이터 점 사이를 부드럽게 이동합니다. 강조 표시가 손의 움직임을 따라갈 수 있도록 가는 안내선, 점, 흐려지는 막대는 즉시 반응합니다. 모션 감소 설정에서는 표시 요소가 완성된 상태로 나타나며 팝오버도 즉시 새 위치로 이동합니다.

#브라우저 기능

  • 막대의 둥근 모서리와 올라오는 효과는 SVG 도형에 적용한 clip-path로 구현합니다. CSS 도형으로 SVG 도형을 자를 수 없는 브라우저에서는 각진 막대가 처음부터 전체 길이로 표시됩니다.
  • 영역의 페이드 효과는 경로에 적용한 mask-image로 구현합니다. 이를 지원하지 않으면 영역 전체가 균일한 색으로 표시됩니다.
  • 점의 반지름은 --chart-dot으로 설정하는 CSS r 속성으로 지정합니다. 이 속성을 지원하지 않으면 마크업에 지정된 반지름을 사용합니다.
  • 라벨 수 줄이기는 플롯 본문에 적용한 컨테이너 쿼리로 구현합니다. 컨테이너 쿼리를 지원하지 않으면 모든 라벨을 표시합니다.
  • 처음 그려지는 효과는 @starting-style로 구현합니다. 이를 지원하지 않으면 표시 요소가 완성된 상태로 나타납니다.

#차트의 사용 범위

차트는 사용자가 개별적으로 탐색할 수 있는 표시 요소 수백 개를 그리도록 설계되었습니다. 데이터 점이 수천 개이거나 실시간으로 값이 들어오는 경우, 또는 확대, 브러시 선택, 지도, 캔들스틱이 필요한 경우에는 캔버스에 그리는 차트 엔진을 사용합니다. 더 간단한 표시에는 문장 안에 추세를 보여 주는 스파크라인, 수치 하나를 보여 주는 통계, 측정값 하나를 보여 주는 미터와 게이지, 전체의 구성을 막대 하나로 보여 주는 구성 내역, 여러 작은 값에 걸친 패턴을 보여 주는 히트맵이 있습니다. 차트 가이드에서 용도에 맞는 컴포넌트를 고를 수 있습니다.

#접근성

  • label에는 측정 대상과 단위를 설명하는 문장을 지정합니다. 이 문장은 목록으로 제공되는 플롯의 이름이 됩니다.
  • 각 데이터 점은 “목: 도쿄 71, 오사카 49”처럼 값을 포함한 이름을 가진 목록 항목입니다. 스크린 리더는 스크립트나 표 없이도 차트를 목록으로 읽습니다. 가는 안내선, 눈금, 팝오버는 데이터 점과 같은 정보를 반복하므로 스크린 리더에서 숨깁니다.
  • 값 표시 팝오버는 값을 눈으로 쉽게 확인할 수 있게 합니다. 포인터를 올리거나 포커스를 옮기거나 손가락으로 터치하면 나타나며 Esc를 누르면 닫힙니다.
  • 색상과 함께 계열 이름을 표시합니다. 범례에 계열 이름을 적고 팝오버에서 값 옆에 같은 이름을 표시합니다. 카테고리 색상으로 상태를 나타내지 않습니다.
  • 포커스를 받은 데이터 점은 해당 띠, 점, 조각 또는 링의 모양을 따라 윤곽선으로 표시합니다.
  • 강제 색상 모드에서는 잉크 색상과 가는 안내선에 시스템 색상을 적용하고 포커스에는 강조 색상을 씁니다. 계열에는 지정된 색상이 유지되므로 범례에 계열 이름을 표시합니다.
  • 눈금은 언어에 관계없이 왼쪽에서 시작합니다. 이름, 값, 범례는 페이지의 쓰기 방향을 따릅니다.

#React, Svelte, Vue

chart 컴포넌트는 chartLayout()의 결과로 차트를 생성하므로 서버가 처음 보내는 HTML에 차트가 포함됩니다. 컴포넌트는 값 표시 팝오버를 채우고 키보드 입력을 처리하는 동작도 연결합니다. 위 옵션을 props로 받으며, 컴포넌트의 값은 숨긴 계열의 이름 목록입니다. npx master-ui add chart로 프로젝트에 복사합니다. 컴포넌트의 구조와 사용법은 React, Svelte, Vue 가이드에서 확인할 수 있습니다.

ui/chart.tsx
'use client'import { useMemo, useState, type ComponentProps, type CSSProperties } from 'react'import { chart, chartLayout, type ChartConfig, type ChartLayout, type ChartMark, type ChartPoint, type ChartSeries } from '@master/ui/behaviors/chart.js'import { useBehavior } from './use-behavior'export type { ChartConfig, ChartSeries }export interface ChartProps extends Omit<ComponentProps<'figure'>, 'defaultValue' | 'children' | 'ref'>, Omit<ChartConfig, 'hidden'> {  /** The names of the hidden series, as the legend's unchecked boxes say. None by default. */  value?: string[]  defaultValue?: string[]  onValueChange?: (value: string[]) => void}const style = (properties: Record<string, string | number>) => properties as CSSPropertiesconst drawn = (item: ChartMark, index: number) => {  const className = item.category ? `${item.classes} category-${item.category}` : item.classes  const named = { 'data-name': item.name, 'data-value': item.name === undefined ? undefined : item.value ?? '' }  // What only this mark knows, a share of its color or a bubble's size, goes on as a custom property.  const known = item.tone === undefined && item.size === undefined ? undefined : style({ ...(item.tone === undefined ? null : { '--chart-tone': `${item.tone}%` }), ...(item.size === undefined ? null : { '--chart-dot': `${item.size}px` }) })  if (item.kind === 'bar') return <rect className={className} x={item.x} y={item.y} width={item.width} height={item.height} style={known} {...named} key={index} />  if (item.kind === 'dot') return <circle className={className} cx={item.cx} cy={item.cy} r={item.r || undefined} style={known} {...named} key={index} />  if (item.kind === 'line') return <line className={className} x1={item.x1} y1={item.y1} x2={item.x2} y2={item.y2} {...named} key={index} />  return <path className={className} d={item.d} strokeWidth={item.stroke || undefined} pathLength={item.kind === 'arc' ? 1 : undefined} style={known} {...named} key={index} />}const hit = (area: NonNullable<ChartPoint['hit']>) => 'd' in area  ? <path className="chart-hit" d={area.d} />  : 'r' in area    ? <circle className="chart-hit" cx={area.cx} cy={area.cy} r={area.r} />    : <rect className="chart-hit" x={area.x} y={area.y} width={area.width} height={area.height} />const entry = (key: ChartLayout['legend'][number]) => (  <><span className={key.mark} />{key.name}{key.value === undefined ? null : <span className="chart-key-value">{key.value}</span>}</>)/** * A chart, in every form the chart behavior lays out, in one SVG. React writes it from * `chartLayout()`, the same layout the behavior writes, so it is in the first HTML; the behavior shows the * readout of the point under the pointer or the keys, and says which series the legend hides. */export function Chart({ type, label, labels, series, stacked, horizontal, mark, curve, min, max, ticks, axis, format, tickFormat, xMin, xMax, xTicks, xFormat, dots, values, current, legend, toggle, legendLabel, hole, center, total, bins, ascending, words, locale, value, defaultValue, onValueChange, className, ...root }: ChartProps) {  const [first] = useState(() => value ?? defaultValue ?? [])  const [hidden, setHidden] = useState(first)  const layout = useMemo(    () => chartLayout({ type, label, labels, series, stacked, horizontal, mark, curve, min, max, ticks, axis, format, tickFormat, xMin, xMax, xTicks, xFormat, dots, values, current, legend, toggle, legendLabel, hole, center, total, bins, ascending, words, locale, hidden }),    [type, label, labels, series, stacked, horizontal, mark, curve, min, max, ticks, axis, format, tickFormat, xMin, xMax, xTicks, xFormat, dots, values, current, legend, toggle, legendLabel, hole, center, total, bins, ascending, words, locale, hidden],  )  const ref = useBehavior(chart, { hidden: first, draw: setHidden }, { value, defaultValue, onValueChange })  // The first point is the stop in the tab order of the first render; the behavior moves it from there.  const points = layout.points.map((point, index) => (    <g className="chart-point" role="listitem" aria-label={point.text} aria-current={point.current ? 'true' : undefined} data-label={point.label} tabIndex={index ? -1 : 0} style={style({ '--chart-x': point.x, '--chart-y': point.y, '--chart-reach': point.reach, '--chart-index': point.index })} key={point.index}>      {point.hit ? hit(point.hit) : null}      {point.cursor ? <line className="chart-cursor" x1={point.cursor.x1} y1={point.cursor.y1} x2={point.cursor.x2} y2={point.cursor.y2} /> : null}      {point.marks.map(drawn)}    </g>  ))  const paths = layout.paths.map((path, index) => <path className={path.category ? `${path.classes} category-${path.category}` : path.classes} d={path.d} style={path.tone === undefined ? undefined : style({ '--chart-tone': `${path.tone}%` })} key={index} />)  return (    <figure className={className ? `chart ${className}` : 'chart'} ref={ref} {...root}>      <div className="chart-body" style={style({ '--chart-gutter': layout.gutter, '--chart-tail': layout.tail })}>        <svg className={layout.classes} role="list" aria-label={layout.label || undefined}>          <g aria-hidden="true">            {layout.grid.map((line, index) => <line className={line.base ? 'chart-grid chart-grid-base' : 'chart-grid'} x1={line.x1} y1={line.y1} x2={line.x2} y2={line.y2} key={index} />)}            {layout.ticks.map((tick, index) => <text className={tick.classes} x={tick.x} y={tick.y} style={tick.at ? style({ '--chart-x': tick.at[0], '--chart-y': tick.at[1] }) : undefined} key={index}>{tick.text}</text>)}          </g>          <svg className="chart-canvas" viewBox={layout.viewBox} preserveAspectRatio={layout.stretch ? 'none' : undefined} role={layout.radial ? 'presentation' : undefined} aria-hidden={layout.radial ? undefined : 'true'}>{paths}{layout.radial ? points : null}</svg>          {layout.radial ? null : points}          {layout.values.length ? <g aria-hidden="true">{layout.values.map((written, index) => <text className={written.classes} x={written.x} y={written.y} key={index}>{written.text}</text>)}</g> : null}        </svg>        {layout.center ? (          <div className="chart-center">            {layout.center.value ? <p className="chart-center-value">{layout.center.value}</p> : null}            {layout.center.label ? <p className="chart-center-label">{layout.center.label}</p> : null}          </div>        ) : null}        <div className="chart-tip" aria-hidden="true" hidden />      </div>      {!layout.legend.length ? null : layout.toggle ? (        <div className="chart-legend" role="group" aria-label={layout.legendLabel}>          {layout.legend.map(key => (            <label className={key.category ? `chart-key category-${key.category}` : 'chart-key'} key={key.name}>              <input type="checkbox" className="chart-key-input" value={key.name} defaultChecked={!key.hidden} />{entry(key)}            </label>          ))}        </div>      ) : (        <ul className="chart-legend" aria-label={layout.legendLabel}>          {layout.legend.map(key => <li className={key.category ? `chart-key category-${key.category}` : 'chart-key'} key={key.name}>{entry(key)}</li>)}        </ul>      )}    </figure>  )}
ui/Chart.svelte
<script lang="ts" module>  import type { HTMLAttributes } from 'svelte/elements'  import type { ChartConfig, ChartSeries } from '@master/ui/behaviors/chart.js'  export type { ChartConfig, ChartSeries }  export interface ChartProps extends Omit<HTMLAttributes<HTMLElement>, 'children'>, Omit<ChartConfig, 'hidden'> {    /** The names of the hidden series, as the legend's unchecked boxes say. Bind it, or leave it out: none. */    value?: string[]    onValueChange?: (value: string[]) => void  }</script><script lang="ts">  import { untrack } from 'svelte'  import { chart, chartLayout, type ChartLayout, type ChartMark } from '@master/ui/behaviors/chart.js'  import { behavior } from './behavior.svelte.js'  let { type, label, labels, series, stacked, horizontal, mark, curve, min, max, ticks, axis, format, tickFormat, xMin, xMax, xTicks, xFormat, dots, values, current, legend, toggle, legendLabel, hole, center, total, bins, ascending, words, locale, value = $bindable(), onValueChange, class: className, ...root }: ChartProps = $props()  const first = untrack(() => value ?? [])  let hidden = $state.raw(first)  const layout = $derived(chartLayout({ type, label, labels, series, stacked, horizontal, mark, curve, min, max, ticks, axis, format, tickFormat, xMin, xMax, xTicks, xFormat, dots, values, current, legend, toggle, legendLabel, hole, center, total, bins, ascending, words, locale, hidden }))  const attach = behavior(chart, () => ({ hidden: first, draw: (next: string[]) => { hidden = next } }), {    value: () => value,    change: (next) => { value = next; onValueChange?.(next) },  })  const classes = (item: ChartMark | ChartLayout['paths'][number]) => (item.category ? `${item.classes} category-${item.category}` : item.classes)  /** What only a mark knows, a share of its color or a bubble's size, goes on as a custom property. */  const known = (item: { tone?: number, size?: number }) => [item.tone === undefined ? '' : `--chart-tone: ${item.tone}%`, item.size === undefined ? '' : `--chart-dot: ${item.size}px`].filter(Boolean).join('; ') || undefined</script><!--  @component  A chart, in every form the chart behavior lays out, in one SVG. Svelte writes it from  `chartLayout()`, the same layout the behavior writes, so it is in the first HTML; the behavior shows the  readout of the point under the pointer or the keys, and says which series the legend hides.-->{#snippet points()}  {#each layout.points as point, at (point.index)}    <!-- The first point is the stop in the tab order of the first render; the behavior moves it from there. A form         may pass over a series, so the first point is the first written, whatever its index. -->    <!-- svelte-ignore a11y_no_noninteractive_tabindex -->    <g class="chart-point" role="listitem" aria-label={point.text} aria-current={point.current ? 'true' : undefined} data-label={point.label} tabindex={at ? -1 : 0} style="--chart-x: {point.x}; --chart-y: {point.y}; --chart-reach: {point.reach}; --chart-index: {point.index}">      {#if point.hit && 'd' in point.hit}        <path class="chart-hit" d={point.hit.d} />      {:else if point.hit && 'r' in point.hit}        <circle class="chart-hit" cx={point.hit.cx} cy={point.hit.cy} r={point.hit.r} />      {:else if point.hit}        <rect class="chart-hit" x={point.hit.x} y={point.hit.y} width={point.hit.width} height={point.hit.height} />      {/if}      {#if point.cursor}<line class="chart-cursor" x1={point.cursor.x1} y1={point.cursor.y1} x2={point.cursor.x2} y2={point.cursor.y2} />{/if}      {#each point.marks as item, at (at)}        {#if item.kind === 'bar'}          <rect class={classes(item)} x={item.x} y={item.y} width={item.width} height={item.height} style={known(item)} data-name={item.name} data-value={item.name === undefined ? undefined : item.value ?? ''} />        {:else if item.kind === 'dot'}          <circle class={classes(item)} cx={item.cx} cy={item.cy} r={item.r || undefined} style={known(item)} data-name={item.name} data-value={item.name === undefined ? undefined : item.value ?? ''} />        {:else if item.kind === 'line'}          <line class={classes(item)} x1={item.x1} y1={item.y1} x2={item.x2} y2={item.y2} data-name={item.name} data-value={item.name === undefined ? undefined : item.value ?? ''} />        {:else}          <path class={classes(item)} d={item.d} stroke-width={item.stroke || undefined} pathLength={item.kind === 'arc' ? 1 : undefined} style={known(item)} data-name={item.name} data-value={item.name === undefined ? undefined : item.value ?? ''} />        {/if}      {/each}    </g>  {/each}{/snippet}{#snippet entry(key: ChartLayout['legend'][number])}  <span class={key.mark}></span>{key.name}{#if key.value !== undefined}<span class="chart-key-value">{key.value}</span>{/if}{/snippet}<figure class={['chart', className]} {@attach attach} {...root}>  <div class="chart-body" style="--chart-gutter: {layout.gutter}; --chart-tail: {layout.tail}">    <svg class={layout.classes} role="list" aria-label={layout.label || undefined}>      <g aria-hidden="true">        {#each layout.grid as line, index (index)}<line class={['chart-grid', line.base && 'chart-grid-base']} x1={line.x1} y1={line.y1} x2={line.x2} y2={line.y2} />{/each}        {#each layout.ticks as tick, index (index)}<text class={tick.classes} x={tick.x} y={tick.y} style={tick.at ? `--chart-x: ${tick.at[0]}; --chart-y: ${tick.at[1]}` : undefined}>{tick.text}</text>{/each}      </g>      <svg class="chart-canvas" viewBox={layout.viewBox} preserveAspectRatio={layout.stretch ? 'none' : undefined} role={layout.radial ? 'presentation' : undefined} aria-hidden={layout.radial ? undefined : 'true'}>        {#each layout.paths as path, index (index)}<path class={classes(path)} d={path.d} style={known(path)} />{/each}        {#if layout.radial}{@render points()}{/if}      </svg>      {#if !layout.radial}{@render points()}{/if}      {#if layout.values.length}        <g aria-hidden="true">          {#each layout.values as written, index (index)}<text class={written.classes} x={written.x} y={written.y}>{written.text}</text>{/each}        </g>      {/if}    </svg>    {#if layout.center}      <div class="chart-center">        {#if layout.center.value}<p class="chart-center-value">{layout.center.value}</p>{/if}        {#if layout.center.label}<p class="chart-center-label">{layout.center.label}</p>{/if}      </div>    {/if}    <div class="chart-tip" aria-hidden="true" hidden></div>  </div>  {#if layout.legend.length && layout.toggle}    <div class="chart-legend" role="group" aria-label={layout.legendLabel}>      {#each layout.legend as key (key.name)}        <label class={['chart-key', key.category && `category-${key.category}`]}><input type="checkbox" class="chart-key-input" value={key.name} checked={!key.hidden} />{@render entry(key)}</label>      {/each}    </div>  {:else if layout.legend.length}    <ul class="chart-legend" aria-label={layout.legendLabel}>      {#each layout.legend as key (key.name)}<li class={['chart-key', key.category && `category-${key.category}`]}>{@render entry(key)}</li>{/each}    </ul>  {/if}</figure>
ui/Chart.vue
<script lang="ts">import type { ChartConfig, ChartSeries } from '@master/ui/behaviors/chart.js'export type { ChartConfig, ChartSeries }</script><script setup lang="ts">import { computed, shallowRef, useTemplateRef } from 'vue'import { chart, chartLayout, type ChartLayout, type ChartMark, type ChartType } from '@master/ui/behaviors/chart.js'import { useBehavior } from './use-behavior'defineOptions({ inheritAttrs: false })// A legend, its checkboxes and the scale's figures are the chart's to decide when they are left out: absent is not false.const { type, label, labels, series, stacked, horizontal, mark, curve, min, max, ticks, axis = undefined, format, tickFormat, xMin, xMax, xTicks, xFormat, dots, values, current, legend = undefined, toggle = undefined, legendLabel, hole, center, total, bins, ascending, words, locale } = defineProps<{  /** `bar` by default. */  type?: ChartType  /** What the chart shows and in what unit: the plot's accessible name. */  label?: string  /** The names along the scale, around a radar or of a heatmap's columns. */  labels?: string[]  series?: ChartSeries[]  /** Bars, or areas, stand on each other instead of side by side. `percent` makes every stack a whole; `stream` centers stacked areas on a middle line. */  stacked?: boolean | 'percent' | 'stream'  /** Bars, ranges, dumbbells and boxes run across, one row to a label. */  horizontal?: boolean  /** How a bar is drawn: `lollipop` is a stem with a dot at its end. */  mark?: 'bar' | 'lollipop'  /** How a line goes from point to point. `smooth` never overshoots a value. */  curve?: 'smooth' | 'linear' | 'step'  /** Where the scale starts and ends. 0, or the lowest value below it, to a round number above the highest by default. */  min?: number  max?: number  /** About how many steps the scale is marked in. 4 by default. */  ticks?: number  /** Whether the scale's figures are written. False leaves its hairlines alone. */  axis?: boolean  /** How a value is written beside its name. */  format?: (value: number) => string  /** How a tick is written. Compact once the scale reaches 10,000 by default. */  tickFormat?: (value: number) => string  /** A scatter's scale across, as `min`, `max`, `ticks` and `tickFormat`. */  xMin?: number  xMax?: number  xTicks?: number  xFormat?: (value: number) => string  /** A line's points are always marked, not only the one under the pointer. */  dots?: boolean  /** Every bar's value is written at its end. */  values?: boolean  /** The index of the point that is the point of the chart: it is marked `aria-current`. */  current?: number  /** Whether a legend is written. With two series or more by default. */  legend?: boolean  /** Whether the legend's entries are checkboxes that show and hide a series. True by default. */  toggle?: boolean  /** The legend's accessible name. `Series` by default. */  legendLabel?: string  /** A donut's hole, as a share of its radius. .7 by default. */  hole?: number  /** What stands in a donut's hole or within rings. */  center?: { value: string, label?: string }  /** A waterfall's closing bar: its name. Without one the chart ends on its last step. */  total?: string  /** About how many bins a histogram sorts its readings into. Chosen from their count by default. */  bins?: number  /** In a bump chart, the lowest value ranks first. */  ascending?: boolean  /** The names of a box plot's five figures, in the page's language. */  words?: { min?: string, q1?: string, median?: string, q3?: string, max?: string }  /** A BCP 47 tag for the numbers. `en-US` by default. */  locale?: string}>()/** The names of the hidden series, as the legend's unchecked boxes say: `v-model`. None by default. */const model = defineModel<string[]>()/* * A chart, in every form the chart behavior lays out, in one SVG. Vue writes it from * `chartLayout()`, the same layout the behavior writes, so it is in the first HTML; the behavior shows the * readout of the point under the pointer or the keys, and says which series the legend hides. * * The points are written in one of two places: in the canvas where the layout is `radial`, on the plot otherwise. The * first written, whatever its index, is the stop in the tab order of the first render; the behavior moves it from * there. */const first = model.value ?? []const hidden = shallowRef<string[]>(first)const layout = computed(() => chartLayout({ type, label, labels, series, stacked, horizontal, mark, curve, min, max, ticks, axis, format, tickFormat, xMin, xMax, xTicks, xFormat, dots, values, current, legend, toggle, legendLabel, hole, center, total, bins, ascending, words, locale, hidden: hidden.value }))const root = useTemplateRef<HTMLElement>('root')useBehavior(root, chart, () => ({ hidden: first, draw: (next: string[]) => { hidden.value = next } }), model)const classes = (item: ChartMark | ChartLayout['paths'][number]) => (item.category ? `${item.classes} category-${item.category}` : item.classes)const named = (item: ChartMark) => (item.name === undefined ? undefined : item.value ?? '')/** What only a mark knows, a share of its color or a bubble's size, goes on as a custom property; any other mark has no style. */const known = (item: { tone?: number, size?: number }) => {  const style = [item.tone === undefined ? '' : `--chart-tone: ${item.tone}%`, item.size === undefined ? '' : `--chart-dot: ${item.size}px`].filter(Boolean).join('; ')  return style ? { style } : undefined}/** A name around a radar is moved to its place in the square; any other tick has no style. */const place = (at: [number, number] | null) => (at ? { style: `--chart-x: ${at[0]}; --chart-y: ${at[1]}` } : undefined)</script><template>  <figure class="chart" ref="root" v-bind="$attrs">    <div class="chart-body" :style="`--chart-gutter: ${layout.gutter}; --chart-tail: ${layout.tail}`">      <svg :class="layout.classes" role="list" :aria-label="layout.label || undefined">        <g aria-hidden="true">          <line v-for="(line, index) in layout.grid" :key="index" class="chart-grid" :class="{ 'chart-grid-base': line.base }" :x1="line.x1" :y1="line.y1" :x2="line.x2" :y2="line.y2" />          <text v-for="(tick, index) in layout.ticks" :key="index" :class="tick.classes" :x="tick.x" :y="tick.y" v-bind="place(tick.at)">{{ tick.text }}</text>        </g>        <svg class="chart-canvas" :viewBox="layout.viewBox" :preserveAspectRatio="layout.stretch ? 'none' : undefined" :role="layout.radial ? 'presentation' : undefined" :aria-hidden="layout.radial ? undefined : 'true'">          <path v-for="(path, index) in layout.paths" :key="index" :class="classes(path)" :d="path.d" v-bind="known(path)" />          <template v-if="layout.radial">            <g v-for="(point, position) in layout.points" :key="point.index" class="chart-point" role="listitem" :aria-label="point.text" :aria-current="point.current ? 'true' : undefined" :data-label="point.label" :tabindex="position ? -1 : 0" :style="`--chart-x: ${point.x}; --chart-y: ${point.y}; --chart-reach: ${point.reach}; --chart-index: ${point.index}`">              <path v-if="point.hit && 'd' in point.hit" class="chart-hit" :d="point.hit.d" />              <circle v-else-if="point.hit && 'r' in point.hit" class="chart-hit" :cx="point.hit.cx" :cy="point.hit.cy" :r="point.hit.r" />              <rect v-else-if="point.hit" class="chart-hit" :x="point.hit.x" :y="point.hit.y" :width="point.hit.width" :height="point.hit.height" />              <line v-if="point.cursor" class="chart-cursor" :x1="point.cursor.x1" :y1="point.cursor.y1" :x2="point.cursor.x2" :y2="point.cursor.y2" />              <template v-for="(item, at) in point.marks" :key="at">                <rect v-if="item.kind === 'bar'" :class="classes(item)" :x="item.x" :y="item.y" :width="item.width" :height="item.height" v-bind="known(item)" :data-name="item.name" :data-value="named(item)" />                <circle v-else-if="item.kind === 'dot'" :class="classes(item)" :cx="item.cx" :cy="item.cy" :r="item.r || undefined" v-bind="known(item)" :data-name="item.name" :data-value="named(item)" />                <line v-else-if="item.kind === 'line'" :class="classes(item)" :x1="item.x1" :y1="item.y1" :x2="item.x2" :y2="item.y2" :data-name="item.name" :data-value="named(item)" />                <path v-else :class="classes(item)" :d="item.d" :stroke-width="item.stroke || undefined" :pathLength="item.kind === 'arc' ? 1 : undefined" v-bind="known(item)" :data-name="item.name" :data-value="named(item)" />              </template>            </g>          </template>        </svg>        <template v-if="!layout.radial">          <g v-for="(point, position) in layout.points" :key="point.index" class="chart-point" role="listitem" :aria-label="point.text" :aria-current="point.current ? 'true' : undefined" :data-label="point.label" :tabindex="position ? -1 : 0" :style="`--chart-x: ${point.x}; --chart-y: ${point.y}; --chart-reach: ${point.reach}; --chart-index: ${point.index}`">            <path v-if="point.hit && 'd' in point.hit" class="chart-hit" :d="point.hit.d" />            <circle v-else-if="point.hit && 'r' in point.hit" class="chart-hit" :cx="point.hit.cx" :cy="point.hit.cy" :r="point.hit.r" />            <rect v-else-if="point.hit" class="chart-hit" :x="point.hit.x" :y="point.hit.y" :width="point.hit.width" :height="point.hit.height" />            <line v-if="point.cursor" class="chart-cursor" :x1="point.cursor.x1" :y1="point.cursor.y1" :x2="point.cursor.x2" :y2="point.cursor.y2" />            <template v-for="(item, at) in point.marks" :key="at">              <rect v-if="item.kind === 'bar'" :class="classes(item)" :x="item.x" :y="item.y" :width="item.width" :height="item.height" v-bind="known(item)" :data-name="item.name" :data-value="named(item)" />              <circle v-else-if="item.kind === 'dot'" :class="classes(item)" :cx="item.cx" :cy="item.cy" :r="item.r || undefined" v-bind="known(item)" :data-name="item.name" :data-value="named(item)" />              <line v-else-if="item.kind === 'line'" :class="classes(item)" :x1="item.x1" :y1="item.y1" :x2="item.x2" :y2="item.y2" :data-name="item.name" :data-value="named(item)" />              <path v-else :class="classes(item)" :d="item.d" :stroke-width="item.stroke || undefined" :pathLength="item.kind === 'arc' ? 1 : undefined" v-bind="known(item)" :data-name="item.name" :data-value="named(item)" />            </template>          </g>        </template>        <g v-if="layout.values.length" aria-hidden="true">          <text v-for="(written, index) in layout.values" :key="index" :class="written.classes" :x="written.x" :y="written.y">{{ written.text }}</text>        </g>      </svg>      <div v-if="layout.center" class="chart-center">        <p v-if="layout.center.value" class="chart-center-value">{{ layout.center.value }}</p>        <p v-if="layout.center.label" class="chart-center-label">{{ layout.center.label }}</p>      </div>      <div class="chart-tip" aria-hidden="true" hidden></div>    </div>    <div v-if="layout.legend.length && layout.toggle" class="chart-legend" role="group" :aria-label="layout.legendLabel">      <label v-for="key in layout.legend" :key="key.name" class="chart-key" :class="key.category && `category-${key.category}`"><input type="checkbox" class="chart-key-input" :value="key.name" :checked="!key.hidden" /><span :class="key.mark"></span>{{ key.name }}<span v-if="key.value !== undefined" class="chart-key-value">{{ key.value }}</span></label>    </div>    <ul v-else-if="layout.legend.length" class="chart-legend" :aria-label="layout.legendLabel">      <li v-for="key in layout.legend" :key="key.name" class="chart-key" :class="key.category && `category-${key.category}`"><span :class="key.mark"></span>{{ key.name }}<span v-if="key.value !== undefined" class="chart-key-value">{{ key.value }}</span></li>    </ul>  </figure></template>

복사한 컴포넌트가 선, 영역, 막대 차트만 그린다면 chart.js 임포트를 차트 코어와 Cartesian 형식으로 바꾸세요. 필요한 타입도 chart-core.js에서 임포트하고 모듈 범위에서 형식을 등록합니다.

import { chartCore as chart, chartForms, chartLayout } from '@master/ui/behaviors/chart-core.js'import { chartCartesian } from '@master/ui/behaviors/chart-cartesian.js'chartForms(chartCartesian)

별칭을 사용하면 복사한 컴포넌트가 기존 동작 연결을 그대로 사용합니다. 서버는 chartLayout()으로 렌더링하고, 연결된 동작으로 방향키를 사용해 점 사이를 이동하거나 Escape로 값 표시를 닫을 수 있습니다.

#클래스

클래스설명
chart차트는 플롯 영역 본체와 그 아래의 범례로 구성됩니다.
chart-quiet막대는 옅은 색으로 표시하고, aria-current로 표시한 지점에는 기본 전경색을 사용합니다.적용할 클래스는 chart입니다
chart-split범례는 이름과 수치를 세로로 나열해 플롯 영역 옆에 배치하며, 옆에 공간이 부족하면 아래에 배치합니다.적용할 클래스는 chart입니다
chart-body플롯 영역을 기준으로 값 표시창을 배치합니다. --chart-gutter는 그 옆에 눈금 숫자가 들어갈 공간을 확보합니다.
chart-plotSVG입니다. 너비는 주어진 공간을 채우고 높이는 --chart-height입니다. role="list"와 함께 무엇을 어떤 단위로 보여 주는지 알려 주는 이름을 지정하세요.
chart-plot-radial원형 차트, 도넛 차트, 링, 선버스트 또는 와플 차트에 사용합니다. 한 변의 길이가 --chart-size인 정사각형입니다.적용할 클래스는 chart-plot입니다
chart-plot-radar레이더 차트는 플롯 영역 가운데의 정사각형에 놓이며, 정사각형 주위에는 이름을 표시할 공간을 둡니다.적용할 클래스는 chart-plot입니다
chart-canvas중첩 SVG 경로를 그리는 좌표 영역입니다. 100 × 100 영역은 preserveAspectRatio="none"으로 플롯 영역에 맞춰 늘립니다. 방사형 차트에서는 0을 중심으로 하는 영역의 비율을 유지합니다. 데이터 포인트를 경로로 표시하는 차트에서는 해당 경로를 이 영역에 배치합니다.
chart-grid백분율로 배치하는 눈금의 가는 선
chart-grid-base기준선입니다. 한 단계 더 진하게 표시합니다.적용할 클래스는 chart-grid입니다
chart-tick눈금 숫자 또는 눈금을 따라 놓이는 이름
chart-tick-y플롯 영역 옆에서 해당 눈금선에 맞춰 배치합니다.적용할 클래스는 chart-tick입니다
chart-tick-x플롯 영역 아래에서 해당 위치에 가운데를 맞춥니다.적용할 클래스는 chart-tick입니다
chart-tick-around레이더 차트의 둘레에 배치합니다. 플롯 영역 가운데를 기준으로 정사각형의 --chart-x 및 --chart-y 위치로 옮깁니다.적용할 클래스는 chart-tick입니다
chart-tick-start해당 위치를 중심으로 놓이는 대신 그 위치에서 시작합니다. 가장자리에서 가장자리까지 이어지는 선의 첫 번째 이름에 사용합니다.적용할 클래스는 chart-tick입니다
chart-tick-end해당 위치에서 끝납니다.적용할 클래스는 chart-tick입니다
chart-tick-scale레이더의 눈금 숫자입니다. 첫 번째 축선 옆에 작게 표시합니다.적용할 클래스는 chart-tick입니다
chart-tick-minor플롯 영역이 24rem보다 좁으면 숨기는 이름적용할 클래스는 chart-tick입니다
chart-line선으로 나타낸 계열입니다. 캔버스가 아무리 늘어나도 --chart-stroke 두께를 유지합니다.
chart-area선 아래의 영역입니다. 선과 같은 색을 옅게 깔고 아래로 갈수록 흐려집니다.
chart-area-stacked누적 영역의 한 층입니다. 아래층을 가리는 옅은 색으로 채웁니다.적용할 클래스는 chart-area입니다
chart-point축의 한 단계, 부채꼴 하나, 링 하나, 타일 하나, 기울기 차트의 계열 하나 또는 점 하나와 그 표시 요소를 담습니다. role="listitem"과 값을 설명하는 이름을 지정합니다. 값 표시에는 --chart-x, --chart-y, --chart-reach가 사용됩니다.
chart-hit표식 자체를 넘어 포인터 입력을 받는 영역입니다. 한 눈금 간격에 해당하는 띠, 점 주변의 공간, 레이더 차트의 부채꼴이 이에 해당합니다. 포커스 링은 이 영역에 그립니다.
chart-hit-line선을 따라 배치한 넓고 투명한 획으로 포인터 입력을 받습니다.적용할 클래스는 chart-hit입니다
chart-cursor지점을 지나는 가는 선으로, 지점이 포인터 아래에 있거나 포커스를 받는 동안 표시됩니다.
chart-bar백분율로 배치하는 막대입니다. 기준선 반대쪽 끝의 모서리가 둥글게 처리됩니다.
chart-bar-inner누적 막대에서 다른 막대 아래에 놓이는 막대입니다. 모서리가 각지고, 다음 막대와의 사이에 --chart-gap만큼 간격을 둡니다.적용할 클래스는 chart-bar입니다
chart-bar-down0보다 작은 값입니다. 아래쪽 끝의 모서리가 둥글게 처리되며, 가로 막대에서는 시작 쪽 끝의 모서리가 둥글게 처리됩니다.적용할 클래스는 chart-bar입니다
chart-bar-across가로 막대입니다. 먼 쪽 끝의 모서리가 둥글게 처리됩니다.적용할 클래스는 chart-bar입니다
chart-bar-floating기준선에 닿지 않는 두 값 사이의 막대는 양쪽 끝을 둥글게 처리합니다.적용할 클래스는 chart-bar입니다
chart-bar-bin히스토그램의 구간 막대는 이웃한 막대와 맞닿으며, 표면 색상의 아주 가는 선으로 구분합니다.적용할 클래스는 chart-bar입니다
chart-bar-rise폭포 차트의 상승 단계에는 성공 색상을 적용합니다.적용할 클래스는 chart-bar입니다
chart-bar-fall폭포 차트의 하락 단계에는 위험 색상을 적용합니다.적용할 클래스는 chart-bar입니다
chart-dot선, 레이더 또는 산점도의 지점입니다. 계열 색의 점에 표면색 테두리를 두릅니다.
chart-dot-quiet해당 지점이 포인터 아래에 있거나 포커스를 받는 동안에만 표시됩니다.적용할 클래스는 chart-dot입니다
chart-dot-bubble버블은 --chart-dot 크기이며, 테두리 안쪽을 같은 색의 옅은 색조로 채웁니다.적용할 클래스는 chart-dot입니다
chart-dot-outlier상자 수염 그림에서 다른 값들과 멀리 떨어진 이상치는 속이 빈 작은 점으로 표시합니다.적용할 클래스는 chart-dot입니다
chart-value플롯 영역에 표시하는 레이블. 막대 끝에는 값, 선의 마지막 데이터 점에는 계열 이름, 타일에는 이름을 표시합니다.
chart-value-across가로 막대의 끝 다음에 놓입니다.적용할 클래스는 chart-value입니다
chart-value-before플롯 영역 앞에서 시작해 플롯 영역의 경계에서 끝납니다.적용할 클래스는 chart-value입니다
chart-value-tile타일의 첫 모서리부터 이름을 표시합니다.적용할 클래스는 chart-value입니다
chart-value-quiet타일 이름 아래에 값을 덜 강조해 표시합니다.적용할 클래스는 chart-value입니다
chart-slice원형 차트 또는 도넛 차트의 조각
chart-track링의 트랙입니다. 값을 견주어 읽는 전체를 나타내며, 링 색을 옅게 입혀 표시합니다.
chart-arc링의 값을 나타냅니다. 맨 위에서 시작하며 양 끝이 둥급니다. 처음 나타날 때 채워지도록 pathLength="1"을 지정합니다.
chart-web레이더의 방사형 격자입니다. 눈금마다 링이 하나씩, 이름마다 축선이 하나씩 놓입니다.
chart-shape레이더의 계열입니다. 윤곽선과 그 안에 옅게 깔린 같은 색으로 그립니다.
chart-band선의 값이 가질 수 있는 하한과 상한 사이를 띠로 표시합니다.
chart-stem롤리팝 차트에서 기준선과 점을 잇는 선과 덤벨 차트에서 양 끝점을 잇는 선
chart-whisker값의 하한에서 상한까지 이어지며 막대 끝이나 상자를 지나는 선
chart-box제1사분위수에서 제3사분위수까지 이어지는 상자 수염 그림의 상자
chart-median중앙값을 표시하는 선이 상자를 가로지르며, 선에는 표면 색상을 적용합니다.
chart-link폭포 차트에서 한 막대의 끝과 다음 막대를 잇는 가는 선
chart-knot기울기 차트나 순위 변화 차트의 점은 길이가 0이고 끝이 둥근 경로로 그립니다. 캔버스가 늘어나도 원형을 유지합니다.
chart-cell히트맵의 셀입니다. --chart-tone으로 지정한 비율만큼 색상을 적용합니다.
chart-unit와플 차트의 한 칸은 전체의 1%를 나타냅니다.
chart-stage퍼널 차트의 각 단계는 이전 단계보다 한 톤 밝습니다.
chart-tile트리맵의 타일은 옅은 색으로 채우고 그 안에 이름을 표시합니다.
chart-center도넛의 구멍이나 링 안쪽에 놓이는 내용
chart-center-value가운데에 놓이는 수치
chart-center-label수치가 세는 대상
chart-tip포인터 아래의 지점 옆에 놓이는 값 표시창입니다. 동작이 내용을 채우기 전까지는 숨겨져 있습니다.
chart-tip-title지점의 이름
chart-tip-row값 표시창의 계열 하나입니다. 해당 계열의 카테고리 클래스를 받습니다.
chart-tip-key계열 색의 짧은 획
chart-tip-name계열의 이름
chart-tip-value해당 지점에서의 계열 값
chart-legend계열의 이름입니다. 각 이름은 계열 색의 표시 옆에 놓입니다.
chart-key범례 항목 하나에 해당 계열의 카테고리 클래스를 적용합니다. 체크박스를 감싸는 레이블로 계열의 표시 여부를 전환합니다.
chart-key-input항목의 체크박스입니다. 화면에 보이지 않지만 탭 순서에 포함되며, 계열이 표시되는 동안 체크된 상태입니다.
chart-key-mark항목의 표시입니다. 막대, 영역, 조각처럼 작은 블록 모양입니다.
chart-key-line선처럼 짧은 획 모양입니다.적용할 클래스는 chart-key-mark입니다
chart-key-dot산점도의 지점처럼 점 모양입니다.적용할 클래스는 chart-key-mark입니다
chart-key-value이름 뒤에 오는 수치로, 조각의 비중이나 링의 값을 나타냅니다.

#사용자 지정 속성

속성기본값설명
--chart-height14rem플롯 영역의 높이입니다. 레이더 차트의 정사각형 높이는 이 값을 넘지 않습니다.
--chart-size12rem원형, 도넛, 링, 선버스트 또는 와플 차트의 너비
--chart-colorvar(--color-surface-inverse)카테고리가 없는 표식에 적용하는 기본 전경색
--chart-stroke2px선과 레이더 윤곽선의 두께
--chart-dot4px점의 반지름입니다. 버블에는 각 버블의 반지름이 적용됩니다.
--chart-bar-radius.25rem막대의 둥근 모서리 반경
--chart-gap2px누적 막대를 이루는 막대 사이의 간격
--chart-surfacevar(--surface-color, var(--color-surface-base))차트가 놓이는 표면입니다. 점을 두르는 테두리와 옅은 색은 이 표면색을 섞어 만듭니다.
--chart-gutter플롯 영역 옆에 눈금 숫자를 표시할 공간의 너비를 자릿수로 지정합니다. 0이면 공간을 두지 않습니다.chart-body에 설정합니다
--chart-tail플롯 영역 끝 바깥쪽에 확보할 공간의 너비를 숫자 자릿수로 지정합니다. 이 공간에는 가로 막대 끝의 값이나 기울기 차트에서 선 끝의 이름을 표시합니다.chart-body에 설정합니다
--chart-x플롯 영역에서 값 표시창의 가로 위치를 0에서 1 사이의 값으로 지정합니다. 차트 동작은 각 지점에 지정된 가로 위치 값을 값 표시창에 전달합니다. 레이더 차트 둘레의 이름에는 정사각형 안에서의 위치를 지정합니다.chart-tip에 설정합니다
--chart-y플롯 영역에서 값 표시창의 세로 위치를 맨 위의 0에서 맨 아래의 1까지 지정합니다.chart-tip에 설정합니다
--chart-reach값 표시창의 기준 위치에서 지점의 표식까지의 거리를 플롯 영역에 대한 비율로 지정합니다. 값 표시창이 표식을 가리지 않도록 양옆 중 한쪽에, 가로 막대에서는 위나 아래에 배치하는 데 쓰입니다.chart-tip에 설정합니다
--chart-tone셀, 퍼널 차트의 단계 또는 바깥쪽 링 조각에 색상을 적용하는 비율(%)입니다. 기본값은 100%입니다.chart-cell에 설정합니다
--chart-index지점의 순서입니다. 표식이 순차적으로 그려지도록 애니메이션 시작 시점을 조정합니다.chart-point에 설정합니다

#소스

@master/ui/components/chart.css
/* * Chart: numbers drawn in one SVG, in every form the chart behavior lays out: lines, areas and bars, a scatter, * a pie and a donut, rings, a radar, a waterfall, ranges, a slope, a bump, a marimekko, a histogram, a box plot, * a heatmap, a funnel, a waffle, a treemap and a sunburst. * The plot is an SVG with no box of its own units: it is as wide as the room it is given and --chart-height * tall, and everything that stands on a scale (a hairline, a tick, a bar, a dot) is placed by percentages of it. * Only what must be a path (a line, an area, a slice) is drawn in chart-canvas, a 100 by 100 box inside the plot * that stretches to it, with strokes that keep their width however far it stretches. So one drawing fits any * width, nothing is measured, and text is never scaled. A pie, a donut and rings are square, --chart-size wide. * * A chart of one series is ink, as a progress bar fills with ink. Several series, and the parts of a whole, are * told apart by category: a mark with a category-<name> class takes that category's mark color, and its name * stands in the legend. The scale is hairlines with the baseline one step firmer, and its figures are muted. * Bars turn their corners at the end away from the baseline, and stacked bars are parted by a gap of * --chart-gap. A line is --chart-stroke wide; the area under it fades out downward. * * Each step of the scale, each slice and each dot is a chart-point: a list item that says its values in words. * Under the pointer, or with the focus, a point shows the hairline through it and its dots, and the bars and * slices of the other points step back to a tint, at once. chart-tip is the readout beside the point: it stands * at --chart-x and --chart-y of the plot, on the side with more room, and never leaves the plot. * In a chart-quiet chart every bar is a tint and the point marked aria-current is ink. * * Marks that are steps of one color (a heatmap's cells, a funnel's stages, the outer ring of a sunburst) take * --chart-tone of it. A waterfall's steps up and down are the two status inks, beside the sign of their value. * * Marks draw themselves in when they first appear: bars rise from the baseline, lines run in from the start, * slices and shapes open from the center, a ring fills. Reduced motion removes all of it. * The area's fade is a mask and the bars' corners a clip; a browser without either on an SVG shape shows an even * tint and square bars. Labels thin out in a narrow plot with a container query, and stay without one. */@layer components.ui {  .chart {    --chart-height: 14rem;    --chart-size: 12rem;    --chart-color: var(--color-surface-inverse);    --chart-stroke: 2px;    --chart-dot: 4px;    --chart-bar-radius: .25rem;    --chart-gap: 2px;    /* The surface the chart stands on, which a card or a sheet publishes: gaps and the rings around dots are cut from it. */    --chart-surface: var(--surface-color, var(--color-surface-base));    display: grid;    grid-template-columns: minmax(0, 1fr);    gap: .875rem;    min-width: 0;    margin: 0;    padding: 0;    color: var(--color-text-muted);    font: 400 .71875rem/1.4 var(--font-family-sans);    font-feature-settings: inherit;    font-variant-numeric: tabular-nums;    /* Split: the legend stands beside the plot as a column of names and figures, and goes under it when there is no room. */    &.chart-split {      display: flex;      flex-wrap: wrap;      align-items: center;      gap: 1rem 1.75rem;      .chart-body {        flex: 1 1 14rem;      }      .chart-body:has(.chart-plot-radial) {        flex: none;      }      .chart-legend {        flex: 1 1 9rem;        flex-direction: column;        gap: .125rem;      }      .chart-key-value {        margin-inline-start: auto;        padding-inline-start: 1rem;      }    }    /* Quiet: bars are a tint, and the point marked aria-current is the ink. For a period in which one day matters. */    &.chart-quiet {      .chart-point:not([aria-current='true']) .chart-bar {        fill: color-mix(in oklab, var(--chart-bar-color) 16%, var(--chart-surface));      }      @media (hover: hover) {        .chart-point:not([aria-current='true']):hover .chart-bar {          fill: color-mix(in oklab, var(--chart-bar-color) 36%, var(--chart-surface));        }      }      .chart-point:not([aria-current='true']):focus .chart-bar {        fill: color-mix(in oklab, var(--chart-bar-color) 36%, var(--chart-surface));      }      /* In forced colors the current point is the system's highlight, as a gantt's and a schedule's current mark is. */      @media (forced-colors: active) {        .chart-point[aria-current='true'] .chart-bar {          fill: Highlight;        }      }    }    @media (forced-colors: active) {      --chart-color: CanvasText;      --chart-surface: Canvas;    }  }  /*   * The plot's place: the tip is placed against it, and the figures of the scale stand in the room beside and   * under it, --chart-gutter digits wide. It is the container the labels' thinning asks about.   */  .chart-body {    position: relative;    container-type: inline-size;    min-width: 0;    /* The plot runs from the left in every language, so its gutter and its tail are left and right. */    margin-left: calc(var(--chart-gutter, 0) * 1ch + min(var(--chart-gutter, 0), 1) * .625rem);    margin-right: calc(var(--chart-tail, 0) * 1ch + min(var(--chart-tail, 0), 1) * .625rem);    &:has(.chart-tick-x) {      margin-bottom: 1.375rem;    }    /* Values written over the bars need a line above the plot; those written beside or on a mark do not. */    &:has(.chart-value) {      margin-top: 1rem;    }    &:has(.chart-value-across), &:has(.chart-value-before), &:has(.chart-value-tile) {      margin-top: 0;    }    /* A pie, a donut and rings: a square, as wide as --chart-size and no wider than its room. */    &:has(.chart-plot-radial) {      container-type: normal;      width: var(--chart-size);      max-width: 100%;      margin-inline: auto;    }    /* A radar: a square in the middle of the plot, with room beside it for the names around it. */    &:has(.chart-plot-radar) {      --chart-side: min(var(--chart-height), 100cqi - 9rem);      margin-block: .75rem;    }  }  .chart-plot {    display: block;    width: 100%;    height: var(--chart-height);    overflow: visible;    /* The scale runs from the left in every language, so a label's anchor means the same side. */    direction: ltr;    /* A finger moves along the points; the page still scrolls the other way. */    touch-action: pan-y;    user-select: none;    -webkit-user-select: none;    /* A point a finger focuses is marked on its marks: the browser's tap flash would cover its whole box. */    -webkit-tap-highlight-color: transparent;    &.chart-plot-radial {      height: auto;      aspect-ratio: 1;      touch-action: auto;    }    &.chart-plot-radar {      height: var(--chart-side);      touch-action: auto;    }    /* Under the pointer or with the focus, the bars and slices of the other points step back to a tint, at once. */    @media (hover: hover) {      &:has(.chart-point:hover) .chart-point:not(:hover) {        .chart-bar {          fill: color-mix(in oklab, var(--chart-bar-color) 30%, var(--chart-surface));        }        .chart-slice, .chart-arc, .chart-line, .chart-knot, .chart-unit, .chart-stage, .chart-box, .chart-stem {          opacity: .32;        }      }    }    &:has(.chart-point:focus) .chart-point:not(:focus) {      .chart-bar {        fill: color-mix(in oklab, var(--chart-bar-color) 30%, var(--chart-surface));      }      .chart-slice, .chart-arc, .chart-line, .chart-knot, .chart-unit, .chart-stage, .chart-box, .chart-stem {        opacity: .32;      }    }  }  /* The box paths are written in: it stretches to the plot, or keeps its shape in a radial chart. */  .chart-canvas {    overflow: visible;  }  /* The scale: a hairline at each tick. The baseline is one step firmer. */  .chart-grid {    stroke: var(--color-line-hair);    stroke-width: 1px;    shape-rendering: crispEdges;    &.chart-grid-base {      stroke: var(--color-line-divider);    }    @media (forced-colors: active) {      stroke: GrayText;    }  }  /* A figure of the scale or a name along it, placed on its hairline and moved into the room beside the plot. */  .chart-tick {    fill: currentColor;    stroke: none;    &.chart-tick-y {      text-anchor: end;      dominant-baseline: central;      transform: translate(-.625rem, 0);    }    &.chart-tick-x {      text-anchor: middle;      transform: translate(0, 1.25rem);    }    /* Around a radar: moved from the middle of the plot to its place in the square. */    &.chart-tick-around {      text-anchor: middle;      dominant-baseline: central;      fill: var(--color-text-body);      transform: translate(calc((var(--chart-x) - .5) * var(--chart-side)), calc((var(--chart-y) - .5) * var(--chart-side)));    }    &.chart-tick-start {      text-anchor: start;    }    &.chart-tick-end {      text-anchor: end;    }    /* A figure of a radar's scale: small, beside the first spoke, in the room between two rings. */    &.chart-tick-scale {      text-anchor: start;      dominant-baseline: auto;      fill: currentColor;      font-size: .625rem;      transform: translate(calc((var(--chart-x) - .5) * var(--chart-side) + .25rem), calc((var(--chart-y) - .5) * var(--chart-side) - .1875rem));    }    /* Every other name gives way when the plot is narrow, and a small radar keeps only its names. */    @container (width < 24rem) {      &.chart-tick-minor, &.chart-tick-scale {        display: none;      }    }    /* A fill named from a token is an author color: the names around a radar take the system's text. */    @media (forced-colors: active) {      &.chart-tick-around {        fill: CanvasText;      }    }  }  /* A line: one series from point to point. */  .chart-line {    fill: none;    stroke: var(--category-mark, var(--chart-color));    stroke-width: var(--chart-stroke);    stroke-linecap: round;    stroke-linejoin: round;    vector-effect: non-scaling-stroke;    /* It runs in from the start; the clip stays a little outside the line so its round ends are whole. */    clip-path: inset(-12% -4% -12% -4%);    transition: clip-path 720ms var(--easing-glide);    @starting-style {      clip-path: inset(-12% 100% -12% -4%);    }    @media (prefers-reduced-motion: reduce) {      transition: none;    }  }  /* The area under a line: a wash of its color that fades out downward. */  .chart-area {    /* A wash of a category's color; ink, which is far darker, is thinned first so its wash is as quiet. */    fill: color-mix(in oklab, var(--category-mark, color-mix(in oklab, var(--chart-color) 55%, transparent)) 22%, transparent);    stroke: none;    mask-image: linear-gradient(to bottom, black, transparent);    transition: opacity 720ms var(--easing-glide);    @starting-style {      opacity: 0;    }    /* Stacked: each layer is a tint of its own that hides the one under it. */    &.chart-area-stacked {      fill: color-mix(in oklab, var(--category-mark, var(--chart-color)) 26%, var(--chart-surface));      mask-image: none;    }    @media (prefers-reduced-motion: reduce) {      transition: none;    }  }  /*   * One step of the scale, one slice, one ring or one dot, with its marks: a list item that says its values.   * It takes the focus from the keys, and what marks it then is drawn on its marks, not around its box.   */  .chart-point {    outline: none;    @media (hover: hover) {      &:hover {        .chart-cursor, .chart-dot {          opacity: 1;        }      }    }    &:focus {      .chart-cursor, .chart-dot {        opacity: 1;      }    }    &:focus-visible {      .chart-hit {        stroke: var(--color-focus);      }      .chart-slice, .chart-track, .chart-stage {        stroke: var(--color-focus);        stroke-width: 2px;      }      /* A mark cut by a clip takes the ring in place of the cut, so the ring is whole. */      .chart-cell, .chart-unit, .chart-tile {        stroke: var(--color-focus);        stroke-width: 2px;        clip-path: none;      }      /* A line's ring is a band of the focus color along it. */      .chart-hit-line {        stroke: color-mix(in oklab, var(--color-focus) 24%, transparent);      }    }    /*     * Every ring a point draws is the system's highlight, and along a line it stays a band of it, as it is     * without forced colors, so the line under it still shows.     */    @media (forced-colors: active) {      &:focus-visible {        .chart-hit, .chart-slice, .chart-track, .chart-stage, .chart-cell, .chart-unit, .chart-tile {          stroke: Highlight;        }        .chart-hit-line {          stroke: color-mix(in oklab, Highlight 24%, transparent);        }      }    }  }  /* What the pointer lands on: the whole band of a step, the room around a dot, a radar's wedge. The focus ring is drawn on it. */  .chart-hit {    fill: transparent;    stroke: transparent;    stroke-width: 2px;    vector-effect: non-scaling-stroke;    rx: var(--chart-bar-radius);    pointer-events: all;    /* Along a line: a wide stroke nobody sees, so the pointer does not have to find a line two pixels wide. */    &.chart-hit-line {      fill: none;      stroke-width: 18px;      stroke-linecap: round;      stroke-linejoin: round;      pointer-events: stroke;    }  }  /* The hairline through the point under the pointer. */  .chart-cursor {    stroke: var(--color-line-mark);    stroke-width: 1px;    shape-rendering: crispEdges;    opacity: 0;    pointer-events: none;    /* A hairline named from a token: in forced colors it is the system's gray, as the grid is. */    @media (forced-colors: active) {      stroke: GrayText;    }  }  /*   * A bar. Its corners turn at the end away from the baseline, cut with a clip so the radius is true at any   * width, and it rises from the baseline when it first appears, each a moment after the one before it.   */  .chart-bar {    --chart-bar-color: var(--category-mark, var(--chart-color));    fill: var(--chart-bar-color);    stroke: none;    clip-path: inset(0 round var(--chart-bar-radius) var(--chart-bar-radius) 0 0);    transition: clip-path 560ms var(--easing-glide) calc(min(var(--chart-index, 0), 30) * 14ms);    @starting-style {      clip-path: inset(100% 0 0 0 round var(--chart-bar-radius) var(--chart-bar-radius) 0 0);    }    /* Under another bar of its stack: square, with the gap above it. */    &.chart-bar-inner {      clip-path: inset(var(--chart-gap) 0 0 0);      @starting-style {        clip-path: inset(100% 0 0 0);      }    }    /* A value under zero: it hangs from the baseline. */    &.chart-bar-down {      clip-path: inset(0 round 0 0 var(--chart-bar-radius) var(--chart-bar-radius));      @starting-style {        clip-path: inset(0 0 100% 0 round 0 0 var(--chart-bar-radius) var(--chart-bar-radius));      }    }    &.chart-bar-down.chart-bar-inner {      clip-path: inset(0 0 var(--chart-gap) 0);      @starting-style {        clip-path: inset(0 0 100% 0);      }    }    /* Across: a row of a ranking, turned at its far end. */    &.chart-bar-across {      clip-path: inset(0 round 0 var(--chart-bar-radius) var(--chart-bar-radius) 0);      @starting-style {        clip-path: inset(0 100% 0 0 round 0 var(--chart-bar-radius) var(--chart-bar-radius) 0);      }    }    &.chart-bar-across.chart-bar-inner {      clip-path: inset(0 var(--chart-gap) 0 0);      @starting-style {        clip-path: inset(0 100% 0 0);      }    }    &.chart-bar-across.chart-bar-down {      clip-path: inset(0 round var(--chart-bar-radius) 0 0 var(--chart-bar-radius));      @starting-style {        clip-path: inset(0 0 0 100% round var(--chart-bar-radius) 0 0 var(--chart-bar-radius));      }    }    &.chart-bar-across.chart-bar-down.chart-bar-inner {      clip-path: inset(0 0 0 var(--chart-gap));      @starting-style {        clip-path: inset(0 0 0 100%);      }    }    /* Between two values, with no end on the baseline: both ends are turned, and it opens from its middle. */    &.chart-bar-floating {      clip-path: inset(0 round var(--chart-bar-radius));      @starting-style {        clip-path: inset(50% round var(--chart-bar-radius));      }    }    /* A histogram's bin: it meets the bins beside it, parted by a hairline of the surface. */    &.chart-bar-bin {      clip-path: inset(0 .5px 0 .5px round var(--chart-bar-radius) var(--chart-bar-radius) 0 0);      @starting-style {        clip-path: inset(100% .5px 0 .5px round var(--chart-bar-radius) var(--chart-bar-radius) 0 0);      }    }    /* A waterfall's step up and step down: the two status inks, beside the sign written with the value. */    &.chart-bar-rise {      --chart-bar-color: var(--color-success);    }    &.chart-bar-fall {      --chart-bar-color: var(--color-danger);    }    @media (prefers-reduced-motion: reduce) {      transition: none;    }  }  /* A point of a line or a scatter: a dot of its color with a ring of the surface, so it reads where lines cross. */  .chart-dot {    r: var(--chart-dot);    fill: var(--category-mark, var(--chart-color));    stroke: var(--chart-surface);    stroke-width: 2px;    paint-order: stroke;    vector-effect: non-scaling-stroke;    pointer-events: none;    /* Shown only while its point is under the pointer or has the focus. */    &.chart-dot-quiet {      opacity: 0;    }    /* A bubble: a wash of its color inside an edge of it, so bubbles that overlap show through each other. */    &.chart-dot-bubble {      fill: color-mix(in oklab, var(--category-mark, var(--chart-color)) 34%, transparent);      stroke: var(--category-mark, var(--chart-color));      stroke-width: 1.5px;      paint-order: normal;    }    /* A reading far from the others in a box plot: small and hollow. */    &.chart-dot-outlier {      r: 2.5px;      fill: var(--chart-surface);      stroke: var(--category-mark, var(--chart-color));      stroke-width: 1.5px;      paint-order: normal;    }  }  /* In a radial canvas a length is a share of the square: a dot there is drawn by its own r. */  .chart-canvas .chart-dot {    r: 1.7px;  }  /* A value written at a bar's end. */  .chart-value {    fill: var(--color-text-body);    stroke: none;    text-anchor: middle;    transform: translate(0, -.4375rem);    pointer-events: none;    &.chart-value-across {      text-anchor: start;      dominant-baseline: central;      transform: translate(.5rem, 0);    }    /* Before the plot, ending at its edge: a slope's value at its first end. */    &.chart-value-before {      text-anchor: end;      dominant-baseline: central;      transform: translate(-.5rem, 0);    }    /* On a tile, from its first corner: its name. */    &.chart-value-tile {      fill: var(--color-text-strong);      font-weight: var(--font-weight-control);      text-anchor: start;      dominant-baseline: hanging;      transform: translate(.5rem, .5625rem);    }    /* Under a tile's name: its value, quieter. */    &.chart-value-quiet {      fill: var(--color-text-muted);      font-weight: 400;      transform: translate(.5rem, 1.5625rem);    }    /* Its fill is named from a token, an author color: in forced colors every value takes the system's text. */    @media (forced-colors: active) {      fill: CanvasText;    }  }  /* A slice of a pie or a donut. It opens from the center when it first appears. */  .chart-slice {    /* A slice of an outer ring takes a share of its part's color, --chart-tone. */    fill: color-mix(in oklab, var(--category-mark, var(--chart-color)) var(--chart-tone, 100%), var(--chart-surface));    stroke: transparent;    stroke-width: 0;    stroke-linejoin: round;    vector-effect: non-scaling-stroke;    paint-order: stroke;    transition: opacity 480ms var(--easing-glide) calc(min(var(--chart-index, 0), 12) * 40ms), scale 640ms var(--easing-glide) calc(min(var(--chart-index, 0), 12) * 40ms);    @starting-style {      opacity: 0;      scale: .9;    }    @media (prefers-reduced-motion: reduce) {      transition: none;    }  }  /* A ring's track: the whole it is read against, in a tint of its color. */  .chart-track {    fill: none;    stroke: color-mix(in oklab, var(--category-mark, var(--chart-color)) 16%, transparent);    pointer-events: stroke;  }  /* A ring's value: it fills from the top, with round ends. */  .chart-arc {    fill: none;    stroke: var(--category-mark, var(--chart-color));    stroke-linecap: round;    stroke-dasharray: 1;    stroke-dashoffset: 0;    pointer-events: stroke;    transition: stroke-dashoffset 900ms var(--easing-glide) calc(min(var(--chart-index, 0), 12) * 80ms);    @starting-style {      stroke-dashoffset: 1;    }    @media (prefers-reduced-motion: reduce) {      transition: none;    }  }  /* A radar's web: a ring at each tick and a spoke to each name. */  .chart-web {    fill: none;    stroke: var(--color-line-contour);    stroke-width: 1px;    stroke-linejoin: round;    vector-effect: non-scaling-stroke;    @media (forced-colors: active) {      stroke: GrayText;    }  }  /* A radar's series: its outline, with a wash of the same color that lets the others show through. */  .chart-shape {    fill: color-mix(in oklab, var(--category-mark, var(--chart-color)) 14%, transparent);    stroke: var(--category-mark, var(--chart-color));    stroke-width: var(--chart-stroke);    stroke-linejoin: round;    vector-effect: non-scaling-stroke;    transition: opacity 480ms var(--easing-glide), scale 720ms var(--easing-glide);    @starting-style {      opacity: 0;      scale: .6;    }    @media (prefers-reduced-motion: reduce) {      transition: none;    }  }  /* What a line's values may be: a band between their lower and upper ends, behind the line. */  .chart-band {    fill: color-mix(in oklab, var(--category-mark, color-mix(in oklab, var(--chart-color) 55%, transparent)) 18%, transparent);    stroke: none;    transition: opacity 720ms var(--easing-glide);    @starting-style {      opacity: 0;    }    @media (prefers-reduced-motion: reduce) {      transition: none;    }  }  /* A stem: a lollipop's line from the baseline to its dot, and the line between a dumbbell's ends. */  .chart-stem {    stroke: color-mix(in oklab, var(--category-mark, var(--chart-color)) 42%, var(--chart-surface));    stroke-width: 2px;    stroke-linecap: round;    pointer-events: none;  }  /* A whisker: from the lowest to the highest a value may be, through a bar's end or a box. */  .chart-whisker {    /* Halfway between the ink and the surface, so it reads over a bar of ink and over the plot alike. */    stroke: color-mix(in oklab, var(--chart-color) 52%, var(--chart-surface));    stroke-width: 1.5px;    pointer-events: none;  }  /* A box plot's box: from the first quartile to the third. */  .chart-box {    fill: var(--category-mark, var(--chart-color));    stroke: none;    clip-path: inset(0 round calc(var(--chart-bar-radius) * .75));  }  /* The median: a line of the surface cut through the box. */  .chart-median {    stroke: var(--chart-surface);    stroke-width: 2px;    pointer-events: none;  }  /* A waterfall's hairline from one bar's end to the next bar. */  .chart-link {    fill: none;    stroke: var(--color-line-mark);    stroke-width: 1px;    vector-effect: non-scaling-stroke;    shape-rendering: crispEdges;    @media (forced-colors: active) {      stroke: GrayText;    }  }  /* A point of a slope or a bump: a round end of no length, so it stays a circle in a canvas that stretches. */  .chart-knot {    fill: none;    stroke: var(--category-mark, var(--chart-color));    stroke-width: calc(var(--chart-dot) * 2);    stroke-linecap: round;    vector-effect: non-scaling-stroke;    pointer-events: none;  }  /* A heatmap's cell: as much of its color as its value is of the range, --chart-tone, parted from its neighbors. */  .chart-cell {    fill: color-mix(in oklab, var(--category-mark, var(--chart-color)) var(--chart-tone, 100%), var(--chart-surface));    stroke: none;    clip-path: inset(1px round 3px);    @media (forced-colors: active) {      forced-color-adjust: none;    }  }  /* Under the pointer a cell takes the gap around it. */  @media (hover: hover) {    .chart-point:hover .chart-cell {      clip-path: inset(0 round 3px);    }  }  /* A waffle's unit: one percent of the whole. */  .chart-unit {    fill: var(--category-mark, var(--chart-color));    stroke: none;    clip-path: inset(1.5px round 3px);    transition: opacity 400ms var(--easing-glide) calc(min(var(--chart-index, 0), 12) * 60ms);    @starting-style {      opacity: 0;    }    @media (prefers-reduced-motion: reduce) {      transition: none;    }  }  /* A funnel's stage: a step lighter than the stage before it. */  .chart-stage {    fill: color-mix(in oklab, var(--category-mark, var(--chart-color)) var(--chart-tone, 100%), var(--chart-surface));    stroke: transparent;    stroke-width: 0;    stroke-linejoin: round;    vector-effect: non-scaling-stroke;    transition: opacity 480ms var(--easing-glide) calc(min(var(--chart-index, 0), 12) * 60ms);    @starting-style {      opacity: 0;    }    @media (prefers-reduced-motion: reduce) {      transition: none;    }  }  /* A treemap's tile: a tint that holds its name, in its category's surface or a wash of ink. */  .chart-tile {    fill: var(--category-surface, color-mix(in oklab, var(--chart-color) 7%, var(--chart-surface)));    stroke: none;    clip-path: inset(1px round calc(var(--chart-bar-radius) * 1.25));  }  @media (hover: hover) {    .chart-point:hover .chart-tile {      fill: color-mix(in oklab, var(--category-mark, var(--chart-color)) 16%, var(--chart-surface));    }  }  .chart-point:focus .chart-tile {    fill: color-mix(in oklab, var(--category-mark, var(--chart-color)) 16%, var(--chart-surface));  }  /* What stands in a donut's hole or within rings: a figure and what it counts. */  .chart-center {    position: absolute;    inset: 0;    display: grid;    place-content: center;    justify-items: center;    gap: .125rem;    text-align: center;    pointer-events: none;  }  .chart-center-value {    margin: 0;    color: var(--color-text-strong);    font: 400 1.5rem/1.15 var(--font-family-sans);    font-feature-settings: inherit;    /* The shorthand resets the chart's figures; a figure that changes keeps its width. */    font-variant-numeric: tabular-nums;    letter-spacing: -.02em;  }  .chart-center-label {    margin: 0;    font-size: .75rem;    line-height: 1.3;  }  /*   * The readout beside the point under the pointer: the point's name, then a row for each series with a stroke   * of its color, its name and its value. It stands at --chart-x and --chart-y of the plot, past the point's   * marks (--chart-reach) on the side with more room, and slides along its own height so it never leaves the plot.   */  .chart-tip {    --chart-tip-gap: .75rem;    /* 0 while the point is in the first half of the plot, 1 in the second: which side the readout stands on. */    --chart-tip-side: clamp(0, (var(--chart-x, 0) - .5) * 1000, 1);    position: absolute;    top: calc(var(--chart-y, 0) * 100%);    left: calc((var(--chart-x, 0) + var(--chart-reach, 0) * (1 - 2 * var(--chart-tip-side))) * 100%);    z-index: 1;    display: grid;    grid-template-columns: auto minmax(0, 1fr) auto;    column-gap: .4375rem;    row-gap: .1875rem;    align-items: center;    width: max-content;    min-width: 5.5rem;    max-width: 16rem;    margin: 0;    padding: .4375rem .625rem .5rem;    border-radius: calc(var(--radius-control-sm) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: var(--color-surface-tip);    color: light-dark(var(--color-text-inverse), var(--color-text-strong));    box-shadow: var(--shadow-tip);    font-size: .75rem;    line-height: 1.35;    white-space: nowrap;    translate: calc(var(--chart-tip-side) * (-100% - 2 * var(--chart-tip-gap)) + var(--chart-tip-gap)) calc(var(--chart-y, 0) * -100%);    pointer-events: none;    transition-property: opacity, display, top, left, translate;    transition-duration: var(--duration-quick);    transition-timing-function: var(--easing-glide);    transition-behavior: allow-discrete;    @starting-style {      opacity: 0;    }    &[hidden] {      display: none;      opacity: 0;    }    @media (prefers-reduced-motion: reduce) {      transition-property: opacity, display;    }    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;    }  }  /*   * Over bars that run across, the readout stands under the row in the upper half of the plot and over it in the   * lower half, clear of the bar by --chart-reach, and slides along its own width.   */  .chart-body:has(.chart-bar-across) .chart-tip {    --chart-tip-gap: .375rem;    --chart-tip-under: clamp(0, (.5 - var(--chart-y, 0)) * 1000, 1);    top: calc((var(--chart-y, 0) + var(--chart-reach, 0) * (2 * var(--chart-tip-under) - 1)) * 100%);    left: calc(var(--chart-x, 0) * 100%);    translate: calc(var(--chart-x, 0) * -100%) calc(var(--chart-tip-under) * (100% + 2 * var(--chart-tip-gap)) - 100% - var(--chart-tip-gap));  }  /* In a square the readout stands on the point and slides along both of its sides. */  .chart-body:has(.chart-plot-radial) .chart-tip {    left: calc(var(--chart-x, 0) * 100%);    translate: calc(var(--chart-x, 0) * -100%) calc(var(--chart-y, 0) * -100%);  }  .chart-body:has(.chart-plot-radar) .chart-tip {    top: calc(var(--chart-y, 0) * var(--chart-side));    left: calc(50% + (var(--chart-x, 0) - .5) * var(--chart-side));    translate: calc(var(--chart-x, 0) * -100%) calc(var(--chart-y, 0) * -100%);  }  /*   * In a donut or rings the readout takes the middle: the value as the figure and the series' name under it,   * in the place of what the middle held, so nothing covers the marks.   */  .chart-body:has(.chart-center) {    .chart-tip {      inset: 0;      grid-template-columns: auto auto;      place-content: center;      column-gap: .3125rem;      row-gap: .125rem;      width: auto;      min-width: 0;      max-width: none;      padding: 0;      background: none;      color: var(--color-text-muted);      box-shadow: none;      translate: none;      transition-property: opacity, display;      @media (forced-colors: active) {        outline: none;      }    }    .chart-tip-value {      grid-row: 1;      grid-column: 1 / -1;      padding: 0;      color: var(--color-text-strong);      font: 400 1.5rem/1.15 var(--font-family-sans);      font-feature-settings: inherit;      /* The shorthand resets the readout's tabular figures, which keep the value still as the point changes. */      font-variant-numeric: tabular-nums;      letter-spacing: -.02em;      text-align: center;    }    .chart-tip-key {      grid-row: 2;      width: .5rem;      height: .5rem;      border-radius: 50%;    }    .chart-tip-name {      grid-row: 2;      color: inherit;    }    &:has(.chart-tip:not([hidden])) .chart-center {      visibility: hidden;    }  }  .chart-tip-title {    grid-column: 1 / -1;    margin: 0 0 .0625rem;    color: color-mix(in oklab, currentColor 64%, transparent);    font-size: .6875rem;  }  /* One series of the readout. Its parts stand in the readout's columns. */  .chart-tip-row {    display: contents;    margin: 0;  }  /* A short stroke of the series' color. */  .chart-tip-key {    width: .625rem;    height: .125rem;    border-radius: 1px;    corner-shape: round;    background: var(--category-mark, currentColor);    /*     * It keeps its series' color in forced colors, as the legend's mark does, instead of the forced canvas. A     * series with no category is the system's text, as its marks are, not the readout's own ink.     */    @media (forced-colors: active) {      forced-color-adjust: none;      background: var(--category-mark, CanvasText);    }  }  .chart-tip-name {    overflow: hidden;    color: color-mix(in oklab, currentColor 76%, transparent);    text-overflow: ellipsis;  }  .chart-tip-value {    padding-inline-start: .625rem;    font-weight: var(--font-weight-control);    font-variant-numeric: tabular-nums;    text-align: end;  }  /* The legend: the name of each series beside a mark of its color. */  .chart-legend {    display: flex;    flex-wrap: wrap;    gap: .125rem 1rem;    min-width: 0;    margin: 0;    padding: 0;    /* The entries' touch targets stand behind them, within the legend. */    isolation: isolate;    color: var(--color-text-body);    font-size: .75rem;    line-height: 1.35;    list-style: none;  }  /* One entry. With a checkbox in it, it shows and hides its series. */  .chart-key {    position: relative;    display: inline-flex;    align-items: center;    gap: .4375rem;    min-height: 1.5rem;    margin: 0;    padding: 0;    &:has(.chart-key-input) {      border-radius: calc(var(--radius-chip) * var(--corner-scale));      corner-shape: var(--corner-shape);      cursor: pointer;      user-select: none;      -webkit-user-select: none;      -webkit-tap-highlight-color: transparent;      @media (hover: hover) {        &:hover {          color: var(--color-text-strong);        }      }    }    /* A hidden series: its name steps back and its mark is an outline. */    &:has(.chart-key-input:not(:checked)) {      color: var(--color-text-disabled);      .chart-key-mark {        background: transparent;        box-shadow: inset 0 0 0 1.5px var(--color-line-mark);      }      .chart-key-value {        visibility: hidden;      }      /* It can still be shown again: under the pointer its name comes a step forward, as a shown one's does. */      @media (hover: hover) {        &:hover {          color: var(--color-text-muted);        }      }      /* Forced colors would make the name the text color again and the outline an author color: both are the system's gray. */      @media (forced-colors: active) {        &, &:hover {          color: GrayText;        }        .chart-key-mark {          box-shadow: inset 0 0 0 1.5px GrayText;        }      }    }    &:has(.chart-key-input:focus-visible) {      @apply --focus-ring;      @media (forced-colors: active) {        outline-color: Highlight;      }    }    /*     * A finger's target reaches above and below the entry, behind every entry, so where it overlaps the entry     * beside or under it in a column or a wrapped row, the entry that is seen is the one that is touched.     */    @media (pointer: coarse) {      &:has(.chart-key-input)::after {        @apply --touch-target-block;        z-index: -1;      }    }  }  /* The checkbox: it keeps its place in the tab order and its name, and the entry is what is seen. */  .chart-key-input {    position: absolute;    inset: 0;    width: 100%;    height: 100%;    margin: 0;    padding: 0;    border: 0;    appearance: none;    opacity: 0;    cursor: inherit;  }  /* The mark: a small block of the series' color, as a bar, an area or a slice is. */  .chart-key-mark {    flex: none;    width: .625rem;    height: .625rem;    border-radius: calc(.1875rem * var(--corner-scale));    corner-shape: var(--corner-shape);    background: var(--category-mark, var(--chart-color));    /* A short stroke, as a line is. */    &.chart-key-line {      width: .875rem;      height: .125rem;      border-radius: 1px;      corner-shape: round;    }    /* A dot, as a scatter's point is. */    &.chart-key-dot {      width: .5rem;      height: .5rem;      border-radius: 50%;      corner-shape: round;    }    @media (forced-colors: active) {      forced-color-adjust: none;    }  }  /* A figure after the name: a slice's share, a ring's value. */  .chart-key-value {    color: var(--color-text-muted);    font-variant-numeric: tabular-nums;  }}