@altertable/data-app-examples 0.74.0 → 0.75.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 -4
- package/dist/index.js +38 -11
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +20 -0
- package/package.json +1 -1
- package/templates/starter-finding-data-app/LICENSE +21 -0
- package/templates/starter-finding-data-app/index.tsx +177 -0
- package/templates/starter-local-data-app/AGENTS.md +9 -9
- package/templates/starter-local-data-app/README.md +4 -4
- package/templates/starter-local-data-app/package.json +3 -3
- package/templates/starter-local-finding-data-app/.bun-version +1 -0
- package/templates/starter-local-finding-data-app/.node-version +1 -0
- package/templates/starter-local-finding-data-app/.oxfmtrc.json +11 -0
- package/templates/starter-local-finding-data-app/.oxlintrc.json +33 -0
- package/templates/starter-local-finding-data-app/AGENTS.md +18 -0
- package/templates/starter-local-finding-data-app/LICENSE +21 -0
- package/templates/starter-local-finding-data-app/README.md +43 -0
- package/templates/starter-local-finding-data-app/_gitignore +3 -0
- package/templates/starter-local-finding-data-app/app.ts +25 -0
- package/templates/starter-local-finding-data-app/bunfig.toml +2 -0
- package/templates/starter-local-finding-data-app/package.json +36 -0
- package/templates/starter-local-finding-data-app/src/App.tsx +122 -0
- package/templates/starter-local-finding-data-app/src/assets.d.ts +1 -0
- package/templates/starter-local-finding-data-app/src/data-context.ts +13 -0
- package/templates/starter-local-finding-data-app/src/favicon.svg +13 -0
- package/templates/starter-local-finding-data-app/src/index.html +14 -0
- package/templates/starter-local-finding-data-app/src/main.tsx +8 -0
- package/templates/starter-local-finding-data-app/src/operations.ts +17 -0
- package/templates/starter-local-finding-data-app/src/server.ts +7 -0
- package/templates/starter-local-finding-data-app/tsconfig.json +21 -0
- package/templates/starter-local-metric-data-app/.bun-version +1 -0
- package/templates/starter-local-metric-data-app/.node-version +1 -0
- package/templates/starter-local-metric-data-app/.oxfmtrc.json +11 -0
- package/templates/starter-local-metric-data-app/.oxlintrc.json +33 -0
- package/templates/starter-local-metric-data-app/AGENTS.md +18 -0
- package/templates/starter-local-metric-data-app/LICENSE +21 -0
- package/templates/starter-local-metric-data-app/README.md +43 -0
- package/templates/starter-local-metric-data-app/_gitignore +3 -0
- package/templates/starter-local-metric-data-app/app.ts +39 -0
- package/templates/starter-local-metric-data-app/bunfig.toml +2 -0
- package/templates/starter-local-metric-data-app/package.json +36 -0
- package/templates/starter-local-metric-data-app/src/App.tsx +124 -0
- package/templates/starter-local-metric-data-app/src/assets.d.ts +1 -0
- package/templates/starter-local-metric-data-app/src/data-context.ts +19 -0
- package/templates/starter-local-metric-data-app/src/favicon.svg +13 -0
- package/templates/starter-local-metric-data-app/src/index.html +14 -0
- package/templates/starter-local-metric-data-app/src/main.tsx +8 -0
- package/templates/starter-local-metric-data-app/src/operations.ts +50 -0
- package/templates/starter-local-metric-data-app/src/server.ts +7 -0
- package/templates/starter-local-metric-data-app/tsconfig.json +21 -0
- package/templates/starter-metric-data-app/LICENSE +21 -0
- package/templates/starter-metric-data-app/index.tsx +229 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createDataHooks,
|
|
3
|
+
DataApp,
|
|
4
|
+
DataSection,
|
|
5
|
+
VisualizationWidget,
|
|
6
|
+
DataValue,
|
|
7
|
+
TableWidget,
|
|
8
|
+
Ranking,
|
|
9
|
+
Stack,
|
|
10
|
+
TextContent,
|
|
11
|
+
} from '@altertable/data-app-react';
|
|
12
|
+
import { createDataClient } from '@altertable/data-app/client';
|
|
13
|
+
|
|
14
|
+
import { sampleDataContext } from '#app/data-context.ts';
|
|
15
|
+
import type { operations } from '#app/operations.ts';
|
|
16
|
+
const { defineDataView } =
|
|
17
|
+
createDataHooks(createDataClient<typeof operations>());
|
|
18
|
+
const sampleCountsView = defineDataView({
|
|
19
|
+
dataContext: sampleDataContext,
|
|
20
|
+
operation: 'sampleCountsByGroup',
|
|
21
|
+
describeInput: () => 'fixture groups',
|
|
22
|
+
isEmpty: sampleCounts => sampleCounts.length === 0,
|
|
23
|
+
emptyFallback: {
|
|
24
|
+
title: 'No matching groups',
|
|
25
|
+
description: 'No observations are available for this query.',
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
const sampleCounts = sampleCountsView.dataset({
|
|
29
|
+
name: 'Sample counts',
|
|
30
|
+
select: rows => rows,
|
|
31
|
+
rowKey: row => row.groupName,
|
|
32
|
+
columns: {
|
|
33
|
+
groupName: { label: 'Group', value: row => row.groupName },
|
|
34
|
+
sampleCount: { value: row => row.sampleCount, format: { kind: 'count' } },
|
|
35
|
+
},
|
|
36
|
+
evidence: {
|
|
37
|
+
id: 'counts-by-group',
|
|
38
|
+
glossaryIds: ['sampleCount'],
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const totalSamples = sampleCountsView.metric(
|
|
42
|
+
{
|
|
43
|
+
id: 'total-samples',
|
|
44
|
+
label: 'Total samples',
|
|
45
|
+
glossaryId: 'sampleCount',
|
|
46
|
+
format: { kind: 'count' },
|
|
47
|
+
},
|
|
48
|
+
rows => ({ current: rows.reduce((sum, row) => sum + row.sampleCount, 0) })
|
|
49
|
+
);
|
|
50
|
+
const alphaSamples = sampleCountsView.metric(
|
|
51
|
+
{
|
|
52
|
+
id: 'alpha-samples',
|
|
53
|
+
label: 'Alpha samples',
|
|
54
|
+
glossaryId: 'sampleCount',
|
|
55
|
+
format: { kind: 'count' },
|
|
56
|
+
},
|
|
57
|
+
rows => {
|
|
58
|
+
const alpha = rows.find(row => row.groupName === 'Alpha');
|
|
59
|
+
if (!alpha)
|
|
60
|
+
throw new Error('The sample Finding requires evidence for Alpha.');
|
|
61
|
+
return { current: alpha.sampleCount };
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
// This fictional Finding demonstrates prose, inline evidence, and a Markdown-table equivalent.
|
|
65
|
+
// Preserve each real Finding's own headings and argument instead of reusing these sections.
|
|
66
|
+
const sampleContent = sampleCountsView.content(result => (
|
|
67
|
+
<Stack>
|
|
68
|
+
<TextContent>
|
|
69
|
+
<h2>Contribution by group</h2>
|
|
70
|
+
<p>
|
|
71
|
+
<strong>Alpha</strong> contributed{' '}
|
|
72
|
+
<DataValue metric={alphaSamples} source={result} /> of the{' '}
|
|
73
|
+
<DataValue metric={totalSamples} source={result} /> recorded samples.
|
|
74
|
+
The group comparison below supports that concentration; it does not
|
|
75
|
+
explain its cause.
|
|
76
|
+
</p>
|
|
77
|
+
</TextContent>
|
|
78
|
+
<VisualizationWidget
|
|
79
|
+
dataset={sampleCounts}
|
|
80
|
+
source={result}
|
|
81
|
+
title="Sample count"
|
|
82
|
+
>
|
|
83
|
+
{rows => (
|
|
84
|
+
<Ranking
|
|
85
|
+
aria-label="Samples by group"
|
|
86
|
+
items={rows.map(row => ({
|
|
87
|
+
id: row.groupName,
|
|
88
|
+
label: row.groupName,
|
|
89
|
+
value: row.sampleCount,
|
|
90
|
+
}))}
|
|
91
|
+
/>
|
|
92
|
+
)}
|
|
93
|
+
</VisualizationWidget>
|
|
94
|
+
<TextContent>
|
|
95
|
+
<h2>Supporting evidence</h2>
|
|
96
|
+
<p>
|
|
97
|
+
The source rows are grouped by <code>group_name</code> and summed using{' '}
|
|
98
|
+
<code>sample_count</code>. The table retains the exact values behind the
|
|
99
|
+
comparison.
|
|
100
|
+
</p>
|
|
101
|
+
<ul>
|
|
102
|
+
<li>Compare the groups within the same sample population.</li>
|
|
103
|
+
<li>
|
|
104
|
+
<em>Volume alone does not establish performance or causality.</em>
|
|
105
|
+
</li>
|
|
106
|
+
</ul>
|
|
107
|
+
</TextContent>
|
|
108
|
+
<TableWidget
|
|
109
|
+
dataset={sampleCounts}
|
|
110
|
+
source={result}
|
|
111
|
+
title="Counts by group"
|
|
112
|
+
pagination={false}
|
|
113
|
+
/>
|
|
114
|
+
</Stack>
|
|
115
|
+
));
|
|
116
|
+
export function App() {
|
|
117
|
+
return (
|
|
118
|
+
<DataApp view={sampleCountsView} showToolbar={false}>
|
|
119
|
+
<DataSection content={sampleContent} />
|
|
120
|
+
</DataApp>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module '*.css';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createDataContext } from '@altertable/data-app-react';
|
|
2
|
+
const queryNames = { sampleCountsByGroup: 'sampleCountsByGroup' } as const;
|
|
3
|
+
export const sampleDataContext = createDataContext(queryNames)({
|
|
4
|
+
description:
|
|
5
|
+
'Fictional sample volumes grouped from starter_demo.sample_counts. Replace this evidence with the actual Finding queries.',
|
|
6
|
+
glossary: {
|
|
7
|
+
sampleCount: {
|
|
8
|
+
term: 'Sample count',
|
|
9
|
+
definition: 'A fixture value: Alpha is 2,200,000 and Beta is 600,000.',
|
|
10
|
+
queryNames: [queryNames.sampleCountsByGroup],
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 51 44">
|
|
2
|
+
<style>
|
|
3
|
+
path { fill: #01050b; }
|
|
4
|
+
@media (prefers-color-scheme: dark) {
|
|
5
|
+
path { fill: #fff; }
|
|
6
|
+
}
|
|
7
|
+
</style>
|
|
8
|
+
<path
|
|
9
|
+
fill-rule="evenodd"
|
|
10
|
+
clip-rule="evenodd"
|
|
11
|
+
d="M40.3274 28.9788L35.9663 28.8378L34.9541 28.6881L18.1066 10.301L24.1073 0L26.8738 0.545413L41.5212 25.6848L40.3274 28.9788ZM20.5319 20.1112L18.1894 15.6731L14.6154 16.2904L0 41.378L0.894584 44H12.9453L20.5769 20.4134L20.5319 20.1112ZM44.9804 31.6253L20.3808 36.9197L17.5838 41.2974L19.9001 44H49.2036L51 41.9551L44.9804 31.6253Z"
|
|
12
|
+
/>
|
|
13
|
+
</svg>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<meta name="theme-color" content="#ffffff" />
|
|
7
|
+
<title>Altertable app</title>
|
|
8
|
+
<link rel="icon" href="./favicon.svg" type="image/svg+xml" />
|
|
9
|
+
<script type="module" src="./main.tsx"></script>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="root"></div>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { parseCount } from '@altertable/data-app/contract';
|
|
2
|
+
|
|
3
|
+
import { dataApp } from '#config';
|
|
4
|
+
export const operations = {
|
|
5
|
+
sampleCountsByGroup: dataApp.defineOperation({
|
|
6
|
+
input: () => ({}),
|
|
7
|
+
checks: [{}],
|
|
8
|
+
policy: { maxQueryRows: 10, maxDurationMs: 15000 },
|
|
9
|
+
async run({ query }) {
|
|
10
|
+
const result = await query('sampleCountsByGroup', {});
|
|
11
|
+
return result.rows.map(row => ({
|
|
12
|
+
groupName: row.group_name,
|
|
13
|
+
sampleCount: parseCount(row.sample_count),
|
|
14
|
+
}));
|
|
15
|
+
},
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "Preserve",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"allowImportingTsExtensions": true,
|
|
7
|
+
"resolveJsonModule": true,
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"noUncheckedIndexedAccess": true,
|
|
11
|
+
"noEmit": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"types": ["bun"],
|
|
14
|
+
"noImplicitReturns": true,
|
|
15
|
+
"noFallthroughCasesInSwitch": true,
|
|
16
|
+
"noImplicitOverride": true,
|
|
17
|
+
"allowUnreachableCode": false,
|
|
18
|
+
"noUncheckedSideEffectImports": true
|
|
19
|
+
},
|
|
20
|
+
"include": ["src", "app.ts"]
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.4.4
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
24.18.0
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
|
|
3
|
+
"ignorePatterns": ["dist/**", "bun.lock"],
|
|
4
|
+
"singleQuote": true,
|
|
5
|
+
"trailingComma": "es5",
|
|
6
|
+
"arrowParens": "avoid",
|
|
7
|
+
"printWidth": 80,
|
|
8
|
+
"endOfLine": "lf",
|
|
9
|
+
"sortImports": true,
|
|
10
|
+
"sortPackageJson": false
|
|
11
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/oxlint/configuration_schema.json",
|
|
3
|
+
"plugins": ["eslint", "typescript", "unicorn", "oxc", "react", "jsx-a11y"],
|
|
4
|
+
"categories": {
|
|
5
|
+
"correctness": "error"
|
|
6
|
+
},
|
|
7
|
+
"options": {
|
|
8
|
+
"typeAware": true
|
|
9
|
+
},
|
|
10
|
+
"rules": {
|
|
11
|
+
"react/unsupported-syntax": "error",
|
|
12
|
+
"eslint/no-restricted-imports": [
|
|
13
|
+
"error",
|
|
14
|
+
{
|
|
15
|
+
"patterns": [
|
|
16
|
+
{
|
|
17
|
+
"regex": "^\\.\\.?/",
|
|
18
|
+
"message": "Use #app/* or #config for app-owned files."
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"func-style": [
|
|
24
|
+
"error",
|
|
25
|
+
"declaration",
|
|
26
|
+
{
|
|
27
|
+
"overrides": {
|
|
28
|
+
"namedExports": "declaration"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Build this local data app
|
|
2
|
+
|
|
3
|
+
Read `node_modules/@altertable/data-app/docs/app-authoring.md` and use this project
|
|
4
|
+
as the selected scaffold. If dependencies are unavailable, read the
|
|
5
|
+
[version-matched recipe](https://github.com/altertable-ai/data-app/blob/v0.75.0/docs/app-authoring.md). <!-- x-release-please-version -->
|
|
6
|
+
|
|
7
|
+
| Task | App-owned files |
|
|
8
|
+
| ------------------------------------------ | -------------------------------------------------------- |
|
|
9
|
+
| Define queries and inputs | `app.ts`, `src/operations.ts`, optional shared contracts |
|
|
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
|
+
|
|
16
|
+
See [README.md](README.md) for setup and checks.
|
|
17
|
+
|
|
18
|
+
Keep reusable app-specific conventions here.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Altertable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Local metric data app starter
|
|
2
|
+
|
|
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.75.0/docs/app-authoring.md). <!-- x-release-please-version -->
|
|
5
|
+
See [AGENTS.md](AGENTS.md) for app-owned files.
|
|
6
|
+
|
|
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.75.0/docs/local-data-apps.md#preview-the-use-case-starters). <!-- x-release-please-version -->
|
|
9
|
+
Use that mock for development, or replace the example queries with verified data
|
|
10
|
+
in your lakehouse. The starter does not install a mock or create demo tables.
|
|
11
|
+
|
|
12
|
+
## Run the app
|
|
13
|
+
|
|
14
|
+
From the copied starter directory, install dependencies and set server-only
|
|
15
|
+
credentials before starting:
|
|
16
|
+
|
|
17
|
+
```fish
|
|
18
|
+
bun install
|
|
19
|
+
set -gx ALTERTABLE_LAKEHOUSE_USERNAME your-username
|
|
20
|
+
read --silent --prompt-str 'Lakehouse password: ' ALTERTABLE_LAKEHOUSE_PASSWORD
|
|
21
|
+
set -gx ALTERTABLE_LAKEHOUSE_PASSWORD $ALTERTABLE_LAKEHOUSE_PASSWORD
|
|
22
|
+
bun run dev
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Open <http://127.0.0.1:25837>. Alternatively, configure
|
|
26
|
+
`ALTERTABLE_DATA_PROXY_URL` and `ALTERTABLE_DATA_PROXY_TOKEN` for an existing
|
|
27
|
+
CLI proxy. Missing credentials stop startup.
|
|
28
|
+
|
|
29
|
+
## Build the app
|
|
30
|
+
|
|
31
|
+
Replace the fixture queries and example content with the evidence and content
|
|
32
|
+
specified by the app brief. Change identity, appearance, and queries in `app.ts`.
|
|
33
|
+
|
|
34
|
+
```fish
|
|
35
|
+
bun run check
|
|
36
|
+
```
|
|
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.
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { defineDataApp } from '@altertable/data-app';
|
|
2
|
+
export const dataApp = defineDataApp({
|
|
3
|
+
title: 'Sample metric',
|
|
4
|
+
description: 'Fixture counts by group; replace with the requested metric.',
|
|
5
|
+
scope: { organization: 'demo', environment: 'sample' },
|
|
6
|
+
appearance: { theme: 'system' },
|
|
7
|
+
queries: {
|
|
8
|
+
sampleCountsBySegment: {
|
|
9
|
+
projections: {
|
|
10
|
+
segment_name: { type: 'string' },
|
|
11
|
+
sample_count: { type: 'number' },
|
|
12
|
+
},
|
|
13
|
+
statement: `
|
|
14
|
+
SELECT segment_name, sample_count FROM SEMANTIC_VIEW(
|
|
15
|
+
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`,
|
|
18
|
+
params: {
|
|
19
|
+
groupName: { type: 'string', defaultValue: '' },
|
|
20
|
+
limit: { type: 'number', defaultValue: 10 },
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
sampleCountsByGroup: {
|
|
24
|
+
projections: {
|
|
25
|
+
group_name: { type: 'string' },
|
|
26
|
+
sample_count: { type: 'number' },
|
|
27
|
+
},
|
|
28
|
+
statement: `
|
|
29
|
+
SELECT group_name, sample_count FROM SEMANTIC_VIEW(
|
|
30
|
+
starter_sample_counts DIMENSIONS samples.group_name METRICS samples.sample_count
|
|
31
|
+
WHERE $groupName = '' OR samples.group_name = $groupName
|
|
32
|
+
) ORDER BY group_name LIMIT $limit`,
|
|
33
|
+
params: {
|
|
34
|
+
groupName: { type: 'string', defaultValue: '' },
|
|
35
|
+
limit: { type: 'number', defaultValue: 10 },
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "data-app-metric-starter",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"imports": {
|
|
6
|
+
"#app/*": "./src/*",
|
|
7
|
+
"#config": "./app.ts"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"typecheck": "tsc --noEmit",
|
|
11
|
+
"lint": "oxlint --type-aware src",
|
|
12
|
+
"format": "oxfmt src app.ts",
|
|
13
|
+
"format:check": "oxfmt --check src app.ts",
|
|
14
|
+
"dev": "bun --hot src/server.ts",
|
|
15
|
+
"build": "bun run typecheck && bun build src/index.html --outdir=dist --production",
|
|
16
|
+
"check": "bun run lint && bun run format:check && bun run build",
|
|
17
|
+
"lint:fix": "oxlint --type-aware --fix src"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@altertable/data-app": "0.75.0",
|
|
21
|
+
"@altertable/data-app-bun": "0.75.0",
|
|
22
|
+
"@altertable/data-app-react": "0.75.0",
|
|
23
|
+
"react": "19.3.1",
|
|
24
|
+
"react-dom": "19.3.1"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/bun": "1.4.3",
|
|
28
|
+
"@types/react": "19.3.0",
|
|
29
|
+
"@types/react-dom": "19.3.0",
|
|
30
|
+
"oxfmt": "0.71.0",
|
|
31
|
+
"oxlint": "1.86.0",
|
|
32
|
+
"oxlint-tsgolint": "7.0.2003",
|
|
33
|
+
"typescript": "7.0.2"
|
|
34
|
+
},
|
|
35
|
+
"packageManager": "bun@1.4.4"
|
|
36
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createDataHooks,
|
|
3
|
+
DataApp,
|
|
4
|
+
DataSection,
|
|
5
|
+
VisualizationWidget,
|
|
6
|
+
Stack,
|
|
7
|
+
choiceVariable,
|
|
8
|
+
} from '@altertable/data-app-react';
|
|
9
|
+
import { BarChart } from '@altertable/data-app-react/ui';
|
|
10
|
+
import { createDataClient } from '@altertable/data-app/client';
|
|
11
|
+
|
|
12
|
+
import { sampleDataContext } from '#app/data-context.ts';
|
|
13
|
+
import type { operations } from '#app/operations.ts';
|
|
14
|
+
const { defineDataView } =
|
|
15
|
+
createDataHooks(createDataClient<typeof operations>());
|
|
16
|
+
const sampleCountsView = defineDataView({
|
|
17
|
+
dataContext: sampleDataContext,
|
|
18
|
+
operation: 'sampleCountsByGroup',
|
|
19
|
+
variables: {
|
|
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,
|
|
34
|
+
emptyFallback: {
|
|
35
|
+
title: 'No matching groups',
|
|
36
|
+
description: 'No observations are available for this query.',
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
const sampleCounts = sampleCountsView.dataset({
|
|
40
|
+
name: 'Sample counts',
|
|
41
|
+
select: result => result.groups,
|
|
42
|
+
rowKey: row => row.groupName,
|
|
43
|
+
columns: {
|
|
44
|
+
groupName: { label: 'Group', value: row => row.groupName },
|
|
45
|
+
sampleCount: { value: row => row.sampleCount, format: { kind: 'count' } },
|
|
46
|
+
},
|
|
47
|
+
evidence: {
|
|
48
|
+
id: 'counts-by-group',
|
|
49
|
+
glossaryIds: ['sampleCount'],
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
const segments = sampleCountsView.dataset({
|
|
53
|
+
name: 'Counts by segment',
|
|
54
|
+
select: result => result.segments,
|
|
55
|
+
rowKey: row => row.segmentName,
|
|
56
|
+
columns: {
|
|
57
|
+
segmentName: { label: 'Segment', value: row => row.segmentName },
|
|
58
|
+
sampleCount: { value: row => row.sampleCount, format: { kind: 'count' } },
|
|
59
|
+
},
|
|
60
|
+
evidence: { id: 'counts-by-segment', glossaryIds: ['sampleCount'] },
|
|
61
|
+
});
|
|
62
|
+
const groupActions = sampleCounts.actions(
|
|
63
|
+
action => ({
|
|
64
|
+
drill: action.filter({
|
|
65
|
+
label: 'Drill into group',
|
|
66
|
+
target: sampleCountsView.filter(),
|
|
67
|
+
values: row => ({ groupName: row.groupName }),
|
|
68
|
+
}),
|
|
69
|
+
}),
|
|
70
|
+
{ primary: 'drill' }
|
|
71
|
+
);
|
|
72
|
+
// Keep only the breakdowns and interactions relevant to the requested metric.
|
|
73
|
+
const sampleContent = sampleCountsView.content(result => (
|
|
74
|
+
<Stack>
|
|
75
|
+
<VisualizationWidget
|
|
76
|
+
dataset={sampleCounts}
|
|
77
|
+
source={result}
|
|
78
|
+
title="Sample count"
|
|
79
|
+
description="Select a group to filter both charts; choose All groups to reset."
|
|
80
|
+
actions={groupActions}
|
|
81
|
+
>
|
|
82
|
+
{(rows, actions) => (
|
|
83
|
+
<BarChart
|
|
84
|
+
ariaLabel="Sample counts by group"
|
|
85
|
+
unit="samples"
|
|
86
|
+
items={rows.map(row => ({
|
|
87
|
+
...row,
|
|
88
|
+
id: row.groupName,
|
|
89
|
+
label: row.groupName,
|
|
90
|
+
value: row.sampleCount,
|
|
91
|
+
}))}
|
|
92
|
+
itemActions={actions}
|
|
93
|
+
/>
|
|
94
|
+
)}
|
|
95
|
+
</VisualizationWidget>
|
|
96
|
+
<VisualizationWidget
|
|
97
|
+
dataset={segments}
|
|
98
|
+
source={result}
|
|
99
|
+
title="Samples by segment"
|
|
100
|
+
description="Segment breakdown for the selected group scope."
|
|
101
|
+
>
|
|
102
|
+
{(rows, actions) => (
|
|
103
|
+
<BarChart
|
|
104
|
+
ariaLabel="Sample counts by segment"
|
|
105
|
+
unit="samples"
|
|
106
|
+
items={rows.map(row => ({
|
|
107
|
+
...row,
|
|
108
|
+
id: row.segmentName,
|
|
109
|
+
label: row.segmentName,
|
|
110
|
+
value: row.sampleCount,
|
|
111
|
+
}))}
|
|
112
|
+
itemActions={actions}
|
|
113
|
+
/>
|
|
114
|
+
)}
|
|
115
|
+
</VisualizationWidget>
|
|
116
|
+
</Stack>
|
|
117
|
+
));
|
|
118
|
+
export function App() {
|
|
119
|
+
return (
|
|
120
|
+
<DataApp view={sampleCountsView} showToolbar={false}>
|
|
121
|
+
<DataSection content={sampleContent} />
|
|
122
|
+
</DataApp>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module '*.css';
|
|
@@ -0,0 +1,19 @@
|
|
|
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)({
|
|
7
|
+
description:
|
|
8
|
+
'The starter_sample_counts semantic view measures fictional samples by group and segment. Replace it with the requested semantic metric before publishing.',
|
|
9
|
+
glossary: {
|
|
10
|
+
sampleCount: {
|
|
11
|
+
term: 'Sample count',
|
|
12
|
+
definition: 'A fixture value: Alpha is 2,200,000 and Beta is 600,000.',
|
|
13
|
+
queryNames: [
|
|
14
|
+
queryNames.sampleCountsByGroup,
|
|
15
|
+
queryNames.sampleCountsBySegment,
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 51 44">
|
|
2
|
+
<style>
|
|
3
|
+
path { fill: #01050b; }
|
|
4
|
+
@media (prefers-color-scheme: dark) {
|
|
5
|
+
path { fill: #fff; }
|
|
6
|
+
}
|
|
7
|
+
</style>
|
|
8
|
+
<path
|
|
9
|
+
fill-rule="evenodd"
|
|
10
|
+
clip-rule="evenodd"
|
|
11
|
+
d="M40.3274 28.9788L35.9663 28.8378L34.9541 28.6881L18.1066 10.301L24.1073 0L26.8738 0.545413L41.5212 25.6848L40.3274 28.9788ZM20.5319 20.1112L18.1894 15.6731L14.6154 16.2904L0 41.378L0.894584 44H12.9453L20.5769 20.4134L20.5319 20.1112ZM44.9804 31.6253L20.3808 36.9197L17.5838 41.2974L19.9001 44H49.2036L51 41.9551L44.9804 31.6253Z"
|
|
12
|
+
/>
|
|
13
|
+
</svg>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<meta name="theme-color" content="#ffffff" />
|
|
7
|
+
<title>Altertable app</title>
|
|
8
|
+
<link rel="icon" href="./favicon.svg" type="image/svg+xml" />
|
|
9
|
+
<script type="module" src="./main.tsx"></script>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="root"></div>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|