@altertable/data-app-examples 0.76.0 → 0.78.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/package.json +1 -1
- package/templates/starter-data-app/index.tsx +686 -136
- package/templates/starter-finding-data-app/index.tsx +530 -188
- package/templates/starter-local-data-app/AGENTS.md +9 -9
- package/templates/starter-local-data-app/README.md +14 -5
- package/templates/starter-local-data-app/app.ts +256 -21
- package/templates/starter-local-data-app/package.json +5 -5
- package/templates/starter-local-data-app/src/App.tsx +276 -5
- package/templates/starter-local-data-app/src/data-context.ts +28 -14
- package/templates/starter-local-data-app/src/filters.ts +35 -0
- package/templates/starter-local-data-app/src/main.tsx +3 -3
- package/templates/starter-local-data-app/src/operations.ts +129 -4
- package/templates/starter-local-data-app/src/server.ts +1 -2
- package/templates/starter-local-finding-data-app/AGENTS.md +9 -9
- package/templates/starter-local-finding-data-app/README.md +3 -4
- package/templates/starter-local-finding-data-app/app.ts +63 -34
- package/templates/starter-local-finding-data-app/package.json +5 -5
- package/templates/starter-local-finding-data-app/src/App.tsx +308 -126
- package/templates/starter-local-finding-data-app/src/data-context.ts +19 -4
- package/templates/starter-local-finding-data-app/src/filters.ts +66 -0
- package/templates/starter-local-finding-data-app/src/main.tsx +3 -3
- package/templates/starter-local-finding-data-app/src/operations.ts +101 -37
- package/templates/starter-local-finding-data-app/src/server.ts +4 -2
- package/templates/starter-local-metric-data-app/AGENTS.md +9 -9
- package/templates/starter-local-metric-data-app/README.md +3 -4
- package/templates/starter-local-metric-data-app/app.ts +5 -2
- package/templates/starter-local-metric-data-app/package.json +5 -5
- package/templates/starter-local-metric-data-app/src/App.tsx +69 -71
- package/templates/starter-local-metric-data-app/src/data-context.ts +9 -5
- package/templates/starter-local-metric-data-app/src/filters.ts +18 -0
- package/templates/starter-local-metric-data-app/src/main.tsx +3 -3
- package/templates/starter-local-metric-data-app/src/operations.ts +34 -41
- package/templates/starter-local-metric-data-app/src/server.ts +4 -2
- package/templates/starter-metric-data-app/index.tsx +125 -122
|
@@ -1,111 +1,283 @@
|
|
|
1
1
|
import { defineDataApp } from '@altertable/data-app';
|
|
2
2
|
import {
|
|
3
3
|
createDataContext,
|
|
4
|
-
injectDataAppStyles,
|
|
5
|
-
mountDataApp,
|
|
6
|
-
} from '@altertable/data-app-react';
|
|
7
|
-
import {
|
|
8
|
-
choiceVariable,
|
|
9
4
|
createDataHooks,
|
|
5
|
+
mountDataApp,
|
|
10
6
|
DataApp,
|
|
11
7
|
DataSection,
|
|
12
|
-
|
|
8
|
+
Button,
|
|
9
|
+
Grid,
|
|
10
|
+
GridItem,
|
|
11
|
+
Notice,
|
|
13
12
|
Stack,
|
|
14
13
|
TableWidget,
|
|
15
14
|
VisualizationWidget,
|
|
15
|
+
Ranking,
|
|
16
|
+
Comparison,
|
|
16
17
|
} from '@altertable/data-app-react';
|
|
17
|
-
import { BarChart, ComposedChart } from '@altertable/data-app-react/ui';
|
|
18
|
-
import { createDataClient } from '@altertable/data-app/client';
|
|
19
18
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
Tabs,
|
|
20
|
+
TabList,
|
|
21
|
+
Tab,
|
|
22
|
+
TabPanels,
|
|
23
|
+
TabPanel,
|
|
24
|
+
useViewTab,
|
|
25
|
+
ComposedChart,
|
|
26
|
+
useAppFilters,
|
|
27
|
+
} from '@altertable/data-app-react/ui';
|
|
28
|
+
import {
|
|
29
|
+
choiceFilter,
|
|
30
|
+
dateTimeRangeFilter,
|
|
31
|
+
displayChoice,
|
|
22
32
|
parseCount,
|
|
33
|
+
queryDateTimeRangeParams,
|
|
23
34
|
} from '@altertable/data-app/contract';
|
|
24
|
-
|
|
35
|
+
import {
|
|
36
|
+
formatDateRange,
|
|
37
|
+
formatCount,
|
|
38
|
+
formatNumber,
|
|
39
|
+
formatPercent,
|
|
40
|
+
} from '@altertable/data-app/format';
|
|
41
|
+
export const dataApp = defineDataApp({
|
|
42
|
+
// Replace the demo title, description, and scope labels with the app's identity.
|
|
25
43
|
title: 'Sample finding',
|
|
26
44
|
description:
|
|
27
|
-
'
|
|
45
|
+
'Explore sample volume over time and across groups and segments.',
|
|
28
46
|
scope: { organization: 'demo', environment: 'sample' },
|
|
29
47
|
appearance: { theme: 'system' },
|
|
48
|
+
// starter_demo.daily_samples contains seeded fictional observations.
|
|
49
|
+
// Replace these queries with verified sources before publishing.
|
|
30
50
|
queries: {
|
|
31
|
-
|
|
51
|
+
sampleTotals: {
|
|
52
|
+
projections: { sample_count: { type: 'number' } },
|
|
53
|
+
statement: `
|
|
54
|
+
SELECT SUM(sample_count) AS sample_count
|
|
55
|
+
FROM starter_demo.daily_samples
|
|
56
|
+
WHERE sample_date >= CAST($period_from AS TIMESTAMP) AND sample_date < CAST($period_to AS TIMESTAMP)
|
|
57
|
+
AND ($groupName = 'all' OR group_name = $groupName)
|
|
58
|
+
HAVING COUNT(*) > 0`,
|
|
59
|
+
params: {
|
|
60
|
+
groupName: { type: 'string', defaultValue: 'Alpha' },
|
|
61
|
+
period_from: { type: 'string' },
|
|
62
|
+
period_to: { type: 'string' },
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
samplesOverTime: {
|
|
66
|
+
projections: {
|
|
67
|
+
period_start: { type: 'string' },
|
|
68
|
+
sample_count: { type: 'number' },
|
|
69
|
+
},
|
|
70
|
+
statement: `
|
|
71
|
+
SELECT strftime(date_trunc($grain, sample_date), '%Y-%m-%d') AS period_start,
|
|
72
|
+
SUM(sample_count) AS sample_count
|
|
73
|
+
FROM starter_demo.daily_samples
|
|
74
|
+
WHERE sample_date >= CAST($period_from AS TIMESTAMP) AND sample_date < CAST($period_to AS TIMESTAMP)
|
|
75
|
+
AND ($groupName = 'all' OR group_name = $groupName)
|
|
76
|
+
GROUP BY ALL ORDER BY period_start LIMIT 200`,
|
|
77
|
+
params: {
|
|
78
|
+
groupName: { type: 'string', defaultValue: 'Alpha' },
|
|
79
|
+
period_from: { type: 'string' },
|
|
80
|
+
period_to: { type: 'string' },
|
|
81
|
+
grain: { type: 'string', defaultValue: 'day' },
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
samplesByMember: {
|
|
85
|
+
projections: {
|
|
86
|
+
member: { type: 'string' },
|
|
87
|
+
sample_count: { type: 'number' },
|
|
88
|
+
},
|
|
89
|
+
statement: `
|
|
90
|
+
SELECT CASE WHEN $breakdown = 'group' THEN group_name ELSE segment_name END AS member,
|
|
91
|
+
SUM(sample_count) AS sample_count
|
|
92
|
+
FROM starter_demo.daily_samples
|
|
93
|
+
WHERE sample_date >= CAST($period_from AS TIMESTAMP) AND sample_date < CAST($period_to AS TIMESTAMP)
|
|
94
|
+
AND ($groupName = 'all' OR group_name = $groupName)
|
|
95
|
+
GROUP BY ALL ORDER BY sample_count DESC LIMIT 50`,
|
|
96
|
+
params: {
|
|
97
|
+
groupName: { type: 'string', defaultValue: 'Alpha' },
|
|
98
|
+
period_from: { type: 'string' },
|
|
99
|
+
period_to: { type: 'string' },
|
|
100
|
+
breakdown: { type: 'string', defaultValue: 'segment' },
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
sampleRows: {
|
|
32
104
|
projections: {
|
|
33
105
|
period_start: { type: 'string' },
|
|
34
106
|
member: { type: 'string' },
|
|
35
|
-
selected: { type: 'boolean' },
|
|
36
107
|
sample_count: { type: 'number' },
|
|
37
108
|
},
|
|
38
109
|
statement: `
|
|
39
110
|
SELECT strftime(date_trunc($grain, sample_date), '%Y-%m-%d') AS period_start,
|
|
40
111
|
CASE WHEN $breakdown = 'group' THEN group_name ELSE segment_name END AS member,
|
|
41
|
-
sample_date >= CAST($selected_start AS TIMESTAMP) AS selected,
|
|
42
112
|
SUM(sample_count) AS sample_count
|
|
43
113
|
FROM starter_demo.daily_samples
|
|
44
|
-
WHERE sample_date >= CAST($
|
|
45
|
-
|
|
114
|
+
WHERE sample_date >= CAST($period_from AS TIMESTAMP) AND sample_date < CAST($period_to AS TIMESTAMP)
|
|
115
|
+
AND ($groupName = 'all' OR group_name = $groupName)
|
|
116
|
+
GROUP BY ALL ORDER BY period_start, member LIMIT 500`,
|
|
46
117
|
params: {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
type: 'string',
|
|
51
|
-
defaultValue: '2026-03-09T00:00:00Z',
|
|
52
|
-
},
|
|
118
|
+
groupName: { type: 'string', defaultValue: 'Alpha' },
|
|
119
|
+
period_from: { type: 'string' },
|
|
120
|
+
period_to: { type: 'string' },
|
|
53
121
|
grain: { type: 'string', defaultValue: 'day' },
|
|
54
122
|
breakdown: { type: 'string', defaultValue: 'segment' },
|
|
55
|
-
limit: { type: 'number', defaultValue: 500 },
|
|
56
123
|
},
|
|
57
124
|
},
|
|
58
125
|
},
|
|
59
126
|
});
|
|
60
|
-
|
|
61
|
-
minDate: '2026-01-05',
|
|
62
|
-
maxDate: '2026-03-29',
|
|
63
|
-
maxRangeDays: 28,
|
|
64
|
-
timeZone: 'UTC',
|
|
65
|
-
});
|
|
127
|
+
// Replace this fictional finding period with the period supported by its evidence.
|
|
66
128
|
const findingPeriod = {
|
|
67
129
|
from: new Date('2026-03-09T00:00:00Z'),
|
|
68
130
|
to: new Date('2026-03-16T00:00:00Z'),
|
|
69
131
|
};
|
|
70
|
-
|
|
132
|
+
function periodLabel(range: { from: Date; to: Date }) {
|
|
133
|
+
return formatDateRange({
|
|
134
|
+
start: range.from.toISOString().slice(0, 10),
|
|
135
|
+
end: new Date(range.to.getTime() - 1).toISOString().slice(0, 10),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
const findingPeriodLabel = periodLabel(findingPeriod);
|
|
139
|
+
const periodFilter = dateTimeRangeFilter({
|
|
71
140
|
key: 'period',
|
|
72
|
-
contract: calendar,
|
|
73
|
-
allowComparison: true,
|
|
74
141
|
defaultValue: findingPeriod,
|
|
142
|
+
comparison: 'on',
|
|
143
|
+
// These bounds match the seeded demo history. Use the real source coverage.
|
|
144
|
+
minDate: '2026-01-05',
|
|
145
|
+
maxDate: '2026-03-29',
|
|
146
|
+
maxRangeDays: 28,
|
|
75
147
|
presets: [{ label: 'Finding period', range: findingPeriod }],
|
|
76
148
|
});
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
149
|
+
const groupName = choiceFilter({
|
|
150
|
+
key: 'group',
|
|
151
|
+
label: 'Group',
|
|
152
|
+
defaultValue: 'Alpha',
|
|
153
|
+
options: [
|
|
154
|
+
{ id: 'all', label: 'All groups' },
|
|
155
|
+
{ id: 'Alpha', label: 'Alpha' },
|
|
156
|
+
{ id: 'Beta', label: 'Beta' },
|
|
157
|
+
],
|
|
158
|
+
});
|
|
159
|
+
const grain = displayChoice({
|
|
160
|
+
key: 'grain',
|
|
161
|
+
label: 'Grain',
|
|
162
|
+
defaultValue: 'day',
|
|
163
|
+
options: [
|
|
164
|
+
{ id: 'day', label: 'Day' },
|
|
165
|
+
{ id: 'week', label: 'Week' },
|
|
166
|
+
],
|
|
167
|
+
presentation: { control: 'widget' },
|
|
168
|
+
});
|
|
169
|
+
const breakdown = displayChoice({
|
|
170
|
+
key: 'breakdown',
|
|
171
|
+
label: 'Breakdown',
|
|
172
|
+
defaultValue: 'segment',
|
|
173
|
+
options: [
|
|
174
|
+
{ id: 'segment', label: 'Segment' },
|
|
175
|
+
{ id: 'group', label: 'Group' },
|
|
176
|
+
],
|
|
177
|
+
presentation: { control: 'widget' },
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const operationFilters = {
|
|
181
|
+
sampleTotals: { period: periodFilter, groupName },
|
|
182
|
+
samplesOverTime: { period: periodFilter, groupName, grain },
|
|
183
|
+
samplesByMember: { period: periodFilter, groupName, breakdown },
|
|
184
|
+
sampleRows: { period: periodFilter, groupName, grain, breakdown },
|
|
185
|
+
};
|
|
186
|
+
const policy = { maxQueryRows: 500, maxDurationMs: 15000 };
|
|
187
|
+
export const operations = dataApp.defineOperations({
|
|
188
|
+
sampleTotals: dataApp.defineOperation({
|
|
189
|
+
filters: operationFilters.sampleTotals,
|
|
190
|
+
policy,
|
|
191
|
+
async run({ query }, { period, groupName }) {
|
|
192
|
+
const bounds = queryDateTimeRangeParams(periodFilter, period, 'period');
|
|
193
|
+
const [current, previous] = await Promise.all([
|
|
194
|
+
query('sampleTotals', { ...bounds.current, groupName }),
|
|
195
|
+
bounds.comparison
|
|
196
|
+
? query('sampleTotals', { ...bounds.comparison, groupName })
|
|
197
|
+
: null,
|
|
198
|
+
]);
|
|
199
|
+
const row = current.rows[0];
|
|
200
|
+
if (!row) return [];
|
|
201
|
+
const baseline = previous?.rows[0];
|
|
202
|
+
return [
|
|
203
|
+
{
|
|
204
|
+
currentCount: parseCount(row.sample_count),
|
|
205
|
+
previousCount: baseline ? parseCount(baseline.sample_count) : null,
|
|
206
|
+
},
|
|
207
|
+
];
|
|
208
|
+
},
|
|
209
|
+
}),
|
|
210
|
+
samplesOverTime: dataApp.defineOperation({
|
|
211
|
+
filters: operationFilters.samplesOverTime,
|
|
212
|
+
policy,
|
|
213
|
+
async run({ query }, { period, groupName, grain }) {
|
|
214
|
+
const bounds = queryDateTimeRangeParams(periodFilter, period, 'period');
|
|
215
|
+
const result = await query('samplesOverTime', {
|
|
216
|
+
...bounds.combined,
|
|
217
|
+
groupName,
|
|
82
218
|
grain,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
throw new Error('Expected a segment or group breakdown.');
|
|
89
|
-
return { period: period.parseInput(selection), grain, breakdown };
|
|
219
|
+
});
|
|
220
|
+
return result.rows.map(row => ({
|
|
221
|
+
periodStart: row.period_start,
|
|
222
|
+
sampleCount: parseCount(row.sample_count),
|
|
223
|
+
}));
|
|
90
224
|
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
225
|
+
}),
|
|
226
|
+
samplesByMember: dataApp.defineOperation({
|
|
227
|
+
filters: operationFilters.samplesByMember,
|
|
228
|
+
policy,
|
|
229
|
+
async run({ query }, { period, groupName, breakdown }) {
|
|
230
|
+
const bounds = queryDateTimeRangeParams(periodFilter, period, 'period');
|
|
231
|
+
const [current, previous] = await Promise.all([
|
|
232
|
+
query('samplesByMember', { ...bounds.current, groupName, breakdown }),
|
|
233
|
+
bounds.comparison
|
|
234
|
+
? query('samplesByMember', {
|
|
235
|
+
...bounds.comparison,
|
|
236
|
+
groupName,
|
|
237
|
+
breakdown,
|
|
238
|
+
})
|
|
239
|
+
: null,
|
|
240
|
+
]);
|
|
241
|
+
const currentCounts = new Map(
|
|
242
|
+
current.rows.map(row => [row.member, parseCount(row.sample_count)])
|
|
243
|
+
);
|
|
244
|
+
const previousCounts = new Map(
|
|
245
|
+
previous?.rows.map(row => [row.member, parseCount(row.sample_count)])
|
|
246
|
+
);
|
|
247
|
+
const members = new Set([
|
|
248
|
+
...currentCounts.keys(),
|
|
249
|
+
...previousCounts.keys(),
|
|
250
|
+
]);
|
|
251
|
+
return [...members]
|
|
252
|
+
.map(member => {
|
|
253
|
+
const currentCount = currentCounts.get(member) ?? null;
|
|
254
|
+
const previousCount = previousCounts.get(member) ?? null;
|
|
255
|
+
const change =
|
|
256
|
+
currentCount !== null && previousCount !== null
|
|
257
|
+
? currentCount - previousCount
|
|
258
|
+
: null;
|
|
259
|
+
return {
|
|
260
|
+
member,
|
|
261
|
+
currentCount,
|
|
262
|
+
previousCount,
|
|
263
|
+
change,
|
|
264
|
+
changeRate:
|
|
265
|
+
change !== null && previousCount !== null && previousCount > 0
|
|
266
|
+
? change / previousCount
|
|
267
|
+
: null,
|
|
268
|
+
};
|
|
269
|
+
})
|
|
270
|
+
.sort((a, b) => Math.abs(b.change ?? 0) - Math.abs(a.change ?? 0));
|
|
271
|
+
},
|
|
272
|
+
}),
|
|
273
|
+
sampleRows: dataApp.defineOperation({
|
|
274
|
+
filters: operationFilters.sampleRows,
|
|
275
|
+
policy,
|
|
276
|
+
async run({ query }, { period, groupName, grain, breakdown }) {
|
|
277
|
+
const bounds = queryDateTimeRangeParams(periodFilter, period, 'period');
|
|
278
|
+
const result = await query('sampleRows', {
|
|
279
|
+
...bounds.combined,
|
|
280
|
+
groupName,
|
|
109
281
|
grain,
|
|
110
282
|
breakdown,
|
|
111
283
|
});
|
|
@@ -113,111 +285,141 @@ const operations = {
|
|
|
113
285
|
periodStart: row.period_start,
|
|
114
286
|
member: row.member,
|
|
115
287
|
sampleCount: parseCount(row.sample_count),
|
|
116
|
-
selected: row.selected,
|
|
117
288
|
}));
|
|
118
289
|
},
|
|
119
290
|
}),
|
|
291
|
+
});
|
|
292
|
+
const queryNames = {
|
|
293
|
+
...operations.sampleTotals.queryNames,
|
|
294
|
+
...operations.samplesOverTime.queryNames,
|
|
295
|
+
...operations.samplesByMember.queryNames,
|
|
296
|
+
...operations.sampleRows.queryNames,
|
|
120
297
|
};
|
|
121
|
-
const queryNames = operations.samples.queryNames;
|
|
122
298
|
const sampleDataContext = createDataContext(queryNames)({
|
|
123
299
|
description:
|
|
124
|
-
'Fictional daily
|
|
300
|
+
'Fictional daily sample counts by group and segment. Comparisons use equal-length periods in UTC.',
|
|
125
301
|
glossary: {
|
|
302
|
+
sampleChange: {
|
|
303
|
+
term: 'Sample change',
|
|
304
|
+
definition:
|
|
305
|
+
'Selected-period samples minus the previous equal-length period in the same scope. Missing observations remain unavailable; they are not measured zeroes.',
|
|
306
|
+
queryNames: ['samplesByMember'],
|
|
307
|
+
},
|
|
126
308
|
sampleCount: {
|
|
127
309
|
term: 'Sample count',
|
|
128
|
-
definition:
|
|
129
|
-
|
|
310
|
+
definition:
|
|
311
|
+
'Number of samples recorded for each day, group, and segment.',
|
|
312
|
+
queryNames: Object.values(queryNames),
|
|
130
313
|
},
|
|
131
314
|
},
|
|
132
315
|
});
|
|
133
|
-
const {
|
|
134
|
-
const
|
|
316
|
+
const { defineView } = createDataHooks(operations.createDataClient());
|
|
317
|
+
const count = { kind: 'count' } as const;
|
|
318
|
+
const emptyFallback = {
|
|
319
|
+
title: 'No samples in this period',
|
|
320
|
+
description: 'No observations are available for this period.',
|
|
321
|
+
};
|
|
322
|
+
const totalsView = defineView({
|
|
135
323
|
dataContext: sampleDataContext,
|
|
136
|
-
operation: '
|
|
137
|
-
time: period,
|
|
138
|
-
variables: {
|
|
139
|
-
grain: choiceVariable({
|
|
140
|
-
key: 'grain',
|
|
141
|
-
label: 'Grain',
|
|
142
|
-
defaultValue: 'day',
|
|
143
|
-
options: [
|
|
144
|
-
{ id: 'day', label: 'Day' },
|
|
145
|
-
{ id: 'week', label: 'Week' },
|
|
146
|
-
],
|
|
147
|
-
presentation: { group: 'display', control: 'widget' },
|
|
148
|
-
}),
|
|
149
|
-
breakdown: choiceVariable({
|
|
150
|
-
key: 'breakdown',
|
|
151
|
-
label: 'Breakdown',
|
|
152
|
-
defaultValue: 'segment',
|
|
153
|
-
options: [
|
|
154
|
-
{ id: 'segment', label: 'Segment' },
|
|
155
|
-
{ id: 'group', label: 'Group' },
|
|
156
|
-
],
|
|
157
|
-
presentation: { group: 'display', control: 'widget' },
|
|
158
|
-
}),
|
|
159
|
-
},
|
|
324
|
+
operation: 'sampleTotals',
|
|
160
325
|
isEmpty: rows => rows.length === 0,
|
|
161
|
-
emptyFallback
|
|
162
|
-
title: 'No samples in this period',
|
|
163
|
-
description: 'No observations are available for this period.',
|
|
164
|
-
},
|
|
326
|
+
emptyFallback,
|
|
165
327
|
});
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
{
|
|
182
|
-
id: 'total-samples',
|
|
183
|
-
label: 'Samples',
|
|
184
|
-
glossaryId: 'sampleCount',
|
|
185
|
-
format: count,
|
|
328
|
+
const totals = totalsView.dataset({
|
|
329
|
+
name: 'Period totals',
|
|
330
|
+
select: rows => rows,
|
|
331
|
+
rowKey: () => 'total',
|
|
332
|
+
columns: {
|
|
333
|
+
currentCount: {
|
|
334
|
+
label: 'Selected period',
|
|
335
|
+
value: row => row.currentCount,
|
|
336
|
+
format: count,
|
|
337
|
+
},
|
|
338
|
+
previousCount: {
|
|
339
|
+
label: 'Previous period',
|
|
340
|
+
value: row => row.previousCount,
|
|
341
|
+
format: count,
|
|
342
|
+
},
|
|
186
343
|
},
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
344
|
+
evidence: { id: 'period-totals', glossaryIds: ['sampleCount'] },
|
|
345
|
+
});
|
|
346
|
+
const trendView = defineView({
|
|
347
|
+
dataContext: sampleDataContext,
|
|
348
|
+
operation: 'samplesOverTime',
|
|
349
|
+
isEmpty: rows => rows.length === 0,
|
|
350
|
+
emptyFallback,
|
|
351
|
+
});
|
|
352
|
+
const trend = trendView.dataset({
|
|
195
353
|
name: 'Samples over time',
|
|
196
|
-
select: rows =>
|
|
197
|
-
rowKey: row => row.
|
|
354
|
+
select: rows => rows,
|
|
355
|
+
rowKey: row => row.periodStart,
|
|
198
356
|
columns: {
|
|
199
|
-
|
|
357
|
+
periodStart: { label: 'Period start', value: row => row.periodStart },
|
|
200
358
|
sampleCount: { value: row => row.sampleCount, format: count },
|
|
201
359
|
},
|
|
202
360
|
evidence: { id: 'samples-over-time', glossaryIds: ['sampleCount'] },
|
|
203
361
|
});
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
362
|
+
const memberView = defineView({
|
|
363
|
+
dataContext: sampleDataContext,
|
|
364
|
+
operation: 'samplesByMember',
|
|
365
|
+
isEmpty: rows => rows.length === 0,
|
|
366
|
+
emptyFallback,
|
|
367
|
+
});
|
|
368
|
+
const byMember = memberView.dataset({
|
|
369
|
+
name: 'Member comparison',
|
|
370
|
+
select: rows => rows,
|
|
371
|
+
rowKey: row => row.member,
|
|
212
372
|
columns: {
|
|
213
|
-
|
|
214
|
-
|
|
373
|
+
member: { label: 'Member', value: row => row.member },
|
|
374
|
+
currentCount: {
|
|
375
|
+
label: 'Selected period',
|
|
376
|
+
value: row => row.currentCount,
|
|
377
|
+
format: count,
|
|
378
|
+
},
|
|
379
|
+
previousCount: {
|
|
380
|
+
label: 'Previous period',
|
|
381
|
+
value: row => row.previousCount,
|
|
382
|
+
format: count,
|
|
383
|
+
},
|
|
384
|
+
change: {
|
|
385
|
+
label: 'Change',
|
|
386
|
+
value: row => row.change,
|
|
387
|
+
format: row => formatNumber(row.change, { signDisplay: 'exceptZero' }),
|
|
388
|
+
},
|
|
389
|
+
changeRate: {
|
|
390
|
+
label: 'Change %',
|
|
391
|
+
value: row => row.changeRate,
|
|
392
|
+
format: row => formatPercent(row.changeRate),
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
evidence: {
|
|
396
|
+
id: 'samples-by-member',
|
|
397
|
+
glossaryIds: ['sampleCount', 'sampleChange'],
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
const selectedMembers = memberView.dataset({
|
|
401
|
+
name: 'Selected-period samples',
|
|
402
|
+
select: rows => rows,
|
|
403
|
+
rowKey: row => row.member,
|
|
404
|
+
columns: {
|
|
405
|
+
member: { label: 'Member', value: row => row.member },
|
|
406
|
+
currentCount: {
|
|
407
|
+
label: 'Samples',
|
|
408
|
+
value: row => row.currentCount,
|
|
409
|
+
format: count,
|
|
410
|
+
},
|
|
215
411
|
},
|
|
216
|
-
evidence: { id: '
|
|
412
|
+
evidence: { id: 'selected-members', glossaryIds: ['sampleCount'] },
|
|
217
413
|
});
|
|
218
|
-
const
|
|
414
|
+
const rowsView = defineView({
|
|
415
|
+
dataContext: sampleDataContext,
|
|
416
|
+
operation: 'sampleRows',
|
|
417
|
+
isEmpty: rows => rows.length === 0,
|
|
418
|
+
emptyFallback,
|
|
419
|
+
});
|
|
420
|
+
const sampleRows = rowsView.dataset({
|
|
219
421
|
name: 'Samples',
|
|
220
|
-
select: rows => rows
|
|
422
|
+
select: rows => rows,
|
|
221
423
|
rowKey: row => `${row.periodStart}:${row.member}`,
|
|
222
424
|
columns: {
|
|
223
425
|
periodStart: { label: 'Period start', value: row => row.periodStart },
|
|
@@ -226,57 +428,197 @@ const sampleRows = samplesView.dataset({
|
|
|
226
428
|
},
|
|
227
429
|
evidence: { id: 'samples', glossaryIds: ['sampleCount'] },
|
|
228
430
|
});
|
|
229
|
-
//
|
|
230
|
-
const
|
|
231
|
-
<
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
value: row.sampleCount,
|
|
267
|
-
}))}
|
|
431
|
+
// Compare current and previous periods from the same displayed result.
|
|
432
|
+
const totalsContent = totalsView.content(result => (
|
|
433
|
+
<VisualizationWidget
|
|
434
|
+
dataset={totals}
|
|
435
|
+
source={result}
|
|
436
|
+
title={
|
|
437
|
+
result.loading || result.input.period.comparison
|
|
438
|
+
? 'Period comparison'
|
|
439
|
+
: 'Selected period'
|
|
440
|
+
}
|
|
441
|
+
>
|
|
442
|
+
{rows =>
|
|
443
|
+
result.loading ? null : result.input.period.comparison ? (
|
|
444
|
+
<Comparison
|
|
445
|
+
label="Samples"
|
|
446
|
+
current={{
|
|
447
|
+
value: rows[0]!.currentCount,
|
|
448
|
+
formattedValue: formatCount(rows[0]!.currentCount),
|
|
449
|
+
periodLabel: periodLabel(result.input.period.range),
|
|
450
|
+
}}
|
|
451
|
+
previous={{
|
|
452
|
+
value: rows[0]!.previousCount,
|
|
453
|
+
formattedValue: formatCount(rows[0]!.previousCount, {
|
|
454
|
+
missing: 'Not available',
|
|
455
|
+
}),
|
|
456
|
+
periodLabel: periodLabel(result.input.period.comparison),
|
|
457
|
+
}}
|
|
458
|
+
/>
|
|
459
|
+
) : (
|
|
460
|
+
<Ranking
|
|
461
|
+
items={[
|
|
462
|
+
{
|
|
463
|
+
id: 'selected',
|
|
464
|
+
label: periodLabel(result.input.period.range),
|
|
465
|
+
value: rows[0]!.currentCount,
|
|
466
|
+
},
|
|
467
|
+
]}
|
|
268
468
|
/>
|
|
269
|
-
)
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
469
|
+
)
|
|
470
|
+
}
|
|
471
|
+
</VisualizationWidget>
|
|
472
|
+
));
|
|
473
|
+
const trendContent = trendView.content(result => (
|
|
474
|
+
<VisualizationWidget
|
|
475
|
+
dataset={trend}
|
|
476
|
+
source={result}
|
|
477
|
+
title="Samples over time"
|
|
478
|
+
breakdown={trendView.breakdown('grain')}
|
|
479
|
+
>
|
|
480
|
+
{rows => (
|
|
481
|
+
<ComposedChart
|
|
482
|
+
ariaLabel="Samples over time"
|
|
483
|
+
data={rows}
|
|
484
|
+
valueFormat={count}
|
|
485
|
+
>
|
|
486
|
+
<ComposedChart.XAxis dataKey="periodStart" />
|
|
487
|
+
<ComposedChart.YAxis />
|
|
488
|
+
<ComposedChart.Line dataKey="sampleCount" name="Samples" />
|
|
489
|
+
<ComposedChart.Tooltip />
|
|
490
|
+
</ComposedChart>
|
|
491
|
+
)}
|
|
492
|
+
</VisualizationWidget>
|
|
273
493
|
));
|
|
494
|
+
const memberContent = memberView.content(result => (
|
|
495
|
+
<VisualizationWidget
|
|
496
|
+
dataset={byMember}
|
|
497
|
+
source={result}
|
|
498
|
+
title={
|
|
499
|
+
result.loading || result.input.period.comparison
|
|
500
|
+
? 'Where volume changed'
|
|
501
|
+
: 'Samples by member'
|
|
502
|
+
}
|
|
503
|
+
breakdown={memberView.breakdown('breakdown')}
|
|
504
|
+
>
|
|
505
|
+
{rows => (
|
|
506
|
+
<ComposedChart
|
|
507
|
+
ariaLabel="Samples by member"
|
|
508
|
+
data={rows}
|
|
509
|
+
valueFormat={count}
|
|
510
|
+
>
|
|
511
|
+
<ComposedChart.XAxis dataKey="member" />
|
|
512
|
+
<ComposedChart.YAxis />
|
|
513
|
+
{!result.loading && result.input.period.comparison && (
|
|
514
|
+
<ComposedChart.Bar
|
|
515
|
+
dataKey="previousCount"
|
|
516
|
+
name="Previous period"
|
|
517
|
+
fill="var(--atbl-muted)"
|
|
518
|
+
fillOpacity={0.45}
|
|
519
|
+
/>
|
|
520
|
+
)}
|
|
521
|
+
<ComposedChart.Bar dataKey="currentCount" name="Selected period" />
|
|
522
|
+
<ComposedChart.Tooltip />
|
|
523
|
+
<ComposedChart.Legend />
|
|
524
|
+
</ComposedChart>
|
|
525
|
+
)}
|
|
526
|
+
</VisualizationWidget>
|
|
527
|
+
));
|
|
528
|
+
const memberTableContent = memberView.content(result => (
|
|
529
|
+
<TableWidget
|
|
530
|
+
dataset={
|
|
531
|
+
result.loading || result.input.period.comparison
|
|
532
|
+
? byMember
|
|
533
|
+
: selectedMembers
|
|
534
|
+
}
|
|
535
|
+
source={result}
|
|
536
|
+
title={
|
|
537
|
+
result.loading || result.input.period.comparison
|
|
538
|
+
? 'Change by member'
|
|
539
|
+
: 'Samples by member'
|
|
540
|
+
}
|
|
541
|
+
/>
|
|
542
|
+
));
|
|
543
|
+
const rowsContent = rowsView.content(result => (
|
|
544
|
+
<TableWidget dataset={sampleRows} source={result} title="Sample details" />
|
|
545
|
+
));
|
|
546
|
+
// Show this notice when scope or display choices differ from the original finding.
|
|
547
|
+
// Back to finding restores both scope filters and display choices to their defaults.
|
|
548
|
+
function FindingScope() {
|
|
549
|
+
const filters = useAppFilters({
|
|
550
|
+
period: periodFilter,
|
|
551
|
+
groupName,
|
|
552
|
+
grain,
|
|
553
|
+
breakdown,
|
|
554
|
+
});
|
|
555
|
+
const scopeChanged =
|
|
556
|
+
!periodFilter.same(filters.values.period, periodFilter.defaultValue) ||
|
|
557
|
+
!groupName.same(filters.values.groupName, groupName.defaultValue);
|
|
558
|
+
const displayChanged =
|
|
559
|
+
!grain.same(filters.values.grain, grain.defaultValue) ||
|
|
560
|
+
!breakdown.same(filters.values.breakdown, breakdown.defaultValue);
|
|
561
|
+
if (!scopeChanged && !displayChanged) return null;
|
|
562
|
+
return (
|
|
563
|
+
<Notice
|
|
564
|
+
title={
|
|
565
|
+
scopeChanged
|
|
566
|
+
? 'Exploring a different scope'
|
|
567
|
+
: 'Viewing a different breakdown'
|
|
568
|
+
}
|
|
569
|
+
description={
|
|
570
|
+
<>
|
|
571
|
+
Original finding · {findingPeriodLabel} {periodFilter.policy.timeZone}{' '}
|
|
572
|
+
vs previous period ·{' '}
|
|
573
|
+
{groupName.describe?.(groupName.defaultValue) ??
|
|
574
|
+
groupName.defaultValue}
|
|
575
|
+
</>
|
|
576
|
+
}
|
|
577
|
+
action={
|
|
578
|
+
<Button size="compact" onClick={() => filters.resetAll()}>
|
|
579
|
+
Back to finding
|
|
580
|
+
</Button>
|
|
581
|
+
}
|
|
582
|
+
/>
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
const views = ['overview', 'data'] as const;
|
|
274
586
|
function App() {
|
|
587
|
+
const [view, setView] = useViewTab(views, 'overview');
|
|
275
588
|
return (
|
|
276
|
-
<DataApp view={
|
|
277
|
-
<
|
|
589
|
+
<DataApp view={trendView} showToolbar={false}>
|
|
590
|
+
<Stack>
|
|
591
|
+
<FindingScope />
|
|
592
|
+
<Tabs selectedKey={view} onSelectionChange={setView}>
|
|
593
|
+
<TabList aria-label="Finding views">
|
|
594
|
+
<Tab id="overview">Overview</Tab>
|
|
595
|
+
<Tab id="data">Data</Tab>
|
|
596
|
+
</TabList>
|
|
597
|
+
<TabPanels>
|
|
598
|
+
<TabPanel id="overview">
|
|
599
|
+
<Stack>
|
|
600
|
+
<Grid columns={3}>
|
|
601
|
+
<GridItem span={2}>
|
|
602
|
+
<DataSection content={trendContent} />
|
|
603
|
+
</GridItem>
|
|
604
|
+
<GridItem>
|
|
605
|
+
<DataSection content={totalsContent} />
|
|
606
|
+
</GridItem>
|
|
607
|
+
</Grid>
|
|
608
|
+
<DataSection content={memberContent} />
|
|
609
|
+
</Stack>
|
|
610
|
+
</TabPanel>
|
|
611
|
+
<TabPanel id="data">
|
|
612
|
+
<Stack>
|
|
613
|
+
<DataSection content={memberTableContent} />
|
|
614
|
+
<DataSection content={rowsContent} />
|
|
615
|
+
</Stack>
|
|
616
|
+
</TabPanel>
|
|
617
|
+
</TabPanels>
|
|
618
|
+
</Tabs>
|
|
619
|
+
</Stack>
|
|
278
620
|
</DataApp>
|
|
279
621
|
);
|
|
280
622
|
}
|
|
281
|
-
|
|
623
|
+
|
|
282
624
|
mountDataApp({ app: dataApp, component: App });
|