@altertable/data-app-examples 0.75.0 → 0.77.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/README.md +8 -8
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +4 -4
- package/package.json +13 -1
- package/templates/starter-data-app/index.tsx +60 -57
- package/templates/starter-finding-data-app/index.tsx +279 -116
- package/templates/starter-local-data-app/AGENTS.md +9 -9
- package/templates/starter-local-data-app/README.md +1 -1
- package/templates/starter-local-data-app/package.json +3 -3
- package/templates/starter-local-finding-data-app/AGENTS.md +9 -9
- package/templates/starter-local-finding-data-app/README.md +2 -2
- package/templates/starter-local-finding-data-app/app.ts +53 -8
- package/templates/starter-local-finding-data-app/package.json +3 -3
- package/templates/starter-local-finding-data-app/src/App.tsx +125 -97
- package/templates/starter-local-finding-data-app/src/data-context.ts +10 -4
- package/templates/starter-local-finding-data-app/src/filters.ts +48 -0
- package/templates/starter-local-finding-data-app/src/operations.ts +58 -7
- package/templates/starter-local-metric-data-app/AGENTS.md +9 -9
- package/templates/starter-local-metric-data-app/README.md +2 -2
- package/templates/starter-local-metric-data-app/package.json +3 -3
- package/templates/starter-local-metric-data-app/src/App.tsx +66 -67
- package/templates/starter-local-metric-data-app/src/filters.ts +20 -0
- package/templates/starter-local-metric-data-app/src/operations.ts +32 -39
- package/templates/starter-metric-data-app/index.tsx +110 -107
|
@@ -2,121 +2,149 @@ import {
|
|
|
2
2
|
createDataHooks,
|
|
3
3
|
DataApp,
|
|
4
4
|
DataSection,
|
|
5
|
-
|
|
6
|
-
DataValue,
|
|
7
|
-
TableWidget,
|
|
8
|
-
Ranking,
|
|
5
|
+
MetricWidget,
|
|
9
6
|
Stack,
|
|
10
|
-
|
|
7
|
+
TableWidget,
|
|
8
|
+
VisualizationWidget,
|
|
11
9
|
} from '@altertable/data-app-react';
|
|
10
|
+
import { BarChart, ComposedChart } from '@altertable/data-app-react/ui';
|
|
12
11
|
import { createDataClient } from '@altertable/data-app/client';
|
|
13
12
|
|
|
14
13
|
import { sampleDataContext } from '#app/data-context.ts';
|
|
14
|
+
import { operationFilters } from '#app/filters.ts';
|
|
15
15
|
import type { operations } from '#app/operations.ts';
|
|
16
|
-
const {
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const { defineView } = createDataHooks(
|
|
17
|
+
createDataClient<typeof operations>({ filters: operationFilters })
|
|
18
|
+
);
|
|
19
|
+
const count = { kind: 'count' } as const;
|
|
20
|
+
const emptyFallback = {
|
|
21
|
+
title: 'No samples in this period',
|
|
22
|
+
description: 'No observations are available for this period.',
|
|
23
|
+
};
|
|
24
|
+
const totalView = defineView({
|
|
19
25
|
dataContext: sampleDataContext,
|
|
20
|
-
operation: '
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
operation: 'sampleTotal',
|
|
27
|
+
});
|
|
28
|
+
const totalSamples = totalView.metric(
|
|
29
|
+
{
|
|
30
|
+
id: 'total-samples',
|
|
31
|
+
label: 'Samples',
|
|
32
|
+
glossaryId: 'sampleCount',
|
|
33
|
+
format: count,
|
|
26
34
|
},
|
|
35
|
+
total => ({
|
|
36
|
+
current: total.current,
|
|
37
|
+
...(total.previous !== null && { previous: total.previous }),
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
const trendView = defineView({
|
|
41
|
+
dataContext: sampleDataContext,
|
|
42
|
+
operation: 'samplesOverTime',
|
|
43
|
+
isEmpty: rows => rows.length === 0,
|
|
44
|
+
emptyFallback,
|
|
27
45
|
});
|
|
28
|
-
const
|
|
29
|
-
name: '
|
|
46
|
+
const trend = trendView.dataset({
|
|
47
|
+
name: 'Samples over time',
|
|
30
48
|
select: rows => rows,
|
|
31
|
-
rowKey: row => row.
|
|
49
|
+
rowKey: row => row.periodStart,
|
|
32
50
|
columns: {
|
|
33
|
-
|
|
34
|
-
sampleCount: { value: row => row.sampleCount, format:
|
|
35
|
-
},
|
|
36
|
-
evidence: {
|
|
37
|
-
id: 'counts-by-group',
|
|
38
|
-
glossaryIds: ['sampleCount'],
|
|
51
|
+
periodStart: { label: 'Period start', value: row => row.periodStart },
|
|
52
|
+
sampleCount: { value: row => row.sampleCount, format: count },
|
|
39
53
|
},
|
|
54
|
+
evidence: { id: 'samples-over-time', glossaryIds: ['sampleCount'] },
|
|
40
55
|
});
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
const memberView = defineView({
|
|
57
|
+
dataContext: sampleDataContext,
|
|
58
|
+
operation: 'samplesByMember',
|
|
59
|
+
isEmpty: rows => rows.length === 0,
|
|
60
|
+
emptyFallback,
|
|
61
|
+
});
|
|
62
|
+
const byMember = memberView.dataset({
|
|
63
|
+
name: 'Samples by member',
|
|
64
|
+
select: rows => rows,
|
|
65
|
+
rowKey: row => row.member,
|
|
66
|
+
columns: {
|
|
67
|
+
member: { label: 'Member', value: row => row.member },
|
|
68
|
+
sampleCount: { value: row => row.sampleCount, format: count },
|
|
47
69
|
},
|
|
48
|
-
|
|
49
|
-
);
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
70
|
+
evidence: { id: 'samples-by-member', glossaryIds: ['sampleCount'] },
|
|
71
|
+
});
|
|
72
|
+
const rowsView = defineView({
|
|
73
|
+
dataContext: sampleDataContext,
|
|
74
|
+
operation: 'sampleRows',
|
|
75
|
+
isEmpty: rows => rows.length === 0,
|
|
76
|
+
emptyFallback,
|
|
77
|
+
});
|
|
78
|
+
const sampleRows = rowsView.dataset({
|
|
79
|
+
name: 'Samples',
|
|
80
|
+
select: rows => rows,
|
|
81
|
+
rowKey: row => `${row.periodStart}:${row.member}`,
|
|
82
|
+
columns: {
|
|
83
|
+
periodStart: { label: 'Period start', value: row => row.periodStart },
|
|
84
|
+
member: { label: 'Member', value: row => row.member },
|
|
85
|
+
sampleCount: { value: row => row.sampleCount, format: count },
|
|
56
86
|
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
<TableWidget
|
|
109
|
-
dataset={sampleCounts}
|
|
110
|
-
source={result}
|
|
111
|
-
title="Counts by group"
|
|
112
|
-
pagination={false}
|
|
113
|
-
/>
|
|
114
|
-
</Stack>
|
|
87
|
+
evidence: { id: 'samples', glossaryIds: ['sampleCount'] },
|
|
88
|
+
});
|
|
89
|
+
// The Finding's text is shown above the app; keep content to charts and captions.
|
|
90
|
+
const totalContent = totalView.content(result => (
|
|
91
|
+
<MetricWidget metric={totalSamples} source={result} />
|
|
92
|
+
));
|
|
93
|
+
const trendContent = trendView.content(result => (
|
|
94
|
+
<VisualizationWidget
|
|
95
|
+
dataset={trend}
|
|
96
|
+
source={result}
|
|
97
|
+
title="Samples over time"
|
|
98
|
+
description="Includes the previous period when comparison is on."
|
|
99
|
+
breakdown={trendView.breakdown('grain')}
|
|
100
|
+
>
|
|
101
|
+
{rows => (
|
|
102
|
+
<ComposedChart
|
|
103
|
+
ariaLabel="Samples over time"
|
|
104
|
+
data={rows}
|
|
105
|
+
valueFormat={count}
|
|
106
|
+
>
|
|
107
|
+
<ComposedChart.XAxis dataKey="periodStart" />
|
|
108
|
+
<ComposedChart.YAxis />
|
|
109
|
+
<ComposedChart.Line dataKey="sampleCount" name="Samples" />
|
|
110
|
+
<ComposedChart.Tooltip />
|
|
111
|
+
</ComposedChart>
|
|
112
|
+
)}
|
|
113
|
+
</VisualizationWidget>
|
|
114
|
+
));
|
|
115
|
+
const memberContent = memberView.content(result => (
|
|
116
|
+
<VisualizationWidget
|
|
117
|
+
dataset={byMember}
|
|
118
|
+
source={result}
|
|
119
|
+
title="Samples by member"
|
|
120
|
+
breakdown={memberView.breakdown('breakdown')}
|
|
121
|
+
>
|
|
122
|
+
{rows => (
|
|
123
|
+
<BarChart
|
|
124
|
+
ariaLabel="Samples by member"
|
|
125
|
+
unit="samples"
|
|
126
|
+
items={rows.map(row => ({
|
|
127
|
+
...row,
|
|
128
|
+
id: row.member,
|
|
129
|
+
label: row.member,
|
|
130
|
+
value: row.sampleCount,
|
|
131
|
+
}))}
|
|
132
|
+
/>
|
|
133
|
+
)}
|
|
134
|
+
</VisualizationWidget>
|
|
135
|
+
));
|
|
136
|
+
const rowsContent = rowsView.content(result => (
|
|
137
|
+
<TableWidget dataset={sampleRows} source={result} title="Samples" />
|
|
115
138
|
));
|
|
116
139
|
export function App() {
|
|
117
140
|
return (
|
|
118
|
-
<DataApp view={
|
|
119
|
-
<
|
|
141
|
+
<DataApp view={totalView} showToolbar={false}>
|
|
142
|
+
<Stack>
|
|
143
|
+
<DataSection content={totalContent} />
|
|
144
|
+
<DataSection content={trendContent} />
|
|
145
|
+
<DataSection content={memberContent} />
|
|
146
|
+
<DataSection content={rowsContent} />
|
|
147
|
+
</Stack>
|
|
120
148
|
</DataApp>
|
|
121
149
|
);
|
|
122
150
|
}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { createDataContext } from '@altertable/data-app-react';
|
|
2
|
-
|
|
2
|
+
// The browser imports operations by type only, so name their queries here.
|
|
3
|
+
const queryNames = {
|
|
4
|
+
sampleTotal: 'sampleTotal',
|
|
5
|
+
samplesOverTime: 'samplesOverTime',
|
|
6
|
+
samplesByMember: 'samplesByMember',
|
|
7
|
+
sampleRows: 'sampleRows',
|
|
8
|
+
} as const;
|
|
3
9
|
export const sampleDataContext = createDataContext(queryNames)({
|
|
4
10
|
description:
|
|
5
|
-
'Fictional
|
|
11
|
+
'Fictional daily samples from starter_demo.daily_samples. Replace this evidence with the actual Finding queries.',
|
|
6
12
|
glossary: {
|
|
7
13
|
sampleCount: {
|
|
8
14
|
term: 'Sample count',
|
|
9
|
-
definition: '
|
|
10
|
-
queryNames:
|
|
15
|
+
definition: 'Fixture samples recorded per day, group, and segment.',
|
|
16
|
+
queryNames: Object.values(queryNames),
|
|
11
17
|
},
|
|
12
18
|
},
|
|
13
19
|
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dateTimeRangeFilter,
|
|
3
|
+
displayChoice,
|
|
4
|
+
} from '@altertable/data-app/contract';
|
|
5
|
+
|
|
6
|
+
// Declare each filter once in this browser-safe module: operations read them on
|
|
7
|
+
// the server, and the browser client renders their controls.
|
|
8
|
+
const findingPeriod = {
|
|
9
|
+
from: new Date('2026-03-09T00:00:00Z'),
|
|
10
|
+
to: new Date('2026-03-16T00:00:00Z'),
|
|
11
|
+
};
|
|
12
|
+
const period = dateTimeRangeFilter({
|
|
13
|
+
key: 'period',
|
|
14
|
+
defaultValue: findingPeriod,
|
|
15
|
+
minDate: '2026-01-05',
|
|
16
|
+
maxDate: '2026-03-29',
|
|
17
|
+
maxRangeDays: 28,
|
|
18
|
+
comparison: 'off',
|
|
19
|
+
presets: [{ label: 'Finding period', range: findingPeriod }],
|
|
20
|
+
});
|
|
21
|
+
const grain = displayChoice({
|
|
22
|
+
key: 'grain',
|
|
23
|
+
label: 'Grain',
|
|
24
|
+
defaultValue: 'day',
|
|
25
|
+
options: [
|
|
26
|
+
{ id: 'day', label: 'Day' },
|
|
27
|
+
{ id: 'week', label: 'Week' },
|
|
28
|
+
],
|
|
29
|
+
presentation: { control: 'widget' },
|
|
30
|
+
});
|
|
31
|
+
const breakdown = displayChoice({
|
|
32
|
+
key: 'breakdown',
|
|
33
|
+
label: 'Breakdown',
|
|
34
|
+
defaultValue: 'segment',
|
|
35
|
+
options: [
|
|
36
|
+
{ id: 'segment', label: 'Segment' },
|
|
37
|
+
{ id: 'group', label: 'Group' },
|
|
38
|
+
],
|
|
39
|
+
presentation: { control: 'widget' },
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/** The filters each operation reads. */
|
|
43
|
+
export const operationFilters = {
|
|
44
|
+
sampleTotal: { period },
|
|
45
|
+
samplesOverTime: { period, grain },
|
|
46
|
+
samplesByMember: { period, breakdown },
|
|
47
|
+
sampleRows: { period, grain, breakdown },
|
|
48
|
+
};
|
|
@@ -1,15 +1,66 @@
|
|
|
1
1
|
import { parseCount } from '@altertable/data-app/contract';
|
|
2
2
|
|
|
3
|
+
import { operationFilters } from '#app/filters.ts';
|
|
3
4
|
import { dataApp } from '#config';
|
|
5
|
+
// One query per widget: each section loads its own result when it nears the viewport.
|
|
6
|
+
const policy = { maxQueryRows: 500, maxDurationMs: 15000 };
|
|
4
7
|
export const operations = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
8
|
+
sampleTotal: dataApp.defineOperation({
|
|
9
|
+
filters: operationFilters.sampleTotal,
|
|
10
|
+
policy,
|
|
11
|
+
async run({ query }, { period }) {
|
|
12
|
+
const current = await query('sampleTotal', { period: period.range });
|
|
13
|
+
const previous = period.comparison
|
|
14
|
+
? await query('sampleTotal', { period: period.comparison })
|
|
15
|
+
: null;
|
|
16
|
+
return {
|
|
17
|
+
current: parseCount(current.rows[0]!.sample_count),
|
|
18
|
+
previous: previous && parseCount(previous.rows[0]!.sample_count),
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
samplesOverTime: dataApp.defineOperation({
|
|
23
|
+
filters: operationFilters.samplesOverTime,
|
|
24
|
+
policy,
|
|
25
|
+
async run({ query }, { period, grain }) {
|
|
26
|
+
// With the comparison on, the trend starts at the previous period.
|
|
27
|
+
const range = {
|
|
28
|
+
from: period.comparison?.from ?? period.range.from,
|
|
29
|
+
to: period.range.to,
|
|
30
|
+
};
|
|
31
|
+
const result = await query('samplesOverTime', { period: range, grain });
|
|
32
|
+
return result.rows.map(row => ({
|
|
33
|
+
periodStart: row.period_start,
|
|
34
|
+
sampleCount: parseCount(row.sample_count),
|
|
35
|
+
}));
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
samplesByMember: dataApp.defineOperation({
|
|
39
|
+
filters: operationFilters.samplesByMember,
|
|
40
|
+
policy,
|
|
41
|
+
async run({ query }, { period, breakdown }) {
|
|
42
|
+
const result = await query('samplesByMember', {
|
|
43
|
+
period: period.range,
|
|
44
|
+
breakdown,
|
|
45
|
+
});
|
|
46
|
+
return result.rows.map(row => ({
|
|
47
|
+
member: row.member,
|
|
48
|
+
sampleCount: parseCount(row.sample_count),
|
|
49
|
+
}));
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
sampleRows: dataApp.defineOperation({
|
|
53
|
+
filters: operationFilters.sampleRows,
|
|
54
|
+
policy,
|
|
55
|
+
async run({ query }, { period, grain, breakdown }) {
|
|
56
|
+
const result = await query('sampleRows', {
|
|
57
|
+
period: period.range,
|
|
58
|
+
grain,
|
|
59
|
+
breakdown,
|
|
60
|
+
});
|
|
11
61
|
return result.rows.map(row => ({
|
|
12
|
-
|
|
62
|
+
periodStart: row.period_start,
|
|
63
|
+
member: row.member,
|
|
13
64
|
sampleCount: parseCount(row.sample_count),
|
|
14
65
|
}));
|
|
15
66
|
},
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Read `node_modules/@altertable/data-app/docs/app-authoring.md` and use this project
|
|
4
4
|
as the selected scaffold. If dependencies are unavailable, read the
|
|
5
|
-
[version-matched recipe](https://github.com/altertable-ai/data-app/blob/v0.
|
|
5
|
+
[version-matched recipe](https://github.com/altertable-ai/data-app/blob/v0.77.0/docs/app-authoring.md). <!-- x-release-please-version -->
|
|
6
6
|
|
|
7
|
-
| Task | App-owned files
|
|
8
|
-
| ------------------------------------------ |
|
|
9
|
-
| Define queries and
|
|
10
|
-
| Compose app content and supported features | `src/App.tsx`
|
|
11
|
-
| Bind definitions and source evidence | `src/data-context.ts`
|
|
12
|
-
| Change identity and appearance | `app.ts`
|
|
13
|
-
| Inject styles and mount React | `src/main.tsx`
|
|
14
|
-
| Configure local serving | `src/server.ts`
|
|
7
|
+
| Task | App-owned files |
|
|
8
|
+
| ------------------------------------------ | ----------------------------------------------- |
|
|
9
|
+
| Define queries, filters, and operations | `app.ts`, `src/filters.ts`, `src/operations.ts` |
|
|
10
|
+
| Compose app content and supported features | `src/App.tsx` |
|
|
11
|
+
| Bind definitions and source evidence | `src/data-context.ts` |
|
|
12
|
+
| Change identity and appearance | `app.ts` |
|
|
13
|
+
| Inject styles and mount React | `src/main.tsx` |
|
|
14
|
+
| Configure local serving | `src/server.ts` |
|
|
15
15
|
|
|
16
16
|
See [README.md](README.md) for setup and checks.
|
|
17
17
|
|
|
@@ -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.
|
|
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 -->
|
|
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.
|
|
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 -->
|
|
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
|
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"lint:fix": "oxlint --type-aware --fix src"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@altertable/data-app": "0.
|
|
21
|
-
"@altertable/data-app-bun": "0.
|
|
22
|
-
"@altertable/data-app-react": "0.
|
|
20
|
+
"@altertable/data-app": "0.77.0",
|
|
21
|
+
"@altertable/data-app-bun": "0.77.0",
|
|
22
|
+
"@altertable/data-app-react": "0.77.0",
|
|
23
23
|
"react": "19.3.1",
|
|
24
24
|
"react-dom": "19.3.1"
|
|
25
25
|
},
|
|
@@ -4,33 +4,20 @@ import {
|
|
|
4
4
|
DataSection,
|
|
5
5
|
VisualizationWidget,
|
|
6
6
|
Stack,
|
|
7
|
-
choiceVariable,
|
|
8
7
|
} from '@altertable/data-app-react';
|
|
9
8
|
import { BarChart } from '@altertable/data-app-react/ui';
|
|
10
9
|
import { createDataClient } from '@altertable/data-app/client';
|
|
11
10
|
|
|
12
11
|
import { sampleDataContext } from '#app/data-context.ts';
|
|
12
|
+
import { operationFilters } from '#app/filters.ts';
|
|
13
13
|
import type { operations } from '#app/operations.ts';
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const { defineView } = createDataHooks(
|
|
15
|
+
createDataClient<typeof operations>({ filters: operationFilters })
|
|
16
|
+
);
|
|
17
|
+
const sampleCountsView = defineView({
|
|
17
18
|
dataContext: sampleDataContext,
|
|
18
19
|
operation: 'sampleCountsByGroup',
|
|
19
|
-
|
|
20
|
-
groupName: choiceVariable({
|
|
21
|
-
key: 'group',
|
|
22
|
-
label: 'Group',
|
|
23
|
-
defaultValue: 'all',
|
|
24
|
-
options: [
|
|
25
|
-
{ id: 'all', label: 'All groups' },
|
|
26
|
-
{ id: 'Alpha', label: 'Alpha' },
|
|
27
|
-
{ id: 'Beta', label: 'Beta' },
|
|
28
|
-
],
|
|
29
|
-
}),
|
|
30
|
-
},
|
|
31
|
-
describeInput: ({ groupName }) =>
|
|
32
|
-
groupName === 'all' ? 'all groups' : groupName,
|
|
33
|
-
isEmpty: result => result.groups.length === 0,
|
|
20
|
+
isEmpty: rows => rows.length === 0,
|
|
34
21
|
emptyFallback: {
|
|
35
22
|
title: 'No matching groups',
|
|
36
23
|
description: 'No observations are available for this query.',
|
|
@@ -38,7 +25,7 @@ const sampleCountsView = defineDataView({
|
|
|
38
25
|
});
|
|
39
26
|
const sampleCounts = sampleCountsView.dataset({
|
|
40
27
|
name: 'Sample counts',
|
|
41
|
-
select:
|
|
28
|
+
select: rows => rows,
|
|
42
29
|
rowKey: row => row.groupName,
|
|
43
30
|
columns: {
|
|
44
31
|
groupName: { label: 'Group', value: row => row.groupName },
|
|
@@ -49,9 +36,18 @@ const sampleCounts = sampleCountsView.dataset({
|
|
|
49
36
|
glossaryIds: ['sampleCount'],
|
|
50
37
|
},
|
|
51
38
|
});
|
|
52
|
-
const
|
|
39
|
+
const segmentCountsView = defineView({
|
|
40
|
+
dataContext: sampleDataContext,
|
|
41
|
+
operation: 'sampleCountsBySegment',
|
|
42
|
+
isEmpty: rows => rows.length === 0,
|
|
43
|
+
emptyFallback: {
|
|
44
|
+
title: 'No matching segments',
|
|
45
|
+
description: 'No observations are available for this query.',
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
const segmentCounts = segmentCountsView.dataset({
|
|
53
49
|
name: 'Counts by segment',
|
|
54
|
-
select:
|
|
50
|
+
select: rows => rows,
|
|
55
51
|
rowKey: row => row.segmentName,
|
|
56
52
|
columns: {
|
|
57
53
|
segmentName: { label: 'Segment', value: row => row.segmentName },
|
|
@@ -70,55 +66,58 @@ const groupActions = sampleCounts.actions(
|
|
|
70
66
|
{ primary: 'drill' }
|
|
71
67
|
);
|
|
72
68
|
// Keep only the breakdowns and interactions relevant to the requested metric.
|
|
73
|
-
const
|
|
74
|
-
<
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
</
|
|
69
|
+
const groupContent = sampleCountsView.content(result => (
|
|
70
|
+
<VisualizationWidget
|
|
71
|
+
dataset={sampleCounts}
|
|
72
|
+
source={result}
|
|
73
|
+
title="Sample count"
|
|
74
|
+
description="Select a group to filter both charts; choose All groups to reset."
|
|
75
|
+
actions={groupActions}
|
|
76
|
+
>
|
|
77
|
+
{(rows, actions) => (
|
|
78
|
+
<BarChart
|
|
79
|
+
ariaLabel="Sample counts by group"
|
|
80
|
+
unit="samples"
|
|
81
|
+
items={rows.map(row => ({
|
|
82
|
+
...row,
|
|
83
|
+
id: row.groupName,
|
|
84
|
+
label: row.groupName,
|
|
85
|
+
value: row.sampleCount,
|
|
86
|
+
}))}
|
|
87
|
+
itemActions={actions}
|
|
88
|
+
/>
|
|
89
|
+
)}
|
|
90
|
+
</VisualizationWidget>
|
|
91
|
+
));
|
|
92
|
+
const segmentContent = segmentCountsView.content(result => (
|
|
93
|
+
<VisualizationWidget
|
|
94
|
+
dataset={segmentCounts}
|
|
95
|
+
source={result}
|
|
96
|
+
title="Samples by segment"
|
|
97
|
+
description="Segment breakdown for the selected group scope."
|
|
98
|
+
>
|
|
99
|
+
{(rows, actions) => (
|
|
100
|
+
<BarChart
|
|
101
|
+
ariaLabel="Sample counts by segment"
|
|
102
|
+
unit="samples"
|
|
103
|
+
items={rows.map(row => ({
|
|
104
|
+
...row,
|
|
105
|
+
id: row.segmentName,
|
|
106
|
+
label: row.segmentName,
|
|
107
|
+
value: row.sampleCount,
|
|
108
|
+
}))}
|
|
109
|
+
itemActions={actions}
|
|
110
|
+
/>
|
|
111
|
+
)}
|
|
112
|
+
</VisualizationWidget>
|
|
117
113
|
));
|
|
118
114
|
export function App() {
|
|
119
115
|
return (
|
|
120
116
|
<DataApp view={sampleCountsView} showToolbar={false}>
|
|
121
|
-
<
|
|
117
|
+
<Stack>
|
|
118
|
+
<DataSection content={groupContent} label="Sample count" />
|
|
119
|
+
<DataSection content={segmentContent} label="Samples by segment" />
|
|
120
|
+
</Stack>
|
|
122
121
|
</DataApp>
|
|
123
122
|
);
|
|
124
123
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { choiceFilter } from '@altertable/data-app/contract';
|
|
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.
|
|
5
|
+
const groupName = choiceFilter({
|
|
6
|
+
key: 'group',
|
|
7
|
+
label: 'Group',
|
|
8
|
+
defaultValue: 'all',
|
|
9
|
+
options: [
|
|
10
|
+
{ id: 'all', label: 'All groups' },
|
|
11
|
+
{ id: 'Alpha', label: 'Alpha' },
|
|
12
|
+
{ id: 'Beta', label: 'Beta' },
|
|
13
|
+
],
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
/** The filters each operation reads. */
|
|
17
|
+
export const operationFilters = {
|
|
18
|
+
sampleCountsByGroup: { groupName },
|
|
19
|
+
sampleCountsBySegment: { groupName },
|
|
20
|
+
};
|