@altertable/data-app-examples 0.78.0 → 0.79.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 (28) hide show
  1. package/dist/index.js +2 -2
  2. package/dist/index.js.map +1 -1
  3. package/dist/types/index.d.ts +2 -2
  4. package/package.json +1 -1
  5. package/templates/starter-data-app/index.tsx +71 -680
  6. package/templates/starter-finding-data-app/index.tsx +9 -31
  7. package/templates/starter-local-data-app/AGENTS.md +1 -1
  8. package/templates/starter-local-data-app/README.md +5 -8
  9. package/templates/starter-local-data-app/app.ts +15 -246
  10. package/templates/starter-local-data-app/package.json +3 -3
  11. package/templates/starter-local-data-app/src/App.tsx +32 -253
  12. package/templates/starter-local-data-app/src/data-context.ts +8 -27
  13. package/templates/starter-local-data-app/src/filters.ts +9 -30
  14. package/templates/starter-local-data-app/src/operations.ts +9 -125
  15. package/templates/starter-local-finding-data-app/AGENTS.md +1 -1
  16. package/templates/starter-local-finding-data-app/README.md +2 -2
  17. package/templates/starter-local-finding-data-app/package.json +3 -3
  18. package/templates/starter-local-finding-data-app/src/App.tsx +7 -23
  19. package/templates/starter-local-finding-data-app/src/data-context.ts +3 -9
  20. package/templates/starter-local-metric-data-app/AGENTS.md +1 -1
  21. package/templates/starter-local-metric-data-app/README.md +2 -2
  22. package/templates/starter-local-metric-data-app/app.ts +4 -4
  23. package/templates/starter-local-metric-data-app/package.json +3 -3
  24. package/templates/starter-local-metric-data-app/src/App.tsx +4 -8
  25. package/templates/starter-local-metric-data-app/src/data-context.ts +4 -8
  26. package/templates/starter-local-metric-data-app/src/filters.ts +1 -0
  27. package/templates/starter-local-metric-data-app/src/operations.ts +4 -12
  28. package/templates/starter-metric-data-app/index.tsx +18 -32
@@ -1,741 +1,132 @@
1
1
  import { defineDataApp } from '@altertable/data-app';
2
2
  import {
3
3
  createDataContext,
4
- mountDataApp,
5
4
  createDataHooks,
6
5
  DataApp,
7
6
  DataSection,
8
- Grid,
9
- MetricWidget,
10
- TableWidget,
7
+ mountDataApp,
11
8
  VisualizationWidget,
12
- Stack,
13
9
  } from '@altertable/data-app-react';
14
- import { BarChart, ComposedChart } from '@altertable/data-app-react/ui';
15
- import {
16
- parseCount,
17
- choiceFilter,
18
- displayChoice,
19
- } from '@altertable/data-app/contract';
20
- import { formatDateRange } from '@altertable/data-app/format';
10
+ import { BarChart } from '@altertable/data-app-react/ui';
11
+ import { choiceFilter } from '@altertable/data-app/contract';
21
12
 
22
13
  export const dataApp = defineDataApp({
23
14
  // Replace the demo title, description, and scope labels with the app's identity.
24
- title: 'Infrastructure costs',
25
- description: 'USD · Fictional weekly allocations',
15
+ title: 'Sample counts',
16
+ description: 'Compare fictional sample counts across groups.',
26
17
  scope: { organization: 'demo', environment: 'sample' },
27
18
  appearance: { theme: 'system' },
28
19
  queries: {
29
- costBreakdown: {
30
- projections: {
31
- member_name: { type: 'string' },
32
- cost_cents: { type: 'number' },
33
- },
20
+ sampleCountsByGroup: {
21
+ // Fictional rows. Replace the CTE with an inspected source.
34
22
  statement: `
35
- WITH infrastructure_costs(month, service_name, customer_name, week_1, week_2, week_3, week_4) AS (
36
- -- Fictional allocation batches in integer cents.
37
- -- Replace this CTE with verified billing data.
38
- VALUES
39
- ('2026-09', 'Compute', 'Atlas', 84000, 126000, 84000, 126000),
40
- ('2026-09', 'Compute', 'Beacon', 42000, 63000, 42000, 63000),
41
- ('2026-09', 'Compute', 'Cedar', 18000, 27000, 18000, 27000),
42
- ('2026-09', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
43
- ('2026-09', 'Storage', 'Beacon', 84000, 56000, 84000, 56000),
44
- ('2026-09', 'Storage', 'Cedar', 36000, 24000, 36000, 24000),
45
- ('2026-09', 'Networking', 'Atlas', 3000, 6000, 9000, 12000),
46
- ('2026-09', 'Networking', 'Beacon', 6000, 12000, 18000, 24000),
47
- ('2026-09', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
48
- ('2026-09', 'Logging', 'Atlas', 0, 0, 0, 0),
49
- ('2026-09', 'Logging', 'Beacon', 0, 0, 0, 0),
50
- ('2026-09', 'Logging', 'Cedar', 0, 0, 0, 0),
51
- ('2026-08', 'Compute', 'Atlas', 76000, 114000, 76000, 114000),
52
- ('2026-08', 'Compute', 'Beacon', 40000, 60000, 40000, 60000),
53
- ('2026-08', 'Compute', 'Cedar', 16000, 24000, 16000, 24000),
54
- ('2026-08', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
55
- ('2026-08', 'Storage', 'Beacon', 75000, 50000, 75000, 50000),
56
- ('2026-08', 'Storage', 'Cedar', 33000, 22000, 33000, 22000),
57
- ('2026-08', 'Networking', 'Atlas', 2000, 4000, 6000, 8000),
58
- ('2026-08', 'Networking', 'Beacon', 5000, 10000, 15000, 20000),
59
- ('2026-08', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
60
- ('2026-08', 'Logging', 'Atlas', 0, 0, 0, 0),
61
- ('2026-08', 'Logging', 'Beacon', 0, 0, 0, 0),
62
- ('2026-08', 'Logging', 'Cedar', 0, 0, 0, 0)
63
- ),
64
- selected_costs AS (
65
- SELECT service_name, customer_name,
66
- week_1 + week_2 + week_3 + week_4 AS cost_cents
67
- FROM infrastructure_costs
68
- WHERE month = $month AND ($customerName = '' OR customer_name = $customerName)
23
+ WITH sample_counts(group_name, sample_count) AS (
24
+ VALUES ('Alpha', 1200), ('Alpha', 800), ('Beta', 450), ('Gamma', 0)
69
25
  )
70
- SELECT CASE WHEN $breakdown = 'service' THEN service_name ELSE customer_name END AS member_name,
71
- CAST(SUM(cost_cents) AS BIGINT) AS cost_cents
72
- FROM selected_costs GROUP BY member_name
73
- ORDER BY cost_cents DESC, member_name LIMIT $limit`,
26
+ SELECT group_name, CAST(SUM(sample_count) AS BIGINT) AS sample_count
27
+ FROM sample_counts
28
+ WHERE $groupName = 'all' OR group_name = $groupName
29
+ GROUP BY group_name
30
+ ORDER BY sample_count DESC, group_name
31
+ LIMIT $limit`,
74
32
  params: {
75
- month: { type: 'string', defaultValue: '2026-09' },
76
- customerName: { type: 'string', defaultValue: '' },
77
- breakdown: { type: 'string', defaultValue: 'service' },
33
+ groupName: { type: 'string', defaultValue: 'all' },
78
34
  limit: { type: 'number', defaultValue: 10 },
79
35
  },
80
- },
81
- totalCost: {
82
- projections: {
83
- cost_cents: { type: 'number' },
84
- customer_count: { type: 'number' },
85
- },
86
- statement: `
87
- WITH infrastructure_costs(month, service_name, customer_name, week_1, week_2, week_3, week_4) AS (
88
- -- Fictional allocation batches in integer cents.
89
- -- Replace this CTE with verified billing data.
90
- VALUES
91
- ('2026-09', 'Compute', 'Atlas', 84000, 126000, 84000, 126000),
92
- ('2026-09', 'Compute', 'Beacon', 42000, 63000, 42000, 63000),
93
- ('2026-09', 'Compute', 'Cedar', 18000, 27000, 18000, 27000),
94
- ('2026-09', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
95
- ('2026-09', 'Storage', 'Beacon', 84000, 56000, 84000, 56000),
96
- ('2026-09', 'Storage', 'Cedar', 36000, 24000, 36000, 24000),
97
- ('2026-09', 'Networking', 'Atlas', 3000, 6000, 9000, 12000),
98
- ('2026-09', 'Networking', 'Beacon', 6000, 12000, 18000, 24000),
99
- ('2026-09', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
100
- ('2026-09', 'Logging', 'Atlas', 0, 0, 0, 0),
101
- ('2026-09', 'Logging', 'Beacon', 0, 0, 0, 0),
102
- ('2026-09', 'Logging', 'Cedar', 0, 0, 0, 0),
103
- ('2026-08', 'Compute', 'Atlas', 76000, 114000, 76000, 114000),
104
- ('2026-08', 'Compute', 'Beacon', 40000, 60000, 40000, 60000),
105
- ('2026-08', 'Compute', 'Cedar', 16000, 24000, 16000, 24000),
106
- ('2026-08', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
107
- ('2026-08', 'Storage', 'Beacon', 75000, 50000, 75000, 50000),
108
- ('2026-08', 'Storage', 'Cedar', 33000, 22000, 33000, 22000),
109
- ('2026-08', 'Networking', 'Atlas', 2000, 4000, 6000, 8000),
110
- ('2026-08', 'Networking', 'Beacon', 5000, 10000, 15000, 20000),
111
- ('2026-08', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
112
- ('2026-08', 'Logging', 'Atlas', 0, 0, 0, 0),
113
- ('2026-08', 'Logging', 'Beacon', 0, 0, 0, 0),
114
- ('2026-08', 'Logging', 'Cedar', 0, 0, 0, 0)
115
- ),
116
- selected_costs AS (
117
- SELECT service_name, customer_name,
118
- week_1 + week_2 + week_3 + week_4 AS cost_cents
119
- FROM infrastructure_costs
120
- WHERE month = $month AND ($customerName = '' OR customer_name = $customerName)
121
- )
122
- SELECT CAST(SUM(cost_cents) AS BIGINT) AS cost_cents,
123
- COUNT(DISTINCT customer_name) AS customer_count
124
- FROM selected_costs HAVING COUNT(*) > 0`,
125
- params: {
126
- month: { type: 'string', defaultValue: '2026-09' },
127
- customerName: { type: 'string', defaultValue: '' },
128
- },
129
- },
130
- costsByCustomer: {
131
36
  projections: {
132
- customer_name: { type: 'string' },
133
- cost_cents: { type: 'number' },
134
- },
135
- statement: `
136
- WITH infrastructure_costs(month, service_name, customer_name, week_1, week_2, week_3, week_4) AS (
137
- -- Fictional allocation batches in integer cents.
138
- -- Replace this CTE with verified billing data.
139
- VALUES
140
- ('2026-09', 'Compute', 'Atlas', 84000, 126000, 84000, 126000),
141
- ('2026-09', 'Compute', 'Beacon', 42000, 63000, 42000, 63000),
142
- ('2026-09', 'Compute', 'Cedar', 18000, 27000, 18000, 27000),
143
- ('2026-09', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
144
- ('2026-09', 'Storage', 'Beacon', 84000, 56000, 84000, 56000),
145
- ('2026-09', 'Storage', 'Cedar', 36000, 24000, 36000, 24000),
146
- ('2026-09', 'Networking', 'Atlas', 3000, 6000, 9000, 12000),
147
- ('2026-09', 'Networking', 'Beacon', 6000, 12000, 18000, 24000),
148
- ('2026-09', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
149
- ('2026-09', 'Logging', 'Atlas', 0, 0, 0, 0),
150
- ('2026-09', 'Logging', 'Beacon', 0, 0, 0, 0),
151
- ('2026-09', 'Logging', 'Cedar', 0, 0, 0, 0),
152
- ('2026-08', 'Compute', 'Atlas', 76000, 114000, 76000, 114000),
153
- ('2026-08', 'Compute', 'Beacon', 40000, 60000, 40000, 60000),
154
- ('2026-08', 'Compute', 'Cedar', 16000, 24000, 16000, 24000),
155
- ('2026-08', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
156
- ('2026-08', 'Storage', 'Beacon', 75000, 50000, 75000, 50000),
157
- ('2026-08', 'Storage', 'Cedar', 33000, 22000, 33000, 22000),
158
- ('2026-08', 'Networking', 'Atlas', 2000, 4000, 6000, 8000),
159
- ('2026-08', 'Networking', 'Beacon', 5000, 10000, 15000, 20000),
160
- ('2026-08', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
161
- ('2026-08', 'Logging', 'Atlas', 0, 0, 0, 0),
162
- ('2026-08', 'Logging', 'Beacon', 0, 0, 0, 0),
163
- ('2026-08', 'Logging', 'Cedar', 0, 0, 0, 0)
164
- ),
165
- selected_costs AS (
166
- SELECT service_name, customer_name,
167
- week_1 + week_2 + week_3 + week_4 AS cost_cents
168
- FROM infrastructure_costs
169
- WHERE month = $month AND ($customerName = '' OR customer_name = $customerName)
170
- )
171
- SELECT customer_name, CAST(SUM(cost_cents) AS BIGINT) AS cost_cents
172
- FROM selected_costs WHERE service_name = $serviceName
173
- GROUP BY customer_name ORDER BY cost_cents DESC, customer_name LIMIT $limit`,
174
- params: {
175
- month: { type: 'string', defaultValue: '2026-09' },
176
- customerName: { type: 'string', defaultValue: '' },
177
- serviceName: { type: 'string' },
178
- limit: { type: 'number', defaultValue: 10 },
179
- },
180
- },
181
- costTrend: {
182
- projections: {
183
- period_start: { type: 'string' },
184
- cost_cents: { type: 'number' },
185
- },
186
- statement: `
187
- WITH infrastructure_costs(month, service_name, customer_name, week_1, week_2, week_3, week_4) AS (
188
- -- Fictional allocation batches in integer cents.
189
- -- Replace this CTE with verified billing data.
190
- VALUES
191
- ('2026-09', 'Compute', 'Atlas', 84000, 126000, 84000, 126000),
192
- ('2026-09', 'Compute', 'Beacon', 42000, 63000, 42000, 63000),
193
- ('2026-09', 'Compute', 'Cedar', 18000, 27000, 18000, 27000),
194
- ('2026-09', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
195
- ('2026-09', 'Storage', 'Beacon', 84000, 56000, 84000, 56000),
196
- ('2026-09', 'Storage', 'Cedar', 36000, 24000, 36000, 24000),
197
- ('2026-09', 'Networking', 'Atlas', 3000, 6000, 9000, 12000),
198
- ('2026-09', 'Networking', 'Beacon', 6000, 12000, 18000, 24000),
199
- ('2026-09', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
200
- ('2026-09', 'Logging', 'Atlas', 0, 0, 0, 0),
201
- ('2026-09', 'Logging', 'Beacon', 0, 0, 0, 0),
202
- ('2026-09', 'Logging', 'Cedar', 0, 0, 0, 0),
203
- ('2026-08', 'Compute', 'Atlas', 76000, 114000, 76000, 114000),
204
- ('2026-08', 'Compute', 'Beacon', 40000, 60000, 40000, 60000),
205
- ('2026-08', 'Compute', 'Cedar', 16000, 24000, 16000, 24000),
206
- ('2026-08', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
207
- ('2026-08', 'Storage', 'Beacon', 75000, 50000, 75000, 50000),
208
- ('2026-08', 'Storage', 'Cedar', 33000, 22000, 33000, 22000),
209
- ('2026-08', 'Networking', 'Atlas', 2000, 4000, 6000, 8000),
210
- ('2026-08', 'Networking', 'Beacon', 5000, 10000, 15000, 20000),
211
- ('2026-08', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
212
- ('2026-08', 'Logging', 'Atlas', 0, 0, 0, 0),
213
- ('2026-08', 'Logging', 'Beacon', 0, 0, 0, 0),
214
- ('2026-08', 'Logging', 'Cedar', 0, 0, 0, 0)
215
- ),
216
- -- The four fictional batch dates match the week_1 through week_4 columns.
217
- weeks(day) AS (VALUES ('01'), ('08'), ('15'), ('22'))
218
- SELECT $month || '-' || day AS period_start,
219
- CAST(SUM(CASE day WHEN '01' THEN week_1 WHEN '08' THEN week_2
220
- WHEN '15' THEN week_3 ELSE week_4 END) AS BIGINT) AS cost_cents
221
- FROM infrastructure_costs CROSS JOIN weeks
222
- WHERE month = $month AND ($customerName = '' OR customer_name = $customerName)
223
- GROUP BY day ORDER BY day LIMIT $limit`,
224
- params: {
225
- month: { type: 'string', defaultValue: '2026-09' },
226
- customerName: { type: 'string', defaultValue: '' },
227
- limit: { type: 'number', defaultValue: 10 },
228
- },
229
- },
230
- customerServiceMix: {
231
- projections: {
232
- customer_name: { type: 'string' },
233
- service_name: { type: 'string' },
234
- cost_cents: { type: 'number' },
235
- },
236
- statement: `
237
- WITH infrastructure_costs(month, service_name, customer_name, week_1, week_2, week_3, week_4) AS (
238
- -- Fictional allocation batches in integer cents.
239
- -- Replace this CTE with verified billing data.
240
- VALUES
241
- ('2026-09', 'Compute', 'Atlas', 84000, 126000, 84000, 126000),
242
- ('2026-09', 'Compute', 'Beacon', 42000, 63000, 42000, 63000),
243
- ('2026-09', 'Compute', 'Cedar', 18000, 27000, 18000, 27000),
244
- ('2026-09', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
245
- ('2026-09', 'Storage', 'Beacon', 84000, 56000, 84000, 56000),
246
- ('2026-09', 'Storage', 'Cedar', 36000, 24000, 36000, 24000),
247
- ('2026-09', 'Networking', 'Atlas', 3000, 6000, 9000, 12000),
248
- ('2026-09', 'Networking', 'Beacon', 6000, 12000, 18000, 24000),
249
- ('2026-09', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
250
- ('2026-09', 'Logging', 'Atlas', 0, 0, 0, 0),
251
- ('2026-09', 'Logging', 'Beacon', 0, 0, 0, 0),
252
- ('2026-09', 'Logging', 'Cedar', 0, 0, 0, 0),
253
- ('2026-08', 'Compute', 'Atlas', 76000, 114000, 76000, 114000),
254
- ('2026-08', 'Compute', 'Beacon', 40000, 60000, 40000, 60000),
255
- ('2026-08', 'Compute', 'Cedar', 16000, 24000, 16000, 24000),
256
- ('2026-08', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
257
- ('2026-08', 'Storage', 'Beacon', 75000, 50000, 75000, 50000),
258
- ('2026-08', 'Storage', 'Cedar', 33000, 22000, 33000, 22000),
259
- ('2026-08', 'Networking', 'Atlas', 2000, 4000, 6000, 8000),
260
- ('2026-08', 'Networking', 'Beacon', 5000, 10000, 15000, 20000),
261
- ('2026-08', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
262
- ('2026-08', 'Logging', 'Atlas', 0, 0, 0, 0),
263
- ('2026-08', 'Logging', 'Beacon', 0, 0, 0, 0),
264
- ('2026-08', 'Logging', 'Cedar', 0, 0, 0, 0)
265
- ),
266
- selected_costs AS (
267
- SELECT service_name, customer_name,
268
- week_1 + week_2 + week_3 + week_4 AS cost_cents
269
- FROM infrastructure_costs
270
- WHERE month = $month AND ($customerName = '' OR customer_name = $customerName)
271
- )
272
- SELECT customer_name, service_name, CAST(SUM(cost_cents) AS BIGINT) AS cost_cents
273
- FROM selected_costs GROUP BY customer_name, service_name
274
- ORDER BY customer_name, service_name LIMIT $limit`,
275
- params: {
276
- month: { type: 'string', defaultValue: '2026-09' },
277
- customerName: { type: 'string', defaultValue: '' },
278
- limit: { type: 'number', defaultValue: 20 },
37
+ group_name: { type: 'string' },
38
+ sample_count: { type: 'number' },
279
39
  },
280
40
  },
281
41
  },
282
42
  });
283
43
 
284
- // These months match the fictional SQL rows.
285
- // Replace them with months covered by the billing source.
286
- const month = choiceFilter({
287
- key: 'month',
288
- label: 'Month',
289
- defaultValue: '2026-09',
290
- options: [
291
- { id: '2026-09', label: 'September 2026' },
292
- { id: '2026-08', label: 'August 2026' },
293
- ],
294
- });
295
- // These customers match the fictional SQL rows.
296
- // Replace them with customers from the billing source.
297
- const customer = choiceFilter({
298
- key: 'customer',
299
- label: 'Customer',
44
+ // The options match the fictional rows; the query treats 'all' as every group.
45
+ const groupName = choiceFilter({
46
+ key: 'group',
47
+ label: 'Group',
300
48
  defaultValue: 'all',
301
49
  options: [
302
- { id: 'all', label: 'All customers' },
303
- { id: 'Atlas', label: 'Atlas' },
304
- { id: 'Beacon', label: 'Beacon' },
305
- { id: 'Cedar', label: 'Cedar' },
306
- ],
307
- });
308
- const breakdown = displayChoice({
309
- key: 'breakdown',
310
- label: 'Breakdown',
311
- defaultValue: 'service',
312
- options: [
313
- { id: 'service', label: 'Service' },
314
- { id: 'customer', label: 'Customer' },
50
+ { id: 'all', label: 'All groups' },
51
+ { id: 'Alpha', label: 'Alpha' },
52
+ { id: 'Beta', label: 'Beta' },
53
+ { id: 'Gamma', label: 'Gamma' },
315
54
  ],
316
55
  });
317
56
 
318
- function parseService(value: unknown) {
319
- if (
320
- !value ||
321
- typeof value !== 'object' ||
322
- Array.isArray(value) ||
323
- !('serviceName' in value) ||
324
- typeof value.serviceName !== 'string' ||
325
- value.serviceName.trim().length === 0 ||
326
- value.serviceName.length > 100
327
- )
328
- throw new Error('Choose a service to inspect its customer costs.');
329
- return { serviceName: value.serviceName };
330
- }
331
- function queryScope(input: { month: string; customer: string }) {
332
- return {
333
- month: input.month,
334
- customerName: input.customer === 'all' ? '' : input.customer,
335
- };
336
- }
337
57
  export const operations = dataApp.defineOperations({
338
- costBreakdown: dataApp.defineOperation({
339
- filters: { month, customer, breakdown },
340
- policy: { maxQueryRows: 10, maxDurationMs: 15000 },
341
- async run({ query }, input) {
342
- const result = await query('costBreakdown', {
343
- ...queryScope(input),
344
- breakdown: input.breakdown,
345
- });
346
- return result.rows.map(row => ({
347
- memberName: row.member_name,
348
- dimension: input.breakdown,
349
- cost: parseCount(row.cost_cents) / 100,
58
+ sampleCountsByGroup: dataApp.defineOperation({
59
+ filters: { groupName },
60
+ policy: { maxQueryRows: 10 },
61
+ async run({ query }, { groupName }) {
62
+ const { rows } = await query('sampleCountsByGroup', { groupName });
63
+ return rows.map(row => ({
64
+ groupName: row.group_name,
65
+ sampleCount: row.sample_count,
350
66
  }));
351
67
  },
352
68
  }),
353
- totalCost: dataApp.defineOperation({
354
- filters: { month, customer },
355
- policy: { maxQueryRows: 1, maxDurationMs: 15000 },
356
- async run({ query }, input) {
357
- const result = await query('totalCost', queryScope(input));
358
- const row = result.rows[0];
359
- if (!row) return null;
360
- const cost = parseCount(row.cost_cents) / 100;
361
- const customerCount = parseCount(row.customer_count);
362
- if (customerCount === 0)
363
- throw new Error('Allocations must identify at least one customer.');
364
- return {
365
- cost,
366
- customerCount,
367
- averageCost: cost / customerCount,
368
- };
369
- },
370
- }),
371
- costsByCustomer: dataApp.defineOperation({
372
- filters: { month, customer },
373
- input: parseService,
374
- checks: [{ serviceName: 'Compute' }],
375
- policy: { maxQueryRows: 10, maxDurationMs: 15000 },
376
- async run({ query }, input) {
377
- const result = await query('costsByCustomer', {
378
- ...queryScope(input),
379
- serviceName: input.serviceName,
380
- });
381
- return result.rows.map(row => ({
382
- customerName: row.customer_name,
383
- cost: parseCount(row.cost_cents) / 100,
384
- }));
385
- },
386
- }),
387
- costTrend: dataApp.defineOperation({
388
- filters: { month, customer },
389
- policy: { maxQueryRows: 10, maxDurationMs: 15000 },
390
- async run({ query }, input) {
391
- const result = await query('costTrend', queryScope(input));
392
- return result.rows.map(row => ({
393
- periodStart: row.period_start,
394
- cost: parseCount(row.cost_cents) / 100,
395
- }));
396
- },
397
- }),
398
- customerServiceMix: dataApp.defineOperation({
399
- filters: { month, customer },
400
- policy: { maxQueryRows: 20, maxDurationMs: 15000 },
401
- async run({ query }, input) {
402
- const result = await query('customerServiceMix', queryScope(input));
403
- // These service names match the fictional SQL rows and chart series.
404
- // Update the pivot and chart series together when changing the services.
405
- const customers = new Map<
406
- string,
407
- {
408
- customerName: string;
409
- Compute: number;
410
- Storage: number;
411
- Networking: number;
412
- Logging: number;
413
- total: number;
414
- }
415
- >();
416
- for (const row of result.rows) {
417
- const service = row.service_name;
418
- if (
419
- service !== 'Compute' &&
420
- service !== 'Storage' &&
421
- service !== 'Networking' &&
422
- service !== 'Logging'
423
- )
424
- throw new Error('Unexpected fixture service.');
425
- const entry = customers.get(row.customer_name) ?? {
426
- customerName: row.customer_name,
427
- Compute: 0,
428
- Storage: 0,
429
- Networking: 0,
430
- Logging: 0,
431
- total: 0,
432
- };
433
- const cost = parseCount(row.cost_cents) / 100;
434
- entry[service] += cost;
435
- entry.total += cost;
436
- customers.set(row.customer_name, entry);
437
- }
438
- return [...customers.values()].sort(
439
- (a, b) =>
440
- b.total - a.total || a.customerName.localeCompare(b.customerName)
441
- );
442
- },
443
- }),
444
69
  });
445
70
 
446
- const queryNames = {
447
- ...operations.costBreakdown.queryNames,
448
- ...operations.totalCost.queryNames,
449
- ...operations.costsByCustomer.queryNames,
450
- ...operations.costTrend.queryNames,
451
- ...operations.customerServiceMix.queryNames,
452
- };
453
- // Replace these example definitions and coverage with verified source metadata.
454
- const costDataContext = createDataContext(queryNames)({
71
+ // Replace the description and definitions with verified source metadata.
72
+ const dataContext = createDataContext(dataApp.queryNames)({
455
73
  description:
456
- 'Fictional weekly customer allocations for August and September 2026. Scope filters apply to every chart and its contributing records.',
74
+ 'Fictional sample counts by group. Gamma has a recorded count of zero.',
457
75
  glossary: {
458
- allocatedCost: {
459
- term: 'Allocated cost',
460
- definition:
461
- 'USD charges in the selected billing month and customer scope. Four recorded allocation batches, dated the 1st, 8th, 15th and 22nd, sum to each monthly allocation. Customers sum to services; services sum to the total. Zero is a recorded charge of zero.',
462
- queryNames: Object.values(queryNames),
463
- },
464
- customerCount: {
465
- term: 'Customers',
466
- definition:
467
- 'Distinct customers with recorded allocations in the selected scope, including recorded zero charges.',
468
- queryNames: [queryNames.totalCost],
469
- },
470
- averageCustomerCost: {
471
- term: 'Average per customer',
76
+ sampleCount: {
77
+ term: 'Sample count',
472
78
  definition:
473
- 'Total allocated cost divided by the number of distinct customers in the same selected scope, including customers with zero charges.',
474
- queryNames: [queryNames.totalCost],
79
+ 'Sum of recorded samples in the selected group scope. Additive across groups.',
80
+ queryNames: [dataApp.queryNames.sampleCountsByGroup],
475
81
  },
476
82
  },
477
83
  });
478
84
 
479
- // Fictional charges use USD. Match this format to the real billing currency.
480
- const costFormat = { kind: 'currency', currency: 'USD' } as const;
481
- const { defineView, defineDetailView } = createDataHooks(
482
- operations.createDataClient()
483
- );
484
- const emptyFallback = {
485
- title: 'No allocations',
486
- description: 'Choose another month or customer.',
487
- };
488
- const servicesView = defineView({
489
- dataContext: costDataContext,
490
- operation: 'costBreakdown',
491
- isEmpty: rows => rows.length === 0,
492
- emptyFallback,
493
- });
494
- const serviceCosts = servicesView.dataset({
495
- name: 'Cost breakdown',
496
- select: rows => rows,
497
- rowKey: row => row.memberName,
498
- columns: {
499
- memberName: { label: 'Member', value: row => row.memberName },
500
- cost: { label: 'Cost', value: row => row.cost, format: costFormat },
501
- },
502
- evidence: { id: 'cost-breakdown', glossaryIds: ['allocatedCost'] },
503
- });
504
- const totalView = defineView({
505
- dataContext: costDataContext,
506
- operation: 'totalCost',
507
- isEmpty: total => total === null,
508
- emptyFallback: { title: 'No total available' },
509
- });
510
- const totalCost = totalView.metric(
511
- {
512
- id: 'total-cost',
513
- glossaryId: 'allocatedCost',
514
- label: 'Total cost',
515
- format: costFormat,
516
- },
517
- total => {
518
- if (total === null)
519
- throw new Error('No allocated total for this selection.');
520
- return { current: total.cost };
521
- }
522
- );
523
- const customerCount = totalView.metric(
524
- {
525
- id: 'customer-count',
526
- glossaryId: 'customerCount',
527
- label: 'Customers',
528
- format: { kind: 'count' },
529
- },
530
- total => {
531
- if (total === null)
532
- throw new Error('No customer count for this selection.');
533
- return { current: total.customerCount };
534
- }
535
- );
536
- const averageCost = totalView.metric(
537
- {
538
- id: 'average-cost',
539
- glossaryId: 'averageCustomerCost',
540
- label: 'Average per customer',
541
- format: costFormat,
542
- },
543
- total => {
544
- if (total === null) throw new Error('No average cost for this selection.');
545
- return { current: total.averageCost };
546
- }
547
- );
548
- const totalContent = totalView.content(result => (
549
- <Grid columns={3}>
550
- <MetricWidget metric={totalCost} source={result} />
551
- <MetricWidget metric={customerCount} source={result} />
552
- <MetricWidget metric={averageCost} source={result} />
553
- </Grid>
554
- ));
555
- const customersView = defineDetailView({
556
- id: 'service-customers',
557
- title: 'Customer costs',
558
- operation: 'costsByCustomer',
559
- dataContext: costDataContext,
560
- parseInput: operations.costsByCustomer.input,
561
- describeInput: input =>
562
- `${input.serviceName} · ${month.describe?.(input.month)} · USD`,
563
- isEmpty: rows => rows.length === 0,
85
+ const { defineView } = createDataHooks(operations.createDataClient());
86
+ const sampleCountsView = defineView({
87
+ dataContext,
88
+ operation: 'sampleCountsByGroup',
564
89
  emptyFallback: {
565
- title: 'No customer allocations',
566
- description:
567
- 'No allocations are recorded for this service in the selected month and customer scope.',
568
- },
569
- });
570
- const customerCosts = customersView.dataset({
571
- name: 'Customer allocations',
572
- select: rows => rows,
573
- rowKey: row => row.customerName,
574
- columns: {
575
- customerName: { label: 'Customer', value: row => row.customerName },
576
- cost: { label: 'Cost', value: row => row.cost, format: costFormat },
90
+ title: 'No matching groups',
91
+ description: 'Choose another group.',
577
92
  },
578
- evidence: { id: 'costs-by-customer', glossaryIds: ['allocatedCost'] },
579
93
  });
580
- const customersDetail = customersView.content(result => (
581
- <TableWidget
582
- dataset={customerCosts}
583
- source={result}
584
- title="Cost by customer"
585
- pagination={false}
586
- />
587
- ));
588
- const serviceActions = serviceCosts.actions(
589
- action => ({
590
- customers: action.detail({
591
- label: 'View customers',
592
- target: customersView,
593
- when: row => row.dimension === 'service',
594
- input: row => ({ serviceName: row.memberName }),
595
- }),
596
- }),
597
- { primary: 'customers' }
598
- );
599
- const breakdownContent = servicesView.content(result => {
600
- const byService = result.loading || result.input.breakdown === 'service';
601
- return (
602
- <VisualizationWidget
603
- dataset={serviceCosts}
604
- source={result}
605
- title={byService ? 'Cost by service' : 'Cost by customer'}
606
- actions={serviceActions}
607
- breakdown={servicesView.breakdown('breakdown')}
608
- >
609
- {(rows, actions) => (
610
- <BarChart
611
- ariaLabel={byService ? 'Costs by service' : 'Costs by customer'}
612
- unit="USD"
613
- showYAxis
614
- scrollToEnd={false}
615
- valueFormat={costFormat}
616
- items={rows.map(row => ({
617
- ...row,
618
- id: row.memberName,
619
- label: row.memberName,
620
- value: row.cost,
621
- }))}
622
- itemActions={actions}
623
- />
624
- )}
625
- </VisualizationWidget>
626
- );
627
- });
628
- const trendView = defineView({
629
- dataContext: costDataContext,
630
- operation: 'costTrend',
631
- isEmpty: rows => rows.length === 0,
632
- emptyFallback,
633
- });
634
- const weeklyCosts = trendView.dataset({
635
- name: 'Weekly allocations',
636
- select: rows => rows,
637
- rowKey: row => row.periodStart,
94
+ const sampleCounts = sampleCountsView.dataset({
95
+ name: 'Sample counts',
96
+ rowKey: row => row.groupName,
638
97
  columns: {
639
- periodStart: { label: 'Allocation date', value: row => row.periodStart },
640
- cost: { label: 'Cost', value: row => row.cost, format: costFormat },
98
+ groupName: { label: 'Group' },
99
+ sampleCount: { format: { kind: 'count' } },
641
100
  },
642
- evidence: { id: 'cost-trend', glossaryIds: ['allocatedCost'] },
101
+ evidence: { id: 'counts-by-group', glossaryIds: ['sampleCount'] },
643
102
  });
644
- const trendContent = trendView.content(result => (
103
+ const countsContent = sampleCountsView.content(result => (
645
104
  <VisualizationWidget
646
- dataset={weeklyCosts}
105
+ dataset={sampleCounts}
647
106
  source={result}
648
- title="Weekly allocated cost"
107
+ title="Samples by group"
649
108
  >
650
109
  {rows => (
651
- <ComposedChart
652
- data={rows}
653
- ariaLabel="Costs over time"
654
- valueFormat={costFormat}
655
- >
656
- <ComposedChart.XAxis
657
- dataKey="periodStart"
658
- tickFormatter={value =>
659
- formatDateRange({ start: String(value), end: String(value) })
660
- }
661
- />
662
- <ComposedChart.YAxis domain={[0, 'auto']} />
663
- <ComposedChart.Tooltip />
664
- <ComposedChart.Line dataKey="cost" name="Allocated cost" />
665
- </ComposedChart>
666
- )}
667
- </VisualizationWidget>
668
- ));
669
- const mixView = defineView({
670
- dataContext: costDataContext,
671
- operation: 'customerServiceMix',
672
- isEmpty: rows => rows.length === 0,
673
- emptyFallback,
674
- });
675
- const customerMix = mixView.dataset({
676
- name: 'Customer service mix',
677
- select: rows => rows,
678
- rowKey: row => row.customerName,
679
- columns: {
680
- customerName: { label: 'Customer', value: row => row.customerName },
681
- Compute: { value: row => row.Compute, format: costFormat },
682
- Storage: { value: row => row.Storage, format: costFormat },
683
- Networking: { value: row => row.Networking, format: costFormat },
684
- Logging: { value: row => row.Logging, format: costFormat },
685
- },
686
- evidence: { id: 'customer-service-mix', glossaryIds: ['allocatedCost'] },
687
- });
688
- const mixContent = mixView.content(result => (
689
- <VisualizationWidget
690
- dataset={customerMix}
691
- source={result}
692
- title="Service mix by customer"
693
- >
694
- {rows => (
695
- <ComposedChart
696
- data={rows}
697
- ariaLabel="Service mix by customer"
698
- valueFormat={costFormat}
699
- >
700
- <ComposedChart.XAxis dataKey="customerName" />
701
- <ComposedChart.YAxis domain={[0, 'auto']} />
702
- <ComposedChart.Tooltip />
703
- <ComposedChart.Legend />
704
- {/* These service keys must match the columns returned by customerServiceMix. */}
705
- <ComposedChart.Bar dataKey="Compute" name="Compute" stackId="cost" />
706
- <ComposedChart.Bar
707
- dataKey="Storage"
708
- name="Storage"
709
- stackId="cost"
710
- fill="var(--atbl-chart-2)"
711
- />
712
- <ComposedChart.Bar
713
- dataKey="Networking"
714
- name="Networking"
715
- stackId="cost"
716
- fill="var(--atbl-chart-3)"
717
- />
718
- <ComposedChart.Bar
719
- dataKey="Logging"
720
- name="Logging"
721
- stackId="cost"
722
- fill="var(--atbl-chart-4)"
723
- />
724
- </ComposedChart>
110
+ <BarChart
111
+ ariaLabel="Sample counts by group"
112
+ unit="samples"
113
+ valueFormat={{ kind: 'count' }}
114
+ showYAxis
115
+ scrollToEnd={false}
116
+ items={rows.map(row => ({
117
+ id: row.groupName,
118
+ label: row.groupName,
119
+ value: row.sampleCount,
120
+ }))}
121
+ />
725
122
  )}
726
123
  </VisualizationWidget>
727
124
  ));
125
+
728
126
  function App() {
729
127
  return (
730
- <DataApp view={servicesView} details={[customersDetail]}>
731
- <Stack>
732
- <DataSection content={totalContent} label="Cost summary" />
733
- <Grid columns={2}>
734
- <DataSection content={trendContent} label="Cost trend" />
735
- <DataSection content={breakdownContent} label="Cost overview" />
736
- </Grid>
737
- <DataSection content={mixContent} label="Customer composition" />
738
- </Stack>
128
+ <DataApp view={sampleCountsView} datasets={[sampleCounts]}>
129
+ <DataSection content={countsContent} />
739
130
  </DataApp>
740
131
  );
741
132
  }