@gramlot/gramlot 0.3.27 → 0.3.30
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/assets/icons/chart.svg +1 -0
- package/dist/components/audio/__init__.py +13 -0
- package/dist/components/audio/assets/collection.js +3 -0
- package/dist/components/audio/assets/index.js +3 -0
- package/dist/components/audio/commands.json +7 -0
- package/dist/components/audio/grammar.json +335 -0
- package/dist/components/charts/__init__.py +13 -0
- package/dist/components/charts/assets/collection.js +47 -0
- package/dist/components/charts/assets/files/55ea01207028f76d844678511f29fc800f8a1e67a8a0fe80470128677847ad32-echarts-gl.txt +29 -0
- package/dist/components/charts/assets/files/63727832aaf62004a2b249c933e327f3c90caf49e41a72f4bf436edf632cbda8-vega.txt +27 -0
- package/dist/components/charts/assets/files/8c45d9eaf50c2f72dd9c7ab9ef440788ba58a3538484b5c51c1f17d5128752e7-plotly.txt +21 -0
- package/dist/components/charts/assets/files/8f989229699b4fe2f1a0432d0e9edc338a8a911e250e2d1b01ecd770a5f5b1bd-uplot.txt +21 -0
- package/dist/components/charts/assets/files/c8fa058cba98f7f288b5d8fa4116f441d6dacb25b96da859e518c973fff41d0c-claygl.txt +23 -0
- package/dist/components/charts/assets/index.js +3 -0
- package/dist/components/charts/assets/modules/chunk-2CCTLZE7.js +76 -0
- package/dist/components/charts/assets/modules/chunk-RMRBEYTI.js +1 -0
- package/dist/components/charts/assets/modules/echarts-gl-CXVTZA6G.js +4409 -0
- package/dist/components/charts/assets/modules/plotly.min-4LB7HE7P.js +3596 -0
- package/dist/components/charts/assets/modules/uPlot.esm-5JJNHHRF.js +3 -0
- package/dist/components/charts/assets/modules/uPlot.min-N3E3FA74.js +1 -0
- package/dist/components/charts/assets/modules/vega.module-2QCOVQ3A.js +13 -0
- package/dist/components/charts/commands.json +7 -0
- package/dist/components/charts/grammar.json +1113 -0
- package/dist/components/chat/__init__.py +1 -1
- package/dist/components/chat/assets/collection.js +3 -3
- package/dist/components/chat/assets/index.js +1 -1
- package/dist/components/drawing/__init__.py +15 -0
- package/dist/components/drawing/assets/collection.js +28 -0
- package/dist/components/drawing/assets/index.js +3 -0
- package/dist/components/drawing/commands.json +7 -0
- package/dist/components/drawing/grammar.json +110 -0
- package/dist/components/editors/__init__.py +2 -2
- package/dist/components/editors/assets/collection.js +18 -18
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/modules/{prose-mirror-engine-GMZPJPNN.js → prose-mirror-engine-DQEAEIMV.js} +2 -2
- package/dist/components/editors/grammar.json +150 -0
- package/dist/components/grid/__init__.py +1 -1
- package/dist/components/grid/assets/collection.js +51 -30
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/grammar.json +258 -0
- package/dist/components/grouplets/__init__.py +1 -1
- package/dist/components/grouplets/assets/collection.js +3 -3
- package/dist/components/grouplets/assets/index.js +1 -1
- package/dist/components/inputs/__init__.py +3 -2
- package/dist/components/inputs/assets/collection.js +38 -23
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +1533 -321
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +27 -23
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +85 -0
- package/dist/components/selection_trial/__init__.py +1 -1
- package/dist/components/selection_trial/assets/collection.js +3 -3
- package/dist/components/selection_trial/assets/index.js +1 -1
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +11 -11
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +126 -0
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +2 -2
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/collection.js +8 -8
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/components/vizabi/__init__.py +13 -0
- package/dist/components/vizabi/assets/collection.js +22 -0
- package/dist/components/vizabi/assets/index.js +3 -0
- package/dist/components/vizabi/commands.json +7 -0
- package/dist/components/vizabi/grammar.json +128 -0
- package/dist/gramlot.js +572 -176
- package/dist/gramlot.min.js +85 -53
- package/dist/standard-collections.js +2 -0
- package/package.json +12 -4
- package/src/binding/grid-struct.js +2 -2
- package/src/binding/runtime.js +10 -0
- package/src/bootstrap.js +1 -1
- package/src/builder/gramlot-builder.d.ts +15 -2
- package/src/builder/gramlot-builder.js +22 -3
- package/src/builder/source.js +24 -1
- package/src/components/audio-analysis-session.js +65 -0
- package/src/components/audio.js +44 -0
- package/src/components/bases.js +6 -4
- package/src/components/border-container.js +6 -3
- package/src/components/buttons.js +47 -3
- package/src/components/chart-bar3d-options.js +30 -0
- package/src/components/chart-controls.js +83 -0
- package/src/components/chart-data-view.js +52 -0
- package/src/components/chart-data.js +42 -0
- package/src/components/chart-domains.js +46 -0
- package/src/components/chart-engines/echarts-options.js +50 -0
- package/src/components/chart-engines/echarts.js +82 -0
- package/src/components/chart-engines/index.js +22 -0
- package/src/components/chart-engines/plotly-map.js +34 -0
- package/src/components/chart-engines/plotly-spatial.js +35 -0
- package/src/components/chart-engines/plotly.js +138 -0
- package/src/components/chart-engines/uplot.js +57 -0
- package/src/components/chart-engines/vega.js +101 -0
- package/src/components/chart-fields.js +110 -0
- package/src/components/chart-geographic-options.js +47 -0
- package/src/components/chart-geojson.js +60 -0
- package/src/components/chart-geometry.js +11 -0
- package/src/components/chart-map-anchors.js +24 -0
- package/src/components/chart-map-bar3d-options.js +41 -0
- package/src/components/chart-map-data.js +25 -0
- package/src/components/chart-map-labels.js +8 -0
- package/src/components/chart-map-options.js +20 -0
- package/src/components/chart-pane.js +91 -0
- package/src/components/chart-renderer.js +58 -0
- package/src/components/chart-sample-view.js +32 -0
- package/src/components/chart-spatial-options.js +40 -0
- package/src/components/chart-time.js +84 -0
- package/src/components/chart-timeline.js +70 -0
- package/src/components/chart-types/area.js +2 -0
- package/src/components/chart-types/bar.js +2 -0
- package/src/components/chart-types/bar3D.js +2 -0
- package/src/components/chart-types/donut.js +2 -0
- package/src/components/chart-types/horizontalBar.js +2 -0
- package/src/components/chart-types/index.js +26 -0
- package/src/components/chart-types/line.js +2 -0
- package/src/components/chart-types/line3D.js +2 -0
- package/src/components/chart-types/lines3D.js +2 -0
- package/src/components/chart-types/map.js +2 -0
- package/src/components/chart-types/map3D.js +2 -0
- package/src/components/chart-types/mapBar3D.js +2 -0
- package/src/components/chart-types/pie.js +2 -0
- package/src/components/chart-types/polygons3D.js +2 -0
- package/src/components/chart-types/scatter.js +2 -0
- package/src/components/chart-types/scatter3D.js +2 -0
- package/src/components/chart-types/stackedArea.js +2 -0
- package/src/components/chart-types/stackedBar.js +2 -0
- package/src/components/chart-types/surface.js +2 -0
- package/src/components/charts.js +152 -0
- package/src/components/check-box-text-editor.js +88 -0
- package/src/components/check-box-text.js +193 -0
- package/src/components/check-box-tree.js +62 -0
- package/src/components/choice-editor.js +7 -5
- package/src/components/choice-field-styles.js +14 -0
- package/src/components/choices.js +5 -0
- package/src/components/drawing.js +199 -0
- package/src/components/grid-check-sets.js +98 -0
- package/src/components/grid-column-filters.js +198 -0
- package/src/components/grid-grammar.json +44 -0
- package/src/components/grid-header-interaction.js +3 -1
- package/src/components/grid-rows.js +2 -2
- package/src/components/grid-search-box.js +38 -22
- package/src/components/grid-search-styles.js +13 -14
- package/src/components/grid-search.js +8 -1
- package/src/components/grid-structure.js +10 -2
- package/src/components/grid-styles.js +23 -0
- package/src/components/grid.js +52 -10
- package/src/components/image-uploader.js +2 -2
- package/src/components/inputs.js +19 -10
- package/src/components/labelbox.js +5 -1
- package/src/components/licenses/claygl.txt +23 -0
- package/src/components/licenses/echarts-gl.txt +29 -0
- package/src/components/licenses/plotly.txt +21 -0
- package/src/components/licenses/uplot.txt +21 -0
- package/src/components/licenses/vega.txt +27 -0
- package/src/components/menus.js +19 -11
- package/src/components/toolbar-overflow.js +12 -8
- package/src/components/tree.js +30 -8
- package/src/components/typed-editor.js +14 -3
- package/src/components/vizabi-session.js +66 -0
- package/src/components/vizabi.js +66 -0
- package/src/components/window-surface.js +20 -9
- package/src/components/windows.js +1 -1
- package/src/gramlot.d.ts +1 -0
- package/src/gramlot.js +2 -0
- package/src/handlers/device-handler.js +32 -32
- package/src/handlers/source-handler.d.ts +2 -2
- package/src/ide-documents.js +19 -3
- package/src/ide-runtime.d.ts +1 -0
- package/src/ide-runtime.js +45 -31
- package/src/index.d.ts +1 -0
- package/src/renderer/drag-drop.js +1 -0
- package/src/renderer/gramlot-renderer.d.ts +2 -0
- package/src/renderer/gramlot-renderer.js +5 -4
- package/src/server/assets.d.ts +3 -0
- package/src/server/assets.js +9 -0
- package/src/server/gramlot-server.d.ts +1 -1
- package/src/server/gramlot-server.js +2 -1
- package/src/server/index.d.ts +1 -1
- package/src/server/index.js +1 -1
- package/src/server/visual-editor.js +17 -17
- package/src/stores/bag-collection-view.js +79 -17
- package/src/stores/collection-filter.js +2 -1
- package/src/stores/column-filter.js +49 -0
- package/src/stores/id-set.js +10 -0
- package/src/view/controls.js +8 -0
- package/src/view/html.js +10 -1
- package/src/view/label-menu.js +61 -0
- package/src/view/labelbox.js +15 -2
- package/themes/gramlot-base/theme.css +6 -0
- package/tools/gramlot-tools-inspector.js +169 -505
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gramlot/gramlot",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.30",
|
|
4
4
|
"description": "Declarative HTML/SVG interfaces with live data binding, authored in JavaScript or Python.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
12
|
"scripts": {
|
|
13
|
-
"test": "node --test tests/*.test.js tests/binding-contracts/gramlot-quiet-write.test.mjs tests/upstream-regressions/builder-symbolic-attribute.test.mjs",
|
|
13
|
+
"test": "node --test --test-concurrency=2 tests/*.test.js tests/binding-contracts/gramlot-quiet-write.test.mjs tests/upstream-regressions/builder-symbolic-attribute.test.mjs",
|
|
14
14
|
"build": "node scripts/build-runtime.mjs",
|
|
15
15
|
"test:server": "node --test tests/gramlot-server.test.js",
|
|
16
16
|
"prepack": "node scripts/build-runtime.mjs"
|
|
@@ -41,15 +41,20 @@
|
|
|
41
41
|
"@myriaddreamin/typst.ts": "0.7.0",
|
|
42
42
|
"codemirror-lang-typst": "0.6.0",
|
|
43
43
|
"dompurify": "3.4.17",
|
|
44
|
+
"echarts": "^6.1.0",
|
|
45
|
+
"echarts-gl": "2.1.0",
|
|
44
46
|
"jodit": "4.18.10",
|
|
45
47
|
"markdown-it": "14.3.3",
|
|
48
|
+
"plotly.js-dist-min": "4.2.0",
|
|
46
49
|
"prosemirror-commands": "1.6.2",
|
|
47
50
|
"prosemirror-history": "1.4.1",
|
|
48
51
|
"prosemirror-keymap": "1.2.2",
|
|
49
52
|
"prosemirror-markdown": "1.13.1",
|
|
50
53
|
"prosemirror-model": "1.25.12",
|
|
51
54
|
"prosemirror-state": "1.4.3",
|
|
52
|
-
"prosemirror-view": "1.42.6"
|
|
55
|
+
"prosemirror-view": "1.42.6",
|
|
56
|
+
"uplot": "1.6.32",
|
|
57
|
+
"vega": "6.4.0"
|
|
53
58
|
},
|
|
54
59
|
"devDependencies": {
|
|
55
60
|
"c8": "10.1.3",
|
|
@@ -82,7 +87,10 @@
|
|
|
82
87
|
"./mobile-environment": "./src/mobile-environment.js",
|
|
83
88
|
"./chat": "./src/chat.js",
|
|
84
89
|
"./components/chat": "./src/components/chat.js",
|
|
85
|
-
"./components/selection_trial": "./src/experiments/selection-trial.js"
|
|
90
|
+
"./components/selection_trial": "./src/experiments/selection-trial.js",
|
|
91
|
+
"./components/charts": "./src/components/charts.js",
|
|
92
|
+
"./components/drawing": "./src/components/drawing.js",
|
|
93
|
+
"./components/vizabi": "./src/components/vizabi.js"
|
|
86
94
|
},
|
|
87
95
|
"files": [
|
|
88
96
|
"LICENSE",
|
|
@@ -13,7 +13,7 @@ function structureData(source) {
|
|
|
13
13
|
node.builder.validateNode(node);
|
|
14
14
|
if (node.nodeTag !== 'column' || node.staticValue != null) throw new TypeError('grid column must be a scalar declaration');
|
|
15
15
|
const attrs = {tag:'cell'};
|
|
16
|
-
for (const key of ['field', 'name', 'dtype', 'width', 'align', 'format', 'white_space', 'max_height', 'edit']) {
|
|
16
|
+
for (const key of ['field', 'name', 'title', 'dtype', 'width', 'align', 'format', 'white_space', 'max_height', 'edit', 'check', 'checked', 'checkedField']) {
|
|
17
17
|
if (node.getAttr(key) != null) attrs[key] = node.getAttr(key);
|
|
18
18
|
}
|
|
19
19
|
const label = `cell_${attrs.field}`;
|
|
@@ -56,7 +56,7 @@ export function validateGridDeclaration(node) {
|
|
|
56
56
|
export function installGridStruct(node, data) {
|
|
57
57
|
const value = structureData(node.staticValue);
|
|
58
58
|
new GridStructure(value);
|
|
59
|
-
const path = `
|
|
59
|
+
const path = `_gramlot.grid.${crypto.randomUUID().replaceAll('-', '')}.struct`;
|
|
60
60
|
data.setItem(path, value, null, '>', false, true, node);
|
|
61
61
|
node.parentNode.setAttr({structpath: path}, false);
|
|
62
62
|
node.setValue(null, false);
|
package/src/binding/runtime.js
CHANGED
|
@@ -70,6 +70,7 @@ export class BindingRuntime {
|
|
|
70
70
|
get data() { return this.builder.data; }
|
|
71
71
|
/** Resolve a tree store against the selected live root. */
|
|
72
72
|
treeStore(node) {
|
|
73
|
+
if (node.treeStore !== null) return node.treeStore;
|
|
73
74
|
const path = node.getAttr('storepath');
|
|
74
75
|
if (path === '*S' || path.startsWith('*S.')) {
|
|
75
76
|
const root = this.renderer.source.getItem('main');
|
|
@@ -492,6 +493,15 @@ export class NodeBinding {
|
|
|
492
493
|
const component = node._getMeta('gramlot_component');
|
|
493
494
|
for (const [capability, attribute] of [['bagStore', 'storepath'], ['bagStruct', 'structpath']]) {
|
|
494
495
|
if (!component?.[capability]) continue;
|
|
496
|
+
if (capability === 'bagStore' && node.nodeTag === 'tree' && node.treeStore !== null) {
|
|
497
|
+
const store = node.treeStore;
|
|
498
|
+
const subscription = `gramlot-tree-${randomId()}`;
|
|
499
|
+
store.subscribe(subscription, {any: () => {
|
|
500
|
+
if (!this.closed && this.runtime.renderer.attached(node)) this.runtime.renderer.project(node);
|
|
501
|
+
}});
|
|
502
|
+
this.#registrations.push({close: () => store.unsubscribe(subscription, {any: true})});
|
|
503
|
+
continue;
|
|
504
|
+
}
|
|
495
505
|
const value = node.getAttr(attribute);
|
|
496
506
|
if (typeof value !== 'string' || !value || /^[\^=]/.test(value) || value.includes('?')) {
|
|
497
507
|
throw new TypeError(`${attribute} requires a plain Bag data path`);
|
package/src/bootstrap.js
CHANGED
|
@@ -86,7 +86,7 @@ export class PageBootstrap {
|
|
|
86
86
|
// Verify the complete graph before activating any component or command.
|
|
87
87
|
for (const collection of collections) collection.register(window);
|
|
88
88
|
app = new Gramlot({...config, document, serverAdapter:this.serverAdapter,
|
|
89
|
-
collections:[...(config.collections ?? []), ...collections
|
|
89
|
+
collections:[...(config.collections ?? []), ...collections]});
|
|
90
90
|
window.removeEventListener('pagehide', pagehide);
|
|
91
91
|
for (const collection of collections) collection.registerCommands(app);
|
|
92
92
|
for (const {logicClass,group,resource} of entries) app.src.logicRegistry.register(logicClass,{group,resource});
|
|
@@ -4,11 +4,24 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import {HtmlBuilder} from '@genrojs/builders';
|
|
7
|
+
import type {Bag} from '@genrojs/bag';
|
|
7
8
|
import type {SourceAttributes, SourceBag, SourceBagNode, ValidateNodeOptions} from '@genrojs/builders';
|
|
8
9
|
import type {GramlotHtmlRenderer} from '../renderer/gramlot-html-renderer.js';
|
|
9
10
|
import type {SourceReference} from '../references.js';
|
|
10
11
|
import type {NameSyntax} from './name-syntax.js';
|
|
11
12
|
|
|
13
|
+
/** Gramlot Source node, with a non-serialized external Bag reference for a tree. */
|
|
14
|
+
export interface GramlotSourceNode extends SourceBagNode {
|
|
15
|
+
/** Existing shared top toolbar of a frameGrid; never creates a second bar. */
|
|
16
|
+
readonly toolbar: GramlotSourceNode;
|
|
17
|
+
readonly treeStore: Bag | null;
|
|
18
|
+
setTreeStore(bag: Bag | null): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface GramlotSourceBag extends SourceBag {
|
|
22
|
+
getNode(path: string | number, isStatic?: boolean, autocreate?: boolean, defaultValue?: unknown): GramlotSourceNode | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
12
25
|
/** Gramlot vocabulary and inert authoring on the shared builder grammar. */
|
|
13
26
|
export class GramlotBuilder extends HtmlBuilder {
|
|
14
27
|
/** The dialect name, `'gramlot'`. */
|
|
@@ -16,7 +29,7 @@ export class GramlotBuilder extends HtmlBuilder {
|
|
|
16
29
|
static containers: string[];
|
|
17
30
|
/** Build an ordinary framePane containing center.grid; requires layout and grid. */
|
|
18
31
|
frameGrid(parent: SourceBag | SourceBagNode, options: SourceAttributes & {
|
|
19
|
-
storepath: string; rowMode: 'values' | 'attributes'; structpath?: string; searchOn?: boolean | string;
|
|
32
|
+
storepath: string; rowMode: 'values' | 'attributes'; structpath?: string; searchOn?: boolean | string; searchHelp?: boolean; chart?: boolean | string;
|
|
20
33
|
}): SourceBagNode;
|
|
21
34
|
/** Tag prefixes of the parent dialects, from the names of the classes above `GramlotBuilder`. */
|
|
22
35
|
static get dialectPrefixes(): string[];
|
|
@@ -30,7 +43,7 @@ export class GramlotBuilder extends HtmlBuilder {
|
|
|
30
43
|
/** The binding runtime of the Gramlot page that owns this builder, or null for authoring alone; set by `Gramlot` right after creating the builder. */
|
|
31
44
|
binding: unknown;
|
|
32
45
|
/** The node with `nodeId`; inside a Gramlot page it reads the node ids of the binding runtime. */
|
|
33
|
-
nodeById(nodeId: string):
|
|
46
|
+
nodeById(nodeId: string): GramlotSourceNode;
|
|
34
47
|
/** Load a grammar document into the builder. */
|
|
35
48
|
loadCollection(document: unknown): this;
|
|
36
49
|
/** The schema tag of an authored name, or null; the `gramlot_` prefix and excluded declarations raise. */
|
|
@@ -80,17 +80,36 @@ export class GramlotBuilder extends HtmlBuilder {
|
|
|
80
80
|
static { this.defineGrammar(buttons.toDocument()); }
|
|
81
81
|
|
|
82
82
|
/** Compose real Source nodes; frame/grid/menu retain their existing runtime owners. */
|
|
83
|
-
frameGrid(parent, {storepath, rowMode, structpath, searchOn = false, ...attrs} = {}) {
|
|
83
|
+
frameGrid(parent, {storepath, rowMode, structpath, searchOn = false, searchHelp = false, chart = false, ...attrs} = {}) {
|
|
84
84
|
for (const tag of ['framePane', 'grid']) {
|
|
85
85
|
if (!this.schemaTag(tag)) throw new TypeError(`frameGrid requires the ${tag} collection`);
|
|
86
86
|
}
|
|
87
|
+
const chartOptions = {};
|
|
88
|
+
for (const key of Object.keys(attrs)) if (key.startsWith('chart_')) {
|
|
89
|
+
chartOptions[key.slice(6)] = attrs[key]; delete attrs[key];
|
|
90
|
+
}
|
|
91
|
+
if (chart !== false) {
|
|
92
|
+
if (chart !== true && (typeof chart !== 'string' || !chart)) throw new TypeError('chart requires a boolean or chart type');
|
|
93
|
+
if (!attrs.datapath) throw new TypeError('A chart frameGrid requires its own datapath');
|
|
94
|
+
if (!this.schemaTag('chartPane')) throw new TypeError('frameGrid requires the chartPane collection');
|
|
95
|
+
if (typeof chart === 'string') chartOptions.chartType = chart;
|
|
96
|
+
} else if (Object.keys(chartOptions).length) throw new TypeError('chart_* options require chart');
|
|
87
97
|
const gridAttrs = {storepath, rowMode, ...(structpath == null ? {} : {structpath}),
|
|
88
98
|
node_label: 'grid', frameTarget: true, height: '100%', width: '100%'};
|
|
99
|
+
if (chart !== false) gridAttrs.nodeId = randomId();
|
|
89
100
|
this.validateNodeValues('grid', null, gridAttrs);
|
|
90
|
-
if (searchOn !== false) this.validateNodeValues('searchBox', null, {searchOn});
|
|
101
|
+
if (searchOn !== false) this.validateNodeValues('searchBox', null, {searchOn, searchHelp});
|
|
91
102
|
const frame = parent.framePane(attrs);
|
|
92
103
|
frame.center.grid(gridAttrs);
|
|
93
|
-
|
|
104
|
+
const bar = frame.top.menu({presentation:'bar', node_label:'bar', aria_label:'Grid toolbar', class:'gramlot-grid-toolbar'});
|
|
105
|
+
if (searchOn !== false) bar.menuline({group:true, node_label:'search', class:'gramlot-grid-search'}).searchBox({searchOn, searchHelp});
|
|
106
|
+
if (chart !== false) {
|
|
107
|
+
bar.menuline({caption:'Chart', icon:'▥', labelPosition:'tooltip', node_label:'chart', action:"this.SET('._chart.open',true)"});
|
|
108
|
+
const window = frame.center.floatingPane({title:'Chart', open:'^._chart.open', width:'820px', height:'560px',
|
|
109
|
+
movable:true, resizable:true, maximizable:true, node_label:'chartWindow'});
|
|
110
|
+
window.frame.center.chartPane({storepath,rowMode,gridId:gridAttrs.nodeId,configpath:'._chart',
|
|
111
|
+
configDefaults:new Bag(chartOptions),height:'100%'});
|
|
112
|
+
}
|
|
94
113
|
return frame;
|
|
95
114
|
}
|
|
96
115
|
|
package/src/builder/source.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {EditingSession} from '../editing-session.js';
|
|
2
|
-
import {BagCbResolver} from '@genrojs/bag';
|
|
2
|
+
import {Bag, BagCbResolver} from '@genrojs/bag';
|
|
3
3
|
import {SourceBag, SourceBagNode, sourceAttributeItems, wrapSource} from '@genrojs/builders';
|
|
4
4
|
import {fromTytx, getSubtypeDict, setSubtypeDict, toTytx} from '@genrojs/tytx';
|
|
5
5
|
import {pointerTransform, pointerDependencies} from '@genrojs/builders';
|
|
@@ -179,6 +179,23 @@ function isExpression(value) {
|
|
|
179
179
|
*/
|
|
180
180
|
export class GramlotBuilderBagNode extends SourceBagNode {
|
|
181
181
|
#formState = null;
|
|
182
|
+
#treeStore = null;
|
|
183
|
+
|
|
184
|
+
/** An externally owned Bag attached to this tree's Source node. */
|
|
185
|
+
get treeStore() { return this.#treeStore; }
|
|
186
|
+
|
|
187
|
+
setTreeStore(bag) {
|
|
188
|
+
if (this.nodeTag !== 'tree') throw new TypeError('setTreeStore requires a tree Source node');
|
|
189
|
+
if (bag !== null && !(bag instanceof Bag)) throw new TypeError('setTreeStore requires a Bag or null');
|
|
190
|
+
if (bag === this.#treeStore) return;
|
|
191
|
+
this.#treeStore = bag;
|
|
192
|
+
const runtime = this.rootBuilder.binding;
|
|
193
|
+
const binding = runtime?.bindingFor(this);
|
|
194
|
+
if (binding && !binding.closed) {
|
|
195
|
+
binding.rebind();
|
|
196
|
+
if (runtime.renderer.attached(this)) runtime.renderer.project(this);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
182
199
|
/** The local form lifecycle owned by the nearest marked Source ancestor. */
|
|
183
200
|
get formState() {
|
|
184
201
|
for (let owner = this; owner; owner = owner.parentNode) {
|
|
@@ -224,6 +241,12 @@ export class GramlotBuilderBagNode extends SourceBagNode {
|
|
|
224
241
|
}
|
|
225
242
|
return (attrs = {}) => this.builder.wrapSource(this.builder.commandOnNode(this, 'grid', null, attrs));
|
|
226
243
|
}
|
|
244
|
+
get toolbar() {
|
|
245
|
+
if (this.nodeTag !== 'framePane') throw new TypeError('toolbar accessor requires framePane');
|
|
246
|
+
const bar = this.staticValue instanceof SourceBag ? this.staticValue.getNode('top.bar') : null;
|
|
247
|
+
if (!bar || bar.nodeTag !== 'menu') throw new TypeError('This frame has no toolbar');
|
|
248
|
+
return this.builder.wrapSource(bar);
|
|
249
|
+
}
|
|
227
250
|
get top() { return this.frameRegion('top'); }
|
|
228
251
|
get bottom() { return this.frameRegion('bottom'); }
|
|
229
252
|
get left() { return this.frameRegion('left'); }
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** Local microphone FFT acquisition; independent of charts, transport and DOM. */
|
|
2
|
+
export function audioAnalysisOptions({fftSize=1024, frameRate=20, minimumDb=-100}={}) {
|
|
3
|
+
if(!Number.isInteger(fftSize)||fftSize<256||fftSize>8192||(fftSize&(fftSize-1)))throw new RangeError('FFT size must be a power of two from 256 to 8192');
|
|
4
|
+
if(!Number.isFinite(frameRate)||frameRate<1||frameRate>30)throw new RangeError('Frame rate must be between 1 and 30');
|
|
5
|
+
if(!Number.isFinite(minimumDb)||minimumDb>=0||minimumDb < -160)throw new RangeError('Minimum dB must be between -160 and 0 (exclusive)');
|
|
6
|
+
return {fftSize,frameRate,minimumDb};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class AudioAnalysisSession {
|
|
10
|
+
#window; #frame; #state; #error; #generation=0; #context; #stream; #source; #analyser; #raf; #last=-Infinity; #ended;
|
|
11
|
+
constructor(window,{frame,state,error}) { this.#window=window;this.#frame=frame;this.#state=state;this.#error=error; }
|
|
12
|
+
configure(options) {
|
|
13
|
+
this.options=audioAnalysisOptions(options);
|
|
14
|
+
if(this.#analyser)this.#analyser.fftSize=this.options.fftSize;
|
|
15
|
+
}
|
|
16
|
+
async start(options) {
|
|
17
|
+
this.configure(options);
|
|
18
|
+
if(this.#context)return;
|
|
19
|
+
const win=this.#window;
|
|
20
|
+
if(!win.isSecureContext||!win.navigator.mediaDevices?.getUserMedia||!win.AudioContext)throw new Error('Microphone analysis requires HTTPS or localhost and Web Audio support');
|
|
21
|
+
const generation=++this.#generation;
|
|
22
|
+
const context=new win.AudioContext();this.#context=context;
|
|
23
|
+
this.#state('requesting');
|
|
24
|
+
try {
|
|
25
|
+
await context.resume();
|
|
26
|
+
if(generation!==this.#generation)return;
|
|
27
|
+
const stream=await win.navigator.mediaDevices.getUserMedia({audio:true,video:false});
|
|
28
|
+
if(generation!==this.#generation){for(const track of stream.getTracks())track.stop();return;}
|
|
29
|
+
this.#stream=stream;
|
|
30
|
+
this.#ended=()=>{void this.stop().then(()=>this.#error(new Error('Microphone capture ended')),error=>this.#error(error));};
|
|
31
|
+
for(const track of stream.getTracks())track.addEventListener('ended',this.#ended);
|
|
32
|
+
this.#source=context.createMediaStreamSource(stream);
|
|
33
|
+
this.#analyser=context.createAnalyser();this.#analyser.fftSize=this.options.fftSize;
|
|
34
|
+
this.#source.connect(this.#analyser); // Never connected to speakers, recorded or uploaded.
|
|
35
|
+
this.#state('running');this.#last=-Infinity;
|
|
36
|
+
const tick=timestamp=>{
|
|
37
|
+
if(generation!==this.#generation)return;
|
|
38
|
+
try {
|
|
39
|
+
if(timestamp-this.#last>=1000/this.options.frameRate) {
|
|
40
|
+
this.#last=timestamp;
|
|
41
|
+
const analyser=this.#analyser;
|
|
42
|
+
const waveform=new Float32Array(analyser.fftSize),spectrum=new Float32Array(analyser.frequencyBinCount);
|
|
43
|
+
analyser.getFloatTimeDomainData(waveform);analyser.getFloatFrequencyData(spectrum);
|
|
44
|
+
this.#frame({waveform,spectrum,sampleRate:context.sampleRate,minimumDb:this.options.minimumDb});
|
|
45
|
+
}
|
|
46
|
+
this.#raf=win.requestAnimationFrame(tick);
|
|
47
|
+
} catch(error) { void this.stop().then(()=>this.#error(error),cleanupError=>this.#error(cleanupError)); }
|
|
48
|
+
};
|
|
49
|
+
this.#raf=win.requestAnimationFrame(tick);
|
|
50
|
+
} catch(error) {
|
|
51
|
+
if(generation!==this.#generation)return;
|
|
52
|
+
await this.stop();throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async stop() {
|
|
56
|
+
const generation=++this.#generation;
|
|
57
|
+
if(this.#raf!=null)this.#window.cancelAnimationFrame(this.#raf);
|
|
58
|
+
this.#raf=null;
|
|
59
|
+
for(const track of this.#stream?.getTracks()??[]) {track.removeEventListener('ended',this.#ended);track.stop();}
|
|
60
|
+
this.#stream=null;this.#source?.disconnect();this.#analyser?.disconnect();this.#source=this.#analyser=null;
|
|
61
|
+
const context=this.#context;this.#context=null;
|
|
62
|
+
if(context&&context.state!=='closed')await context.close();
|
|
63
|
+
if(generation===this.#generation)this.#state('stopped');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {defineCollection,defineComponent} from '@gramlot/gramlot/components';
|
|
2
|
+
import {Container} from './container.js';
|
|
3
|
+
import {AudioAnalysisSession} from './audio-analysis-session.js';
|
|
4
|
+
|
|
5
|
+
export const AudioAnalyser=defineComponent({
|
|
6
|
+
name:'audioAnalyser',tag:'gramlot-audio-analyser',base:Container,sourceContext:true,
|
|
7
|
+
parameters:{running:{dtype:'B',default:false,binding:'twoWay'},fftSize:{dtype:'L',default:1024,binding:'read'},
|
|
8
|
+
frameRate:{dtype:'N',default:20,binding:'read'},minimumDb:{dtype:'N',default:-100,binding:'read'},
|
|
9
|
+
spectrum:{dtype:'X',nullable:true,binding:'twoWay'},waveform:{dtype:'X',nullable:true,binding:'twoWay'},
|
|
10
|
+
sampleRate:{dtype:'N',default:0,binding:'twoWay'},status:{dtype:'T',default:'stopped',binding:'twoWay'},error:{dtype:'T',default:'',binding:'twoWay'}},
|
|
11
|
+
implementation:Base=>class extends Base {
|
|
12
|
+
#context; #session; #active=false; #requested=false; #hide; #configuration;
|
|
13
|
+
setSourceContext(context){this.#context=context;}
|
|
14
|
+
connectedCallback(){
|
|
15
|
+
this.#active=true;this.style.display='none';
|
|
16
|
+
const write=(name,value)=>{if(this.#active)this.#context.writeParameter(name,value);};
|
|
17
|
+
this.#session=new AudioAnalysisSession(this.ownerDocument.defaultView,{
|
|
18
|
+
state:status=>write('status',status),error:error=>this.#failed(error),
|
|
19
|
+
frame:({waveform,spectrum,sampleRate,minimumDb})=>{
|
|
20
|
+
write('sampleRate',sampleRate);
|
|
21
|
+
write('waveform',Array.from(waveform));
|
|
22
|
+
write('spectrum',Array.from(spectrum,value=>Math.max(minimumDb,value)));
|
|
23
|
+
}});
|
|
24
|
+
this.#hide=()=>{this.#requested=false;write('running',false);void this.#session.stop().catch(error=>this.#failed(error));};
|
|
25
|
+
this.ownerDocument.defaultView.addEventListener('pagehide',this.#hide);
|
|
26
|
+
this.#sync();
|
|
27
|
+
}
|
|
28
|
+
projectAttributes(attrs,adapt){const rest=super.projectAttributes(attrs,adapt);if(this.#active)this.#sync();return rest;}
|
|
29
|
+
#failed(error){if(!this.#active)return;this.#requested=false;this.#context.writeParameter('running',false);this.#context.writeParameter('error',error.message);void this.#session.stop().then(()=>{if(this.#active)this.#context.writeParameter('status','error');},cleanupError=>console.error('Audio cleanup failed',cleanupError));}
|
|
30
|
+
#sync(){
|
|
31
|
+
const {running,fftSize,frameRate,minimumDb}=this.parameters;
|
|
32
|
+
try {
|
|
33
|
+
const configuration=JSON.stringify([fftSize,frameRate,minimumDb]);
|
|
34
|
+
if(configuration!==this.#configuration){this.#configuration=configuration;this.#session.configure({fftSize,frameRate,minimumDb});}
|
|
35
|
+
if(running===this.#requested)return;
|
|
36
|
+
this.#requested=running;
|
|
37
|
+
if(running){this.#context.writeParameter('error','');void this.#session.start({fftSize,frameRate,minimumDb}).catch(error=>this.#failed(error));}
|
|
38
|
+
else void this.#session.stop().catch(error=>this.#failed(error));
|
|
39
|
+
}catch(error){this.#failed(error);}
|
|
40
|
+
}
|
|
41
|
+
disconnectedCallback(){this.#active=false;this.#requested=false;this.ownerDocument.defaultView.removeEventListener('pagehide',this.#hide);void this.#session.stop().catch(error=>console.error('Audio analysis cleanup failed',error));}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
export default defineCollection({name:'audio',components:[AudioAnalyser]});
|
package/src/components/bases.js
CHANGED
|
@@ -133,11 +133,13 @@ export function ChoiceGroup(HTMLElement) {
|
|
|
133
133
|
items[next].focus();
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
|
+
choiceOptions() { return parseChoices(this.parameters.values ?? ""); }
|
|
136
137
|
projectAttributes(attrs, adapt) {
|
|
137
138
|
const rest = super.projectAttributes(attrs, adapt);
|
|
138
|
-
const values = this.
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
const values = this.choiceOptions();
|
|
140
|
+
const signature = JSON.stringify(values);
|
|
141
|
+
if (signature !== this.#values) {
|
|
142
|
+
const options = values;
|
|
141
143
|
const retained = new Set();
|
|
142
144
|
let previous = null;
|
|
143
145
|
for (const {id: code, caption} of options) {
|
|
@@ -159,7 +161,7 @@ export function ChoiceGroup(HTMLElement) {
|
|
|
159
161
|
for (const [code, item] of this.#options) if (!retained.has(code)) {
|
|
160
162
|
item.label.remove(); this.#options.delete(code);
|
|
161
163
|
}
|
|
162
|
-
this.#values =
|
|
164
|
+
this.#values = signature;
|
|
163
165
|
}
|
|
164
166
|
const cols = this.parameters.cols;
|
|
165
167
|
if (!Number.isInteger(cols) || cols < 1) throw new TypeError('cols must be a positive integer');
|
|
@@ -462,7 +462,8 @@ export const BorderContainer = defineComponent({
|
|
|
462
462
|
const state = this.#regions.get(side), c = state.config;
|
|
463
463
|
const opposite = {left:'right',right:'left',top:'bottom',bottom:'top'}[side];
|
|
464
464
|
const box = this.control.getBoundingClientRect();
|
|
465
|
-
const
|
|
465
|
+
const centerMin = this.#regions.get('center').config?.min ?? 0;
|
|
466
|
+
const available = Math.max(0, (horizontal(side) ? box.height : box.width) - this.#extent(opposite) - centerMin);
|
|
466
467
|
const size = Math.max(Math.min(c.min, available), Math.min(desired, c.max, available));
|
|
467
468
|
state.size = `${size}px`; this.#render(side);
|
|
468
469
|
c.writeParameter(size);
|
|
@@ -471,11 +472,13 @@ export const BorderContainer = defineComponent({
|
|
|
471
472
|
const state = this.#regions.get(side);
|
|
472
473
|
if (evt.target !== state.separator || !state.config?.splitter || state.closed) return;
|
|
473
474
|
const keys = horizontal(side) ? ['ArrowUp','ArrowDown'] : ['ArrowLeft','ArrowRight'];
|
|
474
|
-
if (!keys.includes(evt.key)) return;
|
|
475
|
+
if (!keys.includes(evt.key) && !['Home', 'End'].includes(evt.key)) return;
|
|
475
476
|
evt.preventDefault();
|
|
476
477
|
const sign = ['left','top'].includes(side) ? 1 : -1;
|
|
477
478
|
const previousSize = this.#extent(side);
|
|
478
|
-
|
|
479
|
+
const desired = evt.key === 'Home' ? state.config.min : evt.key === 'End' ? state.config.max
|
|
480
|
+
: previousSize + (evt.key === keys[0] ? -1 : 1) * sign;
|
|
481
|
+
this.#resize(side, desired);
|
|
479
482
|
this.#commitResize(side, previousSize);
|
|
480
483
|
}
|
|
481
484
|
#startDrag(side, evt) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {labelboxContent} from '../view/labelbox.js';
|
|
2
|
+
import {choiceFieldStyles} from './choice-field-styles.js';
|
|
2
3
|
/** Built-in command surfaces. Execution stays in ButtonBinding, state in ControlAdapter. */
|
|
3
4
|
import {defineComponent, defineCollection} from './registry.js';
|
|
4
5
|
import {controlElement} from './bases.js';
|
|
@@ -8,6 +9,7 @@ import {MenuContainer, menuLine} from './menus.js';
|
|
|
8
9
|
function Command(HTMLElement) {
|
|
9
10
|
return class extends controlElement(HTMLElement) {
|
|
10
11
|
#actionPresentation = null;
|
|
12
|
+
#captionObserver;
|
|
11
13
|
constructor() {
|
|
12
14
|
super();
|
|
13
15
|
const doc = this.ownerDocument;
|
|
@@ -49,7 +51,43 @@ function Command(HTMLElement) {
|
|
|
49
51
|
:host([role=separator]) button{display:none}
|
|
50
52
|
@media(forced-colors:active){button,:host(.button--secondary) button,:host(.button--quiet) button{background:ButtonFace;color:ButtonText;border-color:ButtonText;filter:none}}
|
|
51
53
|
`;
|
|
54
|
+
style.textContent += `
|
|
55
|
+
#control.icon-only{gap:0;padding:var(--gramlot-button-icon-padding,5px);
|
|
56
|
+
min-width:max(calc(var(--gramlot-button-icon-size,24px) + 12px),var(--gramlot-touch-target,0px));
|
|
57
|
+
min-height:max(calc(var(--gramlot-button-icon-size,24px) + 12px),var(--gramlot-touch-target,0px));
|
|
58
|
+
background:transparent;border-color:transparent;line-height:1}
|
|
59
|
+
#control.icon-only .icon{display:inline-flex;align-items:center;justify-content:center;flex:none;
|
|
60
|
+
width:var(--gramlot-button-icon-size,24px);height:var(--gramlot-button-icon-size,24px);
|
|
61
|
+
font-size:var(--gramlot-button-icon-size,24px);line-height:1}
|
|
62
|
+
#control.icon-only:hover:not(:disabled){background:var(--gramlot-selected,Highlight)}
|
|
63
|
+
#control.icon-only:is([aria-pressed=true],[aria-checked=true],[aria-expanded=true]){background:var(--gramlot-selected,Highlight);color:var(--gramlot-action,CanvasText)}
|
|
64
|
+
#control.icon-only .led{display:none}
|
|
65
|
+
@media(forced-colors:active){#control.icon-only{background:ButtonFace;color:ButtonText;border-color:ButtonText}
|
|
66
|
+
#control.icon-only:is([aria-pressed=true],[aria-checked=true],[aria-expanded=true]){background:Highlight;color:HighlightText}}
|
|
67
|
+
`;
|
|
52
68
|
this.shadowRoot.append(style);
|
|
69
|
+
this.#captionObserver = new this.ownerDocument.defaultView.MutationObserver(() => this.refreshIconOnly());
|
|
70
|
+
}
|
|
71
|
+
connectedCallback() {
|
|
72
|
+
super.connectedCallback();
|
|
73
|
+
const options = {childList:true, subtree:true, characterData:true, attributes:true, attributeFilter:['hidden','slot']};
|
|
74
|
+
this.#captionObserver.observe(this, options);
|
|
75
|
+
this.#captionObserver.observe(this.control, options);
|
|
76
|
+
this.refreshIconOnly();
|
|
77
|
+
}
|
|
78
|
+
disconnectedCallback() { this.#captionObserver.disconnect(); }
|
|
79
|
+
releaseControl() { this.#captionObserver.disconnect(); super.releaseControl(); }
|
|
80
|
+
refreshIconOnly() {
|
|
81
|
+
const hasContent = node => node.nodeType === 3 ? Boolean(node.textContent.trim())
|
|
82
|
+
: node.nodeType === 1 && !node.hidden && node.getAttribute('slot') !== 'menu';
|
|
83
|
+
const slottedCaption = !this.caption.hidden && this.caption.assignedNodes().some(hasContent);
|
|
84
|
+
const extraCaption = [...this.control.children].some(node =>
|
|
85
|
+
node !== this.icon && node !== this.caption && !node.hidden &&
|
|
86
|
+
!node.matches('.led,.menu-check,.menu-arrow') &&
|
|
87
|
+
!(node.matches('.menu-caption') && this.control.classList.contains('toolbar-tooltip')) &&
|
|
88
|
+
Boolean(node.textContent.trim()));
|
|
89
|
+
this.control.classList.toggle('icon-only', !this.control.classList.contains('menu-row') &&
|
|
90
|
+
Boolean(this.icon.textContent || this.icon.firstElementChild) && !slottedCaption && !extraCaption);
|
|
53
91
|
}
|
|
54
92
|
get disabled() { return this.control.disabled; }
|
|
55
93
|
set disabled(value) { this.control.disabled = Boolean(value); }
|
|
@@ -64,7 +102,7 @@ function Command(HTMLElement) {
|
|
|
64
102
|
return rest;
|
|
65
103
|
}
|
|
66
104
|
renderIcon(icon, iconSrc) {
|
|
67
|
-
if (!iconSrc) { this.icon.textContent = icon ?? ''; return; }
|
|
105
|
+
if (!iconSrc) { this.icon.textContent = icon ?? ''; this.refreshIconOnly(); return; }
|
|
68
106
|
let image = this.icon.firstElementChild;
|
|
69
107
|
if (!image) {
|
|
70
108
|
image = this.ownerDocument.createElement('img');
|
|
@@ -72,6 +110,7 @@ function Command(HTMLElement) {
|
|
|
72
110
|
this.icon.replaceChildren(image);
|
|
73
111
|
}
|
|
74
112
|
if (image.getAttribute('src') !== iconSrc) image.setAttribute('src', iconSrc);
|
|
113
|
+
this.refreshIconOnly();
|
|
75
114
|
}
|
|
76
115
|
get entryIcon() { return this.parameters.icon; }
|
|
77
116
|
get entryIconSrc() { return this.parameters.iconSrc; }
|
|
@@ -81,6 +120,7 @@ function Command(HTMLElement) {
|
|
|
81
120
|
this.icon.textContent = presentation.icon;
|
|
82
121
|
this.title = presentation.title;
|
|
83
122
|
this.control.setAttribute('aria-label', presentation.title);
|
|
123
|
+
this.refreshIconOnly();
|
|
84
124
|
}
|
|
85
125
|
attachCommand() {}
|
|
86
126
|
releaseCommand() {}
|
|
@@ -136,7 +176,7 @@ export const MenuLine = defineComponent({name:'menuline',tag:'gramlot-menu-line'
|
|
|
136
176
|
command:{dtype:'T',nullable:true},caption:{dtype:'T',nullable:true},code:{dtype:'T',nullable:true},
|
|
137
177
|
checked:{dtype:'B',nullable:true,binding:'read'},tooltip:{dtype:'T',nullable:true},
|
|
138
178
|
labelPosition:{dtype:'T',binding:'read',nullable:true,enum:['beside','below','tooltip']},iconSize:{dtype:'R',binding:'read',nullable:true},
|
|
139
|
-
group:{dtype:'B',default:false},
|
|
179
|
+
group:{dtype:'B',default:false},
|
|
140
180
|
parameters:{annotation:{kind:'type',module:'builtins',name:'dict'},nullable:true},favorite:{dtype:'B',default:false}
|
|
141
181
|
},implementation:menuLine});
|
|
142
182
|
export const Spacer = defineComponent({name:'spacer',tag:'gramlot-spacer',base:HTMLElement=>class extends HTMLElement {
|
|
@@ -155,8 +195,12 @@ export const DropDownButton = defineComponent({name:'dropDownButton',tag:'gramlo
|
|
|
155
195
|
constructor() {
|
|
156
196
|
super();const doc=this.ownerDocument;
|
|
157
197
|
this.control.classList.add('split');
|
|
198
|
+
this.controlBox.classList.add('choice-field');
|
|
199
|
+
const affordance=doc.createElement('style');
|
|
200
|
+
affordance.textContent=choiceFieldStyles + '.split{border-radius:var(--gramlot-radius-sm,4px);padding-inline-end:calc(var(--gramlot-choice-toggle-width,1.6em) + .5em)}';
|
|
201
|
+
this.shadowRoot.append(affordance);
|
|
158
202
|
this.#chosenCaption=doc.createElement('span');this.#chosenCaption.hidden=true;this.control.append(this.#chosenCaption);
|
|
159
|
-
this.#arrow=doc.createElement('button');this.#arrow.type='button';this.#arrow.className='arrow';
|
|
203
|
+
this.#arrow=doc.createElement('button');this.#arrow.type='button';this.#arrow.className='arrow choice-toggle';
|
|
160
204
|
this.#arrow.setAttribute('aria-label','Open menu');this.#arrow.setAttribute('aria-haspopup','menu');this.#arrow.setAttribute('aria-expanded','false');
|
|
161
205
|
this.controlBox.append(this.#arrow);
|
|
162
206
|
const slot=doc.createElement('slot');slot.name='menu';this.shadowRoot.append(slot);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {chartData3D} from './chart-data.js';
|
|
2
|
+
|
|
3
|
+
/** Place measure bars beside each other inside each category group and plane. */
|
|
4
|
+
export function chartBar3DOptions(view, first, second, fields, settings, domains) {
|
|
5
|
+
const datasets=fields.map(field=>chartData3D(view,first,second,field,domains));
|
|
6
|
+
const dimensions=datasets[0]?.dimensions ?? [[],[]];
|
|
7
|
+
const count=fields.length, span=0.72, step=count ? span/count : 0;
|
|
8
|
+
const boxWidth=100,boxDepth=80;
|
|
9
|
+
return {
|
|
10
|
+
backgroundColor:'#ffffff',
|
|
11
|
+
legend:{show:true,type:'scroll',left:12,right:12,bottom:10,height:24,data:fields},
|
|
12
|
+
tooltip:{renderMode:'richText',formatter:params=>{
|
|
13
|
+
const [x,y,value]=params.value;
|
|
14
|
+
return `${first}: ${dimensions[0][Math.round(x)-1]}\n${second}: ${dimensions[1][y]}\n${params.seriesName}: ${value}`;
|
|
15
|
+
}},
|
|
16
|
+
xAxis3D:{type:'value',name:first,nameGap:35,min:0,max:Math.max(2,dimensions[0].length+1),interval:1,
|
|
17
|
+
axisLabel:{formatter:value=>dimensions[0][value-1] ?? ''}},
|
|
18
|
+
yAxis3D:{type:'category',name:second,nameGap:35,data:dimensions[1]},
|
|
19
|
+
zAxis3D:{type:'value',name:'Value',nameGap:40,...(domains?{min:domains.z[0],max:domains.z[1]}:{})},
|
|
20
|
+
grid3D:{top:8,bottom:64,height:null,left:16,right:16,width:null,boxWidth,boxDepth,viewControl:{projection:'perspective'},
|
|
21
|
+
light:{main:{intensity:1.2},ambient:{intensity:0.4}}},
|
|
22
|
+
series:fields.map((field,index)=>({
|
|
23
|
+
id:field,name:field,type:'bar3D',shading:'lambert',
|
|
24
|
+
barSize:[boxWidth/Math.max(2,dimensions[0].length+1)*step*0.85,
|
|
25
|
+
boxDepth/Math.max(1,dimensions[1].length)*0.55],
|
|
26
|
+
data:datasets[index].source.map(([x,y,value])=>[x+1+(index-(count-1)/2)*step,y,value]),
|
|
27
|
+
itemStyle:{color:settings[index].color}
|
|
28
|
+
}))
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {chartEngines,chartCapabilities} from './chart-engines/index.js';
|
|
2
|
+
import {chartTypes} from './chart-types/index.js';
|
|
3
|
+
|
|
4
|
+
/** Standard Source sections, reused by the type descriptors. No chart state lives here. */
|
|
5
|
+
export function chartControls(config, {configpath,storepath,rowMode,prefix}) {
|
|
6
|
+
const refs={};
|
|
7
|
+
function select(parent,label,key,choices,reference) {
|
|
8
|
+
const id=`${prefix}-${key}`;
|
|
9
|
+
parent.html_label(label,{for:id});
|
|
10
|
+
const attrs={id,value:`^${configpath}.${key}`};
|
|
11
|
+
if(reference) { attrs.nodeId=`${prefix}_${reference}`;refs[reference]=attrs.nodeId; }
|
|
12
|
+
const control=parent.select(attrs);
|
|
13
|
+
for(const [value,caption] of choices) {
|
|
14
|
+
const attrs={value};
|
|
15
|
+
if(key==='timeStep'&&['minute','hour'].includes(value)){
|
|
16
|
+
attrs.disabled=`^${configpath}.timeHasClock:=!{}`;
|
|
17
|
+
} else if(key==='chartType') {
|
|
18
|
+
const engines=Object.entries(chartEngines).filter(([,Adapter])=>chartCapabilities(Adapter).includes(value)).map(([name])=>name);
|
|
19
|
+
attrs.disabled=`^${configpath}.engine:=!${JSON.stringify(engines)}.includes({})`;
|
|
20
|
+
attrs.hidden=attrs.disabled;
|
|
21
|
+
} else if(key==='engine') {
|
|
22
|
+
const types=chartCapabilities(chartEngines[value]);
|
|
23
|
+
attrs.disabled=`^${configpath}.chartType:=!${JSON.stringify(types)}.includes({})`;
|
|
24
|
+
attrs.hidden=attrs.disabled;
|
|
25
|
+
}
|
|
26
|
+
control.option(caption,attrs);
|
|
27
|
+
}
|
|
28
|
+
return control;
|
|
29
|
+
}
|
|
30
|
+
const columns=[['','No columns']];
|
|
31
|
+
select(config,'Engine','engine',Object.entries(chartEngines).map(([id,Adapter])=>[id,Adapter.label]));
|
|
32
|
+
select(config,'Chart type','chartType',chartTypes.map(type=>[type.id,type.label]));
|
|
33
|
+
const animation=config.details({id:`${prefix}-animation`});
|
|
34
|
+
animation.summary('Temporal animation');
|
|
35
|
+
const animationControls=animation.div({display:'grid',gap:'4px'});
|
|
36
|
+
select(animationControls,'Date field','timeField',[['','Off']],'timeFieldId');
|
|
37
|
+
const timing=animationControls.div({display:`^${configpath}.timeField:={} ? 'grid' : 'none'`,gap:'4px'});
|
|
38
|
+
select(timing,'Period','timeStep',[['auto','Automatic'],['minute','Minute'],['hour','Hour'],['day','Day'],['week','Week · Mon–Sun'],['month','Month'],['year','Year']]);
|
|
39
|
+
select(timing,'Empty periods','timeEmpty',[['previous','Keep previous snapshot'],['empty','Show empty']]);
|
|
40
|
+
const resolved=timing.div();
|
|
41
|
+
resolved.span('Current period (UTC): ');resolved.span(`^${configpath}.timeUnit`);
|
|
42
|
+
timing.html_label('Seconds per frame',{for:`${prefix}-time-speed`});
|
|
43
|
+
timing.numberTextBox({id:`${prefix}-time-speed`,value:`^${configpath}.timeSpeed`,min:0.1,max:10});
|
|
44
|
+
config.chartTimeline({storepath,rowMode,configpath,timeField:`^${configpath}.timeField`,timeStep:`^${configpath}.timeStep`,timeIndex:`^${configpath}.timeIndex`});
|
|
45
|
+
const sections={
|
|
46
|
+
category(parent) { select(parent,'Category / territory field','captionField',columns,'categoryId'); },
|
|
47
|
+
geoJSON(parent) {
|
|
48
|
+
parent.chartGeoJSON({value:`^${configpath}.geoJSON`});
|
|
49
|
+
parent.div('Link the category / territory field to GeoJSON properties.name.',{style:'font-size:11px'});
|
|
50
|
+
},
|
|
51
|
+
mapMeasure(parent) {
|
|
52
|
+
select(parent,'Map measure','mapValueField',[['','No measures']],'mapMeasureId');
|
|
53
|
+
select(parent,'Map label field','mapLabelField',columns,'mapLabelId');
|
|
54
|
+
select(parent,'Map labels','mapLabelMode',[['none','None'],['name','Names'],['value','Values'],['nameValue','Names and values']]);
|
|
55
|
+
parent.div('Calculated measures must be supplied as store columns.',{style:'font-size:11px'});
|
|
56
|
+
},
|
|
57
|
+
mapBarScale(parent) {
|
|
58
|
+
select(parent,'Height scale','mapBarScale',[['zero','From zero'],['extent','Data range']]);
|
|
59
|
+
parent.div('Selected measures share one height scale. Data range truncates the baseline; tooltip values are unchanged.',{style:'font-size:11px'});
|
|
60
|
+
},
|
|
61
|
+
secondDimension(parent) { select(parent,'Second dimension','secondCaptionField',columns,'secondCategoryId'); },
|
|
62
|
+
geometry(parent) { select(parent,'Coordinate field','geometryField',columns,'geometryId'); },
|
|
63
|
+
measures(parent) {
|
|
64
|
+
const menu=parent.menu({presentation:'bar',aria_label:'Measures toolbar'})
|
|
65
|
+
.menuline({caption:'Measures',aria_label:'Choose measures'}).menu({nodeId:`${prefix}_measureMenuId`});
|
|
66
|
+
refs.measureMenuId=`${prefix}_measureMenuId`;
|
|
67
|
+
menu.menuline({caption:'No measures',disabled:true});
|
|
68
|
+
const grid=parent.grid({id:`${prefix}-measures`,storepath:`${configpath}.seriesOptions`,rowMode:'values',height:'120px',
|
|
69
|
+
style:'--gramlot-grid-row-height:24px;--gramlot-grid-font-size:12px;--gramlot-grid-cell-padding:2px 5px',
|
|
70
|
+
filter:{value:'^true',columns:['selected'],dtype:'T'}});
|
|
71
|
+
const columns=grid.struct();
|
|
72
|
+
columns.column({field:'caption',name:'Measure',width:'40%'});
|
|
73
|
+
columns.column({field:'color',name:'Color',width:'30%',edit:{tag:'colorpicker'}});
|
|
74
|
+
columns.column({field:'axis',name:'Axis',width:'30%',edit:{tag:'filteringSelect',values:'left:Left,right:Right',validate_select:true}});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
for(const [name,compose] of Object.entries(sections)) {
|
|
78
|
+
const types=chartTypes.filter(type=>type.controls.includes(name)).map(type=>type.id);
|
|
79
|
+
const section=config.div({display:`^${configpath}.chartType:=${JSON.stringify(types)}.includes({}) ? "grid" : "none"`,gap:'4px'});
|
|
80
|
+
compose(section);
|
|
81
|
+
}
|
|
82
|
+
config.chartFields({storepath,rowMode,configpath,...refs});
|
|
83
|
+
}
|