@gramlot/gramlot 0.3.41 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/icons/align-center.svg +4 -0
- package/assets/icons/align-justify.svg +4 -0
- package/assets/icons/align-left.svg +4 -0
- package/assets/icons/align-right.svg +4 -0
- package/assets/icons/applications.svg +4 -0
- package/assets/icons/archive.svg +4 -0
- package/assets/icons/attachment.svg +4 -0
- package/assets/icons/bold.svg +4 -0
- package/assets/icons/book.svg +4 -0
- package/assets/icons/bookmark.svg +4 -0
- package/assets/icons/calendar.svg +4 -0
- package/assets/icons/cancel.svg +4 -0
- package/assets/icons/chart.svg +4 -1
- package/assets/icons/chat.svg +4 -0
- package/assets/icons/clock.svg +4 -0
- package/assets/icons/code.svg +4 -0
- package/assets/icons/collapse.svg +4 -0
- package/assets/icons/columns.svg +4 -0
- package/assets/icons/confirm.svg +4 -0
- package/assets/icons/copy.svg +4 -0
- package/assets/icons/cut.svg +4 -0
- package/assets/icons/database.svg +4 -0
- package/assets/icons/delete.svg +4 -0
- package/assets/icons/detach.svg +4 -0
- package/assets/icons/document.svg +4 -0
- package/assets/icons/download.svg +4 -0
- package/assets/icons/duplicate.svg +4 -0
- package/assets/icons/edit.svg +4 -0
- package/assets/icons/eraser.svg +4 -0
- package/assets/icons/expand.svg +4 -0
- package/assets/icons/export.svg +4 -0
- package/assets/icons/eye.svg +4 -0
- package/assets/icons/filter.svg +4 -0
- package/assets/icons/first.svg +4 -0
- package/assets/icons/folder.svg +4 -0
- package/assets/icons/group.svg +4 -0
- package/assets/icons/help.svg +4 -0
- package/assets/icons/home.svg +4 -0
- package/assets/icons/horizontal-rule.svg +4 -0
- package/assets/icons/image.svg +4 -0
- package/assets/icons/import.svg +4 -0
- package/assets/icons/indent.svg +4 -0
- package/assets/icons/info.svg +4 -0
- package/assets/icons/inspector.svg +4 -0
- package/assets/icons/italic.svg +4 -0
- package/assets/icons/last.svg +4 -0
- package/assets/icons/layers.svg +4 -0
- package/assets/icons/link.svg +4 -0
- package/assets/icons/list-bulleted.svg +4 -0
- package/assets/icons/list-numbered.svg +4 -0
- package/assets/icons/list.svg +4 -0
- package/assets/icons/lock.svg +4 -0
- package/assets/icons/logout.svg +4 -0
- package/assets/icons/navigation.svg +4 -0
- package/assets/icons/new.svg +4 -0
- package/assets/icons/next.svg +4 -0
- package/assets/icons/open.svg +4 -0
- package/assets/icons/outdent.svg +4 -0
- package/assets/icons/palette.svg +4 -0
- package/assets/icons/panel-bottom.svg +4 -0
- package/assets/icons/panel-left.svg +4 -0
- package/assets/icons/panel-right.svg +4 -0
- package/assets/icons/panel-top.svg +4 -0
- package/assets/icons/paragraph.svg +4 -0
- package/assets/icons/paste.svg +4 -0
- package/assets/icons/pause.svg +4 -0
- package/assets/icons/pin.svg +4 -0
- package/assets/icons/play.svg +4 -0
- package/assets/icons/previous.svg +4 -0
- package/assets/icons/print.svg +4 -0
- package/assets/icons/redo.svg +4 -0
- package/assets/icons/refresh.svg +4 -0
- package/assets/icons/save.svg +4 -0
- package/assets/icons/search.svg +4 -0
- package/assets/icons/select-all.svg +4 -0
- package/assets/icons/send.svg +4 -0
- package/assets/icons/settings.svg +4 -0
- package/assets/icons/sort-ascending.svg +4 -0
- package/assets/icons/sort-descending.svg +4 -0
- package/assets/icons/stop.svg +4 -0
- package/assets/icons/strikethrough.svg +4 -0
- package/assets/icons/table.svg +4 -0
- package/assets/icons/tree.svg +4 -0
- package/assets/icons/underline.svg +4 -0
- package/assets/icons/undo.svg +4 -0
- package/assets/icons/unlock.svg +4 -0
- package/assets/icons/upload.svg +4 -0
- package/assets/icons/user.svg +4 -0
- package/assets/icons/warning.svg +4 -0
- package/assets/icons/zoom-in.svg +4 -0
- package/assets/icons/zoom-out.svg +4 -0
- package/dist/components/charts/__init__.py +1 -1
- package/dist/components/charts/assets/index.js +1 -1
- package/dist/components/charts/assets/libraries/vega.js +11 -11
- package/dist/components/charts/grammar.json +2032 -72
- package/dist/components/editors/__init__.py +1 -1
- package/dist/components/editors/assets/collection.js +1 -1
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/libraries/codemirror.js +30 -31
- package/dist/components/editors/assets/libraries/jodit.js +453 -447
- package/dist/components/editors/commands.json +113 -1
- package/dist/components/editors/grammar.json +12 -5
- package/dist/components/grid/__init__.py +1 -1
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/commands.json +4 -6
- package/dist/components/grid/grammar.json +112 -0
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +5165 -359
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +1 -0
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +433 -4
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +51 -0
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +6 -6
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/components/uploads/grammar.json +66 -0
- package/dist/declared-collections.js +1 -1
- package/dist/gramlot.js +5486 -2029
- package/dist/gramlot.min.js +361 -138
- package/dist/libraries.json +6 -4
- package/dist/standard-collections.js +1 -1
- package/dist/standard-grammar.js +1 -1
- package/package.json +6 -2
- package/src/binding/ask-dialog.js +17 -3
- package/src/binding/providers.js +3 -2
- package/src/binding/remote.js +41 -6
- package/src/binding/runtime.js +30 -3
- package/src/builder/gramlot-builder.d.ts +3 -1
- package/src/builder/gramlot-builder.js +77 -26
- package/src/builder/source.js +78 -15
- package/src/builder/xml-recipe.js +144 -0
- package/src/chat-file-types.js +13 -0
- package/src/chat.d.ts +1 -0
- package/src/chat.js +35 -25
- package/src/commands.d.ts +1 -1
- package/src/commands.js +1 -1
- package/src/components/border-container.js +64 -6
- package/src/components/buttons.js +26 -31
- package/src/components/chart-bar3d-options.js +0 -1
- package/src/components/chart-boxplot-options.js +1 -1
- package/src/components/chart-candlestick-options.js +1 -1
- package/src/components/chart-engines/echarts-options.js +6 -5
- package/src/components/chart-engines/echarts.js +27 -10
- package/src/components/chart-engines/plotly-map.js +1 -1
- package/src/components/chart-engines/plotly.js +21 -14
- package/src/components/chart-engines/uplot.js +17 -11
- package/src/components/chart-engines/vega.js +17 -11
- package/src/components/chart-funnel-options.js +1 -1
- package/src/components/chart-geographic-options.js +2 -2
- package/src/components/chart-heatmap-options.js +1 -1
- package/src/components/chart-map-bar3d-options.js +2 -2
- package/src/components/chart-map-options.js +2 -2
- package/src/components/chart-pane.js +5 -5
- package/src/components/chart-parallel-options.js +1 -1
- package/src/components/chart-radar-options.js +1 -1
- package/src/components/chart-renderer.js +6 -1
- package/src/components/chart-sankey-options.js +1 -1
- package/src/components/chart-spatial-options.js +6 -2
- package/src/components/chart-sunburst-options.js +13 -1
- package/src/components/chart-theme.js +14 -0
- package/src/components/chart-treemap-options.js +1 -1
- package/src/components/chart-type-data.js +24 -4
- package/src/components/charts.js +7 -6
- package/src/components/check-box-text-editor.js +1 -0
- package/src/components/check-box-text.js +2 -0
- package/src/components/check-box-tree.js +1 -1
- package/src/components/choice-editor.js +5 -4
- package/src/components/choice-field-styles.js +9 -1
- package/src/components/code-mirror-engine.js +19 -5
- package/src/components/code-mirror-gramlot.js +85 -0
- package/src/components/code-mirror.js +3 -2
- package/src/components/drawing.js +43 -14
- package/src/components/editor-commands.js +69 -0
- package/src/components/editor-options.js +1 -1
- package/src/components/editors.js +5 -3
- package/src/components/form-tray-pane.js +18 -0
- package/src/components/graphical-ranges.js +190 -0
- package/src/components/grid-check-sets.js +39 -3
- package/src/components/grid-footer.js +6 -1
- package/src/components/grid-header-interaction.js +3 -3
- package/src/components/grid-styles.js +30 -5
- package/src/components/grid-tools.js +15 -7
- package/src/components/grid.js +109 -15
- package/src/components/html-editor-commands.js +61 -0
- package/src/components/html-editor.js +18 -3
- package/src/components/inputs.js +94 -23
- package/src/components/jodit-engine.js +110 -7
- package/src/components/layout.js +3 -2
- package/src/components/menus.js +89 -26
- package/src/components/numeric-range.js +39 -0
- package/src/components/selected-container.js +123 -64
- package/src/components/tab-bar.js +389 -0
- package/src/components/toolbar-icon-style.js +22 -0
- package/src/components/toolbar-overflow.js +74 -12
- package/src/components/tray-base.js +528 -0
- package/src/components/tray-pane.js +41 -518
- package/src/components/tree.js +56 -4
- package/src/components/typed-editor.js +5 -2
- package/src/components/typst-preview.js +3 -3
- package/src/components/upload-blocks.js +88 -0
- package/src/components/upload-engine.js +21 -31
- package/src/components/uploader.js +168 -47
- package/src/editing-session.js +2 -1
- package/src/gramlot.js +6 -3
- package/src/handlers/dom-handler.d.ts +2 -0
- package/src/handlers/dom-handler.js +9 -0
- package/src/handlers/rpc-handler.d.ts +1 -1
- package/src/handlers/rpc-handler.js +2 -0
- package/src/handlers/source-handler.d.ts +5 -3
- package/src/handlers/source-handler.js +31 -13
- package/src/icons.js +84 -0
- package/src/ide-runtime.js +3 -1
- package/src/index-page-runtime.js +20 -5
- package/src/index-page-styles.js +1 -1
- package/src/index-theme.js +210 -3
- package/src/index.d.ts +7 -2
- package/src/index.js +7 -2
- package/src/libraries.js +4 -4
- package/src/object-extract.d.ts +7 -0
- package/src/object-extract.js +31 -0
- package/src/renderer/attributes.js +1 -1
- package/src/renderer/gramlot-renderer.d.ts +2 -2
- package/src/renderer/gramlot-renderer.js +4 -1
- package/src/server/chat-attachments.js +139 -0
- package/src/server/chat.d.ts +33 -0
- package/src/server/chat.js +168 -0
- package/src/server/database-selectors.d.ts +6 -0
- package/src/server/database-selectors.js +13 -0
- package/src/server/gramlot-file-server.js +6 -1
- package/src/server/gramlot-server.d.ts +19 -3
- package/src/server/gramlot-server.js +149 -19
- package/src/server/index-page.d.ts +10 -0
- package/src/server/index-page.js +92 -8
- package/src/server/index.d.ts +1 -1
- package/src/server/index.js +1 -1
- package/src/server/page-base.js +4 -0
- package/src/server/page-store.d.ts +21 -0
- package/src/server/page-store.js +219 -0
- package/src/server/page.d.ts +6 -1
- package/src/server/page.js +5 -1
- package/src/server/store-recipe.js +102 -0
- package/src/server/toolbar-icon-name.d.ts +93 -0
- package/src/server/upload.d.ts +2 -0
- package/src/server/upload.js +36 -18
- package/src/server/visual-editor.js +4 -2
- package/src/tree-store.d.ts +5 -1
- package/src/tree-store.js +11 -2
- package/src/view/choice-focus.js +17 -0
- package/src/view/html.js +21 -1
- package/src/view/labelbox.js +6 -1
- package/src/view/menu.js +9 -3
- package/src/visual-editor.d.ts +1 -0
- package/src/visual-editor.js +10 -5
- package/themes/gramlot-base/theme.css +60 -28
- package/themes/gramlot-compact/theme.css +2 -0
- package/themes/gramlot-index/icons/align-center.svg +4 -0
- package/themes/gramlot-index/icons/align-justify.svg +4 -0
- package/themes/gramlot-index/icons/align-left.svg +4 -0
- package/themes/gramlot-index/icons/align-right.svg +4 -0
- package/themes/gramlot-index/icons/applications.svg +4 -0
- package/themes/gramlot-index/icons/archive.svg +4 -0
- package/themes/gramlot-index/icons/attachment.svg +4 -0
- package/themes/gramlot-index/icons/bold.svg +4 -0
- package/themes/gramlot-index/icons/book.svg +4 -0
- package/themes/gramlot-index/icons/bookmark.svg +4 -0
- package/themes/gramlot-index/icons/calendar.svg +4 -0
- package/themes/gramlot-index/icons/cancel.svg +4 -0
- package/themes/gramlot-index/icons/chart.svg +4 -0
- package/themes/gramlot-index/icons/chat.svg +4 -0
- package/themes/gramlot-index/icons/clock.svg +4 -0
- package/themes/gramlot-index/icons/code.svg +4 -0
- package/themes/gramlot-index/icons/collapse.svg +4 -0
- package/themes/gramlot-index/icons/columns.svg +4 -0
- package/themes/gramlot-index/icons/confirm.svg +4 -0
- package/themes/gramlot-index/icons/copy.svg +4 -0
- package/themes/gramlot-index/icons/cut.svg +4 -0
- package/themes/gramlot-index/icons/database.svg +4 -0
- package/themes/gramlot-index/icons/delete.svg +4 -0
- package/themes/gramlot-index/icons/detach.svg +4 -0
- package/themes/gramlot-index/icons/document.svg +4 -0
- package/themes/gramlot-index/icons/download.svg +4 -0
- package/themes/gramlot-index/icons/duplicate.svg +4 -0
- package/themes/gramlot-index/icons/edit.svg +4 -0
- package/themes/gramlot-index/icons/eraser.svg +4 -0
- package/themes/gramlot-index/icons/expand.svg +4 -0
- package/themes/gramlot-index/icons/export.svg +4 -0
- package/themes/gramlot-index/icons/eye.svg +4 -0
- package/themes/gramlot-index/icons/filter.svg +4 -0
- package/themes/gramlot-index/icons/first.svg +4 -0
- package/themes/gramlot-index/icons/folder.svg +4 -0
- package/themes/gramlot-index/icons/group.svg +4 -0
- package/themes/gramlot-index/icons/help.svg +4 -0
- package/themes/gramlot-index/icons/home.svg +4 -0
- package/themes/gramlot-index/icons/horizontal-rule.svg +4 -0
- package/themes/gramlot-index/icons/image.svg +4 -0
- package/themes/gramlot-index/icons/import.svg +4 -0
- package/themes/gramlot-index/icons/indent.svg +4 -0
- package/themes/gramlot-index/icons/info.svg +4 -0
- package/themes/gramlot-index/icons/inspector.svg +4 -0
- package/themes/gramlot-index/icons/italic.svg +4 -0
- package/themes/gramlot-index/icons/last.svg +4 -0
- package/themes/gramlot-index/icons/layers.svg +4 -0
- package/themes/gramlot-index/icons/link.svg +4 -0
- package/themes/gramlot-index/icons/list-bulleted.svg +4 -0
- package/themes/gramlot-index/icons/list-numbered.svg +4 -0
- package/themes/gramlot-index/icons/list.svg +4 -0
- package/themes/gramlot-index/icons/lock.svg +4 -0
- package/themes/gramlot-index/icons/logout.svg +4 -0
- package/themes/gramlot-index/icons/navigation.svg +4 -0
- package/themes/gramlot-index/icons/new.svg +4 -0
- package/themes/gramlot-index/icons/next.svg +4 -0
- package/themes/gramlot-index/icons/open.svg +4 -0
- package/themes/gramlot-index/icons/outdent.svg +4 -0
- package/themes/gramlot-index/icons/palette.svg +4 -0
- package/themes/gramlot-index/icons/panel-bottom.svg +4 -0
- package/themes/gramlot-index/icons/panel-left.svg +4 -0
- package/themes/gramlot-index/icons/panel-right.svg +4 -0
- package/themes/gramlot-index/icons/panel-top.svg +4 -0
- package/themes/gramlot-index/icons/paragraph.svg +4 -0
- package/themes/gramlot-index/icons/paste.svg +4 -0
- package/themes/gramlot-index/icons/pause.svg +4 -0
- package/themes/gramlot-index/icons/pin.svg +4 -0
- package/themes/gramlot-index/icons/play.svg +4 -0
- package/themes/gramlot-index/icons/previous.svg +4 -0
- package/themes/gramlot-index/icons/print.svg +4 -0
- package/themes/gramlot-index/icons/redo.svg +4 -0
- package/themes/gramlot-index/icons/refresh.svg +4 -0
- package/themes/gramlot-index/icons/save.svg +4 -0
- package/themes/gramlot-index/icons/search.svg +4 -0
- package/themes/gramlot-index/icons/select-all.svg +4 -0
- package/themes/gramlot-index/icons/send.svg +4 -0
- package/themes/gramlot-index/icons/settings.svg +4 -0
- package/themes/gramlot-index/icons/sort-ascending.svg +4 -0
- package/themes/gramlot-index/icons/sort-descending.svg +4 -0
- package/themes/gramlot-index/icons/stop.svg +4 -0
- package/themes/gramlot-index/icons/strikethrough.svg +4 -0
- package/themes/gramlot-index/icons/table.svg +4 -0
- package/themes/gramlot-index/icons/tree.svg +4 -0
- package/themes/gramlot-index/icons/underline.svg +4 -0
- package/themes/gramlot-index/icons/undo.svg +4 -0
- package/themes/gramlot-index/icons/unlock.svg +4 -0
- package/themes/gramlot-index/icons/upload.svg +4 -0
- package/themes/gramlot-index/icons/user.svg +4 -0
- package/themes/gramlot-index/icons/warning.svg +4 -0
- package/themes/gramlot-index/icons/zoom-in.svg +4 -0
- package/themes/gramlot-index/icons/zoom-out.svg +4 -0
- package/themes/gramlot-index/icons.json +93 -0
- package/themes/gramlot-index/theme.css +24 -0
- package/themes/joanna/theme.css +2 -0
- package/themes/mela/theme.css +2 -0
- package/themes/mimi/theme.css +2 -0
- package/tools/gramlot-tools-inspector.js +11 -3
|
@@ -29,13 +29,9 @@ export class EChartsAdapter {
|
|
|
29
29
|
await loadLibrary('echartsGl',document,()=>import('echarts-gl/dist/echarts-gl.min.js'));
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
#chart; #type; #element; #options; #renderer;
|
|
32
|
+
#chart; #type; #element; #options; #renderer; #theme;
|
|
33
33
|
#mapName=`chart_${randomId()}`; #mapData;
|
|
34
|
-
constructor(element,options={}) {
|
|
35
|
-
this.#element=element;this.#options=options;
|
|
36
|
-
this.#renderer=options.renderer ?? 'canvas';
|
|
37
|
-
this.#chart=echarts.init(element,null,options);this.#bindSelection();
|
|
38
|
-
}
|
|
34
|
+
constructor(element,options={}) { this.#element=element;this.#options=options; }
|
|
39
35
|
#bindSelection() {
|
|
40
36
|
this.#chart.on('click',event=>{
|
|
41
37
|
if(this.#type==='mapBar3D' && event.seriesType==='bar3D')this.#options.onTerritorySelect?.(event.name);
|
|
@@ -43,12 +39,18 @@ export class EChartsAdapter {
|
|
|
43
39
|
});
|
|
44
40
|
}
|
|
45
41
|
validate(context) { return this[`render_${context.type.id}`](context); }
|
|
42
|
+
/** ECharts takes the theme only at init: a new renderer or new theme colours create the chart again. */
|
|
46
43
|
update(context,option) {
|
|
47
44
|
this.#type=context.type.id;
|
|
48
45
|
const renderer=context.type.threeD?'canvas':(this.#options.renderer ?? 'canvas');
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
const theme=JSON.stringify(context.theme);
|
|
47
|
+
if(!this.#chart || renderer!==this.#renderer || theme!==this.#theme) {
|
|
48
|
+
this.#chart?.dispose();
|
|
49
|
+
this.#chart=echarts.init(this.#element,echartsTheme(context.theme),{...this.#options,renderer});
|
|
50
|
+
this.#renderer=renderer;this.#theme=theme;this.#bindSelection();
|
|
51
51
|
}
|
|
52
|
+
if(!context.legend)option.legend={show:false};
|
|
53
|
+
if(!context.axes)hideAxes(option,context.legend);
|
|
52
54
|
this.#chart.setOption(option,{notMerge:true});
|
|
53
55
|
}
|
|
54
56
|
render_bar(context) { return cartesianOptions(context,{seriesType:'bar'}); }
|
|
@@ -101,6 +103,21 @@ export class EChartsAdapter {
|
|
|
101
103
|
render_treemap(context) { return chartTreemapOptions(context); }
|
|
102
104
|
render_sunburst(context) { return chartSunburstOptions(context); }
|
|
103
105
|
svg() { return this.#chart.renderToSVGString(); }
|
|
104
|
-
resize() { this.#chart
|
|
105
|
-
dispose() { this.#chart
|
|
106
|
+
resize() { this.#chart?.resize(); }
|
|
107
|
+
dispose() { this.#chart?.dispose();if(this.#mapData)echarts.registerMap(this.#mapName,{type:'FeatureCollection',features:[]}); }
|
|
108
|
+
}
|
|
109
|
+
/** Hide the X and Y axes: no name, tick labels, ticks or split lines. The grid takes the whole area, less the bottom space of a legend. */
|
|
110
|
+
function hideAxes(option,legend) {
|
|
111
|
+
if(!option.xAxis && !option.yAxis)return;
|
|
112
|
+
for(const key of ['xAxis','yAxis']) {
|
|
113
|
+
if(option[key])option[key]=[option[key]].flat().map(axis=>({...axis,show:false}));
|
|
114
|
+
}
|
|
115
|
+
option.grid={...option.grid,left:0,right:0,top:0,...(legend?{}:{bottom:0})};
|
|
116
|
+
}
|
|
117
|
+
/** ECharts theme from the chart colours: background, text of the chart, title, legend and visual map, axes and split lines. */
|
|
118
|
+
function echartsTheme({background,text,axis,grid}) {
|
|
119
|
+
const axisTheme={axisLine:{lineStyle:{color:axis}},axisTick:{lineStyle:{color:axis}},axisLabel:{color:text},
|
|
120
|
+
nameTextStyle:{color:text},splitLine:{lineStyle:{color:[grid]}}};
|
|
121
|
+
return {backgroundColor:background,textStyle:{color:text},title:{textStyle:{color:text}},legend:{textStyle:{color:text}},visualMap:{textStyle:{color:text}},
|
|
122
|
+
categoryAxis:axisTheme,valueAxis:axisTheme,timeAxis:axisTheme,logAxis:axisTheme};
|
|
106
123
|
}
|
|
@@ -18,7 +18,7 @@ export function plotlyMap({view,category,structure,seriesOptions,domains},layout
|
|
|
18
18
|
layout.title={text:title};layout.showlegend=false;layout.margin={l:10,r:70,t:45,b:20};
|
|
19
19
|
// Own GeoJSON supplies all geometry; no basemap tiles, tokens or network assets.
|
|
20
20
|
layout.geo={visible:false,showframe:false,showcoastlines:false,showland:false,showocean:false,
|
|
21
|
-
showcountries:false,showlakes:false,showrivers:false,fitbounds:'geojson',projection:{type:'mercator'},bgcolor:
|
|
21
|
+
showcountries:false,showlakes:false,showrivers:false,fitbounds:'geojson',projection:{type:'mercator'},bgcolor:layout.paper_bgcolor};
|
|
22
22
|
const colors=signed?['#b73548','#f7f7f7','#2166ac']:chartMapColors;
|
|
23
23
|
const dataTrace={type:'choropleth',geojson:geometry,featureidkey:'properties.name',
|
|
24
24
|
locations:data.map(row=>row.name),z:data.map(row=>row.value),zmin:min,zmax:max,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {chartPalette} from '../chart-domains.js';
|
|
2
2
|
import {chartData} from '../chart-data.js';
|
|
3
|
+
import {chartCaption} from '../chart-type-data.js';
|
|
3
4
|
import {plotlySpatial} from './plotly-spatial.js';
|
|
4
5
|
import {plotlyMap} from './plotly-map.js';
|
|
5
6
|
import {loadLibrary} from '../../libraries.js';
|
|
@@ -70,11 +71,11 @@ export class PlotlyAdapter {
|
|
|
70
71
|
render_pie(context) { return this.#radial(context,false); }
|
|
71
72
|
render_donut(context) { return this.#radial(context,true); }
|
|
72
73
|
render_scatter(context) { return this.#cartesian(context,{type:'scatter',points:true}); }
|
|
73
|
-
render_line3D(context) { return plotlySpatial(context,'line3D',this.#layout()); }
|
|
74
|
-
render_scatter3D(context) { return plotlySpatial(context,'scatter3D',this.#layout()); }
|
|
75
|
-
render_surface(context) { return plotlySpatial(context,'surface',this.#layout()); }
|
|
76
|
-
render_map(context) { return plotlyMap(context,this.#layout()); }
|
|
77
|
-
#cartesian({view,category,fields,settings,domains},{type,area=false,stacked=false,horizontal=false,points=false}) {
|
|
74
|
+
render_line3D(context) { return plotlySpatial(context,'line3D',this.#layout(context)); }
|
|
75
|
+
render_scatter3D(context) { return plotlySpatial(context,'scatter3D',this.#layout(context)); }
|
|
76
|
+
render_surface(context) { return plotlySpatial(context,'surface',this.#layout(context)); }
|
|
77
|
+
render_map(context) { return plotlyMap(context,this.#layout(context)); }
|
|
78
|
+
#cartesian({view,category,fields,settings,seriesOptions,domains,legend,axes,theme},{type,area=false,stacked=false,horizontal=false,points=false}) {
|
|
78
79
|
const {source,kind}=chartData(view,category,fields,domains?.dimension);
|
|
79
80
|
if(points&&!['value','time'].includes(kind))throw new TypeError('Scatter needs a numeric or date dimension. Choose another column.');
|
|
80
81
|
if(stacked&&new Set(settings.map(option=>option.axis)).size>1)throw new TypeError('Stacked series need the same scale. Assign all selected measures to the same axis.');
|
|
@@ -84,14 +85,19 @@ export class PlotlyAdapter {
|
|
|
84
85
|
if(stacked&&area&&source.some(row=>row.slice(1).some(value=>value<0)))
|
|
85
86
|
throw new TypeError('Plotly stacked areas do not implement separate positive/negative stacks. Choose another type or engine. Configuration retained.');
|
|
86
87
|
const coordinates=source.map(row=>kind==='time'?new Date(row[0]).toISOString():row[0]);
|
|
87
|
-
const layout=this.#layout(),dimension=horizontal?'y':'x',measure=horizontal?'x':'y';
|
|
88
|
+
const layout=this.#layout({legend,theme}),dimension=horizontal?'y':'x',measure=horizontal?'x':'y';
|
|
88
89
|
layout.barmode=stacked?'relative':'group';
|
|
89
|
-
layout[dimension+'axis']={type:kind==='time'&&!horizontal?'date':kind==='category'||type==='bar'?'category':'linear',automargin:true};
|
|
90
|
+
layout[dimension+'axis']={type:kind==='time'&&!horizontal?'date':kind==='category'||type==='bar'?'category':'linear',automargin:true,...this.#axisColors(theme)};
|
|
90
91
|
for(const [index,side] of ['left','right'].entries()) {
|
|
91
92
|
layout[measure+'axis'+(index?'2':'')]={side:horizontal?(index?'top':'bottom'):side,
|
|
92
93
|
visible:settings.some(s=>s.axis===side),automargin:true,
|
|
93
|
-
title:{text:fields.filter((_,i)=>settings[i].axis===side).join(', ')},
|
|
94
|
-
...(index?{overlaying:measure}:{}),rangemode:'tozero'};
|
|
94
|
+
title:{text:fields.filter((_,i)=>settings[i].axis===side).map(field=>chartCaption(seriesOptions,field)).join(', ')},
|
|
95
|
+
...(index?{overlaying:measure}:{}),rangemode:'tozero',...this.#axisColors(theme)};
|
|
96
|
+
}
|
|
97
|
+
if(!axes) {
|
|
98
|
+
// A hidden axis draws no title, tick labels, ticks or grid; the plot keeps only the space of a legend.
|
|
99
|
+
for(const key of [dimension+'axis',measure+'axis',measure+'axis2'])layout[key].visible=false;
|
|
100
|
+
layout.margin={l:0,r:0,t:0,b:legend?75:0};
|
|
95
101
|
}
|
|
96
102
|
if(domains){
|
|
97
103
|
const axis=layout[dimension+'axis'];
|
|
@@ -100,7 +106,7 @@ export class PlotlyAdapter {
|
|
|
100
106
|
axis.autorange=false;
|
|
101
107
|
for(const [i,side] of ['left','right'].entries())Object.assign(layout[measure+'axis'+(i?'2':'')],{range:domains.axes[side],autorange:false});
|
|
102
108
|
}
|
|
103
|
-
const data=fields.map((field,i)=>({type,name:field,
|
|
109
|
+
const data=fields.map((field,i)=>({type,name:chartCaption(seriesOptions,field),
|
|
104
110
|
[dimension]:[...coordinates],[measure]:source.map(row=>row[i+1]),
|
|
105
111
|
[measure+'axis']:measure+(settings[i].axis==='right'?'2':''),marker:{color:settings[i].color},
|
|
106
112
|
...(type==='scatter'?{mode:points?'markers':source.length===1?'lines+markers':'lines',line:{color:settings[i].color},
|
|
@@ -109,20 +115,21 @@ export class PlotlyAdapter {
|
|
|
109
115
|
:{orientation:horizontal?'h':'v',...(stacked?{}:{offsetgroup:field}),alignmentgroup:'measures'})}));
|
|
110
116
|
return {data,layout};
|
|
111
117
|
}
|
|
112
|
-
#radial({view,category,fields,domains},donut) {
|
|
118
|
+
#radial({view,category,fields,seriesOptions,domains,legend,theme},donut) {
|
|
113
119
|
const {source,kind}=chartData(view,category,fields,domains?.dimension);
|
|
114
120
|
const labels=source.map(row=>kind==='time'?new Date(row[0]).toISOString().slice(0,10):String(row[0]));
|
|
115
121
|
if(new Set(labels).size!==source.length)
|
|
116
122
|
throw new TypeError('Plotly pie/donut requires distinct category labels. Prepare the store upstream or choose another engine. Configuration retained.');
|
|
117
123
|
if(source.some(row=>row[1]<0))throw new TypeError('Pie and donut require nonnegative values. Configuration retained.');
|
|
118
|
-
return {layout:this.#layout(),data:fields.map(field=>({type:'pie',name:field,sort:false,hole:donut?0.5:0,
|
|
124
|
+
return {layout:this.#layout({legend,theme}),data:fields.map(field=>({type:'pie',name:chartCaption(seriesOptions,field),sort:false,hole:donut?0.5:0,
|
|
119
125
|
labels,...(domains?{marker:{colors:labels.map(label=>chartPalette[domains.labels.indexOf(label)%chartPalette.length])}}:{}),
|
|
120
126
|
values:source.map(row=>row[1]),textposition:'inside',textinfo:'label+percent',automargin:true}))};
|
|
121
127
|
}
|
|
122
|
-
#layout() {
|
|
123
|
-
return {paper_bgcolor:
|
|
128
|
+
#layout({legend,theme}) {
|
|
129
|
+
return {paper_bgcolor:theme.background,plot_bgcolor:theme.background,font:{color:theme.text},showlegend:legend,
|
|
124
130
|
margin:{l:70,r:70,t:40,b:75},legend:{orientation:'h',y:-0.18,x:0},autosize:true};
|
|
125
131
|
}
|
|
132
|
+
#axisColors(theme) { return {linecolor:theme.axis,tickcolor:theme.axis,gridcolor:theme.grid,zerolinecolor:theme.grid}; }
|
|
126
133
|
resize() {
|
|
127
134
|
if(this.#disposed||!this.#drawn)return;
|
|
128
135
|
// Serialize resize with react, and do not enqueue another resize from its own observer callback.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {chartData} from '../chart-data.js';
|
|
2
|
+
import {chartCaption} from '../chart-type-data.js';
|
|
2
3
|
import {loadLibrary} from '../../libraries.js';
|
|
3
4
|
|
|
4
5
|
let loading,UPlot,styleText;
|
|
@@ -12,12 +13,12 @@ export class UPlotAdapter {
|
|
|
12
13
|
#element; #plot; #style; #signature; #disposed=false;
|
|
13
14
|
constructor(element) { this.#element=element; }
|
|
14
15
|
validate(context) { return this[`render_${context.type.id}`](context); }
|
|
15
|
-
render_line({view,category,fields,settings,domains}) {
|
|
16
|
+
render_line({view,category,fields,settings,seriesOptions,domains,legend,axes,theme}) {
|
|
16
17
|
const {source,kind}=chartData(view,category,fields,domains?.dimension);
|
|
17
18
|
if(source.length&&kind==='category')throw new TypeError('uPlot requires a numeric or date X field. Configuration retained.');
|
|
18
19
|
if(source.some((row,index)=>index>0&&row[0]<=source[index-1][0]))
|
|
19
20
|
throw new TypeError('uPlot requires distinct X values in ascending order. Prepare the store upstream. Configuration retained.');
|
|
20
|
-
return {category,fields,settings,domains,time:kind==='time',
|
|
21
|
+
return {category,fields,captions:fields.map(field=>chartCaption(seriesOptions,field)),settings,domains,time:kind==='time',legend,axes,theme,
|
|
21
22
|
data:[source.map(row=>kind==='time'?row[0]/1000:row[0]),
|
|
22
23
|
...fields.map((_,index)=>source.map(row=>row[index+1]))]};
|
|
23
24
|
}
|
|
@@ -26,23 +27,27 @@ export class UPlotAdapter {
|
|
|
26
27
|
const {data,...configuration}=figure,signature=JSON.stringify(configuration);
|
|
27
28
|
if(!this.#style) {
|
|
28
29
|
this.#style=this.#element.ownerDocument.createElement('style');
|
|
29
|
-
this.#style.textContent=styleText+'\n.uplot{color:#333;background:#fff;font-size:12px}.u-legend{font-size:12px;max-height:90px;overflow:auto}';
|
|
30
30
|
this.#element.append(this.#style);
|
|
31
31
|
}
|
|
32
32
|
if(signature!==this.#signature) {
|
|
33
33
|
this.#plot?.destroy();
|
|
34
|
-
const {category,fields,settings,time,domains}=figure;
|
|
34
|
+
const {category,fields,captions,settings,time,domains,legend,axes:showAxes,theme}=figure;
|
|
35
|
+
// The plot draws axes and grid on a canvas: the theme colours go to the uPlot options.
|
|
36
|
+
this.#style.textContent=styleText+`\n.uplot{color:${theme.text};background:${theme.background};font-size:12px}.u-legend{font-size:12px;max-height:90px;overflow:auto}`;
|
|
35
37
|
const rect=this.#element.getBoundingClientRect();
|
|
36
|
-
|
|
38
|
+
// A hidden axis draws no title, tick labels, ticks or grid, and uPlot gives its space to the plot.
|
|
39
|
+
const axis=label=>({show:showAxes,label,stroke:theme.axis,font:'12px sans-serif',ticks:{stroke:theme.grid}});
|
|
40
|
+
const scales={x:{time,...(domains?{range:()=>domains.dimension.range.map(v=>time?v/1000:v)}:{})}},axes=[{...axis(category),grid:{stroke:theme.grid}}];
|
|
37
41
|
for(const side of ['left','right']) {
|
|
38
|
-
const names=
|
|
42
|
+
const names=captions.filter((_,i)=>settings[i].axis===side);
|
|
39
43
|
if(!names.length)continue;
|
|
40
44
|
scales[side]={time:false,...(domains?{range:()=>domains.axes[side]}:{})};
|
|
41
|
-
axes.push({scale:side,side:side==='left'?3:1,
|
|
45
|
+
axes.push({...axis(names.join(', ')),scale:side,side:side==='left'?3:1,grid:{show:side==='left',stroke:theme.grid}});
|
|
42
46
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
// Without the legend the plot takes the whole height of the element.
|
|
48
|
+
this.#plot=new UPlot({width:Math.max(1,Math.round(rect.width)),height:Math.max(1,Math.round(rect.height)-(legend?50:0)),
|
|
49
|
+
pxAlign:false,scales,axes,legend:{show:legend},
|
|
50
|
+
series:[{label:category},...fields.map((field,i)=>({label:captions[i],stroke:settings[i].color,scale:settings[i].axis,width:1.5}))]},data,this.#element);
|
|
46
51
|
this.#signature=signature;
|
|
47
52
|
} else this.#plot.setData(data);
|
|
48
53
|
this.resize();
|
|
@@ -50,9 +55,10 @@ export class UPlotAdapter {
|
|
|
50
55
|
resize() {
|
|
51
56
|
if(this.#disposed||!this.#plot)return;
|
|
52
57
|
const rect=this.#element.getBoundingClientRect();
|
|
58
|
+
// uPlot creates the .u-legend element only when the legend shows.
|
|
53
59
|
const legend=this.#plot.root.querySelector('.u-legend');
|
|
54
60
|
const width=Math.max(1,Math.round(rect.width));
|
|
55
|
-
const height=Math.max(1,Math.floor(rect.height-legend.getBoundingClientRect().height));
|
|
61
|
+
const height=Math.max(1,Math.floor(rect.height-(legend ? legend.getBoundingClientRect().height : 0)));
|
|
56
62
|
if(this.#plot.width!==width||this.#plot.height!==height)this.#plot.setSize({width,height});
|
|
57
63
|
}
|
|
58
64
|
dispose() { this.#disposed=true;this.#plot?.destroy();this.#plot=null;this.#style?.remove(); }
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {chartPalette} from '../chart-domains.js';
|
|
2
2
|
import {chartData} from '../chart-data.js';
|
|
3
|
+
import {chartCaption} from '../chart-type-data.js';
|
|
3
4
|
import {loadLibrary} from '../../libraries.js';
|
|
4
5
|
|
|
5
6
|
let loading,Vega;
|
|
@@ -32,10 +33,10 @@ export class VegaAdapter {
|
|
|
32
33
|
}
|
|
33
34
|
render_bar(context) { return this.#cartesian(context,true); }
|
|
34
35
|
render_line(context) { return this.#cartesian(context,false); }
|
|
35
|
-
#cartesian({view,category,fields,settings,domains},bar) {
|
|
36
|
+
#cartesian({view,category,fields,settings,seriesOptions,domains,legend,axes,theme},bar) {
|
|
36
37
|
const {source,kind}=chartData(view,category,fields,domains?.dimension);
|
|
37
38
|
const band=bar&&kind!=='time';
|
|
38
|
-
const spec=this.#spec();
|
|
39
|
+
const spec=this.#spec(theme);
|
|
39
40
|
spec.data=[{name:'rows',values:source.map((row,index)=>({x:row[0],index}))},
|
|
40
41
|
...fields.map((field,i)=>({name:`series${i}`,values:source.map(row=>({x:row[0],y:row[i+1],label:kind==='time'?new Date(row[0]).toISOString().slice(0,10):String(row[0])}))}))];
|
|
41
42
|
spec.scales=[{name:'x',type:band?'band':kind==='time'?'utc':kind==='category'?'point':'linear',
|
|
@@ -46,9 +47,14 @@ export class VegaAdapter {
|
|
|
46
47
|
const indexes=fields.map((_,i)=>i).filter(i=>settings[i].axis===side);
|
|
47
48
|
if(!indexes.length)continue;
|
|
48
49
|
spec.scales.push({name:side,type:'linear',domain:domains?domains.axes[side]:{fields:indexes.map(i=>({data:`series${i}`,field:'y'}))},range:'height',zero:true,nice:true});
|
|
49
|
-
spec.axes.push({orient:side,scale:side,grid:side==='left',title:indexes.map(i=>fields[i]).join(', '),format:'~s'});
|
|
50
|
+
spec.axes.push({orient:side,scale:side,grid:side==='left',title:indexes.map(i=>chartCaption(seriesOptions,fields[i])).join(', '),format:'~s'});
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
+
// The color domain keeps the field, so two measures with the same caption stay apart; the label shows the caption.
|
|
53
|
+
const captions=Object.fromEntries(fields.map(field=>[field,chartCaption(seriesOptions,field)]));
|
|
54
|
+
spec.legends=legend?[{fill:'color',orient:'bottom',direction:'horizontal',title:null,
|
|
55
|
+
encode:{labels:{update:{text:{signal:`${JSON.stringify(captions)}[datum.value]`}}}}}]:[];
|
|
56
|
+
// Without axes the marks take the whole area of the chart.
|
|
57
|
+
if(!axes){spec.axes=[];spec.padding=0;}
|
|
52
58
|
if(bar)spec.signals=[{name:'groupWidth',update:band?"bandwidth('x')":"min(60, width / max(1, length(data('rows'))) * 0.7)"}];
|
|
53
59
|
spec.marks=fields.flatMap((field,i)=>{
|
|
54
60
|
const y={scale:settings[i].axis,field:'y'};
|
|
@@ -65,27 +71,27 @@ export class VegaAdapter {
|
|
|
65
71
|
});
|
|
66
72
|
return spec;
|
|
67
73
|
}
|
|
68
|
-
render_pie({view,category,fields,domains}) {
|
|
74
|
+
render_pie({view,category,fields,domains,legend,theme}) {
|
|
69
75
|
const {source,kind}=chartData(view,category,fields,domains?.dimension);
|
|
70
76
|
if(source.some(row=>row[1]<0))throw new TypeError('Pie requires nonnegative values. Configuration retained.');
|
|
71
|
-
const spec=this.#spec();
|
|
77
|
+
const spec=this.#spec(theme);
|
|
72
78
|
spec.data=[{name:'slices',values:fields.length?source.map((row,index)=>({index,label:kind==='time'?new Date(row[0]).toISOString().slice(0,10):String(row[0]),value:row[1]})):[],
|
|
73
79
|
transform:[{type:'pie',field:'value',sort:false}]}];
|
|
74
80
|
spec.scales=[{name:'color',type:'ordinal',domain:domains?domains.labels:{data:'slices',field:'label'},range:domains?chartPalette:{scheme:'tableau10'}}];
|
|
75
|
-
spec.legends=[{fill:'color',orient:'bottom',direction:'horizontal',columns:3,title:null}];
|
|
81
|
+
spec.legends=legend?[{fill:'color',orient:'bottom',direction:'horizontal',columns:3,title:null}]:[];
|
|
76
82
|
const center={x:{signal:'width / 2'},y:{signal:'height / 2'}};
|
|
77
83
|
spec.marks=[{name:'pieSlices',type:'arc',from:{data:'slices'},encode:{update:{...center,
|
|
78
84
|
startAngle:{field:'startAngle'},endAngle:{field:'endAngle'},outerRadius:{signal:'min(width,height) * 0.46'},
|
|
79
|
-
fill:{scale:'color',field:'label'},stroke:{value:
|
|
85
|
+
fill:{scale:'color',field:'label'},stroke:{value:theme.background},tooltip:{signal:'datum.label + ": " + datum.value'}}}},
|
|
80
86
|
{name:'sliceLabels',type:'text',from:{data:'slices'},encode:{update:{...center,
|
|
81
87
|
radius:{signal:'min(width,height) * 0.30'},theta:{signal:'(datum.startAngle + datum.endAngle) / 2'},
|
|
82
88
|
text:{field:'label'},align:{value:'center'},baseline:{value:'middle'},fill:{value:'#222'},
|
|
83
89
|
limit:{signal:'min(width,height) * 0.25'}}}}];
|
|
84
90
|
return spec;
|
|
85
91
|
}
|
|
86
|
-
#spec() {
|
|
87
|
-
return {background:
|
|
88
|
-
data:[],scales:[],axes:[],marks:[],config:{axis:{labelColor:
|
|
92
|
+
#spec(theme) {
|
|
93
|
+
return {background:theme.background,autosize:{type:'fit',contains:'padding',resize:true},padding:12,
|
|
94
|
+
data:[],scales:[],axes:[],marks:[],config:{axis:{labelColor:theme.text,titleColor:theme.text,domainColor:theme.axis,tickColor:theme.axis,gridColor:theme.grid},legend:{labelColor:theme.text}}};
|
|
89
95
|
}
|
|
90
96
|
resize() {
|
|
91
97
|
if(this.#disposed||!this.#view)return;
|
|
@@ -12,7 +12,7 @@ export function chartFunnelOptions({view,category,fields,seriesOptions}) {
|
|
|
12
12
|
const name=chartName(view.value(row,category),category);
|
|
13
13
|
data.push({name,value,itemStyle:{color:chartPalette[data.length%chartPalette.length]}});
|
|
14
14
|
}
|
|
15
|
-
return {
|
|
15
|
+
return {tooltip:{trigger:'item',formatter:'{b}: {c}'},
|
|
16
16
|
legend:{show:true,type:'scroll',orient:'horizontal',left:12,right:12,bottom:10,height:24,data:data.map(item=>item.name)},
|
|
17
17
|
series:[{id:field,name:chartCaption(seriesOptions,field),type:'funnel',top:20,bottom:64,left:'10%',width:'80%',
|
|
18
18
|
sort:'none',gap:2,label:{show:true,position:'inside'},data}]};
|
|
@@ -42,6 +42,6 @@ export function chartGeographicOptions(view,type,nameField,geometryField,fields,
|
|
|
42
42
|
polyline:true,silent:false,lineStyle:{color:settings[index].color,width:4,opacity:1}});
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
|
-
return {
|
|
46
|
-
tooltip:{renderMode:'richText'},geo3D,series};
|
|
45
|
+
return {title,legend:{type:'scroll',data:fields,left:12,right:12,bottom:10},
|
|
46
|
+
tooltip:{renderMode:'richText',formatter:({name,seriesName,value})=>`${name}\n${seriesName}: ${value}`},geo3D,series};
|
|
47
47
|
}
|
|
@@ -19,7 +19,7 @@ export function chartHeatmapOptions({view,category,structure,fields,settings,ser
|
|
|
19
19
|
let min=data.length?Math.min(...data.map(cell=>cell[2])):0,max=data.length?Math.max(...data.map(cell=>cell[2])):1;
|
|
20
20
|
if(min===max){min-=1;max+=1;}
|
|
21
21
|
const name=chartCaption(seriesOptions,field);
|
|
22
|
-
return {
|
|
22
|
+
return {tooltip:{trigger:'item',position:'top'},
|
|
23
23
|
grid:{left:80,right:40,top:36,bottom:110},
|
|
24
24
|
xAxis:{type:'category',data:xs,name:category,splitArea:{show:true}},
|
|
25
25
|
yAxis:{type:'category',data:ys,name:second,splitArea:{show:true}},
|
|
@@ -32,8 +32,8 @@ export function chartMapBar3DOptions({view,category,fields,settings,structure,se
|
|
|
32
32
|
series.push({id:'map-height-reference',type:'scatter3D',coordinateSystem:'geo3D',geo3DIndex:0,
|
|
33
33
|
silent:true,symbolSize:0,itemStyle:{opacity:0},label:{show:false},tooltip:{show:false},
|
|
34
34
|
data:[[...anchor,min],[...anchor,max]]});
|
|
35
|
-
return {
|
|
36
|
-
title:{text:scale==='zero'?'Geographic bars · baseline 0':'Geographic bars · truncated baseline',left:'center',top:8,textStyle:{fontSize:14
|
|
35
|
+
return {legend:{type:'scroll',data:fields.map(caption),bottom:8},
|
|
36
|
+
title:{text:scale==='zero'?'Geographic bars · baseline 0':'Geographic bars · truncated baseline',left:'center',top:8,textStyle:{fontSize:14}},
|
|
37
37
|
tooltip:{renderMode:'richText',formatter:p=>`${p.name}\n${p.seriesName}: ${Number(p.value[2]).toLocaleString('en-GB',{maximumFractionDigits:2})}`},
|
|
38
38
|
geo3D:{map:mapName,top:35,bottom:45,boxWidth:100,boxHeight:35,regionHeight:0.15,
|
|
39
39
|
itemStyle:{color:'#d9e3eb',borderColor:'#8e9ca9',borderWidth:0.3},label:{show:false},shading:'lambert',
|
|
@@ -7,10 +7,10 @@ export function chartMapOptions(view,nameField,valueField,labelField,mapName,geo
|
|
|
7
7
|
const {min,max,signed}=domains?domains.map:extent;
|
|
8
8
|
const format=value=>Number(value).toLocaleString('en-GB',{maximumFractionDigits:2});
|
|
9
9
|
const title=caption || valueField;
|
|
10
|
-
return {
|
|
10
|
+
return {title:{text:title,left:'center',top:8,textStyle:{fontSize:14}},
|
|
11
11
|
tooltip:{trigger:'item',renderMode:'richText',formatter:params=>`${labels.get(params.name) || params.name}\n${title}: ${Number.isFinite(params.value)?format(params.value):'No data'}`},
|
|
12
12
|
visualMap:{type:'continuous',min,max,seriesIndex:0,dimension:0,calculable:true,orient:'horizontal',left:'center',bottom:12,
|
|
13
|
-
itemWidth:12,itemHeight:180,precision:2,formatter:format,
|
|
13
|
+
itemWidth:12,itemHeight:180,precision:2,formatter:format,
|
|
14
14
|
inRange:{color:signed?['#b73548','#f7f7f7','#2166ac']:chartMapColors},outOfRange:{color:'#e2e5e9'}},
|
|
15
15
|
series:[{name:title,type:'map',map:mapName,preserveAspect:'contain',aspectScale:1,roam:true,top:42,bottom:70,left:20,right:20,
|
|
16
16
|
itemStyle:{areaColor:'#e2e5e9',borderColor:'#fff',borderWidth:0.45},
|
|
@@ -52,7 +52,7 @@ export const ChartPane = defineComponent({
|
|
|
52
52
|
options:`^${configpath}.seriesOptions`,roles:`^${configpath}.measureRoles`,type:`^${configpath}.chartType`,_onBuilt:true});
|
|
53
53
|
const toolbar=frame.top.contentPane({display:'flex',justify_content:'flex-end',align_items:'center',padding:'2px 6px'});
|
|
54
54
|
const path=JSON.stringify(`${configpath}.drawer`);
|
|
55
|
-
toolbar.button({icon:'
|
|
55
|
+
toolbar.button({icon:'settings',aria_label:'Chart settings',title:'Chart settings',action:`this.SET(${path},this.GET(${path}) === 'close' ? true : 'close');`});
|
|
56
56
|
const prefix=node.getAttr('id') ?? `chart-${randomId()}`;
|
|
57
57
|
const layout=frame.center.borderContainer({id:`${prefix}-layout`,height:'100%'});
|
|
58
58
|
const config=layout.contentPane({region:'right',width:'260px',drawer:`^${configpath}.drawer`,
|
|
@@ -72,14 +72,14 @@ export const ChartPane = defineComponent({
|
|
|
72
72
|
background:'var(--gramlot-surface-subtle)',border_top:'1px solid var(--gramlot-border)'});
|
|
73
73
|
const get=key=>JSON.stringify(`${configpath}.${key}`);
|
|
74
74
|
const transport=timeline.div({display:'flex',align_items:'center',gap:'2px',flex_shrink:'0'});
|
|
75
|
-
transport.button({icon:'
|
|
75
|
+
transport.button({icon:'previous',aria_label:'Previous period',title:'Previous period',id:`${prefix}-time-previous`,
|
|
76
76
|
disabled:`^${configpath}.timeIndex:={} <= 0`,action:`this.SET(${get('timePlaying')},false);this.SET(${get('timeIndex')},Math.max(0,this.GET(${get('timeIndex')})-1));`});
|
|
77
|
-
transport.button({icon:`^${configpath}.timePlaying:={} ? '
|
|
77
|
+
transport.button({icon:`^${configpath}.timePlaying:={} ? 'pause' : 'play'`,
|
|
78
78
|
aria_label:`^${configpath}.timePlaying:={} ? 'Pause' : 'Play'`,title:`^${configpath}.timePlaying:={} ? 'Pause' : 'Play'`,aria_pressed:`^${configpath}.timePlaying`,id:`${prefix}-time-play`,disabled:`^${configpath}.timeMax:={} === 0`,
|
|
79
79
|
action:`if(!this.GET(${get('timePlaying')}) && this.GET(${get('timeIndex')}) >= this.GET(${get('timeMax')}))this.SET(${get('timeIndex')},0);this.SET(${get('timePlaying')},!this.GET(${get('timePlaying')}));`});
|
|
80
|
-
transport.button({icon:'
|
|
80
|
+
transport.button({icon:'stop',aria_label:'Stop',title:'Stop and return to the beginning',id:`${prefix}-time-stop`,
|
|
81
81
|
disabled:`^${configpath}.timeMax:={} === 0`,action:`this.SET(${get('timePlaying')},false);this.SET(${get('timeIndex')},0);`});
|
|
82
|
-
transport.button({icon:'
|
|
82
|
+
transport.button({icon:'next',aria_label:'Next period',title:'Next period',id:`${prefix}-time-next`,
|
|
83
83
|
disabled:`^${configpath}.timeAtEnd`,action:`this.SET(${get('timePlaying')},false);this.SET(${get('timeIndex')},Math.min(this.GET(${get('timeMax')}),this.GET(${get('timeIndex')})+1));`});
|
|
84
84
|
const scrubber=timeline.div({flex:'1',min_width:'120px'});
|
|
85
85
|
scrubber.horizontalSlider({width:'100%',id:`${prefix}-time-slider`,aria_label:'Temporal snapshot',value:`^${configpath}.timeIndex`,min:0,max:`^${configpath}.timeMax`,step:1,live:true,flex:'1',
|
|
@@ -16,7 +16,7 @@ export function chartParallelOptions({view,category,fields,seriesOptions}) {
|
|
|
16
16
|
if(max!==null)axis.max=max;
|
|
17
17
|
return axis;
|
|
18
18
|
});
|
|
19
|
-
return {
|
|
19
|
+
return {tooltip:{trigger:'item'},
|
|
20
20
|
parallel:{left:60,right:60,top:60,bottom:40,parallelAxisDefault:{type:'value',nameLocation:'start',nameGap:20}},
|
|
21
21
|
parallelAxis,
|
|
22
22
|
series:[{type:'parallel',lineStyle:{width:2,opacity:0.7},emphasis:{lineStyle:{width:4,opacity:1}},
|
|
@@ -20,7 +20,7 @@ export function chartRadarOptions({view,category,fields,seriesOptions}) {
|
|
|
20
20
|
if(max<=min)max=min+1;
|
|
21
21
|
return {name:chartCaption(seriesOptions,field),min,max};
|
|
22
22
|
});
|
|
23
|
-
return {
|
|
23
|
+
return {tooltip:{trigger:'item'},
|
|
24
24
|
legend:{show:true,type:'scroll',orient:'horizontal',left:12,right:12,bottom:10,height:24,data:rows.map(row=>row.name)},
|
|
25
25
|
radar:{indicator,center:['50%','48%'],radius:'62%'},
|
|
26
26
|
series:[{type:'radar',areaStyle:{opacity:0.15},
|
|
@@ -2,6 +2,7 @@ import {Bag} from '@genrojs/bag';
|
|
|
2
2
|
import {chartType} from './chart-types/index.js';
|
|
3
3
|
import {requireChartCapability} from './chart-engines/index.js';
|
|
4
4
|
import {checkChartSyntax} from './chart-syntax.js';
|
|
5
|
+
import {CHART_THEME} from './chart-theme.js';
|
|
5
6
|
|
|
6
7
|
/** Engine-independent context of one draw, built from values read at the draw. Reading it never rewrites Data. */
|
|
7
8
|
export function chartContext(view,structure,seriesOptions) {
|
|
@@ -18,7 +19,10 @@ export function chartContext(view,structure,seriesOptions) {
|
|
|
18
19
|
}
|
|
19
20
|
return {axis,color};
|
|
20
21
|
});
|
|
21
|
-
|
|
22
|
+
// legend is a chartView parameter with default true: only an explicit false hides the legend.
|
|
23
|
+
// axes is a chartView parameter with default true: only an explicit false hides the axes.
|
|
24
|
+
// The context draws with CHART_THEME; a renderer with a theme reader replaces it at each draw.
|
|
25
|
+
return {view,category,structure,fields,settings,seriesOptions,type,legend:structure.getItem('legend')!==false,axes:structure.getItem('axes')!==false,theme:CHART_THEME};
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
/** Own an engine instance; adapters own rendering and engine-specific resources. */
|
|
@@ -38,6 +42,7 @@ export class ChartRenderer {
|
|
|
38
42
|
const engine=structure.getItem('engine') ?? 'echarts';
|
|
39
43
|
const context=chartContext(this.#view,structure,data.getItem(path,null,true));
|
|
40
44
|
context.domains=this.#options.domains ? this.#options.domains(context) : null;
|
|
45
|
+
if(this.#options.theme)context.theme=this.#options.theme();
|
|
41
46
|
const Adapter=requireChartCapability(engine,context.type.id);
|
|
42
47
|
const revision=++this.#revision;
|
|
43
48
|
if(engine!==this.#engine) {
|
|
@@ -36,7 +36,7 @@ export function chartSankeyOptions({view,category,structure,fields,seriesOptions
|
|
|
36
36
|
}
|
|
37
37
|
const cycle=sankeyCycle(links);
|
|
38
38
|
if(cycle)throw new TypeError(`Sankey links contain a cycle: ${cycle.join(' → ')}. Remove or reverse one link.`);
|
|
39
|
-
return {
|
|
39
|
+
return {tooltip:{trigger:'item'},
|
|
40
40
|
series:[{id:field,name:chartCaption(seriesOptions,field),type:'sankey',left:20,right:120,top:20,bottom:20,
|
|
41
41
|
emphasis:{focus:'adjacency'},lineStyle:{color:'gradient',curveness:0.5},
|
|
42
42
|
data:[...nodes].map(name=>({name})),links}]};
|
|
@@ -16,6 +16,10 @@ export function chartSpatialOptions(view,type,first,second,fields,settings,domai
|
|
|
16
16
|
const axisOptions=index=>({type:axes[index].numeric?'value':'category',name:[first,second][index],nameGap:35,
|
|
17
17
|
...(axes[index].numeric?(domains?{min:domains.dimensions[index].range[0],max:domains.dimensions[index].range[1]}:{}):{data:dimensions[index]}),
|
|
18
18
|
...(axes[index].date?{axisLabel:{formatter:value=>new Date(value).toISOString().slice(0,10)}}:{})});
|
|
19
|
+
const axisValue=(index,value)=>axes[index].date ? new Date(value).toISOString()
|
|
20
|
+
: axes[index].numeric ? value : dimensions[index][value];
|
|
21
|
+
const tooltip={renderMode:'richText',formatter:({seriesName,value:[x,y,z]})=>
|
|
22
|
+
`${first}: ${axisValue(0,x)}\n${second}: ${axisValue(1,y)}\n${seriesName}: ${z}`};
|
|
19
23
|
const series=[];
|
|
20
24
|
datasets.forEach((dataset,index)=>{
|
|
21
25
|
const common={name:fields[index],type,itemStyle:{color:settings[index].color},lineStyle:{color:settings[index].color,width:3}};
|
|
@@ -34,7 +38,7 @@ export function chartSpatialOptions(view,type,first,second,fields,settings,domai
|
|
|
34
38
|
data:ys.flatMap(y=>xs.map(x=>[x,y,values.get(JSON.stringify([x,y])) ?? NaN]))});
|
|
35
39
|
} else series.push({...common,id:fields[index],symbolSize:9,data:mapped});
|
|
36
40
|
});
|
|
37
|
-
return {
|
|
38
|
-
tooltip
|
|
41
|
+
return {legend:{type:'scroll',left:12,right:12,bottom:10,data:fields},
|
|
42
|
+
tooltip,xAxis3D:axisOptions(0),yAxis3D:axisOptions(1),zAxis3D:{type:'value',name:'Value',nameGap:40,...(domains?{min:domains.z[0],max:domains.z[1]}:{})},
|
|
39
43
|
grid3D:{top:8,bottom:64,height:null,left:16,right:16,width:null,boxWidth:100,boxDepth:80,viewControl:{projection:'perspective'}},series};
|
|
40
44
|
}
|
|
@@ -1,12 +1,24 @@
|
|
|
1
|
+
import {Bag} from '@genrojs/bag';
|
|
1
2
|
import {chartPalette} from './chart-domains.js';
|
|
2
3
|
import {chartCaption,chartHierarchy} from './chart-type-data.js';
|
|
3
4
|
|
|
5
|
+
/** Level labels on sectors wide enough to hold one, truncated; the tooltip carries the full name. */
|
|
6
|
+
const SUNBURST_LABEL={rotate:0,minAngle:24,overflow:'truncate',width:96};
|
|
7
|
+
|
|
8
|
+
/** The `label` Bag in the seriesOptions of the measure, merged over the default label. */
|
|
9
|
+
function sunburstLabel(seriesOptions,field) {
|
|
10
|
+
const label=seriesOptions?.getItem(field)?.getItem('label');
|
|
11
|
+
if(label==null)return {...SUNBURST_LABEL};
|
|
12
|
+
if(!(label instanceof Bag))throw new TypeError(`seriesOptions.${field}.label requires a Bag`);
|
|
13
|
+
return {...SUNBURST_LABEL,...label.asDict()};
|
|
14
|
+
}
|
|
15
|
+
|
|
4
16
|
/** Concentric rings from a nested Bag, the top level at the center. */
|
|
5
17
|
export function chartSunburstOptions(context) {
|
|
6
18
|
const data=chartHierarchy(context,'Sunburst',chartPalette);
|
|
7
19
|
const [field]=context.fields;
|
|
8
20
|
return {backgroundColor:'#ffffff',tooltip:{trigger:'item',formatter:'{b}: {c}'},
|
|
9
21
|
series:[{id:field,name:chartCaption(context.seriesOptions,field),type:'sunburst',radius:[0,'92%'],center:['50%','50%'],
|
|
10
|
-
sort:null,nodeClick:'rootToNode',label:
|
|
22
|
+
sort:null,nodeClick:'rootToNode',label:sunburstLabel(context.seriesOptions,field),
|
|
11
23
|
itemStyle:{borderColor:'#ffffff',borderWidth:1},data}]};
|
|
12
24
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chart colours from the theme tokens. Each engine reads these four colours for the chart background,
|
|
3
|
+
* the text, the axes and the grid. A token that the page does not define keeps the value of CHART_THEME.
|
|
4
|
+
*/
|
|
5
|
+
export const CHART_THEME=Object.freeze({background:'#ffffff',text:'#333333',axis:'#333333',grid:'#e5e7eb'});
|
|
6
|
+
|
|
7
|
+
const CHART_THEME_TOKENS=Object.freeze({background:'--gramlot-surface',text:'--gramlot-ink',axis:'--gramlot-text-secondary',grid:'--gramlot-border'});
|
|
8
|
+
|
|
9
|
+
/** Read the chart colours from the computed style of `element`, at the draw. */
|
|
10
|
+
export function chartTheme(element) {
|
|
11
|
+
const style=element.ownerDocument.defaultView.getComputedStyle(element);
|
|
12
|
+
return Object.fromEntries(Object.entries(CHART_THEME_TOKENS)
|
|
13
|
+
.map(([role,token])=>[role,style.getPropertyValue(token).trim() || CHART_THEME[role]]));
|
|
14
|
+
}
|
|
@@ -5,7 +5,7 @@ import {chartCaption,chartHierarchy} from './chart-type-data.js';
|
|
|
5
5
|
export function chartTreemapOptions(context) {
|
|
6
6
|
const data=chartHierarchy(context,'Treemap',chartPalette);
|
|
7
7
|
const [field]=context.fields;
|
|
8
|
-
return {
|
|
8
|
+
return {tooltip:{trigger:'item',formatter:'{b}: {c}'},
|
|
9
9
|
series:[{id:field,name:chartCaption(context.seriesOptions,field),type:'treemap',left:10,right:10,top:10,bottom:30,
|
|
10
10
|
roam:false,nodeClick:'zoomToNode',breadcrumb:{show:true,bottom:4},
|
|
11
11
|
label:{show:true,formatter:'{b}'},
|
|
@@ -31,24 +31,44 @@ export function chartSeriesText(seriesOptions,field,key) {
|
|
|
31
31
|
return typeof value==='string'&&value?value:null;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/** Colour of a node from its `color` attribute: `#rgb` or `#rrggbb`, or null when the node has none. */
|
|
35
|
+
function hierarchyColor(node,name) {
|
|
36
|
+
const color=node.getAttr('color');
|
|
37
|
+
if(color==null)return null;
|
|
38
|
+
if(typeof color!=='string'||!/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(color))throw new TypeError(`Node ${name} has color ${String(color)}: write it as #rgb or #rrggbb.`);
|
|
39
|
+
return color.length===4?'#'+[...color.slice(1)].map(digit=>digit+digit).join(''):color.toLowerCase();
|
|
40
|
+
}
|
|
41
|
+
/** Shade of a branch colour for child `index` of `count`: the colour mixed with white, more for each next sibling. */
|
|
42
|
+
export function hierarchyShade(color,index,count) {
|
|
43
|
+
const amount=0.6*(index+1)/(count+1);
|
|
44
|
+
return '#'+[1,3,5].map(start=>{
|
|
45
|
+
const channel=parseInt(color.slice(start,start+2),16);
|
|
46
|
+
return Math.round(channel+(255-channel)*amount).toString(16).padStart(2,'0');
|
|
47
|
+
}).join('');
|
|
48
|
+
}
|
|
49
|
+
|
|
34
50
|
/**
|
|
35
51
|
* Nested Bag read as a tree of `{name,value,children?,itemStyle}` for treemap and sunburst.
|
|
36
52
|
* Needs `rowMode='attributes'`: every node carries the caption and the measure as attributes.
|
|
37
53
|
* The top level is read through the view; deeper levels read the attributes of each BagNode.
|
|
38
54
|
* A node whose value is a Bag is a parent, any other node is a leaf. A parent's value is the sum of its children,
|
|
39
55
|
* so a parent carrying the measure is an error. A null leaf is skipped, a negative leaf is an error,
|
|
40
|
-
* a parent whose leaves are all skipped is skipped. Each top-level node takes one palette color
|
|
56
|
+
* a parent whose leaves are all skipped is skipped. Each top-level node takes one palette color.
|
|
57
|
+
* Each child takes its own shade of the colour of its parent. A `color` attribute sets the colour of a node
|
|
58
|
+
* and is the base of the shades of its descendants.
|
|
41
59
|
*/
|
|
42
60
|
export function chartHierarchy({view,category,fields},typeLabel,palette) {
|
|
43
61
|
if(view.rowMode!=='attributes')throw new TypeError(`${typeLabel} needs rowMode='attributes': each node carries the caption and the measure as attributes.`);
|
|
44
62
|
const [field]=fields;
|
|
63
|
+
if(category==='color'||field==='color')throw new TypeError(`${typeLabel} reserves the attribute color for the colour of a node: give the caption and the measure other names.`);
|
|
45
64
|
const attributes={value:(node,key)=>node.getAttr(key)};
|
|
46
|
-
const read=(nodes,reader,
|
|
65
|
+
const read=(nodes,reader,colorFor)=>nodes.flatMap((node,index)=>{
|
|
47
66
|
const name=chartName(reader.value(node,category),category);
|
|
67
|
+
const color=hierarchyColor(node,name)??colorFor(index,nodes.length);
|
|
48
68
|
const children=node.staticValue;
|
|
49
69
|
if(children instanceof Bag) {
|
|
50
70
|
if(node.getAttr(field)!=null)throw new TypeError(`Node ${name} has children and carries ${field}: the value of a parent is the sum of its children. Remove the attribute from ${name}.`);
|
|
51
|
-
const items=read(children.getNodes(),attributes,color);
|
|
71
|
+
const items=read(children.getNodes(),attributes,(child,count)=>hierarchyShade(color,child,count));
|
|
52
72
|
if(!items.length)return [];
|
|
53
73
|
return [{name,value:items.reduce((sum,item)=>sum+item.value,0),children:items,itemStyle:{color}}];
|
|
54
74
|
}
|
|
@@ -58,5 +78,5 @@ export function chartHierarchy({view,category,fields},typeLabel,palette) {
|
|
|
58
78
|
return [{name,value,itemStyle:{color}}];
|
|
59
79
|
});
|
|
60
80
|
const top=view.getRows();
|
|
61
|
-
return top.flatMap((node,index)=>read([node],view,palette[index%palette.length]));
|
|
81
|
+
return top.flatMap((node,index)=>read([node],view,()=>palette[index%palette.length]));
|
|
62
82
|
}
|