Skip to content

Commit fd6a6fc

Browse files
committed
docs(charts): document ChartGrid audit surface
1 parent 2b2113d commit fd6a6fc

7 files changed

Lines changed: 403 additions & 1 deletion

File tree

‎apps/docsite/src/__tests__/data-extraction.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ describe('componentRegistry', () => {
245245
expect(components['@astryxdesign/charts'].map(comp => comp.name)).toEqual([
246246
'Chart',
247247
'ChartAxis',
248+
'ChartGrid',
248249
'ChartSwatch',
249250
]);
250251
expect(components['@astryxdesign/richtext'].map(comp => comp.name)).toEqual(
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
import type {Meta, StoryObj} from '@storybook/react';
4+
import {Chart, ChartAxis, ChartGrid, bar} from '@astryxdesign/charts';
5+
6+
const CATEGORICAL_DATA = [
7+
{month: 'January', value: 18},
8+
{month: 'February', value: 31},
9+
{month: 'March', value: 24},
10+
{month: 'April', value: 42},
11+
];
12+
13+
const CONTINUOUS_DATA = [
14+
{x: 0, value: 18},
15+
{x: 5, value: 31},
16+
{x: 10, value: 24},
17+
];
18+
19+
const meta = {
20+
title: 'Charts/Chrome/ChartGrid',
21+
component: ChartGrid,
22+
tags: ['autodocs'],
23+
args: {
24+
horizontal: true,
25+
vertical: false,
26+
tickCount: 5,
27+
},
28+
argTypes: {
29+
tickCount: {control: {type: 'range', min: 0, max: 10, step: 1}},
30+
},
31+
render: args => (
32+
<Chart
33+
data={CATEGORICAL_DATA}
34+
xKey="month"
35+
series={[bar('value')]}
36+
title="Monthly value"
37+
grid={<ChartGrid {...args} />}
38+
axes={
39+
<>
40+
<ChartAxis position="bottom" />
41+
<ChartAxis position="left" />
42+
</>
43+
}
44+
height={300}
45+
/>
46+
),
47+
} satisfies Meta<typeof ChartGrid>;
48+
49+
export default meta;
50+
type Story = StoryObj<typeof meta>;
51+
52+
/** Drive horizontal, vertical, combined, empty, and density states. */
53+
export const Playground: Story = {};
54+
55+
/** Continuous x values use d3 ticks rather than categorical band centers. */
56+
export const ContinuousX: Story = {
57+
args: {
58+
horizontal: false,
59+
vertical: true,
60+
tickCount: 5,
61+
},
62+
render: args => (
63+
<Chart
64+
data={CONTINUOUS_DATA}
65+
xKey="x"
66+
series={[bar('value')]}
67+
title="Continuous x values"
68+
grid={<ChartGrid {...args} />}
69+
axes={
70+
<>
71+
<ChartAxis position="bottom" />
72+
<ChartAxis position="left" />
73+
</>
74+
}
75+
height={300}
76+
/>
77+
),
78+
};

‎internal/shadcn-registry/routes.lock.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@
116116
"path": "components/charts/chart-axis",
117117
"aliases": []
118118
},
119+
{
120+
"name": "component-charts-chart-grid",
121+
"path": "components/charts/chart-grid",
122+
"aliases": []
123+
},
119124
{
120125
"name": "component-charts-chart-swatch",
121126
"path": "components/charts/chart-swatch",
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/** @type {import('@astryxdesign/cli/authoring').ComponentDoc} */
4+
5+
export const docs = {
6+
name: 'ChartGrid',
7+
displayName: 'Chart Grid',
8+
group: 'Charts',
9+
category: 'Data Visualization',
10+
isHiddenFromOverview: true,
11+
keywords: ['chart', 'grid', 'guides', 'axis', 'ticks', 'data visualization'],
12+
13+
usage: {
14+
description:
15+
'ChartGrid draws horizontal and vertical guide lines from the scales owned by a parent Chart. Use it in the Chart grid slot so guides share the plot dimensions and tick values used by the chart.',
16+
bestPractices: [
17+
{
18+
guidance: true,
19+
description:
20+
'Pair ChartGrid with ChartAxis when readers need labelled values beside the guide lines.',
21+
},
22+
{
23+
guidance: true,
24+
description:
25+
'Use horizontal guides for value comparison and add vertical guides only when they help readers align categories or continuous x values.',
26+
},
27+
{
28+
guidance: false,
29+
description:
30+
'Use grid lines as the only way to communicate a value or distinction. Keep meaningful chart information in labels, marks, and the parent Chart alternative.',
31+
},
32+
{
33+
guidance: false,
34+
description:
35+
'Expect tickCount to thin categorical band centers. It requests density only for continuous scales; categorical vertical guides render once per band.',
36+
},
37+
],
38+
accessibility: [
39+
{
40+
name: 'Chart alternative',
41+
category: 'Content',
42+
criterion: '1.1.1 Non-text Content',
43+
requirement: 'Required on the parent Chart',
44+
states: ['All'],
45+
description:
46+
'Chart owns the accessible image name and supported small-data table. Grid lines supplement that chart-level alternative rather than replacing it.',
47+
},
48+
{
49+
name: 'Visual-only guides',
50+
category: 'Color contrast',
51+
criterion: '1.4.11 Non-text Contrast',
52+
requirement: 'Do not carry information alone',
53+
states: ['Horizontal', 'Vertical', 'Combined'],
54+
description:
55+
'Grid lines are supporting guides. Preserve visible labels, marks, or another qualifying cue so understanding does not depend on the grid alone.',
56+
},
57+
],
58+
anatomy: [
59+
{
60+
name: 'Grid lines',
61+
required: false,
62+
description:
63+
'Horizontal lines at continuous y ticks and vertical lines at x ticks or categorical band centers.',
64+
},
65+
],
66+
},
67+
68+
props: [
69+
{
70+
name: 'horizontal',
71+
type: 'boolean',
72+
description:
73+
'Whether to draw horizontal guides at continuous y ticks other than zero.',
74+
default: 'true',
75+
},
76+
{
77+
name: 'vertical',
78+
type: 'boolean',
79+
description:
80+
'Whether to draw vertical guides at continuous x ticks or categorical band centers.',
81+
default: 'false',
82+
},
83+
{
84+
name: 'tickCount',
85+
type: 'number',
86+
description:
87+
'Approximate guide count requested from continuous scales. It does not thin categorical band centers.',
88+
default: '5',
89+
},
90+
],
91+
92+
examples: [
93+
{
94+
label: 'Horizontal guides',
95+
code: `import {Chart, ChartGrid, bar} from '@astryxdesign/charts';
96+
97+
<Chart
98+
data={monthlyRevenue}
99+
xKey="month"
100+
series={[bar('revenue')]}
101+
grid={<ChartGrid />}
102+
/>;`,
103+
},
104+
{
105+
label: 'Horizontal and vertical guides',
106+
code: `<Chart
107+
data={monthlyRevenue}
108+
xKey="month"
109+
series={[bar('revenue')]}
110+
grid={<ChartGrid horizontal vertical tickCount={6} />}
111+
/>;`,
112+
},
113+
],
114+
};

0 commit comments

Comments
 (0)