@terreno/ui 57.7.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.
Files changed (186) hide show
  1. package/dist/AreaChart.d.ts +1 -1
  2. package/dist/AreaChart.d.ts.map +1 -1
  3. package/dist/AreaChart.js +70 -22
  4. package/dist/AreaChart.js.map +1 -1
  5. package/dist/Avatar.js +2 -2
  6. package/dist/Avatar.js.map +1 -1
  7. package/dist/BarChart.d.ts.map +1 -1
  8. package/dist/BarChart.js +55 -13
  9. package/dist/BarChart.js.map +1 -1
  10. package/dist/Button.js +2 -2
  11. package/dist/Button.js.map +1 -1
  12. package/dist/ChartCard.d.ts +5 -0
  13. package/dist/ChartCard.d.ts.map +1 -0
  14. package/dist/ChartCard.js +18 -0
  15. package/dist/ChartCard.js.map +1 -0
  16. package/dist/Common.d.ts +128 -5
  17. package/dist/Common.d.ts.map +1 -1
  18. package/dist/Common.js.map +1 -1
  19. package/dist/DashboardGrid.d.ts +6 -2
  20. package/dist/DashboardGrid.d.ts.map +1 -1
  21. package/dist/DashboardGrid.js +43 -10
  22. package/dist/DashboardGrid.js.map +1 -1
  23. package/dist/DateTimeActionSheet.js +2 -2
  24. package/dist/DateTimeActionSheet.js.map +1 -1
  25. package/dist/DateTimeField.js +3 -3
  26. package/dist/DateTimeField.js.map +1 -1
  27. package/dist/DonutChart.d.ts.map +1 -1
  28. package/dist/DonutChart.js +20 -10
  29. package/dist/DonutChart.js.map +1 -1
  30. package/dist/DropdownMenuItem.d.ts +16 -0
  31. package/dist/DropdownMenuItem.d.ts.map +1 -0
  32. package/dist/DropdownMenuItem.js +11 -0
  33. package/dist/DropdownMenuItem.js.map +1 -0
  34. package/dist/DropdownPanel.d.ts.map +1 -1
  35. package/dist/DropdownPanel.js +1 -1
  36. package/dist/DropdownPanel.js.map +1 -1
  37. package/dist/FilePickerButton.d.ts.map +1 -1
  38. package/dist/FilePickerButton.js +70 -10
  39. package/dist/FilePickerButton.js.map +1 -1
  40. package/dist/GPTChat.d.ts.map +1 -1
  41. package/dist/GPTChat.js +103 -14
  42. package/dist/GPTChat.js.map +1 -1
  43. package/dist/HeightField.js +2 -2
  44. package/dist/HeightField.js.map +1 -1
  45. package/dist/IconButton.d.ts.map +1 -1
  46. package/dist/IconButton.js +9 -6
  47. package/dist/IconButton.js.map +1 -1
  48. package/dist/LineChart.d.ts +1 -1
  49. package/dist/LineChart.d.ts.map +1 -1
  50. package/dist/LineChart.js +62 -21
  51. package/dist/LineChart.js.map +1 -1
  52. package/dist/MediaQuery.d.ts +10 -0
  53. package/dist/MediaQuery.d.ts.map +1 -1
  54. package/dist/MediaQuery.js +13 -1
  55. package/dist/MediaQuery.js.map +1 -1
  56. package/dist/MultiselectField.js +2 -2
  57. package/dist/MultiselectField.js.map +1 -1
  58. package/dist/RadioField.js +2 -2
  59. package/dist/RadioField.js.map +1 -1
  60. package/dist/Scorecard.d.ts +5 -0
  61. package/dist/Scorecard.d.ts.map +1 -0
  62. package/dist/Scorecard.js +11 -0
  63. package/dist/Scorecard.js.map +1 -0
  64. package/dist/SparklineChart.d.ts +5 -0
  65. package/dist/SparklineChart.d.ts.map +1 -0
  66. package/dist/SparklineChart.js +35 -0
  67. package/dist/SparklineChart.js.map +1 -0
  68. package/dist/SplitPage.d.ts +1 -1
  69. package/dist/SplitPage.d.ts.map +1 -1
  70. package/dist/SplitPage.js +126 -21
  71. package/dist/SplitPage.js.map +1 -1
  72. package/dist/TextField.d.ts.map +1 -1
  73. package/dist/TextField.js +12 -4
  74. package/dist/TextField.js.map +1 -1
  75. package/dist/ToastNotifications.d.ts.map +1 -1
  76. package/dist/ToastNotifications.js +29 -6
  77. package/dist/ToastNotifications.js.map +1 -1
  78. package/dist/UnifiedAddressAutoComplete.js +2 -2
  79. package/dist/UnifiedAddressAutoComplete.js.map +1 -1
  80. package/dist/WebDropdownMenu.d.ts +2 -1
  81. package/dist/WebDropdownMenu.d.ts.map +1 -1
  82. package/dist/WebDropdownMenu.js +2 -6
  83. package/dist/WebDropdownMenu.js.map +1 -1
  84. package/dist/charts/ChartFacadeContainer.d.ts +10 -0
  85. package/dist/charts/ChartFacadeContainer.d.ts.map +1 -0
  86. package/dist/charts/ChartFacadeContainer.js +10 -0
  87. package/dist/charts/ChartFacadeContainer.js.map +1 -0
  88. package/dist/charts/ChartFrame.d.ts +4 -0
  89. package/dist/charts/ChartFrame.d.ts.map +1 -1
  90. package/dist/charts/ChartFrame.js +4 -2
  91. package/dist/charts/ChartFrame.js.map +1 -1
  92. package/dist/charts/layout.d.ts +9 -2
  93. package/dist/charts/layout.d.ts.map +1 -1
  94. package/dist/charts/layout.js +28 -6
  95. package/dist/charts/layout.js.map +1 -1
  96. package/dist/charts/scales.d.ts +3 -1
  97. package/dist/charts/scales.d.ts.map +1 -1
  98. package/dist/charts/scales.js +7 -7
  99. package/dist/charts/scales.js.map +1 -1
  100. package/dist/charts/series.d.ts +15 -0
  101. package/dist/charts/series.d.ts.map +1 -0
  102. package/dist/charts/series.js +19 -0
  103. package/dist/charts/series.js.map +1 -0
  104. package/dist/charts/types/chartTypes.d.ts +7 -0
  105. package/dist/charts/types/chartTypes.d.ts.map +1 -1
  106. package/dist/dashboardGridLayout.d.ts +6 -0
  107. package/dist/dashboardGridLayout.d.ts.map +1 -1
  108. package/dist/dashboardGridLayout.js +19 -3
  109. package/dist/dashboardGridLayout.js.map +1 -1
  110. package/dist/fieldElements/FieldTitle.js +2 -2
  111. package/dist/fieldElements/FieldTitle.js.map +1 -1
  112. package/dist/index.d.ts +4 -1
  113. package/dist/index.d.ts.map +1 -1
  114. package/dist/index.js +1 -1
  115. package/dist/index.js.map +1 -1
  116. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +9 -0
  117. package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
  118. package/dist/lazyBoundaries/heavyOptionalExports.js +6 -0
  119. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
  120. package/dist/resolveDocumentBodyPortalTarget.d.ts +7 -0
  121. package/dist/resolveDocumentBodyPortalTarget.d.ts.map +1 -0
  122. package/dist/resolveDocumentBodyPortalTarget.js +12 -0
  123. package/dist/resolveDocumentBodyPortalTarget.js.map +1 -0
  124. package/package.json +1 -1
  125. package/src/AIRequestExplorer.test.tsx +2 -2
  126. package/src/AreaChart.test.tsx +81 -0
  127. package/src/AreaChart.tsx +171 -62
  128. package/src/Avatar.tsx +2 -2
  129. package/src/BarChart.test.tsx +119 -0
  130. package/src/BarChart.tsx +94 -20
  131. package/src/Button.test.tsx +7 -7
  132. package/src/Button.tsx +2 -2
  133. package/src/ChartCard.test.tsx +79 -0
  134. package/src/ChartCard.tsx +80 -0
  135. package/src/Common.ts +119 -2
  136. package/src/DashboardGrid.test.tsx +98 -1
  137. package/src/DashboardGrid.tsx +71 -20
  138. package/src/DateTimeActionSheet.tsx +4 -4
  139. package/src/DateTimeField.test.tsx +5 -4
  140. package/src/DateTimeField.tsx +3 -3
  141. package/src/DonutChart.test.tsx +73 -0
  142. package/src/DonutChart.tsx +87 -14
  143. package/src/DropdownMenuItem.tsx +48 -0
  144. package/src/DropdownPanel.test.tsx +12 -0
  145. package/src/DropdownPanel.tsx +8 -1
  146. package/src/FilePickerButton.test.tsx +60 -6
  147. package/src/FilePickerButton.tsx +116 -28
  148. package/src/GPTChat.test.tsx +133 -6
  149. package/src/GPTChat.tsx +196 -38
  150. package/src/HeightField.tsx +2 -2
  151. package/src/IconButton.test.tsx +63 -0
  152. package/src/IconButton.tsx +10 -5
  153. package/src/LineChart.test.tsx +104 -0
  154. package/src/LineChart.tsx +154 -58
  155. package/src/MediaQuery.ts +14 -1
  156. package/src/MultiselectField.tsx +2 -2
  157. package/src/RadioField.tsx +2 -2
  158. package/src/Scorecard.test.tsx +65 -0
  159. package/src/Scorecard.tsx +45 -0
  160. package/src/SparklineChart.test.tsx +69 -0
  161. package/src/SparklineChart.tsx +85 -0
  162. package/src/SplitPage.test.tsx +449 -11
  163. package/src/SplitPage.tsx +255 -21
  164. package/src/TextField.test.tsx +16 -0
  165. package/src/TextField.tsx +13 -3
  166. package/src/ToastNotifications.tsx +33 -6
  167. package/src/ToastNotifications.webModal.test.tsx +285 -0
  168. package/src/UnifiedAddressAutoComplete.test.tsx +4 -4
  169. package/src/UnifiedAddressAutoComplete.tsx +2 -2
  170. package/src/WebDropdownMenu.tsx +3 -7
  171. package/src/__snapshots__/DropdownPanel.test.tsx.snap +3 -1
  172. package/src/bunSetup.ts +3 -1
  173. package/src/charts/ChartFacadeContainer.tsx +35 -0
  174. package/src/charts/ChartFrame.tsx +39 -1
  175. package/src/charts/layout.test.ts +22 -1
  176. package/src/charts/layout.ts +37 -4
  177. package/src/charts/scales.test.ts +33 -0
  178. package/src/charts/scales.ts +10 -6
  179. package/src/charts/series.ts +43 -0
  180. package/src/charts/types/chartTypes.ts +8 -0
  181. package/src/dashboardGridLayout.test.ts +59 -1
  182. package/src/dashboardGridLayout.ts +30 -3
  183. package/src/fieldElements/FieldTitle.tsx +2 -2
  184. package/src/index.tsx +6 -0
  185. package/src/lazyBoundaries/heavyOptionalExports.tsx +21 -0
  186. package/src/resolveDocumentBodyPortalTarget.ts +11 -0
package/src/AreaChart.tsx CHANGED
@@ -4,17 +4,21 @@ import {Circle, Path, Svg, Line as SvgLine} from "react-native-svg";
4
4
 
5
5
  import {Box} from "./Box";
6
6
  import type {AreaChartProps, LayoutChangeEvent} from "./Common";
7
+ import {ChartFacadeContainer} from "./charts/ChartFacadeContainer";
7
8
  import {ChartFrame} from "./charts/ChartFrame";
8
9
  import {
10
+ CHART_ROTATED_X_AXIS_HEIGHT,
9
11
  CHART_X_AXIS_HEIGHT,
10
12
  getChartAxisWidth,
11
13
  getChartPlot,
12
14
  getPlotHeight,
13
15
  getXTickStyle,
14
16
  getYTickStyle,
17
+ shouldRotateChartXTicks,
15
18
  } from "./charts/layout";
16
19
  import {getAreaPath, getLinePath} from "./charts/paths";
17
20
  import {createCartesianScales, getYTickValues} from "./charts/scales";
21
+ import {getAllSeriesPoints, getAxisPoints, resolveChartSeries} 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";
@@ -28,27 +32,41 @@ const MARK_HIT_SIZE = 24;
28
32
  const formatChartTooltip = ({
29
33
  formatValue,
30
34
  point,
35
+ seriesLabel,
31
36
  }: {
32
37
  formatValue: (value: number) => string;
33
38
  point: ChartPoint;
39
+ seriesLabel?: string;
34
40
  }): string => {
35
- return `${point.label}: ${formatValue(point.value)}`;
41
+ const prefix = seriesLabel ? `${seriesLabel} — ` : "";
42
+ return `${prefix}${point.label}: ${formatValue(point.value)}`;
36
43
  };
37
44
 
45
+ interface ActivePoint {
46
+ pointIndex: number;
47
+ seriesIndex: number;
48
+ }
49
+
38
50
  export const AreaChart: FC<AreaChartProps> = ({
39
51
  accessibilityLabel,
52
+ comparisonData = [],
40
53
  data,
41
54
  emptyText = "No data",
42
55
  formatValue = String,
43
56
  height = DEFAULT_HEIGHT,
44
57
  legendLabel,
45
58
  loading = false,
59
+ onPeriodPress,
60
+ periodLabel,
61
+ series,
46
62
  testID,
63
+ title,
64
+ xTickPolicy = "auto",
47
65
  }) => {
48
66
  const {theme} = useTheme();
49
67
  const paint = getChartPaint(theme);
50
68
  const [chartWidth, setChartWidth] = useState(DEFAULT_WIDTH);
51
- const [activePointIndex, setActivePointIndex] = useState<number | undefined>(undefined);
69
+ const [activePoint, setActivePoint] = useState<ActivePoint | undefined>(undefined);
52
70
 
53
71
  const handleLayout = useCallback((event: LayoutChangeEvent): void => {
54
72
  const nextWidth = event.nativeEvent.layout.width;
@@ -57,30 +75,59 @@ export const AreaChart: FC<AreaChartProps> = ({
57
75
  }
58
76
  }, []);
59
77
 
60
- const handleMarkPress = useCallback((pointIndex: number): void => {
61
- setActivePointIndex(pointIndex);
78
+ const handleMarkPress = useCallback((seriesIndex: number, pointIndex: number): void => {
79
+ setActivePoint({pointIndex, seriesIndex});
62
80
  }, []);
63
81
 
82
+ const resolvedSeries = resolveChartSeries({data, legendLabel, series});
83
+ const allPoints = getAllSeriesPoints({comparisonData, series: resolvedSeries});
84
+ const axisPoints = getAxisPoints({comparisonData, series: resolvedSeries});
85
+ const coloredSeries = resolvedSeries.map((entry, index) => ({
86
+ ...entry,
87
+ color: entry.color ?? paint.slices[index % paint.slices.length] ?? paint.series,
88
+ }));
64
89
  const axisWidth = getChartAxisWidth(chartWidth);
65
- const plotHeight = getPlotHeight({hasLegend: Boolean(legendLabel), height});
90
+ const legendItems =
91
+ series && series.length > 0
92
+ ? coloredSeries.map((entry) => ({color: entry.color, label: entry.label}))
93
+ : undefined;
94
+ const isXTickRotated = shouldRotateChartXTicks({
95
+ labelCount: axisPoints.length,
96
+ policy: xTickPolicy,
97
+ });
98
+ const xAxisHeight = isXTickRotated ? CHART_ROTATED_X_AXIS_HEIGHT : CHART_X_AXIS_HEIGHT;
99
+ const plotHeight = getPlotHeight({
100
+ hasLegend: Boolean(legendLabel) || Boolean(legendItems?.length),
101
+ height,
102
+ xAxisHeight,
103
+ });
66
104
  const plot = getChartPlot({chartWidth, height: plotHeight});
67
105
  const plotWidth = chartWidth - axisWidth;
68
- const scales = createCartesianScales({plot, points: data});
69
- const linePath = getLinePath({points: data, scales});
70
- const areaPath = getAreaPath({baselineY: scales.y(0), points: data, scales});
71
- const yTicks = getYTickValues(data);
72
- const activePoint = activePointIndex === undefined ? undefined : data[activePointIndex];
73
- const tooltipText = activePoint
74
- ? formatChartTooltip({formatValue, point: activePoint})
106
+ const scales = createCartesianScales({
107
+ plot,
108
+ points: allPoints,
109
+ xLabels: axisPoints.map((point) => point.label),
110
+ });
111
+ const comparisonPath = getLinePath({points: comparisonData, scales});
112
+ const yTicks = getYTickValues(allPoints);
113
+ const activeSeries = activePoint ? coloredSeries[activePoint.seriesIndex] : undefined;
114
+ const selectedPoint = activePoint ? activeSeries?.data[activePoint.pointIndex] : undefined;
115
+ const tooltipText = selectedPoint
116
+ ? formatChartTooltip({
117
+ formatValue,
118
+ point: selectedPoint,
119
+ seriesLabel: series && series.length > 0 ? activeSeries?.label : undefined,
120
+ })
75
121
  : undefined;
76
122
  const summaryLabel =
77
123
  accessibilityLabel ?? (legendLabel ? `${legendLabel} area chart` : "Area chart");
78
124
 
79
- return (
125
+ const chart = (
80
126
  <ChartFrame
81
127
  accessibilityLabel={summaryLabel}
82
128
  emptyText={emptyText}
83
- isEmpty={data.length === 0}
129
+ isEmpty={allPoints.length === 0}
130
+ legendItems={legendItems}
84
131
  legendLabel={legendLabel}
85
132
  loading={loading}
86
133
  testID={testID}
@@ -116,69 +163,120 @@ export const AreaChart: FC<AreaChartProps> = ({
116
163
  />
117
164
  );
118
165
  })}
119
- {areaPath ? (
120
- <Path d={areaPath} fill={paint.seriesFill} fillOpacity={0.25} stroke="none" />
121
- ) : null}
122
- {linePath ? (
123
- <Path d={linePath} fill="none" stroke={paint.series} strokeWidth={2} />
124
- ) : null}
125
- {data.map((point) => (
126
- <Circle
127
- cx={scales.xCenter(point.label)}
128
- cy={scales.y(point.value)}
129
- fill={paint.series}
130
- key={`dot-${point.label}`}
131
- r={4}
166
+ {comparisonPath ? (
167
+ <Path
168
+ d={comparisonPath}
169
+ fill="none"
170
+ opacity={0.6}
171
+ stroke={paint.series}
172
+ strokeDasharray="4 4"
173
+ strokeWidth={2}
174
+ testID={resolveTestID(testID, "comparison")}
132
175
  />
133
- ))}
176
+ ) : null}
177
+ {coloredSeries.flatMap((entry, seriesIndex) => {
178
+ const areaPath = getAreaPath({
179
+ baselineY: scales.y(0),
180
+ points: entry.data,
181
+ scales,
182
+ });
183
+ const linePath = getLinePath({points: entry.data, scales});
184
+ return [
185
+ areaPath ? (
186
+ <Path
187
+ d={areaPath}
188
+ fill={entry.color}
189
+ fillOpacity={0.2}
190
+ key={`area-${entry.id}`}
191
+ stroke="none"
192
+ testID={resolveTestID(testID, `series.${seriesIndex}.area`)}
193
+ />
194
+ ) : null,
195
+ linePath ? (
196
+ <Path
197
+ d={linePath}
198
+ fill="none"
199
+ key={`line-${entry.id}`}
200
+ stroke={entry.color}
201
+ strokeDasharray={entry.stroke === "dotted" ? "4 4" : undefined}
202
+ strokeWidth={2}
203
+ testID={resolveTestID(testID, `series.${seriesIndex}.path`)}
204
+ />
205
+ ) : null,
206
+ ];
207
+ })}
208
+ {coloredSeries.flatMap((entry, seriesIndex) =>
209
+ entry.data.map((point, pointIndex) => (
210
+ <Circle
211
+ cx={scales.xCenter(point.label)}
212
+ cy={scales.y(point.value)}
213
+ fill={entry.color}
214
+ key={`dot-${entry.id}-${point.label}`}
215
+ r={4}
216
+ testID={resolveTestID(testID, `series.${seriesIndex}.marker.${pointIndex}`)}
217
+ />
218
+ ))
219
+ )}
134
220
  </Svg>
135
- {data.map((point, index) => {
136
- const onPress = (): void => {
137
- handleMarkPress(index);
138
- };
139
- return (
140
- <Box
141
- accessibilityHint={`Show value for ${point.label}`}
142
- accessibilityLabel={`${point.label}: ${formatValue(point.value)}`}
143
- dangerouslySetInlineStyle={{
144
- __style: {
145
- height: MARK_HIT_SIZE,
146
- left: scales.xCenter(point.label) - MARK_HIT_SIZE / 2,
147
- position: "absolute",
148
- top: scales.y(point.value) - MARK_HIT_SIZE / 2,
149
- width: MARK_HIT_SIZE,
150
- },
151
- }}
152
- key={`mark-${point.label}`}
153
- onClick={onPress}
154
- onHoverStart={onPress}
155
- testID={resolveTestID(testID, `point.${index}`)}
156
- />
157
- );
158
- })}
221
+ {coloredSeries.flatMap((entry, seriesIndex) =>
222
+ entry.data.map((point, pointIndex) => {
223
+ const onPress = (): void => {
224
+ handleMarkPress(seriesIndex, pointIndex);
225
+ };
226
+ const markTestID =
227
+ series && series.length > 0
228
+ ? `series.${seriesIndex}.point.${pointIndex}`
229
+ : `point.${pointIndex}`;
230
+ return (
231
+ <Box
232
+ accessibilityHint={`Show value for ${point.label}`}
233
+ accessibilityLabel={
234
+ series && series.length > 0
235
+ ? `${entry.label} — ${point.label}: ${formatValue(point.value)}`
236
+ : `${point.label}: ${formatValue(point.value)}`
237
+ }
238
+ dangerouslySetInlineStyle={{
239
+ __style: {
240
+ height: MARK_HIT_SIZE,
241
+ left: scales.xCenter(point.label) - MARK_HIT_SIZE / 2,
242
+ position: "absolute",
243
+ top: scales.y(point.value) - MARK_HIT_SIZE / 2,
244
+ width: MARK_HIT_SIZE,
245
+ },
246
+ }}
247
+ key={`mark-${entry.id}-${point.label}`}
248
+ onClick={onPress}
249
+ onHoverStart={onPress}
250
+ testID={resolveTestID(testID, markTestID)}
251
+ />
252
+ );
253
+ })
254
+ )}
159
255
  </Box>
160
256
  </Box>
161
257
  <Box direction="row">
162
258
  <Box width={axisWidth} />
163
- <Box
164
- flex="grow"
165
- height={CHART_X_AXIS_HEIGHT}
166
- minWidth={0}
167
- overflow="hidden"
168
- position="relative"
169
- >
170
- {data.map((point, index) => (
259
+ <Box flex="grow" height={xAxisHeight} minWidth={0} overflow="hidden" position="relative">
260
+ {axisPoints.map((point, index) => (
171
261
  <Box
172
262
  dangerouslySetInlineStyle={{
173
263
  __style: getXTickStyle({
174
264
  bandwidth: scales.bandwidth,
265
+ isRotated: isXTickRotated,
175
266
  xCenter: scales.xCenter(point.label),
176
267
  }),
177
268
  }}
178
269
  key={`xtick-${point.label}`}
179
270
  testID={resolveTestID(testID, `xtick.${index}`)}
180
271
  >
181
- <Text align="center" color="secondaryDark" size="sm" skipLinking truncate>
272
+ <Text
273
+ align="center"
274
+ color="secondaryDark"
275
+ numberOfLines={1}
276
+ size="sm"
277
+ skipLinking
278
+ truncate={!isXTickRotated}
279
+ >
182
280
  {point.label}
183
281
  </Text>
184
282
  </Box>
@@ -188,7 +286,18 @@ export const AreaChart: FC<AreaChartProps> = ({
188
286
  </Box>
189
287
  </ChartFrame>
190
288
  );
289
+
290
+ return (
291
+ <ChartFacadeContainer
292
+ onPeriodPress={onPeriodPress}
293
+ periodLabel={periodLabel}
294
+ testID={testID}
295
+ title={title}
296
+ >
297
+ {chart}
298
+ </ChartFacadeContainer>
299
+ );
191
300
  };
192
301
 
193
302
  export type {AreaChartProps} from "./Common";
194
- export type {ChartPoint} from "./charts/types/chartTypes";
303
+ export type {ChartPoint, ChartSeries} from "./charts/types/chartTypes";
package/src/Avatar.tsx CHANGED
@@ -18,7 +18,7 @@ import {MobileIcon} from "./icons/MobileIcon";
18
18
  import {OfflineIcon} from "./icons/OfflineIcon";
19
19
  import {OnlineIcon} from "./icons/OnlineIcon";
20
20
  import {OutOfOfficeIcon} from "./icons/OutOfficeIcon";
21
- import {isMobileDevice} from "./MediaQuery";
21
+ import {isNarrowViewport} from "./MediaQuery";
22
22
  import {useTheme} from "./Theme";
23
23
  import {Tooltip} from "./Tooltip";
24
24
 
@@ -296,7 +296,7 @@ export const Avatar: FC<AvatarProps> = ({
296
296
  width: widthPlusPadding,
297
297
  }}
298
298
  >
299
- <Tooltip idealPosition="top" text={isMobileDevice() ? undefined : status}>
299
+ <Tooltip idealPosition="top" text={isNarrowViewport() ? undefined : status}>
300
300
  {avatar}
301
301
  </Tooltip>
302
302
  {renderStatusIcon()}
@@ -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({hasLegend: Boolean(legendLabel), height});
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({plot, points: data});
69
- const yTicks = getYTickValues(data);
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 activePoint = activePointIndex === undefined ? undefined : data[activePointIndex];
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 ?? (legendLabel ? `${legendLabel} bar chart` : "Bar chart");
112
+ accessibilityLabel ??
113
+ (effectiveLegendLabel ? `${effectiveLegendLabel} bar chart` : "Bar chart");
78
114
 
79
- return (
115
+ const chart = (
80
116
  <ChartFrame
81
117
  accessibilityLabel={summaryLabel}
82
118
  emptyText={emptyText}
83
- isEmpty={data.length === 0}
84
- legendLabel={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
- {data.map((point) => {
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 ?? paint.series}
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
- {data.map((point, index) => {
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
- flex="grow"
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 align="center" color="secondaryDark" size="sm" skipLinking truncate>
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";