@multiplatform.one/components 9.5.0 → 9.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/charts/LineChart.cjs +137 -81
- package/dist/cjs/charts/LineChart.native.js +209 -93
- package/dist/cjs/charts/LineChart.native.js.map +1 -1
- package/dist/cjs/charts/SeriesLegend.cjs +85 -0
- package/dist/cjs/charts/SeriesLegend.native.js +93 -0
- package/dist/cjs/charts/SeriesLegend.native.js.map +1 -0
- package/dist/cjs/charts/series.cjs +47 -3
- package/dist/cjs/charts/series.native.js +49 -5
- package/dist/cjs/charts/series.native.js.map +1 -1
- package/dist/esm/charts/LineChart.mjs +138 -82
- package/dist/esm/charts/LineChart.mjs.map +1 -1
- package/dist/esm/charts/LineChart.native.js +210 -94
- package/dist/esm/charts/LineChart.native.js.map +1 -1
- package/dist/esm/charts/SeriesLegend.mjs +60 -0
- package/dist/esm/charts/SeriesLegend.mjs.map +1 -0
- package/dist/esm/charts/SeriesLegend.native.js +65 -0
- package/dist/esm/charts/SeriesLegend.native.js.map +1 -0
- package/dist/esm/charts/series.mjs +43 -3
- package/dist/esm/charts/series.mjs.map +1 -1
- package/dist/esm/charts/series.native.js +45 -5
- package/dist/esm/charts/series.native.js.map +1 -1
- package/dist/jsx/charts/LineChart.mjs +138 -82
- package/dist/jsx/charts/LineChart.mjs.map +1 -1
- package/dist/jsx/charts/LineChart.native.js +209 -93
- package/dist/jsx/charts/LineChart.native.js.map +1 -1
- package/dist/jsx/charts/SeriesLegend.mjs +60 -0
- package/dist/jsx/charts/SeriesLegend.mjs.map +1 -0
- package/dist/jsx/charts/SeriesLegend.native.js +93 -0
- package/dist/jsx/charts/SeriesLegend.native.js.map +1 -0
- package/dist/jsx/charts/series.mjs +43 -3
- package/dist/jsx/charts/series.mjs.map +1 -1
- package/dist/jsx/charts/series.native.js +49 -5
- package/dist/jsx/charts/series.native.js.map +1 -1
- package/package.json +7 -7
- package/src/charts/Charts.stories.tsx +25 -0
- package/src/charts/LineChart.tsx +185 -105
- package/src/charts/SeriesLegend.native.spec.tsx +99 -0
- package/src/charts/SeriesLegend.tsx +68 -0
- package/src/charts/multiSeriesLine.spec.tsx +111 -0
- package/src/charts/series.tsx +73 -11
- package/types/charts/LineChart.d.ts +21 -5
- package/types/charts/LineChart.d.ts.map +1 -1
- package/types/charts/SeriesLegend.d.ts +21 -0
- package/types/charts/SeriesLegend.d.ts.map +1 -0
- package/types/charts/series.d.ts +18 -1
- package/types/charts/series.d.ts.map +1 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LC-293 under tamagui's NATIVE build: a legend entry reaches the React Native
|
|
3
|
+
* host as a checkbox with its checked state, both as aria-checked and as
|
|
4
|
+
* accessibilityState, so VoiceOver and TalkBack read "checked" or "not
|
|
5
|
+
* checked" whatever RN version maps the aria props.
|
|
6
|
+
*/
|
|
7
|
+
import { act, createElement } from "react";
|
|
8
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
9
|
+
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
|
10
|
+
|
|
11
|
+
const runtime = await vi.hoisted(async () => {
|
|
12
|
+
const { loadNativeTamagui } = await import("@multiplatform.one/test-utils/native-tamagui");
|
|
13
|
+
return loadNativeTamagui();
|
|
14
|
+
});
|
|
15
|
+
vi.mock("react-native-web", () => runtime.reactNative);
|
|
16
|
+
vi.mock("tamagui", () => ({
|
|
17
|
+
...runtime.core,
|
|
18
|
+
XStack: runtime.core.View,
|
|
19
|
+
YStack: runtime.core.View,
|
|
20
|
+
}));
|
|
21
|
+
vi.mock("@multiplatform.one/theme", () => ({
|
|
22
|
+
MIN_PRESS_TARGET: 44,
|
|
23
|
+
useResolvedKnobs: () => ({ knobProps: { body: {}, textAccentColor: "$color" } }),
|
|
24
|
+
}));
|
|
25
|
+
vi.mock("./svg", () => ({
|
|
26
|
+
Svg: () => null,
|
|
27
|
+
Line: () => null,
|
|
28
|
+
Path: () => null,
|
|
29
|
+
chartWebProps: () => ({}),
|
|
30
|
+
}));
|
|
31
|
+
const { SeriesLegend } = await import("./SeriesLegend");
|
|
32
|
+
const { TamaguiProvider, createTamagui, createTokens } = runtime.core;
|
|
33
|
+
const previousConfig = (globalThis as { __tamaguiConfig?: unknown }).__tamaguiConfig;
|
|
34
|
+
const config = createTamagui({
|
|
35
|
+
tokens: createTokens({ size: {}, space: {}, radius: {}, zIndex: {}, color: {} }),
|
|
36
|
+
themes: { light: { background: "rgb(240, 240, 240)", color: "rgb(20, 20, 20)" } },
|
|
37
|
+
shorthands: {},
|
|
38
|
+
media: {},
|
|
39
|
+
});
|
|
40
|
+
let container: HTMLDivElement;
|
|
41
|
+
let root: Root;
|
|
42
|
+
beforeAll(() => {
|
|
43
|
+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
44
|
+
});
|
|
45
|
+
afterEach(() => {
|
|
46
|
+
act(() => root?.unmount());
|
|
47
|
+
container?.remove();
|
|
48
|
+
runtime.resetHosts();
|
|
49
|
+
});
|
|
50
|
+
afterAll(() => {
|
|
51
|
+
(globalThis as { __tamaguiConfig?: unknown }).__tamaguiConfig = previousConfig;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const entry = (id: string, shown: boolean) => ({
|
|
55
|
+
id,
|
|
56
|
+
label: id,
|
|
57
|
+
color: "rgb(0, 144, 255)",
|
|
58
|
+
marker: "circle" as const,
|
|
59
|
+
shown,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
function render(onToggle = vi.fn()) {
|
|
63
|
+
container = document.createElement("div");
|
|
64
|
+
document.body.append(container);
|
|
65
|
+
root = createRoot(container);
|
|
66
|
+
act(() =>
|
|
67
|
+
root.render(
|
|
68
|
+
createElement(
|
|
69
|
+
TamaguiProvider,
|
|
70
|
+
{ config, defaultTheme: "light" },
|
|
71
|
+
createElement(SeriesLegend, {
|
|
72
|
+
entries: [entry("Cash", true), entry("Stocks", false)],
|
|
73
|
+
onToggle,
|
|
74
|
+
}),
|
|
75
|
+
),
|
|
76
|
+
),
|
|
77
|
+
);
|
|
78
|
+
return onToggle;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const checkboxes = () => runtime.allHostProps("View").filter((props) => props.role === "checkbox");
|
|
82
|
+
|
|
83
|
+
describe("LC-293 legend on native", () => {
|
|
84
|
+
it.each(["ios", "android"])("hands the %s host a checkbox with its checked state", (os) => {
|
|
85
|
+
(runtime.reactNative.Platform as { OS: string }).OS = os;
|
|
86
|
+
render();
|
|
87
|
+
const byLabel = new Map(checkboxes().map((props) => [props["aria-label"], props]));
|
|
88
|
+
expect(byLabel.get("Cash")).toMatchObject({
|
|
89
|
+
role: "checkbox",
|
|
90
|
+
"aria-checked": true,
|
|
91
|
+
accessibilityState: { checked: true },
|
|
92
|
+
});
|
|
93
|
+
expect(byLabel.get("Stocks")).toMatchObject({
|
|
94
|
+
role: "checkbox",
|
|
95
|
+
"aria-checked": false,
|
|
96
|
+
accessibilityState: { checked: false },
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { MIN_PRESS_TARGET, useResolvedKnobs } from "@multiplatform.one/theme";
|
|
2
|
+
import { Text, XStack, isWeb } from "tamagui";
|
|
3
|
+
import { markerPath, type MarkerShape } from "./series";
|
|
4
|
+
import { Line, Path, Svg, chartWebProps } from "./svg";
|
|
5
|
+
|
|
6
|
+
export interface SeriesLegendEntry {
|
|
7
|
+
id: string;
|
|
8
|
+
label: string;
|
|
9
|
+
color: string;
|
|
10
|
+
marker: MarkerShape;
|
|
11
|
+
dash?: string;
|
|
12
|
+
shown: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface SeriesLegendProps {
|
|
16
|
+
entries: SeriesLegendEntry[];
|
|
17
|
+
onToggle: (id: string) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* LC-293: one checkbox per series, carrying its line, marker and name. Tapping
|
|
22
|
+
* an entry hides or shows that series. Native gets the checked state through
|
|
23
|
+
* accessibilityState as well, so it never rests on the RN version mapping
|
|
24
|
+
* aria-checked.
|
|
25
|
+
*/
|
|
26
|
+
export function SeriesLegend({ entries, onToggle }: SeriesLegendProps) {
|
|
27
|
+
const { knobProps } = useResolvedKnobs();
|
|
28
|
+
return (
|
|
29
|
+
<XStack flexWrap="wrap" columnGap="$3" {...chartWebProps({ "data-line-legend": "" })}>
|
|
30
|
+
{entries.map((entry) => (
|
|
31
|
+
<XStack
|
|
32
|
+
key={entry.id}
|
|
33
|
+
role="checkbox"
|
|
34
|
+
aria-checked={entry.shown}
|
|
35
|
+
aria-label={entry.label}
|
|
36
|
+
{...(isWeb ? {} : { accessibilityState: { checked: entry.shown } })}
|
|
37
|
+
onPress={() => onToggle(entry.id)}
|
|
38
|
+
minHeight={MIN_PRESS_TARGET}
|
|
39
|
+
alignItems="center"
|
|
40
|
+
gap="$2"
|
|
41
|
+
cursor="pointer"
|
|
42
|
+
opacity={entry.shown ? 1 : 0.45}
|
|
43
|
+
>
|
|
44
|
+
<Svg width={22} height={12}>
|
|
45
|
+
<Line
|
|
46
|
+
x1={1}
|
|
47
|
+
y1={6}
|
|
48
|
+
x2={21}
|
|
49
|
+
y2={6}
|
|
50
|
+
stroke={entry.color}
|
|
51
|
+
strokeWidth={2}
|
|
52
|
+
strokeDasharray={entry.dash}
|
|
53
|
+
/>
|
|
54
|
+
<Path d={markerPath(entry.marker, 11, 6, 3)} fill={entry.color} />
|
|
55
|
+
</Svg>
|
|
56
|
+
<Text
|
|
57
|
+
{...knobProps.body}
|
|
58
|
+
fontSize="$2"
|
|
59
|
+
color={knobProps.textAccentColor}
|
|
60
|
+
textDecorationLine={entry.shown ? "none" : "line-through"}
|
|
61
|
+
>
|
|
62
|
+
{entry.label}
|
|
63
|
+
</Text>
|
|
64
|
+
</XStack>
|
|
65
|
+
))}
|
|
66
|
+
</XStack>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { useChartPalette, type ChartPalette } from "@multiplatform.one/theme";
|
|
2
|
+
import { renderWithProviders } from "@multiplatform.one/test-utils";
|
|
3
|
+
import { cleanup, fireEvent, screen } from "@testing-library/react";
|
|
4
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
+
import { LineChart, type LineChartSeries } from "./LineChart";
|
|
6
|
+
|
|
7
|
+
afterEach(cleanup);
|
|
8
|
+
|
|
9
|
+
const width = 360;
|
|
10
|
+
const months = ["Jan", "Feb", "Mar", "Apr"];
|
|
11
|
+
const make = (id: string, values: number[]): LineChartSeries => ({
|
|
12
|
+
id,
|
|
13
|
+
label: id[0]!.toUpperCase() + id.slice(1),
|
|
14
|
+
data: values.map((value, i) => ({ label: months[i] as string, value })),
|
|
15
|
+
});
|
|
16
|
+
const six = [
|
|
17
|
+
make("cash", [10, 12, 14, 15]),
|
|
18
|
+
make("stocks", [20, 18, 25, 30]),
|
|
19
|
+
make("bonds", [8, 9, 9, 10]),
|
|
20
|
+
make("property", [40, 41, 42, 44]),
|
|
21
|
+
make("crypto", [2, 6, 3, 5]),
|
|
22
|
+
make("debt", [-5, -4, -4, -3]),
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
function PaletteProbe({ into }: { into: { current?: ChartPalette } }) {
|
|
26
|
+
into.current = useChartPalette();
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function lines(container: HTMLElement) {
|
|
31
|
+
return Array.from(container.querySelectorAll("[data-line-series]"));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe("LC-293 MULTI-SERIES-LEGEND: LineChart with several series", () => {
|
|
35
|
+
it("paints each series the theme's categorical colour in order, on one shared scale", () => {
|
|
36
|
+
const palette: { current?: ChartPalette } = {};
|
|
37
|
+
const { container } = renderWithProviders(
|
|
38
|
+
<>
|
|
39
|
+
<PaletteProbe into={palette} />
|
|
40
|
+
<LineChart series={six.slice(0, 3)} width={width} title="Net worth" />
|
|
41
|
+
</>,
|
|
42
|
+
);
|
|
43
|
+
const strokes = lines(container).map((line) =>
|
|
44
|
+
line.querySelector("path")?.getAttribute("stroke"),
|
|
45
|
+
);
|
|
46
|
+
expect(strokes).toEqual(palette.current?.categorical.slice(0, 3));
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("gives every series its own marker shape, and dashes from series 5 on", () => {
|
|
50
|
+
const { container } = renderWithProviders(<LineChart series={six} width={width} />);
|
|
51
|
+
const series = lines(container);
|
|
52
|
+
const markers = series.map((line) => line.getAttribute("data-marker"));
|
|
53
|
+
expect(new Set(markers).size).toBe(6);
|
|
54
|
+
const dashes = series.map((line) =>
|
|
55
|
+
line.querySelector("path")?.getAttribute("stroke-dasharray"),
|
|
56
|
+
);
|
|
57
|
+
expect(dashes.slice(0, 4)).toEqual([null, null, null, null]);
|
|
58
|
+
expect(dashes[4]).toBeTruthy();
|
|
59
|
+
expect(dashes[5]).toBeTruthy();
|
|
60
|
+
expect(dashes[4]).not.toBe(dashes[5]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("draws a legend whose entries toggle their series", () => {
|
|
64
|
+
const { container } = renderWithProviders(
|
|
65
|
+
<LineChart series={six.slice(0, 3)} width={width} title="Net worth" />,
|
|
66
|
+
);
|
|
67
|
+
const toggles = screen.getAllByRole("checkbox");
|
|
68
|
+
expect(toggles).toHaveLength(3);
|
|
69
|
+
expect(toggles.map((t) => t.getAttribute("aria-checked"))).toEqual(["true", "true", "true"]);
|
|
70
|
+
fireEvent.click(screen.getByRole("checkbox", { name: /Stocks/ }));
|
|
71
|
+
expect(lines(container).map((l) => l.getAttribute("data-line-series"))).toEqual([
|
|
72
|
+
"cash",
|
|
73
|
+
"bonds",
|
|
74
|
+
]);
|
|
75
|
+
expect(screen.getByRole("checkbox", { name: /Stocks/ }).getAttribute("aria-checked")).toBe(
|
|
76
|
+
"false",
|
|
77
|
+
);
|
|
78
|
+
fireEvent.click(screen.getByRole("checkbox", { name: /Stocks/ }));
|
|
79
|
+
expect(lines(container)).toHaveLength(3);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("keeps the y scale when a series is hidden, so the others don't jump", () => {
|
|
83
|
+
const { container } = renderWithProviders(<LineChart series={six.slice(0, 4)} width={width} />);
|
|
84
|
+
const before = lines(container)[0]?.querySelector("path")?.getAttribute("d");
|
|
85
|
+
fireEvent.click(screen.getByRole("checkbox", { name: /Property/ }));
|
|
86
|
+
expect(lines(container)[0]?.querySelector("path")?.getAttribute("d")).toBe(before);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("summarises every series for assistive tech", () => {
|
|
90
|
+
renderWithProviders(<LineChart series={six.slice(0, 2)} width={width} title="Net worth" />);
|
|
91
|
+
const label = screen.getByRole("img").getAttribute("aria-label") ?? "";
|
|
92
|
+
expect(label).toContain("Net worth");
|
|
93
|
+
expect(label).toContain("2 series");
|
|
94
|
+
expect(label).toMatch(/Cash: .*highest Apr \(15\)/);
|
|
95
|
+
expect(label).toMatch(/Stocks: .*lowest Feb \(18\)/);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("keeps the single-series API: data draws one identity line and no legend", () => {
|
|
99
|
+
const palette: { current?: ChartPalette } = {};
|
|
100
|
+
const { container } = renderWithProviders(
|
|
101
|
+
<>
|
|
102
|
+
<PaletteProbe into={palette} />
|
|
103
|
+
<LineChart data={six[0]!.data} width={width} />
|
|
104
|
+
</>,
|
|
105
|
+
);
|
|
106
|
+
expect(screen.queryAllByRole("checkbox")).toHaveLength(0);
|
|
107
|
+
const series = lines(container);
|
|
108
|
+
expect(series).toHaveLength(1);
|
|
109
|
+
expect(series[0]?.querySelector("path")?.getAttribute("stroke")).toBe(palette.current?.single);
|
|
110
|
+
});
|
|
111
|
+
});
|
package/src/charts/series.tsx
CHANGED
|
@@ -139,6 +139,55 @@ export interface LineSeriesProps extends DatumTargetCallbacks {
|
|
|
139
139
|
* stays fully tappable at the edges (SVG clips overflowing targets).
|
|
140
140
|
*/
|
|
141
141
|
bounds?: ChartSize;
|
|
142
|
+
/** Point marker shape: a series' identity that does not rest on colour (LC-293). */
|
|
143
|
+
marker?: MarkerShape;
|
|
144
|
+
/** Stroke dash pattern, for series past the fourth (LC-293). */
|
|
145
|
+
dash?: string;
|
|
146
|
+
/** Stable series id, exposed to audits. */
|
|
147
|
+
seriesId?: string;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export type MarkerShape = "circle" | "square" | "triangle" | "diamond" | "triangleDown" | "cross";
|
|
151
|
+
|
|
152
|
+
/** LC-293: one marker per series, in order, so identity never rests on colour alone. */
|
|
153
|
+
export const markerShapes: readonly MarkerShape[] = [
|
|
154
|
+
"circle",
|
|
155
|
+
"square",
|
|
156
|
+
"triangle",
|
|
157
|
+
"diamond",
|
|
158
|
+
"triangleDown",
|
|
159
|
+
"cross",
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
/** LC-293: dash patterns for series 5 on; the first four stay solid. */
|
|
163
|
+
export const seriesDashes: readonly string[] = ["6 4", "2 3", "8 3 2 3", "4 2"];
|
|
164
|
+
|
|
165
|
+
export function seriesEncoding(index: number): { marker: MarkerShape; dash?: string } {
|
|
166
|
+
return {
|
|
167
|
+
marker: markerShapes[index % markerShapes.length] as MarkerShape,
|
|
168
|
+
dash: index >= 4 ? seriesDashes[(index - 4) % seriesDashes.length] : undefined,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Path for a non-circle marker centred on (x, y) with radius r. */
|
|
173
|
+
export function markerPath(shape: MarkerShape, x: number, y: number, r: number): string {
|
|
174
|
+
const s = r * 1.15;
|
|
175
|
+
switch (shape) {
|
|
176
|
+
case "square":
|
|
177
|
+
return `M${x - s},${y - s}H${x + s}V${y + s}H${x - s}Z`;
|
|
178
|
+
case "triangle":
|
|
179
|
+
return `M${x},${y - s * 1.2}L${x + s * 1.15},${y + s * 0.8}H${x - s * 1.15}Z`;
|
|
180
|
+
case "triangleDown":
|
|
181
|
+
return `M${x},${y + s * 1.2}L${x + s * 1.15},${y - s * 0.8}H${x - s * 1.15}Z`;
|
|
182
|
+
case "diamond":
|
|
183
|
+
return `M${x},${y - s * 1.35}L${x + s * 1.35},${y}L${x},${y + s * 1.35}L${x - s * 1.35},${y}Z`;
|
|
184
|
+
case "cross": {
|
|
185
|
+
const t = s * 0.45;
|
|
186
|
+
return `M${x - t},${y - s * 1.2}H${x + t}V${y - t}H${x + s * 1.2}V${y + t}H${x + t}V${y + s * 1.2}H${x - t}V${y + t}H${x - s * 1.2}V${y - t}H${x - t}Z`;
|
|
187
|
+
}
|
|
188
|
+
default:
|
|
189
|
+
return `M${x - r},${y}a${r},${r} 0 1,0 ${r * 2},0a${r},${r} 0 1,0 ${-r * 2},0`;
|
|
190
|
+
}
|
|
142
191
|
}
|
|
143
192
|
|
|
144
193
|
function clampTargetCenter(value: number, radius: number, extent?: number): number {
|
|
@@ -159,30 +208,43 @@ export function LineSeries({
|
|
|
159
208
|
showPoints = true,
|
|
160
209
|
pointRadius = 3,
|
|
161
210
|
bounds,
|
|
211
|
+
marker = "circle",
|
|
212
|
+
dash,
|
|
213
|
+
seriesId = "series",
|
|
162
214
|
...callbacks
|
|
163
215
|
}: LineSeriesProps) {
|
|
164
216
|
const interactive = hasTargets(callbacks);
|
|
165
217
|
const targetRadius = MIN_PRESS_TARGET / 2;
|
|
166
218
|
return (
|
|
167
|
-
<G>
|
|
219
|
+
<G {...chartWebProps({ "data-line-series": seriesId, "data-marker": marker })}>
|
|
168
220
|
<Path
|
|
169
221
|
{...chartMarkProps("series line")}
|
|
170
222
|
d={linePath(points, { curve })}
|
|
171
223
|
fill="none"
|
|
172
224
|
stroke={color}
|
|
173
225
|
strokeWidth={strokeWidth}
|
|
226
|
+
strokeDasharray={dash}
|
|
174
227
|
/>
|
|
175
228
|
{showPoints
|
|
176
|
-
? points.map((point, index) =>
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
229
|
+
? points.map((point, index) =>
|
|
230
|
+
marker === "circle" ? (
|
|
231
|
+
<Circle
|
|
232
|
+
key={`point-${index}`}
|
|
233
|
+
{...chartMarkProps(data[index]?.label ?? `point ${index + 1}`)}
|
|
234
|
+
cx={point.x}
|
|
235
|
+
cy={point.y}
|
|
236
|
+
r={pointRadius}
|
|
237
|
+
fill={color}
|
|
238
|
+
/>
|
|
239
|
+
) : (
|
|
240
|
+
<Path
|
|
241
|
+
key={`point-${index}`}
|
|
242
|
+
{...chartMarkProps(data[index]?.label ?? `point ${index + 1}`)}
|
|
243
|
+
d={markerPath(marker, point.x, point.y, pointRadius)}
|
|
244
|
+
fill={color}
|
|
245
|
+
/>
|
|
246
|
+
),
|
|
247
|
+
)
|
|
186
248
|
: null}
|
|
187
249
|
{interactive
|
|
188
250
|
? points.map((point, index) => (
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
import { type YStackProps } from "tamagui";
|
|
1
2
|
import type { ChartHeight } from "./chartHeight";
|
|
2
|
-
import type { YStackProps } from "tamagui";
|
|
3
3
|
import type { ChartCurve, ChartDatum, ChartDatumEvents } from "./types";
|
|
4
|
-
|
|
4
|
+
/** One line of a multi-series chart (LC-293). */
|
|
5
|
+
export interface LineChartSeries {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
5
8
|
data: ChartDatum[];
|
|
9
|
+
/** Explicit series colour (a data value); defaults to the categorical cycle in order. */
|
|
10
|
+
color?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface LineChartProps extends ChartDatumEvents, Omit<YStackProps, "children" | "width" | "height"> {
|
|
13
|
+
/** A single series. */
|
|
14
|
+
data?: ChartDatum[];
|
|
15
|
+
/**
|
|
16
|
+
* Several series on one scale (LC-293): categorical colours in order, a
|
|
17
|
+
* marker shape per series and dashes from the fifth, and a legend whose
|
|
18
|
+
* entries toggle their series.
|
|
19
|
+
*/
|
|
20
|
+
series?: LineChartSeries[];
|
|
6
21
|
/** Drawing height as a theme size token or pixels (default 200). */
|
|
7
22
|
height?: ChartHeight;
|
|
8
23
|
/** Explicit width bypasses responsive measurement. */
|
|
@@ -30,10 +45,11 @@ export interface LineChartProps extends ChartDatumEvents, Omit<YStackProps, "chi
|
|
|
30
45
|
typeLabel?: string;
|
|
31
46
|
}
|
|
32
47
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
48
|
+
* Line chart over category points: d3 point/linear scales, knob-driven
|
|
49
|
+
* chrome, 44px point hit targets. One series paints the theme identity;
|
|
50
|
+
* several share one scale and a toggling legend (LC-293).
|
|
35
51
|
*/
|
|
36
|
-
export declare function LineChart({ data, height, width, color, showArea, areaOpacity, curve, showPoints, strokeWidth, showXAxis, showYAxis, showGrid, yTicks, valueFormatter, title, label, typeLabel, onDatumPress, onDatumHoverIn, onDatumHoverOut, ...stackProps }: LineChartProps): import("react/jsx-runtime").JSX.Element;
|
|
52
|
+
export declare function LineChart({ data, series, height, width, color, showArea, areaOpacity, curve, showPoints, strokeWidth, showXAxis, showYAxis, showGrid, yTicks, valueFormatter, title, label, typeLabel, onDatumPress, onDatumHoverIn, onDatumHoverOut, ...stackProps }: LineChartProps): import("react/jsx-runtime").JSX.Element;
|
|
37
53
|
export type AreaChartProps = Omit<LineChartProps, "showArea">;
|
|
38
54
|
/** Area chart — the LineChart family with the area fill on by default. */
|
|
39
55
|
export declare function AreaChart(props: AreaChartProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineChart.d.ts","sourceRoot":"","sources":["../../src/charts/LineChart.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LineChart.d.ts","sourceRoot":"","sources":["../../src/charts/LineChart.tsx"],"names":[],"mappings":"AACA,OAAO,EAAU,KAAK,WAAW,EAAE,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AAC,EAAE,MAAM,CAAC;IACf,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,MAAM,EACN,MAAY,EACZ,KAAK,EACL,KAAK,EACL,QAAgB,EAChB,WAAW,EACX,KAAgB,EAChB,UAAiB,EACjB,WAAe,EACf,SAAgB,EAChB,SAAgB,EAChB,QAAe,EACf,MAAU,EACV,cAAc,EACd,KAAK,EACL,KAAK,EACL,SAAS,EACT,YAAY,EACZ,cAAc,EACd,eAAe,EACf,GAAG,UAAU,EACd,EAAE,cAAc,2CA0KhB;AAED,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;AAE9D,0EAA0E;AAC1E,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,2CAE9C"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type MarkerShape } from "./series";
|
|
2
|
+
export interface SeriesLegendEntry {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
color: string;
|
|
6
|
+
marker: MarkerShape;
|
|
7
|
+
dash?: string;
|
|
8
|
+
shown: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface SeriesLegendProps {
|
|
11
|
+
entries: SeriesLegendEntry[];
|
|
12
|
+
onToggle: (id: string) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* LC-293: one checkbox per series, carrying its line, marker and name. Tapping
|
|
16
|
+
* an entry hides or shows that series. Native gets the checked state through
|
|
17
|
+
* accessibilityState as well, so it never rests on the RN version mapping
|
|
18
|
+
* aria-checked.
|
|
19
|
+
*/
|
|
20
|
+
export declare function SeriesLegend({ entries, onToggle }: SeriesLegendProps): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
//# sourceMappingURL=SeriesLegend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SeriesLegend.d.ts","sourceRoot":"","sources":["../../src/charts/SeriesLegend.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAGxD,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,WAAW,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,iBAAiB,2CA0CpE"}
|
package/types/charts/series.d.ts
CHANGED
|
@@ -41,12 +41,29 @@ export interface LineSeriesProps extends DatumTargetCallbacks {
|
|
|
41
41
|
* stays fully tappable at the edges (SVG clips overflowing targets).
|
|
42
42
|
*/
|
|
43
43
|
bounds?: ChartSize;
|
|
44
|
+
/** Point marker shape: a series' identity that does not rest on colour (LC-293). */
|
|
45
|
+
marker?: MarkerShape;
|
|
46
|
+
/** Stroke dash pattern, for series past the fourth (LC-293). */
|
|
47
|
+
dash?: string;
|
|
48
|
+
/** Stable series id, exposed to audits. */
|
|
49
|
+
seriesId?: string;
|
|
44
50
|
}
|
|
51
|
+
export type MarkerShape = "circle" | "square" | "triangle" | "diamond" | "triangleDown" | "cross";
|
|
52
|
+
/** LC-293: one marker per series, in order, so identity never rests on colour alone. */
|
|
53
|
+
export declare const markerShapes: readonly MarkerShape[];
|
|
54
|
+
/** LC-293: dash patterns for series 5 on; the first four stay solid. */
|
|
55
|
+
export declare const seriesDashes: readonly string[];
|
|
56
|
+
export declare function seriesEncoding(index: number): {
|
|
57
|
+
marker: MarkerShape;
|
|
58
|
+
dash?: string;
|
|
59
|
+
};
|
|
60
|
+
/** Path for a non-circle marker centred on (x, y) with radius r. */
|
|
61
|
+
export declare function markerPath(shape: MarkerShape, x: number, y: number, r: number): string;
|
|
45
62
|
/**
|
|
46
63
|
* Stroked data line with optional per-datum dots. Hit targets are invisible
|
|
47
64
|
* 44px-diameter circles centered on each datum.
|
|
48
65
|
*/
|
|
49
|
-
export declare function LineSeries({ data, points, color, strokeWidth, curve, showPoints, pointRadius, bounds, ...callbacks }: LineSeriesProps): import("react/jsx-runtime").JSX.Element;
|
|
66
|
+
export declare function LineSeries({ data, points, color, strokeWidth, curve, showPoints, pointRadius, bounds, marker, dash, seriesId, ...callbacks }: LineSeriesProps): import("react/jsx-runtime").JSX.Element;
|
|
50
67
|
export interface AreaSeriesProps {
|
|
51
68
|
/** Pixel positions of the series top edge. */
|
|
52
69
|
points: PixelPoint[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"series.d.ts","sourceRoot":"","sources":["../../src/charts/series.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAgBvD,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,QAAQ,EACT,MAAM,SAAS,CAAC;AAGjB;;;;;;GAMG;AAEH,UAAU,oBAAqB,SAAQ,gBAAgB;IACrD,wDAAwD;IACxD,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3D;AAuBD,MAAM,WAAW,cAAe,SAAQ,oBAAoB;IAC1D,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAC1B,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,IAAI,EAAE,QAAQ,CAAC;IACf,sEAAsE;IACtE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