@terreno/ui 57.8.0 → 57.9.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/AreaChart.d.ts +1 -1
- package/dist/AreaChart.d.ts.map +1 -1
- package/dist/AreaChart.js +70 -22
- package/dist/AreaChart.js.map +1 -1
- package/dist/BarChart.d.ts.map +1 -1
- package/dist/BarChart.js +55 -13
- package/dist/BarChart.js.map +1 -1
- package/dist/ChartCard.d.ts +5 -0
- package/dist/ChartCard.d.ts.map +1 -0
- package/dist/ChartCard.js +18 -0
- package/dist/ChartCard.js.map +1 -0
- package/dist/Common.d.ts +79 -5
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/DashboardGrid.d.ts +6 -2
- package/dist/DashboardGrid.d.ts.map +1 -1
- package/dist/DashboardGrid.js +43 -10
- package/dist/DashboardGrid.js.map +1 -1
- package/dist/DonutChart.d.ts.map +1 -1
- package/dist/DonutChart.js +20 -10
- package/dist/DonutChart.js.map +1 -1
- package/dist/DropdownMenuItem.d.ts +16 -0
- package/dist/DropdownMenuItem.d.ts.map +1 -0
- package/dist/DropdownMenuItem.js +11 -0
- package/dist/DropdownMenuItem.js.map +1 -0
- package/dist/FilePickerButton.d.ts.map +1 -1
- package/dist/FilePickerButton.js +70 -10
- package/dist/FilePickerButton.js.map +1 -1
- package/dist/GPTChat.d.ts.map +1 -1
- package/dist/GPTChat.js +103 -14
- package/dist/GPTChat.js.map +1 -1
- package/dist/LineChart.d.ts +1 -1
- package/dist/LineChart.d.ts.map +1 -1
- package/dist/LineChart.js +62 -21
- package/dist/LineChart.js.map +1 -1
- package/dist/Scorecard.d.ts +5 -0
- package/dist/Scorecard.d.ts.map +1 -0
- package/dist/Scorecard.js +11 -0
- package/dist/Scorecard.js.map +1 -0
- package/dist/SparklineChart.d.ts +5 -0
- package/dist/SparklineChart.d.ts.map +1 -0
- package/dist/SparklineChart.js +35 -0
- package/dist/SparklineChart.js.map +1 -0
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TextField.js +12 -4
- package/dist/TextField.js.map +1 -1
- package/dist/ToastNotifications.d.ts.map +1 -1
- package/dist/ToastNotifications.js +29 -6
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/WebDropdownMenu.d.ts +2 -1
- package/dist/WebDropdownMenu.d.ts.map +1 -1
- package/dist/WebDropdownMenu.js +2 -6
- package/dist/WebDropdownMenu.js.map +1 -1
- package/dist/charts/ChartFacadeContainer.d.ts +10 -0
- package/dist/charts/ChartFacadeContainer.d.ts.map +1 -0
- package/dist/charts/ChartFacadeContainer.js +10 -0
- package/dist/charts/ChartFacadeContainer.js.map +1 -0
- package/dist/charts/ChartFrame.d.ts +4 -0
- package/dist/charts/ChartFrame.d.ts.map +1 -1
- package/dist/charts/ChartFrame.js +4 -2
- package/dist/charts/ChartFrame.js.map +1 -1
- package/dist/charts/layout.d.ts +9 -2
- package/dist/charts/layout.d.ts.map +1 -1
- package/dist/charts/layout.js +28 -6
- package/dist/charts/layout.js.map +1 -1
- package/dist/charts/scales.d.ts +3 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +7 -7
- package/dist/charts/scales.js.map +1 -1
- package/dist/charts/series.d.ts +15 -0
- package/dist/charts/series.d.ts.map +1 -0
- package/dist/charts/series.js +19 -0
- package/dist/charts/series.js.map +1 -0
- package/dist/charts/types/chartTypes.d.ts +7 -0
- package/dist/charts/types/chartTypes.d.ts.map +1 -1
- package/dist/dashboardGridLayout.d.ts +6 -0
- package/dist/dashboardGridLayout.d.ts.map +1 -1
- package/dist/dashboardGridLayout.js +19 -3
- package/dist/dashboardGridLayout.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +9 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.js +6 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
- package/dist/resolveDocumentBodyPortalTarget.d.ts +7 -0
- package/dist/resolveDocumentBodyPortalTarget.d.ts.map +1 -0
- package/dist/resolveDocumentBodyPortalTarget.js +12 -0
- package/dist/resolveDocumentBodyPortalTarget.js.map +1 -0
- package/package.json +1 -1
- package/src/AIRequestExplorer.test.tsx +2 -2
- package/src/AreaChart.test.tsx +81 -0
- package/src/AreaChart.tsx +171 -62
- package/src/BarChart.test.tsx +119 -0
- package/src/BarChart.tsx +94 -20
- package/src/ChartCard.test.tsx +79 -0
- package/src/ChartCard.tsx +80 -0
- package/src/Common.ts +69 -2
- package/src/DashboardGrid.test.tsx +98 -1
- package/src/DashboardGrid.tsx +71 -20
- package/src/DonutChart.test.tsx +73 -0
- package/src/DonutChart.tsx +87 -14
- package/src/DropdownMenuItem.tsx +48 -0
- package/src/FilePickerButton.test.tsx +60 -6
- package/src/FilePickerButton.tsx +116 -28
- package/src/GPTChat.test.tsx +133 -6
- package/src/GPTChat.tsx +196 -38
- package/src/LineChart.test.tsx +104 -0
- package/src/LineChart.tsx +154 -58
- package/src/Scorecard.test.tsx +65 -0
- package/src/Scorecard.tsx +45 -0
- package/src/SparklineChart.test.tsx +69 -0
- package/src/SparklineChart.tsx +85 -0
- package/src/TextField.test.tsx +16 -0
- package/src/TextField.tsx +13 -3
- package/src/ToastNotifications.tsx +33 -6
- package/src/ToastNotifications.webModal.test.tsx +285 -0
- package/src/WebDropdownMenu.tsx +3 -7
- package/src/bunSetup.ts +1 -0
- package/src/charts/ChartFacadeContainer.tsx +35 -0
- package/src/charts/ChartFrame.tsx +39 -1
- package/src/charts/layout.test.ts +22 -1
- package/src/charts/layout.ts +37 -4
- package/src/charts/scales.test.ts +33 -0
- package/src/charts/scales.ts +10 -6
- package/src/charts/series.ts +43 -0
- package/src/charts/types/chartTypes.ts +8 -0
- package/src/dashboardGridLayout.test.ts +59 -1
- package/src/dashboardGridLayout.ts +30 -3
- package/src/index.tsx +6 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +21 -0
- package/src/resolveDocumentBodyPortalTarget.ts +11 -0
package/src/BarChart.test.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {describe, expect, it} from "bun:test";
|
|
2
2
|
import {act, fireEvent} from "@testing-library/react-native";
|
|
3
|
+
import {assert} from "chai";
|
|
3
4
|
|
|
4
5
|
import {BarChart} from "./BarChart";
|
|
5
6
|
import {renderWithTheme} from "./test-utils";
|
|
@@ -10,7 +11,125 @@ const POINTS = [
|
|
|
10
11
|
{label: "C", value: 100},
|
|
11
12
|
];
|
|
12
13
|
|
|
14
|
+
const DATE_POINTS = Array.from({length: 14}, (_, index) => ({
|
|
15
|
+
label: `Sep ${index + 1}, 2026`,
|
|
16
|
+
value: index + 1,
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
const WEEKDAY_POINTS = [
|
|
20
|
+
"Monday",
|
|
21
|
+
"Tuesday",
|
|
22
|
+
"Wednesday",
|
|
23
|
+
"Thursday",
|
|
24
|
+
"Friday",
|
|
25
|
+
"Saturday",
|
|
26
|
+
"Sunday",
|
|
27
|
+
].map((label, index) => ({label, value: index + 1}));
|
|
28
|
+
|
|
13
29
|
describe("BarChart", () => {
|
|
30
|
+
it("rotates dense time labels in auto mode and keeps seven categories horizontal", () => {
|
|
31
|
+
const dense = renderWithTheme(<BarChart data={DATE_POINTS} testID="dense-chart" />);
|
|
32
|
+
const denseStyle = dense.getByTestId("dense-chart.xtick.0").props.style;
|
|
33
|
+
const denseStyles = Array.isArray(denseStyle) ? denseStyle : [denseStyle];
|
|
34
|
+
assert.isTrue(denseStyles.some((style) => Array.isArray(style?.transform)));
|
|
35
|
+
|
|
36
|
+
const categorical = renderWithTheme(<BarChart data={WEEKDAY_POINTS} testID="weekday-chart" />);
|
|
37
|
+
const categoryStyle = categorical.getByTestId("weekday-chart.xtick.0").props.style;
|
|
38
|
+
const categoryStyles = Array.isArray(categoryStyle) ? categoryStyle : [categoryStyle];
|
|
39
|
+
assert.isFalse(categoryStyles.some((style) => Array.isArray(style?.transform)));
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("draws lighter comparison bars on the shared scale", () => {
|
|
43
|
+
const comparisonData = POINTS.map((point) => ({...point, value: point.value + 10}));
|
|
44
|
+
const {getByTestId} = renderWithTheme(
|
|
45
|
+
<BarChart comparisonData={comparisonData} data={POINTS} testID="chart" />
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
assert.exists(getByTestId("chart.comparison.1"));
|
|
49
|
+
assert.isBelow(getByTestId("chart.comparison.1").props.opacity, 1);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("scales current and comparison bars against the same y domain", () => {
|
|
53
|
+
const currentOnly = renderWithTheme(
|
|
54
|
+
<BarChart data={[{label: "A", value: 10}]} testID="current-only" />
|
|
55
|
+
);
|
|
56
|
+
const compared = renderWithTheme(
|
|
57
|
+
<BarChart
|
|
58
|
+
comparisonData={[{label: "A", value: 100}]}
|
|
59
|
+
data={[{label: "A", value: 10}]}
|
|
60
|
+
testID="compared"
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
assert.isAbove(
|
|
65
|
+
currentOnly.getByTestId("current-only.current.0").props.height,
|
|
66
|
+
compared.getByTestId("compared.current.0").props.height
|
|
67
|
+
);
|
|
68
|
+
assert.isAbove(
|
|
69
|
+
compared.getByTestId("compared.comparison.0").props.height,
|
|
70
|
+
compared.getByTestId("compared.current.0").props.height
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("uses only the first named series for bars and legend", () => {
|
|
75
|
+
const firstSeries = [
|
|
76
|
+
{label: "A", value: 10},
|
|
77
|
+
{label: "B", value: 20},
|
|
78
|
+
];
|
|
79
|
+
const {getByTestId, getByText, queryByTestId, queryByText} = renderWithTheme(
|
|
80
|
+
<BarChart
|
|
81
|
+
data={POINTS}
|
|
82
|
+
series={[
|
|
83
|
+
{data: firstSeries, id: "first", label: "Series A"},
|
|
84
|
+
{data: [{label: "C", value: 30}], id: "second", label: "Series B"},
|
|
85
|
+
]}
|
|
86
|
+
testID="chart"
|
|
87
|
+
/>
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
assert.exists(getByText("Series A"));
|
|
91
|
+
assert.notExists(queryByText("Series B"));
|
|
92
|
+
assert.exists(getByTestId("chart.point.1-clickable"));
|
|
93
|
+
assert.notExists(queryByTestId("chart.point.2-clickable"));
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("renders comparison-only data instead of the empty state", () => {
|
|
97
|
+
const {getByTestId, queryByText} = renderWithTheme(
|
|
98
|
+
<BarChart comparisonData={POINTS} data={[]} testID="chart" />
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
assert.exists(getByTestId("chart.comparison.1"));
|
|
102
|
+
assert.notExists(queryByText("No data"));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("renders chart-card header shortcuts and invokes the period action", async (): Promise<void> => {
|
|
106
|
+
let pressCount = 0;
|
|
107
|
+
const handlePeriodPress = (): void => {
|
|
108
|
+
pressCount += 1;
|
|
109
|
+
};
|
|
110
|
+
const {getByTestId, getByText} = renderWithTheme(
|
|
111
|
+
<BarChart
|
|
112
|
+
data={POINTS}
|
|
113
|
+
onPeriodPress={handlePeriodPress}
|
|
114
|
+
periodLabel="Last 14 days"
|
|
115
|
+
testID="chart"
|
|
116
|
+
title="Cost / conv. over time"
|
|
117
|
+
/>
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
assert.exists(getByText("Cost / conv. over time"));
|
|
121
|
+
assert.exists(getByText("Last 14 days"));
|
|
122
|
+
fireEvent.press(getByTestId("chart.card.period-clickable"));
|
|
123
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
124
|
+
assert.equal(pressCount, 1);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("does not add ChartCard chrome when title is omitted", () => {
|
|
128
|
+
const {queryByTestId} = renderWithTheme(<BarChart data={POINTS} testID="chart" />);
|
|
129
|
+
|
|
130
|
+
assert.notExists(queryByTestId("chart.card"));
|
|
131
|
+
});
|
|
132
|
+
|
|
14
133
|
it("renders one mark testID per point", () => {
|
|
15
134
|
const {getByTestId, queryByTestId} = renderWithTheme(<BarChart data={POINTS} testID="chart" />);
|
|
16
135
|
|
package/src/BarChart.tsx
CHANGED
|
@@ -5,16 +5,20 @@ import {Rect, Svg, Line as SvgLine} from "react-native-svg";
|
|
|
5
5
|
import {Box} from "./Box";
|
|
6
6
|
import type {BarChartProps, LayoutChangeEvent} from "./Common";
|
|
7
7
|
import {getBarLayout} from "./charts/bars";
|
|
8
|
+
import {ChartFacadeContainer} from "./charts/ChartFacadeContainer";
|
|
8
9
|
import {ChartFrame} from "./charts/ChartFrame";
|
|
9
10
|
import {
|
|
11
|
+
CHART_ROTATED_X_AXIS_HEIGHT,
|
|
10
12
|
CHART_X_AXIS_HEIGHT,
|
|
11
13
|
getChartAxisWidth,
|
|
12
14
|
getChartPlot,
|
|
13
15
|
getPlotHeight,
|
|
14
16
|
getXTickStyle,
|
|
15
17
|
getYTickStyle,
|
|
18
|
+
shouldRotateChartXTicks,
|
|
16
19
|
} from "./charts/layout";
|
|
17
20
|
import {createCartesianScales, getYTickValues} from "./charts/scales";
|
|
21
|
+
import {getAxisPoints} from "./charts/series";
|
|
18
22
|
import {getChartPaint} from "./charts/theme";
|
|
19
23
|
import type {ChartPoint} from "./charts/types/chartTypes";
|
|
20
24
|
import {Text} from "./Text";
|
|
@@ -37,13 +41,19 @@ const formatChartTooltip = ({
|
|
|
37
41
|
|
|
38
42
|
export const BarChart: FC<BarChartProps> = ({
|
|
39
43
|
accessibilityLabel,
|
|
44
|
+
comparisonData = [],
|
|
40
45
|
data,
|
|
41
46
|
emptyText = "No data",
|
|
42
47
|
formatValue = String,
|
|
43
48
|
height = DEFAULT_HEIGHT,
|
|
44
49
|
legendLabel,
|
|
45
50
|
loading = false,
|
|
51
|
+
onPeriodPress,
|
|
52
|
+
periodLabel,
|
|
53
|
+
series,
|
|
46
54
|
testID,
|
|
55
|
+
title,
|
|
56
|
+
xTickPolicy = "auto",
|
|
47
57
|
}) => {
|
|
48
58
|
const {theme} = useTheme();
|
|
49
59
|
const paint = getChartPaint(theme);
|
|
@@ -61,27 +71,53 @@ export const BarChart: FC<BarChartProps> = ({
|
|
|
61
71
|
setActivePointIndex(pointIndex);
|
|
62
72
|
}, []);
|
|
63
73
|
|
|
74
|
+
const primarySeries = series && series.length > 0 ? series[0] : undefined;
|
|
75
|
+
const chartData = primarySeries?.data ?? data;
|
|
76
|
+
const seriesColor = primarySeries?.color ?? paint.series;
|
|
77
|
+
const effectiveLegendLabel = primarySeries?.label ?? legendLabel;
|
|
78
|
+
const axisPoints = getAxisPoints({
|
|
79
|
+
comparisonData,
|
|
80
|
+
series: [
|
|
81
|
+
{data: chartData, id: primarySeries?.id ?? "default", label: effectiveLegendLabel ?? ""},
|
|
82
|
+
],
|
|
83
|
+
});
|
|
84
|
+
const allPoints = [...chartData, ...comparisonData];
|
|
85
|
+
const isXTickRotated = shouldRotateChartXTicks({
|
|
86
|
+
labelCount: axisPoints.length,
|
|
87
|
+
policy: xTickPolicy,
|
|
88
|
+
});
|
|
89
|
+
const xAxisHeight = isXTickRotated ? CHART_ROTATED_X_AXIS_HEIGHT : CHART_X_AXIS_HEIGHT;
|
|
64
90
|
const axisWidth = getChartAxisWidth(chartWidth);
|
|
65
|
-
const plotHeight = getPlotHeight({
|
|
91
|
+
const plotHeight = getPlotHeight({
|
|
92
|
+
hasLegend: Boolean(effectiveLegendLabel),
|
|
93
|
+
height,
|
|
94
|
+
xAxisHeight,
|
|
95
|
+
});
|
|
66
96
|
const plot = getChartPlot({chartWidth, height: plotHeight});
|
|
67
97
|
const plotWidth = chartWidth - axisWidth;
|
|
68
|
-
const scales = createCartesianScales({
|
|
69
|
-
|
|
98
|
+
const scales = createCartesianScales({
|
|
99
|
+
plot,
|
|
100
|
+
points: allPoints,
|
|
101
|
+
xLabels: axisPoints.map((point) => point.label),
|
|
102
|
+
});
|
|
103
|
+
const yTicks = getYTickValues(allPoints);
|
|
70
104
|
const baselineY = scales.y(0);
|
|
71
105
|
const barWidth = Math.max(scales.bandwidth * BAR_FILL, 1);
|
|
72
|
-
const
|
|
106
|
+
const comparisonBarWidth = Math.max(scales.bandwidth * 0.9, 1);
|
|
107
|
+
const activePoint = activePointIndex === undefined ? undefined : chartData[activePointIndex];
|
|
73
108
|
const tooltipText = activePoint
|
|
74
109
|
? formatChartTooltip({formatValue, point: activePoint})
|
|
75
110
|
: undefined;
|
|
76
111
|
const summaryLabel =
|
|
77
|
-
accessibilityLabel ??
|
|
112
|
+
accessibilityLabel ??
|
|
113
|
+
(effectiveLegendLabel ? `${effectiveLegendLabel} bar chart` : "Bar chart");
|
|
78
114
|
|
|
79
|
-
|
|
115
|
+
const chart = (
|
|
80
116
|
<ChartFrame
|
|
81
117
|
accessibilityLabel={summaryLabel}
|
|
82
118
|
emptyText={emptyText}
|
|
83
|
-
isEmpty={
|
|
84
|
-
legendLabel={
|
|
119
|
+
isEmpty={allPoints.length === 0}
|
|
120
|
+
legendLabel={effectiveLegendLabel}
|
|
85
121
|
loading={loading}
|
|
86
122
|
testID={testID}
|
|
87
123
|
tooltipText={tooltipText}
|
|
@@ -116,7 +152,31 @@ export const BarChart: FC<BarChartProps> = ({
|
|
|
116
152
|
/>
|
|
117
153
|
);
|
|
118
154
|
})}
|
|
119
|
-
{
|
|
155
|
+
{comparisonData.map((point, index) => {
|
|
156
|
+
const layout = getBarLayout({
|
|
157
|
+
barWidth: comparisonBarWidth,
|
|
158
|
+
baselineY,
|
|
159
|
+
value: point.value,
|
|
160
|
+
xCenter: scales.xCenter(point.label),
|
|
161
|
+
y: scales.y,
|
|
162
|
+
});
|
|
163
|
+
if (layout.height === 0) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
return (
|
|
167
|
+
<Rect
|
|
168
|
+
fill={seriesColor}
|
|
169
|
+
height={layout.height}
|
|
170
|
+
key={`comparison-${point.label}`}
|
|
171
|
+
opacity={0.3}
|
|
172
|
+
testID={resolveTestID(testID, `comparison.${index}`)}
|
|
173
|
+
width={layout.width}
|
|
174
|
+
x={layout.x}
|
|
175
|
+
y={layout.y}
|
|
176
|
+
/>
|
|
177
|
+
);
|
|
178
|
+
})}
|
|
179
|
+
{chartData.map((point, index) => {
|
|
120
180
|
const layout = getBarLayout({
|
|
121
181
|
barWidth,
|
|
122
182
|
baselineY,
|
|
@@ -129,9 +189,10 @@ export const BarChart: FC<BarChartProps> = ({
|
|
|
129
189
|
}
|
|
130
190
|
return (
|
|
131
191
|
<Rect
|
|
132
|
-
fill={point.color ??
|
|
192
|
+
fill={point.color ?? seriesColor}
|
|
133
193
|
height={layout.height}
|
|
134
194
|
key={`bar-${point.label}`}
|
|
195
|
+
testID={resolveTestID(testID, `current.${index}`)}
|
|
135
196
|
width={layout.width}
|
|
136
197
|
x={layout.x}
|
|
137
198
|
y={layout.y}
|
|
@@ -139,7 +200,7 @@ export const BarChart: FC<BarChartProps> = ({
|
|
|
139
200
|
);
|
|
140
201
|
})}
|
|
141
202
|
</Svg>
|
|
142
|
-
{
|
|
203
|
+
{chartData.map((point, index) => {
|
|
143
204
|
const onPress = (): void => {
|
|
144
205
|
handleMarkPress(index);
|
|
145
206
|
};
|
|
@@ -174,25 +235,27 @@ export const BarChart: FC<BarChartProps> = ({
|
|
|
174
235
|
</Box>
|
|
175
236
|
<Box direction="row">
|
|
176
237
|
<Box width={axisWidth} />
|
|
177
|
-
<Box
|
|
178
|
-
|
|
179
|
-
height={CHART_X_AXIS_HEIGHT}
|
|
180
|
-
minWidth={0}
|
|
181
|
-
overflow="hidden"
|
|
182
|
-
position="relative"
|
|
183
|
-
>
|
|
184
|
-
{data.map((point, index) => (
|
|
238
|
+
<Box flex="grow" height={xAxisHeight} minWidth={0} overflow="hidden" position="relative">
|
|
239
|
+
{axisPoints.map((point, index) => (
|
|
185
240
|
<Box
|
|
186
241
|
dangerouslySetInlineStyle={{
|
|
187
242
|
__style: getXTickStyle({
|
|
188
243
|
bandwidth: scales.bandwidth,
|
|
244
|
+
isRotated: isXTickRotated,
|
|
189
245
|
xCenter: scales.xCenter(point.label),
|
|
190
246
|
}),
|
|
191
247
|
}}
|
|
192
248
|
key={`xtick-${point.label}`}
|
|
193
249
|
testID={resolveTestID(testID, `xtick.${index}`)}
|
|
194
250
|
>
|
|
195
|
-
<Text
|
|
251
|
+
<Text
|
|
252
|
+
align="center"
|
|
253
|
+
color="secondaryDark"
|
|
254
|
+
numberOfLines={1}
|
|
255
|
+
size="sm"
|
|
256
|
+
skipLinking
|
|
257
|
+
truncate={!isXTickRotated}
|
|
258
|
+
>
|
|
196
259
|
{point.label}
|
|
197
260
|
</Text>
|
|
198
261
|
</Box>
|
|
@@ -202,6 +265,17 @@ export const BarChart: FC<BarChartProps> = ({
|
|
|
202
265
|
</Box>
|
|
203
266
|
</ChartFrame>
|
|
204
267
|
);
|
|
268
|
+
|
|
269
|
+
return (
|
|
270
|
+
<ChartFacadeContainer
|
|
271
|
+
onPeriodPress={onPeriodPress}
|
|
272
|
+
periodLabel={periodLabel}
|
|
273
|
+
testID={testID}
|
|
274
|
+
title={title}
|
|
275
|
+
>
|
|
276
|
+
{chart}
|
|
277
|
+
</ChartFacadeContainer>
|
|
278
|
+
);
|
|
205
279
|
};
|
|
206
280
|
|
|
207
281
|
export type {BarChartProps} from "./Common";
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {describe, it} from "bun:test";
|
|
2
|
+
import {fireEvent} from "@testing-library/react-native";
|
|
3
|
+
import {assert} from "chai";
|
|
4
|
+
|
|
5
|
+
import {ChartCard} from "./ChartCard";
|
|
6
|
+
import {ChartCard as RootChartCard} from "./index";
|
|
7
|
+
import {Text} from "./Text";
|
|
8
|
+
import {renderWithTheme} from "./test-utils";
|
|
9
|
+
|
|
10
|
+
describe("ChartCard", () => {
|
|
11
|
+
it("renders title, filter summary, period badge, and children", () => {
|
|
12
|
+
const {getByText} = renderWithTheme(
|
|
13
|
+
<ChartCard
|
|
14
|
+
filterSummary="Report filters: status is Eligible"
|
|
15
|
+
periodLabel="Last 30 days"
|
|
16
|
+
title="Cost by Device"
|
|
17
|
+
>
|
|
18
|
+
<Text>Chart body</Text>
|
|
19
|
+
</ChartCard>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
assert.exists(getByText("Cost by Device"));
|
|
23
|
+
assert.exists(getByText("Report filters: status is Eligible"));
|
|
24
|
+
assert.exists(getByText("Last 30 days"));
|
|
25
|
+
assert.exists(getByText("Chart body"));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("makes the period badge pressable only when a handler is provided", async (): Promise<void> => {
|
|
29
|
+
let pressCount = 0;
|
|
30
|
+
const handlePeriodPress = (): void => {
|
|
31
|
+
pressCount += 1;
|
|
32
|
+
};
|
|
33
|
+
const interactive = renderWithTheme(
|
|
34
|
+
<ChartCard
|
|
35
|
+
onPeriodPress={handlePeriodPress}
|
|
36
|
+
periodLabel="Last 14 days"
|
|
37
|
+
testID="cost-card"
|
|
38
|
+
title="Cost"
|
|
39
|
+
>
|
|
40
|
+
<Text>Body</Text>
|
|
41
|
+
</ChartCard>
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const periodButton = interactive.getByTestId("cost-card.period-clickable");
|
|
45
|
+
assert.equal(periodButton.props.accessibilityRole, "button");
|
|
46
|
+
assert.equal(periodButton.props["aria-label"], "Last 14 days");
|
|
47
|
+
assert.equal(periodButton.props.accessibilityHint, "Change reporting period");
|
|
48
|
+
fireEvent.press(periodButton);
|
|
49
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
50
|
+
assert.equal(pressCount, 1);
|
|
51
|
+
|
|
52
|
+
const displayOnly = renderWithTheme(
|
|
53
|
+
<ChartCard periodLabel="Previous period" testID="display-card" title="Cost">
|
|
54
|
+
<Text>Body</Text>
|
|
55
|
+
</ChartCard>
|
|
56
|
+
);
|
|
57
|
+
assert.notExists(displayOnly.queryByTestId("display-card.period-clickable"));
|
|
58
|
+
assert.notEqual(
|
|
59
|
+
displayOnly.getByTestId("display-card.period").props.accessibilityRole,
|
|
60
|
+
"button"
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("omits optional period and filter chrome", () => {
|
|
65
|
+
const {queryByTestId, queryByText} = renderWithTheme(
|
|
66
|
+
<ChartCard testID="plain-card" title="Conversions">
|
|
67
|
+
<Text>Body</Text>
|
|
68
|
+
</ChartCard>
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
assert.notExists(queryByTestId("plain-card.period"));
|
|
72
|
+
assert.notExists(queryByTestId("plain-card.filter-summary"));
|
|
73
|
+
assert.notExists(queryByText("Last 30 days"));
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("is available from the package root lazy boundary", () => {
|
|
77
|
+
assert.isFunction(RootChartCard);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type {FC} from "react";
|
|
2
|
+
|
|
3
|
+
import {Badge} from "./Badge";
|
|
4
|
+
import {Box} from "./Box";
|
|
5
|
+
import {Card} from "./Card";
|
|
6
|
+
import type {ChartCardProps} from "./Common";
|
|
7
|
+
import {Heading} from "./Heading";
|
|
8
|
+
import {Text} from "./Text";
|
|
9
|
+
import {resolveTestID} from "./testing/resolveTestId";
|
|
10
|
+
|
|
11
|
+
interface PeriodBadgeProps {
|
|
12
|
+
label: string;
|
|
13
|
+
onPress?: () => void;
|
|
14
|
+
testID?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const PeriodBadge: FC<PeriodBadgeProps> = ({label, onPress, testID}) => {
|
|
18
|
+
const badge = (
|
|
19
|
+
<Badge
|
|
20
|
+
secondary
|
|
21
|
+
status="active"
|
|
22
|
+
testID={onPress ? resolveTestID(testID, "badge") : testID}
|
|
23
|
+
value={label}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
if (onPress) {
|
|
28
|
+
return (
|
|
29
|
+
<Box
|
|
30
|
+
accessibilityHint="Change reporting period"
|
|
31
|
+
accessibilityLabel={label}
|
|
32
|
+
accessibilityRole="button"
|
|
33
|
+
onClick={onPress}
|
|
34
|
+
testID={testID}
|
|
35
|
+
>
|
|
36
|
+
{badge}
|
|
37
|
+
</Box>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return badge;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const ChartCard: FC<ChartCardProps> = ({
|
|
45
|
+
children,
|
|
46
|
+
filterSummary,
|
|
47
|
+
onPeriodPress,
|
|
48
|
+
periodLabel,
|
|
49
|
+
testID,
|
|
50
|
+
title,
|
|
51
|
+
}) => {
|
|
52
|
+
return (
|
|
53
|
+
<Card gap={3} padding={4} testID={testID}>
|
|
54
|
+
<Box alignItems="start" direction="row" gap={2} justifyContent="between" width="100%">
|
|
55
|
+
<Box flex="grow" minWidth={0}>
|
|
56
|
+
<Heading size="sm" testID={resolveTestID(testID, "title")}>
|
|
57
|
+
{title}
|
|
58
|
+
</Heading>
|
|
59
|
+
</Box>
|
|
60
|
+
{periodLabel ? (
|
|
61
|
+
<PeriodBadge
|
|
62
|
+
label={periodLabel}
|
|
63
|
+
onPress={onPeriodPress}
|
|
64
|
+
testID={resolveTestID(testID, "period")}
|
|
65
|
+
/>
|
|
66
|
+
) : null}
|
|
67
|
+
</Box>
|
|
68
|
+
{filterSummary ? (
|
|
69
|
+
<Text color="secondaryDark" size="sm" testID={resolveTestID(testID, "filter-summary")}>
|
|
70
|
+
{filterSummary}
|
|
71
|
+
</Text>
|
|
72
|
+
) : null}
|
|
73
|
+
<Box minWidth={0} width="100%">
|
|
74
|
+
{children}
|
|
75
|
+
</Box>
|
|
76
|
+
</Card>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export type {ChartCardProps} from "./Common";
|
package/src/Common.ts
CHANGED
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
FontAwesome6RegularNames,
|
|
20
20
|
FontAwesome6SolidNames,
|
|
21
21
|
} from "./CommonIconTypes";
|
|
22
|
+
import type {ChartPoint, ChartSeries} from "./charts/types/chartTypes";
|
|
22
23
|
import type {DropdownPanelAlign} from "./dropdownPanelLayout";
|
|
23
24
|
import type {
|
|
24
25
|
DataTableTestIDs,
|
|
@@ -993,6 +994,11 @@ export interface TextFieldProps extends BaseFieldProps, HelperTextProps, ErrorTe
|
|
|
993
994
|
returnKeyType?: "done" | "go" | "next" | "search" | "send";
|
|
994
995
|
|
|
995
996
|
grow?: boolean;
|
|
997
|
+
/**
|
|
998
|
+
* Caps the height (in pixels) a `grow` field expands to. Past the cap the field
|
|
999
|
+
* stops growing and its content scrolls.
|
|
1000
|
+
*/
|
|
1001
|
+
maxHeight?: number;
|
|
996
1002
|
multiline?: boolean;
|
|
997
1003
|
rows?: number;
|
|
998
1004
|
|
|
@@ -2734,8 +2740,10 @@ export interface PaginationProps extends WithTestID {
|
|
|
2734
2740
|
export interface LineChartProps extends WithTestID {
|
|
2735
2741
|
/** Summary announced for the whole chart. */
|
|
2736
2742
|
accessibilityLabel?: string;
|
|
2743
|
+
/** Optional previous-period values drawn as a dotted overlay. */
|
|
2744
|
+
comparisonData?: ChartPoint[];
|
|
2737
2745
|
/** Single series of labeled numeric points. */
|
|
2738
|
-
data:
|
|
2746
|
+
data: ChartPoint[];
|
|
2739
2747
|
/** Copy shown when `data` is empty. */
|
|
2740
2748
|
emptyText?: string;
|
|
2741
2749
|
/** Formats the numeric value in tooltips. */
|
|
@@ -2746,12 +2754,65 @@ export interface LineChartProps extends WithTestID {
|
|
|
2746
2754
|
legendLabel?: string;
|
|
2747
2755
|
/** When true, shows a spinner instead of the plot. */
|
|
2748
2756
|
loading?: boolean;
|
|
2757
|
+
/** Makes `periodLabel` pressable when provided. */
|
|
2758
|
+
onPeriodPress?: () => void;
|
|
2759
|
+
/** Relative or absolute reporting period shown with `title`. */
|
|
2760
|
+
periodLabel?: string;
|
|
2761
|
+
/** Named series. When non-empty, these replace the single `data` series. */
|
|
2762
|
+
series?: ChartSeries[];
|
|
2763
|
+
/** Optional chart-card title shortcut. */
|
|
2764
|
+
title?: string;
|
|
2765
|
+
/** X-label collision policy. `auto` rotates when more than seven labels are present. */
|
|
2766
|
+
xTickPolicy?: "auto" | "rotate" | "truncate";
|
|
2767
|
+
}
|
|
2768
|
+
|
|
2769
|
+
export interface SparklineChartProps extends WithTestID {
|
|
2770
|
+
/** Summary announced for the whole sparkline. */
|
|
2771
|
+
accessibilityLabel?: string;
|
|
2772
|
+
/** Optional previous-period values drawn as a dotted line. */
|
|
2773
|
+
comparisonData?: Array<{label: string; value: number}>;
|
|
2774
|
+
/** Current labeled numeric values. */
|
|
2775
|
+
data: Array<{label: string; value: number}>;
|
|
2776
|
+
/** Whole sparkline height in pixels. */
|
|
2777
|
+
height?: number;
|
|
2778
|
+
}
|
|
2779
|
+
|
|
2780
|
+
export interface ChartCardProps extends WithTestID {
|
|
2781
|
+
children: React.ReactNode;
|
|
2782
|
+
/** Optional context shown below the title row. */
|
|
2783
|
+
filterSummary?: string;
|
|
2784
|
+
/** Makes the period badge pressable when provided. */
|
|
2785
|
+
onPeriodPress?: () => void;
|
|
2786
|
+
/** Date range or relative period shown in the header. */
|
|
2787
|
+
periodLabel?: string;
|
|
2788
|
+
/** Card heading. */
|
|
2789
|
+
title: string;
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2792
|
+
export interface ScorecardProps extends WithTestID {
|
|
2793
|
+
/** Optional previous-period sparkline values. */
|
|
2794
|
+
comparisonData?: Array<{label: string; value: number}>;
|
|
2795
|
+
/** Formats numeric values. String values render unchanged. */
|
|
2796
|
+
formatValue?: (value: number) => string;
|
|
2797
|
+
onPeriodPress?: () => void;
|
|
2798
|
+
periodLabel?: string;
|
|
2799
|
+
/** Current-period sparkline values. */
|
|
2800
|
+
sparklineData?: Array<{label: string; value: number}>;
|
|
2801
|
+
title: string;
|
|
2802
|
+
value: number | string;
|
|
2749
2803
|
}
|
|
2750
2804
|
|
|
2751
2805
|
export interface AreaChartProps extends LineChartProps {}
|
|
2752
2806
|
export interface BarChartProps extends LineChartProps {}
|
|
2753
2807
|
|
|
2754
|
-
export interface DonutChartProps extends LineChartProps {
|
|
2808
|
+
export interface DonutChartProps extends LineChartProps {
|
|
2809
|
+
/** Small copy below the center value. */
|
|
2810
|
+
centerTitle?: string;
|
|
2811
|
+
/** Primary copy inside the donut hole. */
|
|
2812
|
+
centerValue?: string;
|
|
2813
|
+
/** Formats each slice's legend share. Defaults to a rounded percentage. */
|
|
2814
|
+
formatShare?: (value: number, total: number) => string;
|
|
2815
|
+
}
|
|
2755
2816
|
|
|
2756
2817
|
export interface DashboardGridProps extends WithTestID {
|
|
2757
2818
|
children?: React.ReactNode;
|
|
@@ -2760,6 +2821,12 @@ export interface DashboardGridProps extends WithTestID {
|
|
|
2760
2821
|
gap?: UnsignedUpTo12;
|
|
2761
2822
|
}
|
|
2762
2823
|
|
|
2824
|
+
export interface DashboardGridItemProps extends WithTestID {
|
|
2825
|
+
children?: React.ReactNode;
|
|
2826
|
+
/** Number of grid columns occupied at each breakpoint. Defaults to one. */
|
|
2827
|
+
span?: {lg?: number; md?: number; sm?: number};
|
|
2828
|
+
}
|
|
2829
|
+
|
|
2763
2830
|
/**
|
|
2764
2831
|
* Data Table
|
|
2765
2832
|
*/
|