@altertable/data-app-examples 0.77.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 (37) 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 +76 -138
  6. package/templates/starter-finding-data-app/index.tsx +379 -117
  7. package/templates/starter-local-data-app/AGENTS.md +9 -9
  8. package/templates/starter-local-data-app/README.md +11 -5
  9. package/templates/starter-local-data-app/app.ts +25 -21
  10. package/templates/starter-local-data-app/package.json +5 -5
  11. package/templates/starter-local-data-app/src/App.tsx +54 -4
  12. package/templates/starter-local-data-app/src/data-context.ts +8 -13
  13. package/templates/starter-local-data-app/src/filters.ts +14 -0
  14. package/templates/starter-local-data-app/src/main.tsx +3 -3
  15. package/templates/starter-local-data-app/src/operations.ts +14 -5
  16. package/templates/starter-local-data-app/src/server.ts +1 -2
  17. package/templates/starter-local-finding-data-app/AGENTS.md +1 -1
  18. package/templates/starter-local-finding-data-app/README.md +3 -4
  19. package/templates/starter-local-finding-data-app/app.ts +29 -11
  20. package/templates/starter-local-finding-data-app/package.json +5 -5
  21. package/templates/starter-local-finding-data-app/src/App.tsx +237 -56
  22. package/templates/starter-local-finding-data-app/src/data-context.ts +14 -11
  23. package/templates/starter-local-finding-data-app/src/filters.ts +29 -11
  24. package/templates/starter-local-finding-data-app/src/main.tsx +3 -3
  25. package/templates/starter-local-finding-data-app/src/operations.ts +80 -34
  26. package/templates/starter-local-finding-data-app/src/server.ts +4 -2
  27. package/templates/starter-local-metric-data-app/AGENTS.md +1 -1
  28. package/templates/starter-local-metric-data-app/README.md +3 -4
  29. package/templates/starter-local-metric-data-app/app.ts +9 -6
  30. package/templates/starter-local-metric-data-app/package.json +5 -5
  31. package/templates/starter-local-metric-data-app/src/App.tsx +25 -30
  32. package/templates/starter-local-metric-data-app/src/data-context.ts +9 -9
  33. package/templates/starter-local-metric-data-app/src/filters.ts +2 -3
  34. package/templates/starter-local-metric-data-app/src/main.tsx +3 -3
  35. package/templates/starter-local-metric-data-app/src/operations.ts +6 -14
  36. package/templates/starter-local-metric-data-app/src/server.ts +4 -2
  37. package/templates/starter-metric-data-app/index.tsx +49 -63
@@ -1,11 +1,11 @@
1
1
  # Local metric data app starter
2
2
 
3
3
  Use `node_modules/@altertable/data-app/docs/app-authoring.md` for this SDK version.
4
- Otherwise, read the [version-matched authoring recipe](https://github.com/altertable-ai/data-app/blob/v0.77.0/docs/app-authoring.md). <!-- x-release-please-version -->
4
+ Otherwise, read the [version-matched authoring recipe](https://github.com/altertable-ai/data-app/blob/v0.79.0/docs/app-authoring.md). <!-- x-release-please-version -->
5
5
  See [AGENTS.md](AGENTS.md) for app-owned files.
6
6
 
7
7
  The example queries require the seeded sample data described in the
8
- [local preview guide](https://github.com/altertable-ai/data-app/blob/v0.77.0/docs/local-data-apps.md#preview-the-use-case-starters). <!-- x-release-please-version -->
8
+ [local preview guide](https://github.com/altertable-ai/data-app/blob/v0.79.0/docs/local-data-apps.md#preview-the-starters). <!-- x-release-please-version -->
9
9
  Use that mock for development, or replace the example queries with verified data
10
10
  in your lakehouse. The starter does not install a mock or create demo tables.
11
11
 
@@ -35,8 +35,7 @@ specified by the app brief. Change identity, appearance, and queries in `app.ts`
35
35
  bun run check
36
36
  ```
37
37
 
38
- `bun run check` includes the build, which writes browser assets to `dist/`. Hosting them requires an authorized
39
- `/api/data` backend; the local adapter does not authenticate hosted viewers.
38
+ `bun run check` includes the build, which writes browser assets to `dist/`. Hosted apps require an authorized query bridge; the local adapter does not authenticate hosted viewers.
40
39
 
41
40
  ## License
42
41
 
@@ -1,9 +1,12 @@
1
1
  import { defineDataApp } from '@altertable/data-app';
2
2
  export const dataApp = defineDataApp({
3
+ // Replace the demo title, description, and scope labels with the app's identity.
3
4
  title: 'Sample metric',
4
- description: 'Fixture counts by group; replace with the requested metric.',
5
+ description: 'Explore sample volume across groups and segments.',
5
6
  scope: { organization: 'demo', environment: 'sample' },
6
7
  appearance: { theme: 'system' },
8
+ // starter_sample_counts is the seeded semantic view for fictional sample counts.
9
+ // Replace these queries with verified sources before publishing.
7
10
  queries: {
8
11
  sampleCountsBySegment: {
9
12
  projections: {
@@ -13,10 +16,10 @@ export const dataApp = defineDataApp({
13
16
  statement: `
14
17
  SELECT segment_name, sample_count FROM SEMANTIC_VIEW(
15
18
  starter_sample_counts DIMENSIONS samples.segment_name METRICS samples.sample_count
16
- WHERE $groupName = '' OR samples.group_name = $groupName
17
- ) ORDER BY segment_name LIMIT $limit`,
19
+ WHERE $groupName = 'all' OR samples.group_name = $groupName
20
+ ) ORDER BY sample_count DESC, segment_name LIMIT $limit`,
18
21
  params: {
19
- groupName: { type: 'string', defaultValue: '' },
22
+ groupName: { type: 'string', defaultValue: 'all' },
20
23
  limit: { type: 'number', defaultValue: 10 },
21
24
  },
22
25
  },
@@ -28,10 +31,10 @@ SELECT segment_name, sample_count FROM SEMANTIC_VIEW(
28
31
  statement: `
29
32
  SELECT group_name, sample_count FROM SEMANTIC_VIEW(
30
33
  starter_sample_counts DIMENSIONS samples.group_name METRICS samples.sample_count
31
- WHERE $groupName = '' OR samples.group_name = $groupName
34
+ WHERE $groupName = 'all' OR samples.group_name = $groupName
32
35
  ) ORDER BY group_name LIMIT $limit`,
33
36
  params: {
34
- groupName: { type: 'string', defaultValue: '' },
37
+ groupName: { type: 'string', defaultValue: 'all' },
35
38
  limit: { type: 'number', defaultValue: 10 },
36
39
  },
37
40
  },
@@ -8,18 +8,18 @@
8
8
  },
9
9
  "scripts": {
10
10
  "typecheck": "tsc --noEmit",
11
- "lint": "oxlint --type-aware src",
11
+ "lint": "oxlint --type-aware src app.ts",
12
12
  "format": "oxfmt src app.ts",
13
13
  "format:check": "oxfmt --check src app.ts",
14
14
  "dev": "bun --hot src/server.ts",
15
15
  "build": "bun run typecheck && bun build src/index.html --outdir=dist --production",
16
16
  "check": "bun run lint && bun run format:check && bun run build",
17
- "lint:fix": "oxlint --type-aware --fix src"
17
+ "lint:fix": "oxlint --type-aware --fix src app.ts"
18
18
  },
19
19
  "dependencies": {
20
- "@altertable/data-app": "0.77.0",
21
- "@altertable/data-app-bun": "0.77.0",
22
- "@altertable/data-app-react": "0.77.0",
20
+ "@altertable/data-app": "0.79.0",
21
+ "@altertable/data-app-bun": "0.79.0",
22
+ "@altertable/data-app-react": "0.79.0",
23
23
  "react": "19.3.1",
24
24
  "react-dom": "19.3.1"
25
25
  },
@@ -3,21 +3,19 @@ import {
3
3
  DataApp,
4
4
  DataSection,
5
5
  VisualizationWidget,
6
- Stack,
6
+ Ranking,
7
+ Grid,
8
+ GridItem,
7
9
  } from '@altertable/data-app-react';
8
10
  import { BarChart } from '@altertable/data-app-react/ui';
9
- import { createDataClient } from '@altertable/data-app/client';
11
+ import { formatCount } from '@altertable/data-app/format';
10
12
 
11
13
  import { sampleDataContext } from '#app/data-context.ts';
12
- import { operationFilters } from '#app/filters.ts';
13
- import type { operations } from '#app/operations.ts';
14
- const { defineView } = createDataHooks(
15
- createDataClient<typeof operations>({ filters: operationFilters })
16
- );
14
+ import { operations } from '#app/operations.ts';
15
+ const { defineView } = createDataHooks(operations.createDataClient());
17
16
  const sampleCountsView = defineView({
18
17
  dataContext: sampleDataContext,
19
18
  operation: 'sampleCountsByGroup',
20
- isEmpty: rows => rows.length === 0,
21
19
  emptyFallback: {
22
20
  title: 'No matching groups',
23
21
  description: 'No observations are available for this query.',
@@ -25,11 +23,10 @@ const sampleCountsView = defineView({
25
23
  });
26
24
  const sampleCounts = sampleCountsView.dataset({
27
25
  name: 'Sample counts',
28
- select: rows => rows,
29
26
  rowKey: row => row.groupName,
30
27
  columns: {
31
- groupName: { label: 'Group', value: row => row.groupName },
32
- sampleCount: { value: row => row.sampleCount, format: { kind: 'count' } },
28
+ groupName: { label: 'Group' },
29
+ sampleCount: { format: { kind: 'count' } },
33
30
  },
34
31
  evidence: {
35
32
  id: 'counts-by-group',
@@ -39,7 +36,6 @@ const sampleCounts = sampleCountsView.dataset({
39
36
  const segmentCountsView = defineView({
40
37
  dataContext: sampleDataContext,
41
38
  operation: 'sampleCountsBySegment',
42
- isEmpty: rows => rows.length === 0,
43
39
  emptyFallback: {
44
40
  title: 'No matching segments',
45
41
  description: 'No observations are available for this query.',
@@ -47,14 +43,14 @@ const segmentCountsView = defineView({
47
43
  });
48
44
  const segmentCounts = segmentCountsView.dataset({
49
45
  name: 'Counts by segment',
50
- select: rows => rows,
51
46
  rowKey: row => row.segmentName,
52
47
  columns: {
53
- segmentName: { label: 'Segment', value: row => row.segmentName },
54
- sampleCount: { value: row => row.sampleCount, format: { kind: 'count' } },
48
+ segmentName: { label: 'Segment' },
49
+ sampleCount: { format: { kind: 'count' } },
55
50
  },
56
51
  evidence: { id: 'counts-by-segment', glossaryIds: ['sampleCount'] },
57
52
  });
53
+ // Selecting a group applies the shared group filter to both charts.
58
54
  const groupActions = sampleCounts.actions(
59
55
  action => ({
60
56
  drill: action.filter({
@@ -65,13 +61,11 @@ const groupActions = sampleCounts.actions(
65
61
  }),
66
62
  { primary: 'drill' }
67
63
  );
68
- // Keep only the breakdowns and interactions relevant to the requested metric.
69
64
  const groupContent = sampleCountsView.content(result => (
70
65
  <VisualizationWidget
71
66
  dataset={sampleCounts}
72
67
  source={result}
73
- title="Sample count"
74
- description="Select a group to filter both charts; choose All groups to reset."
68
+ title="Samples by group"
75
69
  actions={groupActions}
76
70
  >
77
71
  {(rows, actions) => (
@@ -81,9 +75,10 @@ const groupContent = sampleCountsView.content(result => (
81
75
  items={rows.map(row => ({
82
76
  ...row,
83
77
  id: row.groupName,
84
- label: row.groupName,
78
+ label: `${row.groupName} · ${formatCount(row.sampleCount, { compact: true })}`,
85
79
  value: row.sampleCount,
86
80
  }))}
81
+ horizontalGrid={false}
87
82
  itemActions={actions}
88
83
  />
89
84
  )}
@@ -94,19 +89,15 @@ const segmentContent = segmentCountsView.content(result => (
94
89
  dataset={segmentCounts}
95
90
  source={result}
96
91
  title="Samples by segment"
97
- description="Segment breakdown for the selected group scope."
98
92
  >
99
- {(rows, actions) => (
100
- <BarChart
101
- ariaLabel="Sample counts by segment"
102
- unit="samples"
93
+ {rows => (
94
+ <Ranking
95
+ aria-label="Sample counts by segment"
103
96
  items={rows.map(row => ({
104
- ...row,
105
97
  id: row.segmentName,
106
98
  label: row.segmentName,
107
99
  value: row.sampleCount,
108
100
  }))}
109
- itemActions={actions}
110
101
  />
111
102
  )}
112
103
  </VisualizationWidget>
@@ -114,10 +105,14 @@ const segmentContent = segmentCountsView.content(result => (
114
105
  export function App() {
115
106
  return (
116
107
  <DataApp view={sampleCountsView} showToolbar={false}>
117
- <Stack>
118
- <DataSection content={groupContent} label="Sample count" />
119
- <DataSection content={segmentContent} label="Samples by segment" />
120
- </Stack>
108
+ <Grid columns={3}>
109
+ <GridItem span={2}>
110
+ <DataSection content={groupContent} />
111
+ </GridItem>
112
+ <GridItem>
113
+ <DataSection content={segmentContent} />
114
+ </GridItem>
115
+ </Grid>
121
116
  </DataApp>
122
117
  );
123
118
  }
@@ -1,18 +1,18 @@
1
1
  import { createDataContext } from '@altertable/data-app-react';
2
- const queryNames = {
3
- sampleCountsByGroup: 'sampleCountsByGroup',
4
- sampleCountsBySegment: 'sampleCountsBySegment',
5
- } as const;
6
- export const sampleDataContext = createDataContext(queryNames)({
2
+
3
+ import { dataApp } from '#config';
4
+
5
+ export const sampleDataContext = createDataContext(dataApp.queryNames)({
7
6
  description:
8
- 'The starter_sample_counts semantic view measures fictional samples by group and segment. Replace it with the requested semantic metric before publishing.',
7
+ 'The starter_sample_counts semantic view measures fictional sample volume by group and segment. The source has no time dimension.',
9
8
  glossary: {
10
9
  sampleCount: {
11
10
  term: 'Sample count',
12
- definition: 'A fixture value: Alpha is 2,200,000 and Beta is 600,000.',
11
+ definition:
12
+ 'Sum of recorded sample counts in the selected group scope. Additive across groups and segments.',
13
13
  queryNames: [
14
- queryNames.sampleCountsByGroup,
15
- queryNames.sampleCountsBySegment,
14
+ dataApp.queryNames.sampleCountsByGroup,
15
+ dataApp.queryNames.sampleCountsBySegment,
16
16
  ],
17
17
  },
18
18
  },
@@ -1,7 +1,7 @@
1
1
  import { choiceFilter } from '@altertable/data-app/contract';
2
2
 
3
- // Declare each filter once in this browser-safe module: operations read them on
4
- // the server, and the browser client renders their controls.
3
+ // Reuse this group filter in both operations so one selection updates both charts.
4
+ // The queries treat 'all' as every group.
5
5
  const groupName = choiceFilter({
6
6
  key: 'group',
7
7
  label: 'Group',
@@ -13,7 +13,6 @@ const groupName = choiceFilter({
13
13
  ],
14
14
  });
15
15
 
16
- /** The filters each operation reads. */
17
16
  export const operationFilters = {
18
17
  sampleCountsByGroup: { groupName },
19
18
  sampleCountsBySegment: { groupName },
@@ -1,8 +1,8 @@
1
- import { injectDataAppStyles, mountDataApp } from '@altertable/data-app-react';
1
+ import { mountDataApp } from '@altertable/data-app-react';
2
+ import { installLocalQueryLakehouse } from '@altertable/data-app/client';
2
3
 
3
4
  import { App } from '#app/App.tsx';
4
5
  import { dataApp } from '#config';
5
6
 
6
- injectDataAppStyles();
7
-
7
+ installLocalQueryLakehouse();
8
8
  mountDataApp({ app: dataApp, component: App });
@@ -3,18 +3,12 @@ import { parseCount } from '@altertable/data-app/contract';
3
3
  import { operationFilters } from '#app/filters.ts';
4
4
  import { dataApp } from '#config';
5
5
 
6
- /** The fixture queries read an empty group name as every group. */
7
- function queryGroup(groupName: string) {
8
- return groupName === 'all' ? '' : groupName;
9
- }
10
- export const operations = {
6
+ export const operations = dataApp.defineOperations({
11
7
  sampleCountsByGroup: dataApp.defineOperation({
12
8
  filters: operationFilters.sampleCountsByGroup,
13
- policy: { maxQueryRows: 10, maxDurationMs: 15000 },
9
+ policy: { maxQueryRows: 10 },
14
10
  async run({ query }, { groupName }) {
15
- const queryResult = await query('sampleCountsByGroup', {
16
- groupName: queryGroup(groupName),
17
- });
11
+ const queryResult = await query('sampleCountsByGroup', { groupName });
18
12
  return queryResult.rows.map(
19
13
  (row): { groupName: 'Alpha' | 'Beta'; sampleCount: number } => {
20
14
  if (row.group_name !== 'Alpha' && row.group_name !== 'Beta')
@@ -29,15 +23,13 @@ export const operations = {
29
23
  }),
30
24
  sampleCountsBySegment: dataApp.defineOperation({
31
25
  filters: operationFilters.sampleCountsBySegment,
32
- policy: { maxQueryRows: 10, maxDurationMs: 15000 },
26
+ policy: { maxQueryRows: 10 },
33
27
  async run({ query }, { groupName }) {
34
- const queryResult = await query('sampleCountsBySegment', {
35
- groupName: queryGroup(groupName),
36
- });
28
+ const queryResult = await query('sampleCountsBySegment', { groupName });
37
29
  return queryResult.rows.map(row => ({
38
30
  segmentName: row.segment_name,
39
31
  sampleCount: parseCount(row.sample_count),
40
32
  }));
41
33
  },
42
34
  }),
43
- };
35
+ });
@@ -1,7 +1,9 @@
1
1
  import { serveLocalApp } from '@altertable/data-app-bun';
2
2
 
3
3
  import page from '#app/index.html';
4
- import { operations } from '#app/operations.ts';
5
4
  import { dataApp } from '#config';
6
5
 
7
- serveLocalApp({ page, operations, title: dataApp.title });
6
+ serveLocalApp({
7
+ page,
8
+ app: dataApp,
9
+ });
@@ -1,24 +1,26 @@
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
4
  createDataHooks,
9
5
  DataApp,
10
6
  DataSection,
11
7
  VisualizationWidget,
12
- Stack,
8
+ Ranking,
9
+ Grid,
10
+ GridItem,
11
+ mountDataApp,
13
12
  } from '@altertable/data-app-react';
14
13
  import { BarChart } from '@altertable/data-app-react/ui';
15
- import { createDataClient } from '@altertable/data-app/client';
16
14
  import { choiceFilter, parseCount } from '@altertable/data-app/contract';
17
- const dataApp = defineDataApp({
15
+ import { formatCount } from '@altertable/data-app/format';
16
+ export const dataApp = defineDataApp({
17
+ // Replace the demo title, description, and scope labels with the app's identity.
18
18
  title: 'Sample metric',
19
- description: 'Fixture counts by group; replace with the requested metric.',
19
+ description: 'Explore sample volume across groups and segments.',
20
20
  scope: { organization: 'demo', environment: 'sample' },
21
21
  appearance: { theme: 'system' },
22
+ // starter_sample_counts is the seeded semantic view for fictional sample counts.
23
+ // Replace these queries with verified sources before publishing.
22
24
  queries: {
23
25
  sampleCountsBySegment: {
24
26
  projections: {
@@ -28,10 +30,10 @@ const dataApp = defineDataApp({
28
30
  statement: `
29
31
  SELECT segment_name, sample_count FROM SEMANTIC_VIEW(
30
32
  starter_sample_counts DIMENSIONS samples.segment_name METRICS samples.sample_count
31
- WHERE $groupName = '' OR samples.group_name = $groupName
32
- ) ORDER BY segment_name LIMIT $limit`,
33
+ WHERE $groupName = 'all' OR samples.group_name = $groupName
34
+ ) ORDER BY sample_count DESC, segment_name LIMIT $limit`,
33
35
  params: {
34
- groupName: { type: 'string', defaultValue: '' },
36
+ groupName: { type: 'string', defaultValue: 'all' },
35
37
  limit: { type: 'number', defaultValue: 10 },
36
38
  },
37
39
  },
@@ -43,17 +45,17 @@ SELECT segment_name, sample_count FROM SEMANTIC_VIEW(
43
45
  statement: `
44
46
  SELECT group_name, sample_count FROM SEMANTIC_VIEW(
45
47
  starter_sample_counts DIMENSIONS samples.group_name METRICS samples.sample_count
46
- WHERE $groupName = '' OR samples.group_name = $groupName
48
+ WHERE $groupName = 'all' OR samples.group_name = $groupName
47
49
  ) ORDER BY group_name LIMIT $limit`,
48
50
  params: {
49
- groupName: { type: 'string', defaultValue: '' },
51
+ groupName: { type: 'string', defaultValue: 'all' },
50
52
  limit: { type: 'number', defaultValue: 10 },
51
53
  },
52
54
  },
53
55
  },
54
56
  });
55
- // Declare each filter once; operations list the filters they read, and views,
56
- // controls, and scope derive from them.
57
+ // Reuse this group filter in both operations so one selection updates both charts.
58
+ // The queries treat 'all' as every group.
57
59
  const groupName = choiceFilter({
58
60
  key: 'group',
59
61
  label: 'Group',
@@ -64,18 +66,12 @@ const groupName = choiceFilter({
64
66
  { id: 'Beta', label: 'Beta' },
65
67
  ],
66
68
  });
67
- /** The fixture queries read an empty group name as every group. */
68
- function queryGroup(groupName: string) {
69
- return groupName === 'all' ? '' : groupName;
70
- }
71
- const operations = {
69
+ export const operations = dataApp.defineOperations({
72
70
  sampleCountsByGroup: dataApp.defineOperation({
73
71
  filters: { groupName },
74
- policy: { maxQueryRows: 10, maxDurationMs: 15000 },
72
+ policy: { maxQueryRows: 10 },
75
73
  async run({ query }, { groupName }) {
76
- const queryResult = await query('sampleCountsByGroup', {
77
- groupName: queryGroup(groupName),
78
- });
74
+ const queryResult = await query('sampleCountsByGroup', { groupName });
79
75
  return queryResult.rows.map(
80
76
  (row): { groupName: 'Alpha' | 'Beta'; sampleCount: number } => {
81
77
  if (row.group_name !== 'Alpha' && row.group_name !== 'Beta')
@@ -90,41 +86,35 @@ const operations = {
90
86
  }),
91
87
  sampleCountsBySegment: dataApp.defineOperation({
92
88
  filters: { groupName },
93
- policy: { maxQueryRows: 10, maxDurationMs: 15000 },
89
+ policy: { maxQueryRows: 10 },
94
90
  async run({ query }, { groupName }) {
95
- const queryResult = await query('sampleCountsBySegment', {
96
- groupName: queryGroup(groupName),
97
- });
91
+ const queryResult = await query('sampleCountsBySegment', { groupName });
98
92
  return queryResult.rows.map(row => ({
99
93
  segmentName: row.segment_name,
100
94
  sampleCount: parseCount(row.sample_count),
101
95
  }));
102
96
  },
103
97
  }),
104
- };
105
- const queryNames = {
106
- ...operations.sampleCountsByGroup.queryNames,
107
- ...operations.sampleCountsBySegment.queryNames,
108
- };
109
- const sampleDataContext = createDataContext(queryNames)({
98
+ });
99
+ const sampleDataContext = createDataContext(dataApp.queryNames)({
110
100
  description:
111
- 'The starter_sample_counts semantic view measures fictional samples by group and segment. Replace it with the requested semantic metric before publishing.',
101
+ 'The starter_sample_counts semantic view measures fictional sample volume by group and segment. The source has no time dimension.',
112
102
  glossary: {
113
103
  sampleCount: {
114
104
  term: 'Sample count',
115
- definition: 'A fixture value: Alpha is 2,200,000 and Beta is 600,000.',
105
+ definition:
106
+ 'Sum of recorded sample counts in the selected group scope. Additive across groups and segments.',
116
107
  queryNames: [
117
- queryNames.sampleCountsByGroup,
118
- queryNames.sampleCountsBySegment,
108
+ dataApp.queryNames.sampleCountsByGroup,
109
+ dataApp.queryNames.sampleCountsBySegment,
119
110
  ],
120
111
  },
121
112
  },
122
113
  });
123
- const { defineView } = createDataHooks(createDataClient({ operations }));
114
+ const { defineView } = createDataHooks(operations.createDataClient());
124
115
  const sampleCountsView = defineView({
125
116
  dataContext: sampleDataContext,
126
117
  operation: 'sampleCountsByGroup',
127
- isEmpty: rows => rows.length === 0,
128
118
  emptyFallback: {
129
119
  title: 'No matching groups',
130
120
  description: 'No observations are available for this query.',
@@ -132,11 +122,10 @@ const sampleCountsView = defineView({
132
122
  });
133
123
  const sampleCounts = sampleCountsView.dataset({
134
124
  name: 'Sample counts',
135
- select: rows => rows,
136
125
  rowKey: row => row.groupName,
137
126
  columns: {
138
- groupName: { label: 'Group', value: row => row.groupName },
139
- sampleCount: { value: row => row.sampleCount, format: { kind: 'count' } },
127
+ groupName: { label: 'Group' },
128
+ sampleCount: { format: { kind: 'count' } },
140
129
  },
141
130
  evidence: {
142
131
  id: 'counts-by-group',
@@ -146,7 +135,6 @@ const sampleCounts = sampleCountsView.dataset({
146
135
  const segmentCountsView = defineView({
147
136
  dataContext: sampleDataContext,
148
137
  operation: 'sampleCountsBySegment',
149
- isEmpty: rows => rows.length === 0,
150
138
  emptyFallback: {
151
139
  title: 'No matching segments',
152
140
  description: 'No observations are available for this query.',
@@ -154,14 +142,14 @@ const segmentCountsView = defineView({
154
142
  });
155
143
  const segmentCounts = segmentCountsView.dataset({
156
144
  name: 'Counts by segment',
157
- select: rows => rows,
158
145
  rowKey: row => row.segmentName,
159
146
  columns: {
160
- segmentName: { label: 'Segment', value: row => row.segmentName },
161
- sampleCount: { value: row => row.sampleCount, format: { kind: 'count' } },
147
+ segmentName: { label: 'Segment' },
148
+ sampleCount: { format: { kind: 'count' } },
162
149
  },
163
150
  evidence: { id: 'counts-by-segment', glossaryIds: ['sampleCount'] },
164
151
  });
152
+ // Selecting a group applies the shared group filter to both charts.
165
153
  const groupActions = sampleCounts.actions(
166
154
  action => ({
167
155
  drill: action.filter({
@@ -172,13 +160,11 @@ const groupActions = sampleCounts.actions(
172
160
  }),
173
161
  { primary: 'drill' }
174
162
  );
175
- // Keep only the breakdowns and interactions relevant to the requested metric.
176
163
  const groupContent = sampleCountsView.content(result => (
177
164
  <VisualizationWidget
178
165
  dataset={sampleCounts}
179
166
  source={result}
180
- title="Sample count"
181
- description="Select a group to filter both charts; choose All groups to reset."
167
+ title="Samples by group"
182
168
  actions={groupActions}
183
169
  >
184
170
  {(rows, actions) => (
@@ -188,9 +174,10 @@ const groupContent = sampleCountsView.content(result => (
188
174
  items={rows.map(row => ({
189
175
  ...row,
190
176
  id: row.groupName,
191
- label: row.groupName,
177
+ label: `${row.groupName} · ${formatCount(row.sampleCount, { compact: true })}`,
192
178
  value: row.sampleCount,
193
179
  }))}
180
+ horizontalGrid={false}
194
181
  itemActions={actions}
195
182
  />
196
183
  )}
@@ -201,19 +188,15 @@ const segmentContent = segmentCountsView.content(result => (
201
188
  dataset={segmentCounts}
202
189
  source={result}
203
190
  title="Samples by segment"
204
- description="Segment breakdown for the selected group scope."
205
191
  >
206
- {(rows, actions) => (
207
- <BarChart
208
- ariaLabel="Sample counts by segment"
209
- unit="samples"
192
+ {rows => (
193
+ <Ranking
194
+ aria-label="Sample counts by segment"
210
195
  items={rows.map(row => ({
211
- ...row,
212
196
  id: row.segmentName,
213
197
  label: row.segmentName,
214
198
  value: row.sampleCount,
215
199
  }))}
216
- itemActions={actions}
217
200
  />
218
201
  )}
219
202
  </VisualizationWidget>
@@ -221,12 +204,15 @@ const segmentContent = segmentCountsView.content(result => (
221
204
  function App() {
222
205
  return (
223
206
  <DataApp view={sampleCountsView} showToolbar={false}>
224
- <Stack>
225
- <DataSection content={groupContent} label="Sample count" />
226
- <DataSection content={segmentContent} label="Samples by segment" />
227
- </Stack>
207
+ <Grid columns={3}>
208
+ <GridItem span={2}>
209
+ <DataSection content={groupContent} />
210
+ </GridItem>
211
+ <GridItem>
212
+ <DataSection content={segmentContent} />
213
+ </GridItem>
214
+ </Grid>
228
215
  </DataApp>
229
216
  );
230
217
  }
231
- injectDataAppStyles();
232
218
  mountDataApp({ app: dataApp, component: App });