@gramlot/gramlot 0.3.26 → 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.
Files changed (213) hide show
  1. package/assets/icons/chart.svg +1 -0
  2. package/dist/components/audio/__init__.py +13 -0
  3. package/dist/components/audio/assets/collection.js +3 -0
  4. package/dist/components/audio/assets/index.js +3 -0
  5. package/dist/components/audio/commands.json +7 -0
  6. package/dist/components/audio/grammar.json +335 -0
  7. package/dist/components/charts/__init__.py +13 -0
  8. package/dist/components/charts/assets/collection.js +47 -0
  9. package/dist/components/charts/assets/files/55ea01207028f76d844678511f29fc800f8a1e67a8a0fe80470128677847ad32-echarts-gl.txt +29 -0
  10. package/dist/components/charts/assets/files/63727832aaf62004a2b249c933e327f3c90caf49e41a72f4bf436edf632cbda8-vega.txt +27 -0
  11. package/dist/components/charts/assets/files/8c45d9eaf50c2f72dd9c7ab9ef440788ba58a3538484b5c51c1f17d5128752e7-plotly.txt +21 -0
  12. package/dist/components/charts/assets/files/8f989229699b4fe2f1a0432d0e9edc338a8a911e250e2d1b01ecd770a5f5b1bd-uplot.txt +21 -0
  13. package/dist/components/charts/assets/files/c8fa058cba98f7f288b5d8fa4116f441d6dacb25b96da859e518c973fff41d0c-claygl.txt +23 -0
  14. package/dist/components/charts/assets/index.js +3 -0
  15. package/dist/components/charts/assets/modules/chunk-2CCTLZE7.js +76 -0
  16. package/dist/components/charts/assets/modules/chunk-RMRBEYTI.js +1 -0
  17. package/dist/components/charts/assets/modules/echarts-gl-CXVTZA6G.js +4409 -0
  18. package/dist/components/charts/assets/modules/plotly.min-4LB7HE7P.js +3596 -0
  19. package/dist/components/charts/assets/modules/uPlot.esm-5JJNHHRF.js +3 -0
  20. package/dist/components/charts/assets/modules/uPlot.min-N3E3FA74.js +1 -0
  21. package/dist/components/charts/assets/modules/vega.module-2QCOVQ3A.js +13 -0
  22. package/dist/components/charts/commands.json +7 -0
  23. package/dist/components/charts/grammar.json +1113 -0
  24. package/dist/components/chat/__init__.py +1 -1
  25. package/dist/components/chat/assets/collection.js +3 -3
  26. package/dist/components/chat/assets/index.js +1 -1
  27. package/dist/components/drawing/__init__.py +15 -0
  28. package/dist/components/drawing/assets/collection.js +28 -0
  29. package/dist/components/drawing/assets/index.js +3 -0
  30. package/dist/components/drawing/commands.json +7 -0
  31. package/dist/components/drawing/grammar.json +110 -0
  32. package/dist/components/editors/__init__.py +2 -2
  33. package/dist/components/editors/assets/collection.js +18 -18
  34. package/dist/components/editors/assets/index.js +1 -1
  35. package/dist/components/editors/assets/modules/{prose-mirror-engine-GMZPJPNN.js → prose-mirror-engine-DQEAEIMV.js} +2 -2
  36. package/dist/components/editors/grammar.json +150 -0
  37. package/dist/components/grid/__init__.py +1 -1
  38. package/dist/components/grid/assets/collection.js +63 -33
  39. package/dist/components/grid/assets/index.js +1 -1
  40. package/dist/components/grid/grammar.json +279 -0
  41. package/dist/components/grouplets/__init__.py +1 -1
  42. package/dist/components/grouplets/assets/collection.js +3 -3
  43. package/dist/components/grouplets/assets/index.js +1 -1
  44. package/dist/components/inputs/__init__.py +3 -2
  45. package/dist/components/inputs/assets/collection.js +38 -23
  46. package/dist/components/inputs/assets/index.js +1 -1
  47. package/dist/components/inputs/grammar.json +1533 -321
  48. package/dist/components/layout/__init__.py +1 -1
  49. package/dist/components/layout/assets/collection.js +27 -23
  50. package/dist/components/layout/assets/index.js +1 -1
  51. package/dist/components/layout/grammar.json +85 -0
  52. package/dist/components/selection_trial/__init__.py +1 -1
  53. package/dist/components/selection_trial/assets/collection.js +3 -3
  54. package/dist/components/selection_trial/assets/index.js +1 -1
  55. package/dist/components/tree/__init__.py +1 -1
  56. package/dist/components/tree/assets/collection.js +12 -12
  57. package/dist/components/tree/assets/index.js +1 -1
  58. package/dist/components/tree/grammar.json +126 -0
  59. package/dist/components/typst/__init__.py +1 -1
  60. package/dist/components/typst/assets/collection.js +3 -3
  61. package/dist/components/typst/assets/index.js +1 -1
  62. package/dist/components/uploads/__init__.py +1 -1
  63. package/dist/components/uploads/assets/collection.js +9 -9
  64. package/dist/components/uploads/assets/index.js +1 -1
  65. package/dist/components/vizabi/__init__.py +13 -0
  66. package/dist/components/vizabi/assets/collection.js +22 -0
  67. package/dist/components/vizabi/assets/index.js +3 -0
  68. package/dist/components/vizabi/commands.json +7 -0
  69. package/dist/components/vizabi/grammar.json +128 -0
  70. package/dist/gramlot.js +1190 -256
  71. package/dist/gramlot.min.js +85 -52
  72. package/dist/standard-collections.js +2 -0
  73. package/package.json +12 -4
  74. package/src/binding/grid-struct.js +2 -2
  75. package/src/binding/runtime.js +10 -0
  76. package/src/binding/validation-context.js +2 -1
  77. package/src/bootstrap.js +1 -1
  78. package/src/builder/gramlot-builder.d.ts +15 -2
  79. package/src/builder/gramlot-builder.js +22 -3
  80. package/src/builder/source.js +24 -1
  81. package/src/components/audio-analysis-session.js +65 -0
  82. package/src/components/audio.js +44 -0
  83. package/src/components/bases.js +11 -7
  84. package/src/components/border-container.js +6 -3
  85. package/src/components/buttons.js +47 -3
  86. package/src/components/chart-bar3d-options.js +30 -0
  87. package/src/components/chart-controls.js +83 -0
  88. package/src/components/chart-data-view.js +52 -0
  89. package/src/components/chart-data.js +42 -0
  90. package/src/components/chart-domains.js +46 -0
  91. package/src/components/chart-engines/echarts-options.js +50 -0
  92. package/src/components/chart-engines/echarts.js +82 -0
  93. package/src/components/chart-engines/index.js +22 -0
  94. package/src/components/chart-engines/plotly-map.js +34 -0
  95. package/src/components/chart-engines/plotly-spatial.js +35 -0
  96. package/src/components/chart-engines/plotly.js +138 -0
  97. package/src/components/chart-engines/uplot.js +57 -0
  98. package/src/components/chart-engines/vega.js +101 -0
  99. package/src/components/chart-fields.js +110 -0
  100. package/src/components/chart-geographic-options.js +47 -0
  101. package/src/components/chart-geojson.js +60 -0
  102. package/src/components/chart-geometry.js +11 -0
  103. package/src/components/chart-map-anchors.js +24 -0
  104. package/src/components/chart-map-bar3d-options.js +41 -0
  105. package/src/components/chart-map-data.js +25 -0
  106. package/src/components/chart-map-labels.js +8 -0
  107. package/src/components/chart-map-options.js +20 -0
  108. package/src/components/chart-pane.js +91 -0
  109. package/src/components/chart-renderer.js +58 -0
  110. package/src/components/chart-sample-view.js +32 -0
  111. package/src/components/chart-spatial-options.js +40 -0
  112. package/src/components/chart-time.js +84 -0
  113. package/src/components/chart-timeline.js +70 -0
  114. package/src/components/chart-types/area.js +2 -0
  115. package/src/components/chart-types/bar.js +2 -0
  116. package/src/components/chart-types/bar3D.js +2 -0
  117. package/src/components/chart-types/donut.js +2 -0
  118. package/src/components/chart-types/horizontalBar.js +2 -0
  119. package/src/components/chart-types/index.js +26 -0
  120. package/src/components/chart-types/line.js +2 -0
  121. package/src/components/chart-types/line3D.js +2 -0
  122. package/src/components/chart-types/lines3D.js +2 -0
  123. package/src/components/chart-types/map.js +2 -0
  124. package/src/components/chart-types/map3D.js +2 -0
  125. package/src/components/chart-types/mapBar3D.js +2 -0
  126. package/src/components/chart-types/pie.js +2 -0
  127. package/src/components/chart-types/polygons3D.js +2 -0
  128. package/src/components/chart-types/scatter.js +2 -0
  129. package/src/components/chart-types/scatter3D.js +2 -0
  130. package/src/components/chart-types/stackedArea.js +2 -0
  131. package/src/components/chart-types/stackedBar.js +2 -0
  132. package/src/components/chart-types/surface.js +2 -0
  133. package/src/components/charts.js +152 -0
  134. package/src/components/check-box-text-editor.js +88 -0
  135. package/src/components/check-box-text.js +193 -0
  136. package/src/components/check-box-tree.js +62 -0
  137. package/src/components/choice-editor.js +35 -18
  138. package/src/components/choice-field-styles.js +14 -0
  139. package/src/components/choices.js +5 -0
  140. package/src/components/database-choices.js +9 -6
  141. package/src/components/drawing.js +199 -0
  142. package/src/components/field-state.js +8 -1
  143. package/src/components/grid-cell-editor.js +83 -19
  144. package/src/components/grid-check-sets.js +98 -0
  145. package/src/components/grid-column-filters.js +198 -0
  146. package/src/components/grid-grammar.json +65 -0
  147. package/src/components/grid-header-interaction.js +3 -1
  148. package/src/components/grid-rows.js +2 -2
  149. package/src/components/grid-search-box.js +38 -22
  150. package/src/components/grid-search-styles.js +13 -14
  151. package/src/components/grid-search.js +8 -1
  152. package/src/components/grid-structure.js +13 -2
  153. package/src/components/grid-styles.js +34 -2
  154. package/src/components/grid.js +67 -10
  155. package/src/components/image-uploader.js +2 -2
  156. package/src/components/inputs.js +21 -12
  157. package/src/components/labelbox.js +5 -1
  158. package/src/components/licenses/claygl.txt +23 -0
  159. package/src/components/licenses/echarts-gl.txt +29 -0
  160. package/src/components/licenses/plotly.txt +21 -0
  161. package/src/components/licenses/uplot.txt +21 -0
  162. package/src/components/licenses/vega.txt +27 -0
  163. package/src/components/menus.js +19 -11
  164. package/src/components/parameters.js +6 -2
  165. package/src/components/toolbar-overflow.js +12 -8
  166. package/src/components/tree.js +31 -8
  167. package/src/components/typed-editor.js +18 -7
  168. package/src/components/validation.js +1 -1
  169. package/src/components/vizabi-session.js +66 -0
  170. package/src/components/vizabi.js +66 -0
  171. package/src/components/window-surface.js +20 -9
  172. package/src/components/windows.js +1 -1
  173. package/src/editing-session.d.ts +1 -0
  174. package/src/editing-session.js +113 -15
  175. package/src/editor-values.js +57 -0
  176. package/src/gramlot.d.ts +2 -0
  177. package/src/gramlot.js +9 -4
  178. package/src/handlers/device-handler.js +32 -32
  179. package/src/handlers/source-handler.d.ts +2 -2
  180. package/src/ide-documents.js +19 -3
  181. package/src/ide-runtime.d.ts +1 -0
  182. package/src/ide-runtime.js +45 -31
  183. package/src/index.d.ts +2 -1
  184. package/src/renderer/drag-drop.js +1 -0
  185. package/src/renderer/gramlot-renderer.d.ts +3 -0
  186. package/src/renderer/gramlot-renderer.js +16 -4
  187. package/src/server/assets.d.ts +3 -0
  188. package/src/server/assets.js +9 -0
  189. package/src/server/gramlot-server.d.ts +1 -1
  190. package/src/server/gramlot-server.js +2 -1
  191. package/src/server/index.d.ts +1 -1
  192. package/src/server/index.js +1 -1
  193. package/src/server/source-import.d.ts +1 -1
  194. package/src/server/source-import.js +5 -1
  195. package/src/server/visual-editor.d.ts +1 -1
  196. package/src/server/visual-editor.js +44 -34
  197. package/src/source-picker.d.ts +1 -1
  198. package/src/source-picker.js +1 -2
  199. package/src/stores/bag-collection-view.js +79 -17
  200. package/src/stores/collection-filter.js +2 -1
  201. package/src/stores/column-filter.js +49 -0
  202. package/src/stores/id-set.js +10 -0
  203. package/src/view/controls.js +8 -0
  204. package/src/view/html.js +10 -1
  205. package/src/view/label-menu.js +61 -0
  206. package/src/view/labelbox.js +15 -2
  207. package/src/visual-editor-canvas.js +29 -0
  208. package/src/visual-editor-catalogue.js +34 -0
  209. package/src/visual-editor.d.ts +5 -0
  210. package/src/visual-editor.js +244 -26
  211. package/themes/gramlot-base/theme.css +84 -36
  212. package/tools/gramlot-tools-inspector.js +170 -506
  213. package/tools/inspector-agent.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gramlot/gramlot",
3
- "version": "0.3.26",
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', '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 = `gramlot.grid.${crypto.randomUUID().replaceAll('-', '')}.struct`;
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);
@@ -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`);
@@ -1,6 +1,6 @@
1
1
  import {Bag} from '@genrojs/bag';
2
2
  import {isDecimal} from '@genrojs/tytx';
3
- import {invokeHook} from './hooks.js';
3
+ import {invokeHook, callLogic} from './hooks.js';
4
4
 
5
5
  /** Source-scoped validation services, retained independently of the control view. */
6
6
  export function validationContext(binding) {
@@ -12,6 +12,7 @@ export function validationContext(binding) {
12
12
  };
13
13
  return {
14
14
  isDecimal, invoke,
15
+ callLogic:(method,keywords) => callLogic(binding.runtime,node,method,keywords),
15
16
  remote:(method, keywords, signal) => app.rpc.call('data', method, keywords, {signal}),
16
17
  reportError:(error, title) => { if (!binding.closed) binding.runtime.reportError(error,title); },
17
18
  validationCurrent:() => {
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.map(c=>c.toDocument())]});
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): SourceBagNode;
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
- if (searchOn !== false) frame.top.menu({presentation:'bar', node_label:'search', aria_label:'Grid search', padding:'4px 8px', background:'var(--gramlot-surface-subtle)'}).menuline({group:true}).searchBox({searchOn});
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
 
@@ -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]});
@@ -41,14 +41,16 @@ export function controlElement(HTMLElement) {
41
41
  return {ok:true, value, isCurrent:() => this.pageContext.isActive()};
42
42
  }
43
43
  finishValidation() {}
44
- validationValueCheck() {
45
- const nullable = this.constructor.gramlotComponent.parameters.value.nullable;
44
+ validationValueCheck() { return this.constructor.validationValueCheck(this.pageContext); }
45
+ static validationValueCheck() {
46
+ const nullable = this.gramlotComponent.parameters.value.nullable;
46
47
  return (value, original) => {
47
48
  if (value == null && !nullable) throw new TypeError('This component requires a non-null value.');
48
49
  if (value != null && original != null && typeof value !== typeof original) throw new TypeError('Validation must preserve the component value type.');
49
50
  };
50
51
  }
51
- validationSelection() {
52
+ validationSelection() { return this.constructor.validationSelection(this.parameters,this.pageContext); }
53
+ static validationSelection() {
52
54
  return () => { throw new TypeError('validate_select requires a constrained choice editor.'); };
53
55
  }
54
56
  validateSelection(value) { return this.validationSelection()(value); }
@@ -131,11 +133,13 @@ export function ChoiceGroup(HTMLElement) {
131
133
  items[next].focus();
132
134
  });
133
135
  }
136
+ choiceOptions() { return parseChoices(this.parameters.values ?? ""); }
134
137
  projectAttributes(attrs, adapt) {
135
138
  const rest = super.projectAttributes(attrs, adapt);
136
- const values = this.parameters.values ?? '';
137
- if (values !== this.#values) {
138
- const options = parseChoices(values);
139
+ const values = this.choiceOptions();
140
+ const signature = JSON.stringify(values);
141
+ if (signature !== this.#values) {
142
+ const options = values;
139
143
  const retained = new Set();
140
144
  let previous = null;
141
145
  for (const {id: code, caption} of options) {
@@ -157,7 +161,7 @@ export function ChoiceGroup(HTMLElement) {
157
161
  for (const [code, item] of this.#options) if (!retained.has(code)) {
158
162
  item.label.remove(); this.#options.delete(code);
159
163
  }
160
- this.#values = values;
164
+ this.#values = signature;
161
165
  }
162
166
  const cols = this.parameters.cols;
163
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 available = Math.max(0, (horizontal(side) ? box.height : box.width) - this.#extent(opposite));
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
- this.#resize(side, previousSize + (evt.key === keys[0] ? -1 : 1) * sign);
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},priority:{dtype:'R',default:0},overflowable:{dtype:'B',default:true},
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';this.#arrow.textContent='▾';
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
+ }