You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
244 lines
11 KiB
244 lines
11 KiB
<script lang="ts">
|
|
import { AreaChart } from '$uix/eidos/components/chart';
|
|
import { compileMorfo } from '$uix/morfo';
|
|
import { chartMorfo } from '@/uix/morfo/components/chart';
|
|
import type { CurveName } from '$libs/plots';
|
|
|
|
type Tab = 'live' | 'examples' | 'api' | 'morfo' | 'recipe' | 'a11y';
|
|
let tab = $state<Tab>('live');
|
|
|
|
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
const data = months.map((month, i) => ({
|
|
month,
|
|
revenue: [42, 48, 55, 51, 67, 72, 69, 78, 74, 83, 88, 95][i],
|
|
expenses: [30, 33, 37, 35, 44, 46, 45, 50, 48, 53, 55, 58][i]
|
|
}));
|
|
|
|
let curve = $state<CurveName>('monotone');
|
|
let opacity = $state(0.18);
|
|
let multi = $state(false);
|
|
let legend = $state(true);
|
|
let grid = $state(true);
|
|
let niceY = $state(true);
|
|
let height = $state(260);
|
|
let showTooltip = $state(true);
|
|
|
|
const curves: CurveName[] = ['monotone', 'linear', 'step'];
|
|
const opacities = [0.1, 0.18, 0.3];
|
|
const heights = [200, 260, 320];
|
|
const seriesKeys = $derived(multi ? ['revenue', 'expenses'] : 'revenue');
|
|
|
|
const compiled = compileMorfo(chartMorfo);
|
|
const partsList = $derived([...compiled.parts.byKebab.values()]);
|
|
const money = (v: number) => `${v}k`;
|
|
|
|
const snippet = $derived(
|
|
[
|
|
"<script lang='ts'>",
|
|
" import { AreaChart } from '$uix/eidos/components/chart';",
|
|
'',
|
|
' // rows keyed by x (a month), one column per series',
|
|
' const data = [',
|
|
" { month: 'Jan', revenue: 42, expenses: 30 },",
|
|
" { month: 'Feb', revenue: 48, expenses: 33 }",
|
|
' // …',
|
|
' ];',
|
|
'</' + 'script>',
|
|
'',
|
|
'<AreaChart',
|
|
' {data}',
|
|
' x="month"',
|
|
' xScale="point"',
|
|
multi ? " y={['revenue', 'expenses']}" : ' y="revenue"',
|
|
curve !== 'monotone' && ` curve="${curve}"`,
|
|
opacity !== 0.18 && ` opacity={${opacity}}`,
|
|
!legend && ' legend={false}',
|
|
!grid && ' noGrid',
|
|
!niceY && ' niceY={false}',
|
|
height !== 260 && ` height={${height}}`,
|
|
' formatY={(v) => `${v}k`}',
|
|
'/>'
|
|
]
|
|
.filter(Boolean)
|
|
.join('\n')
|
|
);
|
|
</script>
|
|
|
|
<div data-uix-canvas-inner>
|
|
<header>
|
|
<div data-uix-eyebrow>Charts · Area chart</div>
|
|
<h1 data-uix-page-title>Area chart</h1>
|
|
<p data-uix-page-lede>
|
|
Filled area with a line edge per series, on the zero-dependency <code>$libs/plots</code> engine.
|
|
Smooth / straight / stepped curves; tunable fill opacity; single or stacked-by-series.
|
|
</p>
|
|
<div data-uix-page-meta>
|
|
<span data-uix-meta-pill><span data-uix-meta-key>parts</span>{compiled.parts.order.length}</span>
|
|
<span data-uix-meta-pill><span data-uix-meta-key>render</span>svg · 0-dep</span>
|
|
<span data-uix-meta-pill><span data-uix-meta-key>series</span>{multi ? 2 : 1}</span>
|
|
<span data-uix-meta-pill><span data-uix-meta-key>curve</span>{curve}</span>
|
|
</div>
|
|
</header>
|
|
|
|
<div data-uix-stage>
|
|
<div data-uix-stage-area>
|
|
<AreaChart {data} x="month" xScale="point" y={seriesKeys} {curve} {opacity} {legend} {height} {niceY} tooltip={showTooltip} noGrid={!grid} formatY={money} ariaLabel="Monthly revenue area" />
|
|
</div>
|
|
<div data-uix-stage-trace>
|
|
<span data-uix-stage-trace-key>renders</span>
|
|
<span><span data-uix-stage-trace-event>{multi ? 2 : 1} series</span> · {curve} · opacity {opacity}</span>
|
|
<span style="margin-inline-start: auto;"><span data-uix-stage-trace-key>height</span> {height}px</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div data-uix-tabs role="tablist">
|
|
<button data-uix-tab data-active={tab === 'live'} onclick={() => (tab = 'live')}>Live</button>
|
|
<button data-uix-tab data-active={tab === 'examples'} onclick={() => (tab = 'examples')}>Examples</button>
|
|
<button data-uix-tab data-active={tab === 'api'} onclick={() => (tab = 'api')}>API</button>
|
|
<button data-uix-tab data-active={tab === 'morfo'} onclick={() => (tab = 'morfo')}>
|
|
<span data-uix-layer-badge="morfo">morfo</span>
|
|
<span data-uix-tab-count>{partsList.length}p</span>
|
|
</button>
|
|
<button data-uix-tab data-active={tab === 'recipe'} onclick={() => (tab = 'recipe')}>Recipe</button>
|
|
<button data-uix-tab data-active={tab === 'a11y'} onclick={() => (tab = 'a11y')}>A11y</button>
|
|
</div>
|
|
|
|
{#if tab === 'live'}
|
|
<section data-uix-section>
|
|
<h2 data-uix-section-title>Controls</h2>
|
|
<p data-uix-section-desc>Pure <span data-uix-layer-badge="eidos">eidos</span> display — every control changes the live chart above.</p>
|
|
<div data-uix-controls>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>curve</span>
|
|
<span data-uix-chips role="radiogroup">
|
|
{#each curves as c}<button data-uix-chip data-active={curve === c} onclick={() => (curve = c)}>{c}</button>{/each}
|
|
</span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>fill opacity</span>
|
|
<span data-uix-chips role="radiogroup">
|
|
{#each opacities as o}<button data-uix-chip data-active={opacity === o} onclick={() => (opacity = o)}>{o}</button>{/each}
|
|
</span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>height</span>
|
|
<span data-uix-chips role="radiogroup">
|
|
{#each heights as h}<button data-uix-chip data-active={height === h} onclick={() => (height = h)}>{h}</button>{/each}
|
|
</span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>series</span>
|
|
<span data-uix-switch><input type="checkbox" bind:checked={multi} /><span data-uix-switch-label>{multi ? 'revenue + expenses' : 'revenue only'}</span></span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>legend</span>
|
|
<span data-uix-switch><input type="checkbox" bind:checked={legend} /><span data-uix-switch-label>{legend ? 'on' : 'off'}</span></span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>grid</span>
|
|
<span data-uix-switch><input type="checkbox" bind:checked={grid} /><span data-uix-switch-label>{grid ? 'on' : 'off'}</span></span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>niceY</span>
|
|
<span data-uix-switch><input type="checkbox" bind:checked={niceY} /><span data-uix-switch-label>{niceY ? 'on' : 'off'}</span></span>
|
|
</label>
|
|
<label data-uix-control>
|
|
<span data-uix-control-label>tooltip</span>
|
|
<span data-uix-switch><input type="checkbox" bind:checked={showTooltip} /><span data-uix-switch-label>{showTooltip ? 'on' : 'off'}</span></span>
|
|
</label>
|
|
</div>
|
|
<div data-uix-code>
|
|
<div data-uix-code-head>
|
|
<span data-uix-layer-badge="eidos">eidos</span>
|
|
<span>AreaChart preset</span>
|
|
<span data-uix-code-lang>svelte</span>
|
|
</div>
|
|
<pre><code>{snippet}</code></pre>
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
|
|
{#if tab === 'examples'}
|
|
<section data-uix-section>
|
|
<h2 data-uix-section-title>Examples</h2>
|
|
<div data-uix-stage-area style="display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem;">
|
|
<AreaChart {data} x="month" xScale="point" y="revenue" title="Default" formatY={money} height={200} />
|
|
<AreaChart {data} x="month" xScale="point" y="revenue" curve="step" opacity={0.3} title="Stepped · denser" formatY={money} height={200} />
|
|
<AreaChart {data} x="month" xScale="point" y={['revenue', 'expenses']} title="Two series" formatY={money} height={200} />
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
|
|
{#if tab === 'api'}
|
|
<section data-uix-section>
|
|
<h2 data-uix-section-title>API reference</h2>
|
|
<div data-uix-table-wrap>
|
|
<table data-uix-table>
|
|
<thead><tr><th>Prop</th><th>Type</th><th>Default</th><th>Description</th></tr></thead>
|
|
<tbody>
|
|
<tr><td class="name">data</td><td class="type">{`readonly Record<string, unknown>[]`}</td><td class="default empty">—</td><td>Rows of data.</td></tr>
|
|
<tr><td class="name">x</td><td class="type">string</td><td class="default empty">—</td><td>x position key.</td></tr>
|
|
<tr><td class="name">y</td><td class="type">{`string | string[]`}</td><td class="default empty">—</td><td>Series key(s).</td></tr>
|
|
<tr><td class="name">xScale</td><td class="type">'linear' | 'time' | 'band' | 'point'</td><td class="default">'linear'</td><td>x mapping.</td></tr>
|
|
<tr><td class="name">curve</td><td class="type">'monotone' | 'linear' | 'step'</td><td class="default">'monotone'</td><td>Point connection.</td></tr>
|
|
<tr><td class="name">opacity</td><td class="type">number</td><td class="default">0.18</td><td>Area fill opacity.</td></tr>
|
|
<tr><td class="name">legend / noGrid / niceY</td><td class="type">boolean</td><td class="default">true / false / true</td><td>Chrome toggles.</td></tr>
|
|
<tr><td class="name">height</td><td class="type">number</td><td class="default">260</td><td>Plot height.</td></tr>
|
|
<tr><td class="name">formatX / formatY</td><td class="type">{`(v: number) => string`}</td><td class="default empty">—</td><td>Axis label formatters.</td></tr>
|
|
<tr><td class="name">title / ariaLabel</td><td class="type">string</td><td class="default empty">—</td><td>Title / accessible name.</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
|
|
{#if tab === 'morfo'}
|
|
<section data-uix-section>
|
|
<h2 data-uix-section-title><span data-uix-layer-badge="morfo">morfo</span> · declarative contract</h2>
|
|
<p data-uix-section-desc>Source: <code>src/uix/morfo/components/chart.ts</code>. The chart family shares one <code>scope:['eidos']</code> contract.</p>
|
|
<div data-uix-table-wrap>
|
|
<table data-uix-table>
|
|
<thead><tr><th>Part</th><th>Marker</th><th>Element</th><th>Role</th><th>Optional</th></tr></thead>
|
|
<tbody>
|
|
{#each partsList as part}
|
|
<tr><td class="name">{part.kebab}</td><td><code data-uix-part-marker>[{part.marker}]</code></td><td class="type"><{part.defaultElement}></td><td class="type">{part.role ?? '—'}</td><td class="default">{part.optional ? 'yes' : 'no'}</td></tr>
|
|
{/each}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
|
|
{#if tab === 'recipe'}
|
|
<section data-uix-section>
|
|
<h2 data-uix-section-title>Eidos recipe</h2>
|
|
<p data-uix-section-desc>No <code>--chart-*</code> tokens — styles from global theme tokens.</p>
|
|
<div data-uix-table-wrap>
|
|
<table data-uix-table>
|
|
<thead><tr><th>Surface</th><th>Token</th></tr></thead>
|
|
<tbody>
|
|
<tr><td class="name">series / area</td><td class="type">var(--color-{'{'}role{'}'}-solid) + fill-opacity</td></tr>
|
|
<tr><td class="name">axis / grid</td><td class="type">var(--color-border-default / -subtle)</td></tr>
|
|
<tr><td class="name">labels / title</td><td class="type">var(--color-content-secondary / -primary)</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
|
|
{#if tab === 'a11y'}
|
|
<section data-uix-section>
|
|
<h2 data-uix-section-title>Accessibility</h2>
|
|
<div data-uix-table-wrap>
|
|
<table data-uix-table>
|
|
<thead><tr><th>Part</th><th>Attribute</th><th>Value</th></tr></thead>
|
|
<tbody>
|
|
<tr><td class="name">provider (svg)</td><td>role / aria-label</td><td class="type">"img" / ariaLabel</td></tr>
|
|
<tr><td class="name">grid / axis</td><td>aria-hidden</td><td class="type">"true"</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
{/if}
|
|
</div>
|