ナビゲーション

v2.1.0
データ表示

チャート

折れ線グラフからサンバーストまで、20種類以上の形式で数値を表示します。どの形式も、表示幅に収まる1つのSVGで描画します。

このページの内容

チャートは、読み手が知りたいことに合わせて数値を可視化します。折れ線グラフ、棒グラフ、ドーナツグラフ、ヒストグラム、ファネルチャートなど、全部で20種類以上あります。どの形式も、与えられた幅に収まる1つのSVGです。スケール上の要素はパーセントで配置されるため、プロットが横に伸びても線の太さと文字の大きさは変わりません。系列が1つなら、プログレスバーの塗りと同じインク色を使います。複数の系列にはカテゴリの色を使います。各データ点は、値を文章で伝えるリスト項目です。

チャート

<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 に描画します。これは100×100の座標領域を持ち、プロット全体に伸びる入れ子のSVGです。線幅はSVGの拡大縮小に追従しないため、細いカードでも幅の広いカードでも --chart-stroke のままです。

幅が変わっても計測や再描画は行いません。そのため、サーバー、フレームワークコンポーネント、ビヘイビアは同じマークアップを生成します。チャートは与えられた幅を埋めます。ほかの要素と横に並べる場合は、幅を指定するか、伸びるようにしてください。

#チャートを描く

ビヘイビアは、CSSクラス chart を持つ要素にチャートを書き込みます。label には表示内容と単位を指定し、labels にはスケール上の各位置の名前を指定します。各系列はそれぞれの位置に対応する値を1つずつ持ちます。

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です。使う形式が1つか2つなら、その形式だけを読み込めます。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線の下を同系色で塗りつぶし、単独の系列や積み上げた合計を示します。
スロープグラフslope2つの時点の間で何が上昇し、下降し、順位が入れ替わったかを線の傾きや交差で示します。
順位推移グラフbump複数の項目の順位の推移を示します。順位が入れ替わる箇所で線が交差します。
棒グラフbar基準線から伸びる棒で量を比較します。棒は並列、積み上げ、横向きで表示できます。
レーダーチャートradar共通の指標で複数の項目を比較します。各項目を、同じ中心を囲む輪郭で示します。
ウォーターフォールグラフwaterfall初期値から最終値に至るまでの増減を段階ごとに示します。
範囲グラフrange2つの値の間の範囲を示し、それぞれの始点と終点を比較できます。
ダンベルチャートdumbbell各項目の2つの値を線で結び、その差を示します。
円グラフpie全体の内訳を円の扇形で示します。
ドーナツグラフdonut全体の内訳を、中央に置いた1つの数値の周りに示します。
リンググラフrings複数の測定値を個別のリングで示し、それぞれの全体に対する割合を塗りで表します。
マリメッコチャートmarimekko列の幅で合計を示し、列を分割して内訳を表します。
ファネルチャートfunnel1つのプロセスの各段階を、先に進むほど細くなる形で示します。
ワッフルチャートwaffle100個のセルで全体を示します。1セルは全体の1%です。
ツリーマップtreemap全体の内訳を、構成比に応じた面積のタイルで示します。
サンバーストチャートsunburst全体とその内訳、さらに各部分の内訳を2つのリングで示します。
ヒストグラムhistogram測定値の分布を示します。区切りのよい数値で階級を分け、その度数を棒の高さで表します。
箱ひげ図box複数のグループの分布を、それぞれ5つの統計量に基づく箱、中央値、ひげで示します。
ヒートマップheatmap2つのスケールにまたがるパターンを、値に応じたセルの濃淡で示します。
散布図scatter各項目を1つの点として、2つの指標の関係を示します。

折れ線、面、棒は共通のスケールを使うため、1つのチャートに混在させられます。たとえば系列に個別の type を指定すると、棒グラフに折れ線を重ねられます。

#値の表示とキー操作

chart-tip は値を表示する領域です。データ点の名前に続き、系列ごとに色見本の線、系列名、値を1行で表示します。データ点の横で余裕のある側に置かれ、表示領域自体の高さに応じて上下にずれるため、スクリプトで配置を計算しなくてもプロットからはみ出しません。ビヘイビアはデータ点のマークが持つ情報を使って内容を埋め、点の位置を --chart-x、--chart-y、--chart-reach で渡します。

データ点の数にかかわらず、Tabキーでフォーカスする位置はプロット全体で1か所です。矢印キーでデータ点間を移動し、それぞれの値を表示できます。タッチ操作でも、チャートに沿って指を動かすと同じように確認できます。

キー操作
Tab最後に訪れたポイント、なければ最初のポイントからプロットに入り、その値表示を表示します。続いて凡例のチェックボックスに移動します。
ArrowRight, ArrowDown次のポイントに移動し、その値表示を表示します。
ArrowLeft, ArrowUp前のポイントに移動します。
Home, End最初または最後のポイントに移動します。
Escape値表示を非表示にし、フォーカスはポイントに残します。
Space凡例のチェックボックスで、その系列の表示と非表示を切り替えます。

#凡例

系列が2つ以上あるチャートには凡例があり、色に加えて名前でも系列を区別できます。各項目はチェックボックスを包むラベルです。Tabキーで移動し、Spaceキーで切り替えられます。チェックを外すと該当する系列が非表示になり、スケールは表示中の系列に合わせて調整されます。残った系列の色は維持されます。系列が1つのチャートは、タイトルで内容が分かるため凡例を表示しません。

toggle: false は凡例を通常のリストとして出力します。周囲の文章に系列名が書かれている場合などは、legend: false で凡例を省略できます。チャートの値は非表示の系列名です。chart() の戻り値から読み取ったり、外部から設定して系列を非表示にしたりできます。

#色

系列が1つのチャートは、インク色の --chart-color で描画します。複数の系列や全体の内訳には、青、オレンジ、ティール、紫、アンバー、ピンク、緑、空色の順でカテゴリ色を割り当てます。どちらの配色モードでも、一般的な色覚特性で隣り合う色を見分けられます。9つ目からは同じ順序を繰り返すため、残りを「その他」にまとめるか、別のチャートに分けてください。

対象に合わせて色を固定する場合は、系列に category を指定します。たとえば東京を青にすると、リスト内での位置にかかわらず、チャート、バッジ、表の行で色をそろえられます。系列の色にステータス色は使いません。系列が異常な状態にある場合は、テキストで伝えます。

#スケールと数値

スケールの下限は0で、負の値がある場合は0未満になります。上限は最大値を超える区切りのよい数値で、およそ4段階の目盛りに分けます。min と max で両端を固定でき、ticks で段階数の目安を変更できます。棒の長さが値を表すため、棒グラフのスケールは0から始めてください。

format は値の表示欄や棒の端の数値を整形し、tickFormat はスケールの目盛り値を整形します。既定では、目盛り値が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系列が2つ以上の場合、true凡例を出力するか、凡例の項目をチェックボックスにするかを指定します
hole, center.7、なしドーナツグラフの穴の大きさと、ドーナツグラフまたはリングチャートの中央に表示する内容
totalなしウォーターフォールグラフの最後に表示する棒の名前
binsデータ件数から算出ヒストグラムで測定値を分ける階級数の目安
ascendingfalse順位推移グラフで最小値を1位にします
words英語箱ひげ図の5つの統計量の名前。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 を使います。SVG図形をCSSの基本図形でクリップできないブラウザーでは、角が直角の棒が初めから全長で表示されます。
  • 面グラフのフェードには、パスの mask-image を使います。未対応の場合、面は均一な色で表示されます。
  • 点の半径には、CSSの r プロパティを使い、--chart-dot で設定します。未対応の場合、マークアップで指定した半径が使われます。
  • ラベルの間引きには、プロット本体のコンテナークエリーを使います。未対応の場合はすべてのラベルが表示されます。
  • 初回描画のアニメーションには @starting-style を使います。未対応の場合、マークは描画済みの状態で表示されます。

#チャートの適用範囲

チャートは数百個程度のマークを想定しており、読み手はそれぞれの要素にアクセスできます。数千のデータ点、ストリーミングデータ、ズーム、ブラシ選択、地図、ローソク足には、Canvasに描画するチャートエンジンが適しています。簡潔な表示には、小さなコンポーネントもあります。文章中の推移にはスパークライン、単独の数値には統計値、1つの測定値にはメーターやゲージ、1本の棒で合計の内訳を示すには内訳バー、多数の小さな値にまたがるパターンにはヒートマップを使えます。選び方はチャートガイドを参照してください。

#アクセシビリティ

  • 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 で値の表示を閉じられます。

#CSSクラス

クラス説明
chartチャート本体。プロットの本体と、その下の凡例で構成されます。
chart-quiet棒は淡い色になり、aria-current を付けたポイントはインク色になります。chart と併用します
chart-split凡例を、名前と数値の縦1列としてプロットの横に置きます。余地がなければプロットの下に置きます。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 を中心とする領域の縦横比を維持します。データ点をパスで表す形式では、そのパスをこの SVG 内に配置します。
chart-gridパーセンテージで配置する、スケールの細線。
chart-grid-base基準線。1段階濃くなります。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積み上げ面の1つの層。下の層を隠す淡い色で塗ります。chart-area と併用します
chart-point目盛りの1区間、1つの扇形、リング、タイル、スロープグラフの1系列、または1つの点を、対応する描画要素とともにまとめます。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-downゼロ未満の値。下端の角が丸くなり、横向きの棒では始端の角が丸くなります。chart-bar と併用します
chart-bar-across横向きの棒。遠い側の端の角が丸くなります。chart-bar と併用します
chart-bar-floating2つの値の間を示し、どちらの端も基準線に接しない、両端を丸めたバー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スロープグラフや順位推移グラフの点は、端が丸い長さゼロのパスで描画します。キャンバスが伸縮しても円形を保ちます。
chart-cellヒートマップのセルには、--chart-tone で指定した強さで色を付けます。
chart-unitワッフルチャートの1マスは全体の1%を表します
chart-stageファネルチャートの各段階は、直前の段階より一段明るい色で表示されます
chart-tileツリーマップのタイルは、名前を載せる淡い色の領域です
chart-centerドーナツグラフの穴、またはリングの内側に置く内容。
chart-center-value中央の数値。
chart-center-label中央の数値が何を表すかを示します。
chart-tipポインターが重なっているポイントの横に出る値表示。ビヘイビアが内容を書き込むまでは非表示です。
chart-tip-titleポイントの名前。
chart-tip-row値表示の中の1つの系列。その系列のカテゴリクラスが付きます。
chart-tip-key系列の色の短い線。
chart-tip-name系列の名前。
chart-tip-valueそのポイントでの系列の値。
chart-legend系列の名前の一覧。それぞれの横に、その色の印を置きます。
chart-key凡例の1つの項目です。対応する系列のカテゴリクラスを指定します。ラベルで囲んだチェックボックスを操作して、系列の表示と非表示を切り替えます。
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;  }}