@gramlot/gramlot 0.4.0 → 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.
Files changed (141) hide show
  1. package/assets/icons/align-center.svg +4 -0
  2. package/assets/icons/align-justify.svg +4 -0
  3. package/assets/icons/align-left.svg +4 -0
  4. package/assets/icons/align-right.svg +4 -0
  5. package/assets/icons/bold.svg +4 -0
  6. package/assets/icons/eraser.svg +4 -0
  7. package/assets/icons/horizontal-rule.svg +4 -0
  8. package/assets/icons/image.svg +4 -0
  9. package/assets/icons/indent.svg +4 -0
  10. package/assets/icons/italic.svg +4 -0
  11. package/assets/icons/list-bulleted.svg +4 -0
  12. package/assets/icons/list-numbered.svg +4 -0
  13. package/assets/icons/outdent.svg +4 -0
  14. package/assets/icons/paragraph.svg +4 -0
  15. package/assets/icons/select-all.svg +4 -0
  16. package/assets/icons/strikethrough.svg +4 -0
  17. package/assets/icons/underline.svg +4 -0
  18. package/dist/components/charts/__init__.py +1 -1
  19. package/dist/components/charts/assets/index.js +1 -1
  20. package/dist/components/charts/grammar.json +2032 -72
  21. package/dist/components/editors/__init__.py +1 -1
  22. package/dist/components/editors/assets/collection.js +1 -1
  23. package/dist/components/editors/assets/index.js +1 -1
  24. package/dist/components/editors/assets/libraries/codemirror.js +30 -30
  25. package/dist/components/editors/assets/libraries/jodit.js +452 -448
  26. package/dist/components/editors/commands.json +113 -1
  27. package/dist/components/editors/grammar.json +6 -4
  28. package/dist/components/grid/__init__.py +1 -1
  29. package/dist/components/grid/assets/index.js +1 -1
  30. package/dist/components/grid/grammar.json +61 -0
  31. package/dist/components/inputs/__init__.py +1 -1
  32. package/dist/components/inputs/assets/index.js +1 -1
  33. package/dist/components/inputs/grammar.json +35 -0
  34. package/dist/components/layout/__init__.py +1 -1
  35. package/dist/components/layout/assets/collection.js +1 -0
  36. package/dist/components/layout/assets/index.js +1 -1
  37. package/dist/components/layout/grammar.json +364 -0
  38. package/dist/components/tree/__init__.py +1 -1
  39. package/dist/components/tree/assets/index.js +1 -1
  40. package/dist/components/tree/grammar.json +35 -0
  41. package/dist/gramlot.js +1165 -420
  42. package/dist/gramlot.min.js +125 -100
  43. package/dist/libraries.json +5 -4
  44. package/dist/standard-collections.js +1 -1
  45. package/dist/standard-grammar.js +1 -1
  46. package/package.json +4 -2
  47. package/src/binding/providers.js +2 -1
  48. package/src/binding/remote.js +41 -6
  49. package/src/binding/runtime.js +24 -0
  50. package/src/builder/gramlot-builder.js +52 -18
  51. package/src/builder/source.js +66 -12
  52. package/src/chat.d.ts +1 -0
  53. package/src/chat.js +13 -1
  54. package/src/components/chart-bar3d-options.js +0 -1
  55. package/src/components/chart-boxplot-options.js +1 -1
  56. package/src/components/chart-candlestick-options.js +1 -1
  57. package/src/components/chart-engines/echarts-options.js +6 -5
  58. package/src/components/chart-engines/echarts.js +27 -10
  59. package/src/components/chart-engines/plotly-map.js +1 -1
  60. package/src/components/chart-engines/plotly.js +21 -14
  61. package/src/components/chart-engines/uplot.js +17 -11
  62. package/src/components/chart-engines/vega.js +17 -11
  63. package/src/components/chart-funnel-options.js +1 -1
  64. package/src/components/chart-geographic-options.js +1 -1
  65. package/src/components/chart-heatmap-options.js +1 -1
  66. package/src/components/chart-map-bar3d-options.js +2 -2
  67. package/src/components/chart-map-options.js +2 -2
  68. package/src/components/chart-parallel-options.js +1 -1
  69. package/src/components/chart-radar-options.js +1 -1
  70. package/src/components/chart-renderer.js +6 -1
  71. package/src/components/chart-sankey-options.js +1 -1
  72. package/src/components/chart-spatial-options.js +1 -1
  73. package/src/components/chart-sunburst-options.js +13 -1
  74. package/src/components/chart-theme.js +14 -0
  75. package/src/components/chart-treemap-options.js +1 -1
  76. package/src/components/chart-type-data.js +24 -4
  77. package/src/components/charts.js +7 -6
  78. package/src/components/check-box-tree.js +1 -1
  79. package/src/components/choice-editor.js +3 -3
  80. package/src/components/code-mirror-engine.js +2 -1
  81. package/src/components/code-mirror.js +1 -1
  82. package/src/components/editor-commands.js +69 -0
  83. package/src/components/editors.js +5 -3
  84. package/src/components/form-tray-pane.js +18 -0
  85. package/src/components/graphical-ranges.js +16 -3
  86. package/src/components/grid-check-sets.js +39 -3
  87. package/src/components/grid-header-interaction.js +3 -3
  88. package/src/components/grid-styles.js +19 -3
  89. package/src/components/grid.js +42 -9
  90. package/src/components/html-editor-commands.js +61 -0
  91. package/src/components/html-editor.js +18 -3
  92. package/src/components/inputs.js +1 -0
  93. package/src/components/jodit-engine.js +107 -6
  94. package/src/components/layout.js +3 -2
  95. package/src/components/menus.js +6 -1
  96. package/src/components/selected-container.js +16 -3
  97. package/src/components/tab-bar.js +20 -2
  98. package/src/components/tray-base.js +528 -0
  99. package/src/components/tray-pane.js +41 -518
  100. package/src/components/tree.js +44 -1
  101. package/src/components/typed-editor.js +5 -2
  102. package/src/editing-session.js +2 -1
  103. package/src/ide-runtime.js +3 -1
  104. package/src/index-page-runtime.js +11 -3
  105. package/src/index.d.ts +2 -1
  106. package/src/index.js +2 -1
  107. package/src/libraries.js +4 -4
  108. package/src/object-extract.d.ts +7 -0
  109. package/src/object-extract.js +31 -0
  110. package/src/renderer/attributes.js +1 -1
  111. package/src/renderer/gramlot-renderer.d.ts +2 -2
  112. package/src/server/chat.d.ts +3 -1
  113. package/src/server/chat.js +17 -6
  114. package/src/server/gramlot-server.js +5 -1
  115. package/src/server/index-page.js +27 -8
  116. package/src/server/toolbar-icon-name.d.ts +17 -0
  117. package/src/view/labelbox.js +6 -1
  118. package/src/visual-editor.d.ts +1 -0
  119. package/src/visual-editor.js +4 -3
  120. package/themes/gramlot-base/theme.css +7 -0
  121. package/themes/gramlot-index/icons/align-center.svg +4 -0
  122. package/themes/gramlot-index/icons/align-justify.svg +4 -0
  123. package/themes/gramlot-index/icons/align-left.svg +4 -0
  124. package/themes/gramlot-index/icons/align-right.svg +4 -0
  125. package/themes/gramlot-index/icons/bold.svg +4 -0
  126. package/themes/gramlot-index/icons/eraser.svg +4 -0
  127. package/themes/gramlot-index/icons/horizontal-rule.svg +4 -0
  128. package/themes/gramlot-index/icons/image.svg +4 -0
  129. package/themes/gramlot-index/icons/indent.svg +4 -0
  130. package/themes/gramlot-index/icons/italic.svg +4 -0
  131. package/themes/gramlot-index/icons/list-bulleted.svg +4 -0
  132. package/themes/gramlot-index/icons/list-numbered.svg +4 -0
  133. package/themes/gramlot-index/icons/outdent.svg +4 -0
  134. package/themes/gramlot-index/icons/paragraph.svg +4 -0
  135. package/themes/gramlot-index/icons/select-all.svg +4 -0
  136. package/themes/gramlot-index/icons/strikethrough.svg +4 -0
  137. package/themes/gramlot-index/icons/underline.svg +4 -0
  138. package/themes/gramlot-index/icons.json +17 -0
  139. package/themes/gramlot-index/theme.css +3 -0
  140. package/tools/gramlot-tools-inspector.js +11 -3
  141. package/src/builder/chart-icon.js +0 -2
@@ -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:'#fff',plot_bgcolor:'#fff',font:{color:'#333'},showlegend:true,
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
- const scales={x:{time,...(domains?{range:()=>domains.dimension.range.map(v=>time?v/1000:v)}:{})}},axes=[{label:category,stroke:'#333',font:'12px sans-serif'}];
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=fields.filter((_,i)=>settings[i].axis===side);
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,label:names.join(', '),stroke:'#333',font:'12px sans-serif',grid:{show:side==='left',stroke:'#e5e7eb'}});
45
+ axes.push({...axis(names.join(', ')),scale:side,side:side==='left'?3:1,grid:{show:side==='left',stroke:theme.grid}});
42
46
  }
43
- this.#plot=new UPlot({width:Math.max(1,Math.round(rect.width)),height:Math.max(1,Math.round(rect.height)-50),
44
- pxAlign:false,scales,axes,
45
- series:[{label:category},...fields.map((field,i)=>({label:field,stroke:settings[i].color,scale:settings[i].axis,width:1.5}))]},data,this.#element);
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
- spec.legends=[{fill:'color',orient:'bottom',direction:'horizontal',title:null}];
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:'#fff'},tooltip:{signal:'datum.label + ": " + datum.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:'#fff',autosize:{type:'fit',contains:'padding',resize:true},padding:12,
88
- data:[],scales:[],axes:[],marks:[],config:{axis:{labelColor:'#333',titleColor:'#333',gridColor:'#eee'},legend:{labelColor:'#333'}}};
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 {backgroundColor:'#ffffff',tooltip:{trigger:'item',formatter:'{b}: {c}'},
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 {backgroundColor:'#fff',title,legend:{type:'scroll',data:fields,left:12,right:12,bottom:10},
45
+ return {title,legend:{type:'scroll',data:fields,left:12,right:12,bottom:10},
46
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 {backgroundColor:'#ffffff',tooltip:{trigger:'item',position:'top'},
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 {backgroundColor:'#fff',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,color:'#27344b'}},
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 {backgroundColor:'#fff',title:{text:title,left:'center',top:8,textStyle:{color:'#27344b',fontSize:14}},
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,textStyle:{color:'#27344b'},
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},
@@ -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 {backgroundColor:'#ffffff',tooltip:{trigger:'item'},
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 {backgroundColor:'#ffffff',tooltip:{trigger:'item'},
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
- return {view,category,structure,fields,settings,seriesOptions,type};
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 {backgroundColor:'#ffffff',tooltip:{trigger:'item'},
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}]};
@@ -38,7 +38,7 @@ export function chartSpatialOptions(view,type,first,second,fields,settings,domai
38
38
  data:ys.flatMap(y=>xs.map(x=>[x,y,values.get(JSON.stringify([x,y])) ?? NaN]))});
39
39
  } else series.push({...common,id:fields[index],symbolSize:9,data:mapped});
40
40
  });
41
- return {backgroundColor:'#fff',legend:{type:'scroll',left:12,right:12,bottom:10,data:fields},
41
+ return {legend:{type:'scroll',left:12,right:12,bottom:10,data:fields},
42
42
  tooltip,xAxis3D:axisOptions(0),yAxis3D:axisOptions(1),zAxis3D:{type:'value',name:'Value',nameGap:40,...(domains?{min:domains.z[0],max:domains.z[1]}:{})},
43
43
  grid3D:{top:8,bottom:64,height:null,left:16,right:16,width:null,boxWidth:100,boxDepth:80,viewControl:{projection:'perspective'}},series};
44
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:{rotate:'radial',minAngle:8},
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 {backgroundColor:'#ffffff',tooltip:{trigger:'item',formatter:'{b}: {c}'},
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, descendants inherit it.
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,color)=>nodes.flatMap(node=>{
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
  }
@@ -15,10 +15,11 @@ import {Gauge} from './chart-gauge.js';
15
15
  import {ChartNotice,CHART_NOTICE_STYLE,chartErrorSections,chartTypeSections} from './chart-notice.js';
16
16
  import {ChartSyntaxError} from './chart-syntax.js';
17
17
  import {chartTypes} from './chart-types/index.js';
18
+ import {chartTheme} from './chart-theme.js';
18
19
 
19
20
  const ChartView = defineComponent({
20
21
  name:'chartView', tag:'gramlot-chart-view', base:Container, sourceContext:true,
21
- parameters:{sampleMin:{dtype:'R',nullable:true,binding:'read'},sampleMax:{dtype:'R',nullable:true,binding:'read'},sampleStep:{dtype:'R',default:1,binding:'read'},sampleStart:{dtype:'R',default:0,binding:'read'},mapLabelMode:{dtype:'T',default:'value',binding:'read'},mapBarScale:{dtype:'T',default:'zero',binding:'read'},selectedTerritory:{dtype:'T',default:'',binding:'twoWay'},configpath:{dtype:'T'},timeEmpty:{dtype:'T',default:'previous',binding:'read'},timeField:{dtype:'T',default:'',binding:'read'},timeValue:{dtype:'X',nullable:true,binding:'read'},timeStep:{dtype:'T',default:'month',binding:'read'},engine:{dtype:'T',default:'echarts',binding:'read'},mapValueField:{dtype:'T',binding:'read'},mapLabelField:{dtype:'T',binding:'read'},geoJSON:{dtype:'X',nullable:true,binding:'read'},geometryField:{dtype:'T',binding:'read'},secondCaptionField:{dtype:'T',binding:'read'},seriesOptions:{dtype:'X',binding:'read'},storepath:{dtype:'T'}, rowMode:{dtype:'T'}, gridId:{dtype:'T'},
22
+ parameters:{sampleMin:{dtype:'R',nullable:true,binding:'read'},sampleMax:{dtype:'R',nullable:true,binding:'read'},sampleStep:{dtype:'R',default:1,binding:'read'},sampleStart:{dtype:'R',default:0,binding:'read'},mapLabelMode:{dtype:'T',default:'value',binding:'read'},mapBarScale:{dtype:'T',default:'zero',binding:'read'},selectedTerritory:{dtype:'T',default:'',binding:'twoWay'},configpath:{dtype:'T'},timeEmpty:{dtype:'T',default:'previous',binding:'read'},timeField:{dtype:'T',default:'',binding:'read'},timeValue:{dtype:'X',nullable:true,binding:'read'},timeStep:{dtype:'T',default:'month',binding:'read'},engine:{dtype:'T',default:'echarts',binding:'read'},legend:{dtype:'B',default:true,binding:'read'},axes:{dtype:'B',default:true,binding:'read'},mapValueField:{dtype:'T',binding:'read'},mapLabelField:{dtype:'T',binding:'read'},geoJSON:{dtype:'X',nullable:true,binding:'read'},geometryField:{dtype:'T',binding:'read'},secondCaptionField:{dtype:'T',binding:'read'},seriesOptions:{dtype:'X',binding:'read'},storepath:{dtype:'T'}, rowMode:{dtype:'T'}, gridId:{dtype:'T'},
22
23
  chartType:{dtype:'T',binding:'read'}, captionField:{dtype:'T',binding:'read'}, valueFields:{dtype:'T',nullable:true,binding:'read'}},
23
24
  implementation:Base => class extends Base {
24
25
  #sampleView; #timeView; #revision=0; #active=false; #notice; #context; #grid; #releaseGrid; #view; #releaseView; #renderer; #resize;
@@ -32,7 +33,7 @@ const ChartView = defineComponent({
32
33
  this.control = this.ownerDocument.createElement('div');
33
34
  this.controlBox.append(this.#notice.element, this.control);
34
35
  this.controlBox.style.backgroundColor = 'var(--gramlot-surface,#fff)';
35
- this.control.style.cssText = 'width:100%;height:100%;min-width:0;background:#fff';
36
+ this.control.style.cssText = 'width:100%;height:100%;min-width:0;background:var(--gramlot-surface,#fff)';
36
37
  this.#resize = new this.ownerDocument.defaultView.ResizeObserver(() => this.#renderer?.resize());
37
38
  }
38
39
  setSourceContext(context) { this.#context = context; }
@@ -60,7 +61,7 @@ const ChartView = defineComponent({
60
61
  this.#release();
61
62
  this.#sampleView = new ChartSampleView();
62
63
  this.#timeView = new ChartTimeView(this.#sampleView);
63
- this.#renderer = new ChartRenderer(this.control, this.#timeView, {renderer:'svg', domains:context=>this.#sampleView.domains(context,this.parameters.sampleMin,this.parameters.sampleMax)});
64
+ this.#renderer = new ChartRenderer(this.control, this.#timeView, {renderer:'svg', theme:()=>chartTheme(this.control), domains:context=>this.#sampleView.domains(context,this.parameters.sampleMin,this.parameters.sampleMax)});
64
65
  }
65
66
  return;
66
67
  }
@@ -72,7 +73,7 @@ const ChartView = defineComponent({
72
73
  // shows in the notice, and the Data change that brings them projects the chart again.
73
74
  this.#view = new ChartDataView(this.#context.sourceNode.rootBuilder.binding.collectionStore(path,rowMode));
74
75
  this.#timeView = new ChartTimeView(this.#view.view);
75
- this.#renderer = new ChartRenderer(this.control,this.#timeView,{renderer:'svg',domains:context=>this.#timeView.domains(context),onTerritorySelect:name=>this.#context.writeParameter('selectedTerritory',name)});
76
+ this.#renderer = new ChartRenderer(this.control,this.#timeView,{renderer:'svg',theme:()=>chartTheme(this.control),domains:context=>this.#timeView.domains(context),onTerritorySelect:name=>this.#context.writeParameter('selectedTerritory',name)});
76
77
  this.#releaseView = this.#view.view.subscribe(() => {this.#timeView.invalidateDomains();this.#render();});
77
78
  }
78
79
  this.#linkGrid();
@@ -112,7 +113,7 @@ const ChartView = defineComponent({
112
113
  this.#releaseView = this.#view = this.#renderer = this.#timeView = this.#sampleView = null;
113
114
  }
114
115
  async #render() {
115
- const {engine,chartType:typeId,captionField,valueFields,secondCaptionField,geometryField,geoJSON,mapValueField,mapLabelField,mapLabelMode,mapBarScale} = this.parameters;
116
+ const {engine,legend,axes,chartType:typeId,captionField,valueFields,secondCaptionField,geometryField,geoJSON,mapValueField,mapLabelField,mapLabelMode,mapBarScale} = this.parameters;
116
117
  const revision=++this.#revision;
117
118
  try {
118
119
  this.#connect();
@@ -136,7 +137,7 @@ const ChartView = defineComponent({
136
137
  await this.#renderer.prepare(engine,typeId);
137
138
  if(revision!==this.#revision || !this.#renderer)return;
138
139
  this.control.hidden = false;
139
- const structure=new Bag({engine,chartType:typeId,captionField,valueFields,secondCaptionField,geometryField,mapValueField,mapLabelField,mapLabelMode,mapBarScale});
140
+ const structure=new Bag({engine,legend,axes,chartType:typeId,captionField,valueFields,secondCaptionField,geometryField,mapValueField,mapLabelField,mapLabelMode,mapBarScale});
140
141
  structure.setItem('geoJSON',geoJSON);
141
142
  // The final read: the renderer reads seriesOptions at its address where it hands the values to the engine.
142
143
  await this.#renderer.update(structure, {data:this.#context.sourceNode.data, path:this.#context.attrDatapath('seriesOptions')});
@@ -58,7 +58,7 @@ export class CheckBoxTree {
58
58
  this.element.inert = Boolean(p.disabled || p.readonly);
59
59
  this.element.setAttribute('aria-disabled', String(this.element.inert));
60
60
  const checks = p.identifier ? {[`checked_${p.identifier}`]:'value'} : {checkedPaths:value};
61
- this.element.projectAttributes({...checks, checkChildren:p.checkChildren,
61
+ this.element.projectAttributes({...checks, checkChildren:p.checkChildren, eagerCheck:p.eagerCheck,
62
62
  labelAttribute:p.labelAttribute ?? null, hideValues:true});
63
63
  }
64
64
  focus() { this.element.shadowRoot.querySelector('[role=treeitem]')?.focus(); }
@@ -30,10 +30,10 @@ export function ChoiceEditor(HTMLElement) {
30
30
  .choices{min-width:min(var(--gramlot-choice-popup-min-width,0px),var(--gramlot-popup-available-width,100vw));max-width:var(--gramlot-popup-available-width,100vw);position:fixed;inset:auto;margin:0;padding:var(--gramlot-popup-padding,4px);box-sizing:border-box;max-height:min(var(--gramlot-choice-max-height,20rem),var(--gramlot-popup-available-height,100vh));overflow:auto;
31
31
  border:1px solid var(--gramlot-border-control,#aab4c2);border-radius:var(--gramlot-radius-sm,4px);background:var(--gramlot-surface,Canvas);color:var(--gramlot-ink,CanvasText);font:inherit;font-size:var(--gramlot-field-font-size,1em);line-height:1.4;box-shadow:var(--gramlot-shadow,0 3px 9px #0002)}
32
32
  .choices[hidden]{display:none} .choice{min-height:var(--gramlot-touch-target,0px);display:flex;align-items:center;padding:var(--gramlot-choice-item-padding,.25em .5em);border-radius:var(--gramlot-radius-sm,4px);cursor:pointer}
33
- .choice:nth-child(even){background:var(--gramlot-choice-alternate-background,var(--gramlot-surface-subtle,transparent))}
34
- .choice:hover:not([aria-selected=true]){text-decoration:underline;text-underline-offset:.15em}
33
+ .choice:nth-child(even){background:var(--gramlot-choice-alternate-background,transparent)}
34
+ .choice:hover:not([aria-selected=true]){background:var(--gramlot-choice-hover-background,var(--gramlot-surface-subtle,transparent))}
35
35
  .choice-detail{margin-inline-start:var(--gramlot-space-3,.75rem);color:var(--gramlot-text-secondary,GrayText)}
36
- .choice[aria-selected=true]{background:var(--gramlot-selected,Highlight);color:var(--gramlot-ink,HighlightText)}`;
36
+ .choice[aria-selected=true]{background:var(--gramlot-selected,Highlight);color:var(--gramlot-ink,HighlightText);box-shadow:inset 0 0 0 1px var(--gramlot-focus-ring,Highlight)}`;
37
37
  this.toggle = doc.createElement('button');
38
38
  this.toggle.className = 'toggle choice-toggle'; this.toggle.type = 'button'; this.toggle.tabIndex = -1;
39
39
  this.control.parentElement.classList.add('choice-field');
@@ -18,6 +18,7 @@ import {xml} from '@codemirror/lang-xml';
18
18
  import {markdown} from '@codemirror/lang-markdown';
19
19
  import {typst_lezer} from 'codemirror-lang-typst/lezer';
20
20
  import {sql} from '@codemirror/lang-sql';
21
+ import {yaml} from '@codemirror/lang-yaml';
21
22
 
22
23
  // Rust macro arguments are token trees. The parser classifies their bare names
23
24
  // as identifiers, including the component and attribute names inside gramlot!().
@@ -27,7 +28,7 @@ const rustNames = syntaxHighlighting(HighlightStyle.define([
27
28
  {tag:tags.macroName, color:'var(--gramlot-editor-keyword, #9677d9)', fontWeight:'bold'}
28
29
  ]));
29
30
  const gramlotModes = {'gramlot-py':'python', 'gramlot-js':'javascript', 'gramlot-rs':'rust'};
30
- const languages = {text: () => [], python, rust: () => [rust(), rustNames], javascript, typescript: () => javascript({typescript:true}), json, html, css, xml, markdown, sql, typst:typst_lezer};
31
+ const languages = {text: () => [], python, rust: () => [rust(), rustNames], javascript, typescript: () => javascript({typescript:true}), json, html, css, xml, markdown, sql, typst:typst_lezer, yaml};
31
32
  const colors = syntaxHighlighting(HighlightStyle.define([
32
33
  {tag:[tags.keyword, tags.modifier], color:'var(--gramlot-editor-keyword, #9677d9)'},
33
34
  {tag:[tags.string, tags.regexp], color:'var(--gramlot-editor-string, #318f74)'},
@@ -4,7 +4,7 @@ import {defineComponent} from './registry.js';
4
4
  import {Labelbox} from './labelbox.js';
5
5
  import {FieldState} from './field-state.js';
6
6
 
7
- const languages = ['text', 'gramlot-py', 'gramlot-js', 'gramlot-rs', 'python', 'rust', 'javascript', 'typescript', 'json', 'html', 'css', 'xml', 'markdown', 'sql', 'typst'];
7
+ const languages = ['text', 'gramlot-py', 'gramlot-js', 'gramlot-rs', 'python', 'rust', 'javascript', 'typescript', 'json', 'html', 'css', 'xml', 'markdown', 'sql', 'typst', 'yaml'];
8
8
  let engineModule;
9
9
  function EditorControl(HTMLElement) {
10
10
  return class extends controlElement(HTMLElement) {