@gramlot/gramlot 0.3.27 → 0.3.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/icons/chart.svg +1 -0
- package/dist/components/audio/__init__.py +13 -0
- package/dist/components/audio/assets/collection.js +3 -0
- package/dist/components/audio/assets/index.js +3 -0
- package/dist/components/audio/commands.json +7 -0
- package/dist/components/audio/grammar.json +335 -0
- package/dist/components/charts/__init__.py +13 -0
- package/dist/components/charts/assets/collection.js +47 -0
- package/dist/components/charts/assets/files/55ea01207028f76d844678511f29fc800f8a1e67a8a0fe80470128677847ad32-echarts-gl.txt +29 -0
- package/dist/components/charts/assets/files/63727832aaf62004a2b249c933e327f3c90caf49e41a72f4bf436edf632cbda8-vega.txt +27 -0
- package/dist/components/charts/assets/files/8c45d9eaf50c2f72dd9c7ab9ef440788ba58a3538484b5c51c1f17d5128752e7-plotly.txt +21 -0
- package/dist/components/charts/assets/files/8f989229699b4fe2f1a0432d0e9edc338a8a911e250e2d1b01ecd770a5f5b1bd-uplot.txt +21 -0
- package/dist/components/charts/assets/files/c8fa058cba98f7f288b5d8fa4116f441d6dacb25b96da859e518c973fff41d0c-claygl.txt +23 -0
- package/dist/components/charts/assets/index.js +3 -0
- package/dist/components/charts/assets/modules/chunk-2CCTLZE7.js +76 -0
- package/dist/components/charts/assets/modules/chunk-RMRBEYTI.js +1 -0
- package/dist/components/charts/assets/modules/echarts-gl-CXVTZA6G.js +4409 -0
- package/dist/components/charts/assets/modules/plotly.min-4LB7HE7P.js +3596 -0
- package/dist/components/charts/assets/modules/uPlot.esm-5JJNHHRF.js +3 -0
- package/dist/components/charts/assets/modules/uPlot.min-N3E3FA74.js +1 -0
- package/dist/components/charts/assets/modules/vega.module-2QCOVQ3A.js +13 -0
- package/dist/components/charts/commands.json +7 -0
- package/dist/components/charts/grammar.json +1113 -0
- package/dist/components/chat/__init__.py +1 -1
- package/dist/components/chat/assets/collection.js +3 -3
- package/dist/components/chat/assets/index.js +1 -1
- package/dist/components/drawing/__init__.py +15 -0
- package/dist/components/drawing/assets/collection.js +28 -0
- package/dist/components/drawing/assets/index.js +3 -0
- package/dist/components/drawing/commands.json +7 -0
- package/dist/components/drawing/grammar.json +110 -0
- package/dist/components/editors/__init__.py +2 -2
- package/dist/components/editors/assets/collection.js +18 -18
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/modules/{prose-mirror-engine-GMZPJPNN.js → prose-mirror-engine-DQEAEIMV.js} +2 -2
- package/dist/components/editors/grammar.json +150 -0
- package/dist/components/grid/__init__.py +1 -1
- package/dist/components/grid/assets/collection.js +51 -30
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/grammar.json +258 -0
- package/dist/components/grouplets/__init__.py +1 -1
- package/dist/components/grouplets/assets/collection.js +3 -3
- package/dist/components/grouplets/assets/index.js +1 -1
- package/dist/components/inputs/__init__.py +3 -2
- package/dist/components/inputs/assets/collection.js +38 -23
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +1533 -321
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +27 -23
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +85 -0
- package/dist/components/selection_trial/__init__.py +1 -1
- package/dist/components/selection_trial/assets/collection.js +3 -3
- package/dist/components/selection_trial/assets/index.js +1 -1
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +11 -11
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +126 -0
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +2 -2
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/collection.js +8 -8
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/components/vizabi/__init__.py +13 -0
- package/dist/components/vizabi/assets/collection.js +22 -0
- package/dist/components/vizabi/assets/index.js +3 -0
- package/dist/components/vizabi/commands.json +7 -0
- package/dist/components/vizabi/grammar.json +128 -0
- package/dist/gramlot.js +572 -176
- package/dist/gramlot.min.js +85 -53
- package/dist/standard-collections.js +2 -0
- package/package.json +12 -4
- package/src/binding/grid-struct.js +2 -2
- package/src/binding/runtime.js +10 -0
- package/src/bootstrap.js +1 -1
- package/src/builder/gramlot-builder.d.ts +15 -2
- package/src/builder/gramlot-builder.js +22 -3
- package/src/builder/source.js +24 -1
- package/src/components/audio-analysis-session.js +65 -0
- package/src/components/audio.js +44 -0
- package/src/components/bases.js +6 -4
- package/src/components/border-container.js +6 -3
- package/src/components/buttons.js +47 -3
- package/src/components/chart-bar3d-options.js +30 -0
- package/src/components/chart-controls.js +83 -0
- package/src/components/chart-data-view.js +52 -0
- package/src/components/chart-data.js +42 -0
- package/src/components/chart-domains.js +46 -0
- package/src/components/chart-engines/echarts-options.js +50 -0
- package/src/components/chart-engines/echarts.js +82 -0
- package/src/components/chart-engines/index.js +22 -0
- package/src/components/chart-engines/plotly-map.js +34 -0
- package/src/components/chart-engines/plotly-spatial.js +35 -0
- package/src/components/chart-engines/plotly.js +138 -0
- package/src/components/chart-engines/uplot.js +57 -0
- package/src/components/chart-engines/vega.js +101 -0
- package/src/components/chart-fields.js +110 -0
- package/src/components/chart-geographic-options.js +47 -0
- package/src/components/chart-geojson.js +60 -0
- package/src/components/chart-geometry.js +11 -0
- package/src/components/chart-map-anchors.js +24 -0
- package/src/components/chart-map-bar3d-options.js +41 -0
- package/src/components/chart-map-data.js +25 -0
- package/src/components/chart-map-labels.js +8 -0
- package/src/components/chart-map-options.js +20 -0
- package/src/components/chart-pane.js +91 -0
- package/src/components/chart-renderer.js +58 -0
- package/src/components/chart-sample-view.js +32 -0
- package/src/components/chart-spatial-options.js +40 -0
- package/src/components/chart-time.js +84 -0
- package/src/components/chart-timeline.js +70 -0
- package/src/components/chart-types/area.js +2 -0
- package/src/components/chart-types/bar.js +2 -0
- package/src/components/chart-types/bar3D.js +2 -0
- package/src/components/chart-types/donut.js +2 -0
- package/src/components/chart-types/horizontalBar.js +2 -0
- package/src/components/chart-types/index.js +26 -0
- package/src/components/chart-types/line.js +2 -0
- package/src/components/chart-types/line3D.js +2 -0
- package/src/components/chart-types/lines3D.js +2 -0
- package/src/components/chart-types/map.js +2 -0
- package/src/components/chart-types/map3D.js +2 -0
- package/src/components/chart-types/mapBar3D.js +2 -0
- package/src/components/chart-types/pie.js +2 -0
- package/src/components/chart-types/polygons3D.js +2 -0
- package/src/components/chart-types/scatter.js +2 -0
- package/src/components/chart-types/scatter3D.js +2 -0
- package/src/components/chart-types/stackedArea.js +2 -0
- package/src/components/chart-types/stackedBar.js +2 -0
- package/src/components/chart-types/surface.js +2 -0
- package/src/components/charts.js +152 -0
- package/src/components/check-box-text-editor.js +88 -0
- package/src/components/check-box-text.js +193 -0
- package/src/components/check-box-tree.js +62 -0
- package/src/components/choice-editor.js +7 -5
- package/src/components/choice-field-styles.js +14 -0
- package/src/components/choices.js +5 -0
- package/src/components/drawing.js +199 -0
- package/src/components/grid-check-sets.js +98 -0
- package/src/components/grid-column-filters.js +198 -0
- package/src/components/grid-grammar.json +44 -0
- package/src/components/grid-header-interaction.js +3 -1
- package/src/components/grid-rows.js +2 -2
- package/src/components/grid-search-box.js +38 -22
- package/src/components/grid-search-styles.js +13 -14
- package/src/components/grid-search.js +8 -1
- package/src/components/grid-structure.js +10 -2
- package/src/components/grid-styles.js +23 -0
- package/src/components/grid.js +52 -10
- package/src/components/image-uploader.js +2 -2
- package/src/components/inputs.js +19 -10
- package/src/components/labelbox.js +5 -1
- package/src/components/licenses/claygl.txt +23 -0
- package/src/components/licenses/echarts-gl.txt +29 -0
- package/src/components/licenses/plotly.txt +21 -0
- package/src/components/licenses/uplot.txt +21 -0
- package/src/components/licenses/vega.txt +27 -0
- package/src/components/menus.js +19 -11
- package/src/components/toolbar-overflow.js +12 -8
- package/src/components/tree.js +30 -8
- package/src/components/typed-editor.js +14 -3
- package/src/components/vizabi-session.js +66 -0
- package/src/components/vizabi.js +66 -0
- package/src/components/window-surface.js +20 -9
- package/src/components/windows.js +1 -1
- package/src/gramlot.d.ts +1 -0
- package/src/gramlot.js +2 -0
- package/src/handlers/device-handler.js +32 -32
- package/src/handlers/source-handler.d.ts +2 -2
- package/src/ide-documents.js +19 -3
- package/src/ide-runtime.d.ts +1 -0
- package/src/ide-runtime.js +45 -31
- package/src/index.d.ts +1 -0
- package/src/renderer/drag-drop.js +1 -0
- package/src/renderer/gramlot-renderer.d.ts +2 -0
- package/src/renderer/gramlot-renderer.js +5 -4
- package/src/server/assets.d.ts +3 -0
- package/src/server/assets.js +9 -0
- package/src/server/gramlot-server.d.ts +1 -1
- package/src/server/gramlot-server.js +2 -1
- package/src/server/index.d.ts +1 -1
- package/src/server/index.js +1 -1
- package/src/server/visual-editor.js +17 -17
- package/src/stores/bag-collection-view.js +79 -17
- package/src/stores/collection-filter.js +2 -1
- package/src/stores/column-filter.js +49 -0
- package/src/stores/id-set.js +10 -0
- package/src/view/controls.js +8 -0
- package/src/view/html.js +10 -1
- package/src/view/label-menu.js +61 -0
- package/src/view/labelbox.js +15 -2
- package/themes/gramlot-base/theme.css +6 -0
- package/tools/gramlot-tools-inspector.js +169 -505
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {chartDomains} from './chart-domains.js';
|
|
2
|
+
|
|
3
|
+
/** Numeric snapshot projection; row handles are indices, never Bag nodes. */
|
|
4
|
+
export class ChartSampleView {
|
|
5
|
+
bind(samples, step, start, category, measure) {
|
|
6
|
+
if (!Array.isArray(samples) || samples.some(value => typeof value !== 'number' || !Number.isFinite(value))) {
|
|
7
|
+
throw new TypeError('Sample chart requires an array of finite numbers');
|
|
8
|
+
}
|
|
9
|
+
if (!Number.isFinite(step) || step <= 0 || !Number.isFinite(start)) throw new TypeError('Sample chart requires a positive step and finite start');
|
|
10
|
+
if (typeof category !== 'string' || !category || typeof measure !== 'string' || !measure || measure.includes(',') || category === measure) throw new TypeError('Sample chart requires distinct captionField and one valueFields name');
|
|
11
|
+
this.samples = samples;
|
|
12
|
+
this.step = step; this.start = start; this.category = category; this.measure = measure;
|
|
13
|
+
if (this.rows?.length !== samples.length) this.rows = Array.from(samples.keys());
|
|
14
|
+
}
|
|
15
|
+
domains(context, min, max) {
|
|
16
|
+
if (min == null && max == null) return null;
|
|
17
|
+
if (!Number.isFinite(min) || !Number.isFinite(max) || min >= max) {
|
|
18
|
+
throw new TypeError('Sample bounds require finite sampleMin < sampleMax');
|
|
19
|
+
}
|
|
20
|
+
const domains = chartDomains(this, context);
|
|
21
|
+
domains.dimension.range = [this.start, this.start + Math.max(1, this.samples.length - 1) * this.step];
|
|
22
|
+
domains.axes = {left:[min,max], right:[min,max]};
|
|
23
|
+
domains.z = [min,max];
|
|
24
|
+
return domains;
|
|
25
|
+
}
|
|
26
|
+
getRows() { return this.rows; }
|
|
27
|
+
value(index, field) {
|
|
28
|
+
if (field === this.category) return this.start + index * this.step;
|
|
29
|
+
if (field === this.measure) return this.samples[index];
|
|
30
|
+
throw new TypeError(`Unknown sample field: ${field}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {chartData3D} from './chart-data.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/** Cartesian 3D series keep store values and category labels on their actual axes. */
|
|
5
|
+
export function chartSpatialOptions(view,type,first,second,fields,settings,domains) {
|
|
6
|
+
const rows=view.getRows();
|
|
7
|
+
const numeric=field=>rows.every(row=>{
|
|
8
|
+
const value=view.value(row,field);
|
|
9
|
+
return typeof value==='number'&&Number.isFinite(value) || value instanceof Date&&Number.isFinite(value.getTime());
|
|
10
|
+
});
|
|
11
|
+
const axes=[first,second].map((field,i)=>({numeric:domains?domains.dimensions[i].kind!=='category':numeric(field),date:domains?domains.dimensions[i].kind==='time':rows.length>0&&view.value(rows[0],field) instanceof Date}));
|
|
12
|
+
if(['scatter3D','surface'].includes(type)&&axes.some(axis=>!axis.numeric))throw new TypeError('Choose numeric or date fields for both dimensions');
|
|
13
|
+
const datasets=fields.map(field=>chartData3D(view,first,second,field,domains));
|
|
14
|
+
const dimensions=datasets[0]?.dimensions ?? [[],[]];
|
|
15
|
+
const coordinates=dimensions.map((values,axis)=>values.map((value,index)=>axes[axis].numeric?(axes[axis].date?Date.parse(value):Number(value)):index));
|
|
16
|
+
const axisOptions=index=>({type:axes[index].numeric?'value':'category',name:[first,second][index],nameGap:35,
|
|
17
|
+
...(axes[index].numeric?(domains?{min:domains.dimensions[index].range[0],max:domains.dimensions[index].range[1]}:{}):{data:dimensions[index]}),
|
|
18
|
+
...(axes[index].date?{axisLabel:{formatter:value=>new Date(value).toISOString().slice(0,10)}}:{})});
|
|
19
|
+
const series=[];
|
|
20
|
+
datasets.forEach((dataset,index)=>{
|
|
21
|
+
const common={name:fields[index],type,itemStyle:{color:settings[index].color},lineStyle:{color:settings[index].color,width:3}};
|
|
22
|
+
const mapped=dataset.source.map(([x,y,z])=>[coordinates[0][x],coordinates[1][y],z]);
|
|
23
|
+
if(type==='line3D') {
|
|
24
|
+
dimensions[1].forEach((plane,y)=>{
|
|
25
|
+
const data=dataset.source.filter(row=>row[1]===y).map(([x,,z])=>[coordinates[0][x],coordinates[1][y],z]).sort((a,b)=>a[0]-b[0]);
|
|
26
|
+
series.push({...common,id:`${fields[index]}:${y}`,data});
|
|
27
|
+
});
|
|
28
|
+
} else if(type==='surface') {
|
|
29
|
+
const xs=[...coordinates[0]].sort((a,b)=>a-b),ys=[...coordinates[1]].sort((a,b)=>a-b),values=new Map();
|
|
30
|
+
for(const [x,y,z] of mapped){const key=JSON.stringify([x,y]);if(values.has(key))throw new TypeError('Surface has repeated coordinates: prepare unique coordinate pairs upstream');values.set(key,z);}
|
|
31
|
+
if(xs.length<2||ys.length<2)throw new TypeError('A surface needs at least two distinct values on each dimension');
|
|
32
|
+
series.push({...common,id:fields[index],dataShape:[ys.length,xs.length],shading:'lambert',
|
|
33
|
+
itemStyle:{color:settings[index].color,opacity:fields.length>1?0.7:1},
|
|
34
|
+
data:ys.flatMap(y=>xs.map(x=>[x,y,values.get(JSON.stringify([x,y])) ?? NaN]))});
|
|
35
|
+
} else series.push({...common,id:fields[index],symbolSize:9,data:mapped});
|
|
36
|
+
});
|
|
37
|
+
return {backgroundColor:'#fff',legend:{type:'scroll',left:12,right:12,bottom:10,data:fields},
|
|
38
|
+
tooltip:{renderMode:'richText'},xAxis3D:axisOptions(0),yAxis3D:axisOptions(1),zAxis3D:{type:'value',name:'Value',nameGap:40,...(domains?{min:domains.z[0],max:domains.z[1]}:{})},
|
|
39
|
+
grid3D:{top:8,bottom:64,height:null,left:16,right:16,width:null,boxWidth:100,boxDepth:80,viewControl:{projection:'perspective'}},series};
|
|
40
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {getDateType} from '@genrojs/tytx';
|
|
2
|
+
import {chartDomains} from './chart-domains.js';
|
|
3
|
+
const day=86400000;
|
|
4
|
+
const units={minute:60000,hour:3600000,day,week:7*day};
|
|
5
|
+
const monday=4*day; // 1970-01-05, first Monday after the epoch.
|
|
6
|
+
export function timePeriod(value,step) {
|
|
7
|
+
if(!(value instanceof Date)||!Number.isFinite(value.getTime()))throw new TypeError('Temporal snapshots require Date values');
|
|
8
|
+
if(Object.hasOwn(units,step))return Math.floor((value.getTime()-(step==='week'?monday:0))/units[step]);
|
|
9
|
+
if(step==='month')return value.getUTCFullYear()*12+value.getUTCMonth();
|
|
10
|
+
if(step==='year')return value.getUTCFullYear();
|
|
11
|
+
throw new TypeError('Time step must be minute, hour, day, week, month or year');
|
|
12
|
+
}
|
|
13
|
+
export function timeDate(period,step) {
|
|
14
|
+
if(Object.hasOwn(units,step))return new Date(period*units[step]+(step==='week'?monday:0));
|
|
15
|
+
const date=new Date(0);
|
|
16
|
+
if(step==='month')date.setUTCFullYear(Math.floor(period/12),period-Math.floor(period/12)*12,1);
|
|
17
|
+
else if(step==='year')date.setUTCFullYear(period,0,1);
|
|
18
|
+
else throw new TypeError('Time step must be minute, hour, day, week, month or year');
|
|
19
|
+
return date;
|
|
20
|
+
}
|
|
21
|
+
export function timeExtent(view,field,step) {
|
|
22
|
+
let min=Infinity,max=-Infinity;
|
|
23
|
+
for(const row of view.getRows()) {
|
|
24
|
+
const value=view.value(row,field);
|
|
25
|
+
if(value==null)continue;
|
|
26
|
+
const period=timePeriod(value,step);min=Math.min(min,period);max=Math.max(max,period);
|
|
27
|
+
}
|
|
28
|
+
return min===Infinity?null:{min,max};
|
|
29
|
+
}
|
|
30
|
+
/** Detect available precision using the framework's existing Date classification. */
|
|
31
|
+
export function timeProfile(view,field){
|
|
32
|
+
let min=Infinity,max=-Infinity,hasClock=false;
|
|
33
|
+
for(const row of field?view.getRows():[]){
|
|
34
|
+
const value=view.value(row,field);
|
|
35
|
+
if(value==null)continue;
|
|
36
|
+
timePeriod(value,'day');
|
|
37
|
+
min=Math.min(min,value.getTime());max=Math.max(max,value.getTime());
|
|
38
|
+
hasClock ||= getDateType(value)!=='D';
|
|
39
|
+
}
|
|
40
|
+
const steps=hasClock?['minute','hour','day','week','month','year']:['day','week','month','year'];
|
|
41
|
+
const first=min===Infinity?null:new Date(min),last=min===Infinity?null:new Date(max);
|
|
42
|
+
const suggested=first?steps.find(step=>timePeriod(last,step)-timePeriod(first,step)<=36) ?? 'year':'day';
|
|
43
|
+
return {hasClock,steps,suggested,first,last};
|
|
44
|
+
}
|
|
45
|
+
export function timeLabel(value,step){
|
|
46
|
+
const iso=value.toISOString();
|
|
47
|
+
if(step==='week')return `${iso.slice(0,10)} – ${new Date(value.getTime()+6*day).toISOString().slice(0,10)} UTC`;
|
|
48
|
+
if(step==='hour'||step==='minute')return `${iso.slice(0,16).replace('T',' ')} UTC`;
|
|
49
|
+
return iso.slice(0,step==='year'?4:step==='month'?7:10);
|
|
50
|
+
}
|
|
51
|
+
/** A temporal projection of the already filtered view; no copied or aggregated rows. */
|
|
52
|
+
export class ChartTimeView {
|
|
53
|
+
constructor(view){this.view=view;this.field='';}
|
|
54
|
+
invalidateDomains(){this.domainKey=null;}
|
|
55
|
+
domains(context){
|
|
56
|
+
if(!this.field)return null;
|
|
57
|
+
const key=JSON.stringify([this.field,this.step,context.category,context.fields,context.settings,context.type.id,context.structure.getItem('secondCaptionField'),context.structure.getItem('mapValueField'),context.structure.getItem('mapBarScale')]);
|
|
58
|
+
const geoJSON=context.structure.getItem('geoJSON');
|
|
59
|
+
if(key!==this.domainKey || geoJSON!==this.domainGeoJSON){
|
|
60
|
+
const rows=this.view.getRows().filter(row=>this.value(row,this.field)!=null);
|
|
61
|
+
this.domainValue=chartDomains({getRows:()=>rows,value:(row,field)=>this.value(row,field)},context);
|
|
62
|
+
this.domainKey=key;this.domainGeoJSON=geoJSON;
|
|
63
|
+
}
|
|
64
|
+
return this.domainValue;
|
|
65
|
+
}
|
|
66
|
+
setPeriod(field,value,step,empty='previous'){
|
|
67
|
+
if(!['previous','empty'].includes(empty))throw new TypeError('Empty periods require previous or empty');
|
|
68
|
+
this.field=field;this.date=value;this.step=step;this.empty=empty;
|
|
69
|
+
}
|
|
70
|
+
value(row,field){return this.view.value(row,field);}
|
|
71
|
+
getRows(){
|
|
72
|
+
const rows=this.view.getRows();
|
|
73
|
+
this.snapshotDate=null;
|
|
74
|
+
if(!this.field)return rows;
|
|
75
|
+
if(this.date==null)return [];
|
|
76
|
+
const selected=timePeriod(this.date,this.step);
|
|
77
|
+
let period=this.empty==='empty'?selected:-Infinity;
|
|
78
|
+
const dated=rows.map(row=>{const value=this.value(row,this.field);return {row,period:value==null?null:timePeriod(value,this.step)};});
|
|
79
|
+
if(this.empty==='previous')for(const entry of dated)if(entry.period!==null&&entry.period<=selected)period=Math.max(period,entry.period);
|
|
80
|
+
const snapshot=dated.filter(entry=>entry.period===period).map(entry=>entry.row);
|
|
81
|
+
if(snapshot.length)this.snapshotDate=timeDate(period,this.step);
|
|
82
|
+
return snapshot;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {defineComponent} from '@gramlot/gramlot/components';
|
|
2
|
+
import {Container} from './container.js';
|
|
3
|
+
import {randomId} from '../random-id.js';
|
|
4
|
+
import {timeProfile,timeLabel,timeDate,timePeriod} from './chart-time.js';
|
|
5
|
+
|
|
6
|
+
const scripts=new WeakMap();
|
|
7
|
+
export function chartTimeLogic(binding){
|
|
8
|
+
if(!scripts.has(binding)){
|
|
9
|
+
const group=`chart_time_${randomId()}`;
|
|
10
|
+
class Logic {
|
|
11
|
+
tick(node){
|
|
12
|
+
const path=node.getAttr('configpath'),config=node.getRelativeData(path);
|
|
13
|
+
if(!config.getItem('timePlaying')||!config.getItem('timeField'))return;
|
|
14
|
+
const next=config.getItem('timeIndex')+1,max=config.getItem('timeMax');
|
|
15
|
+
if(next<=max)node.setRelativeData(`${path}.timeIndex`,next);
|
|
16
|
+
if(next>=max)node.setRelativeData(`${path}.timePlaying`,false);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
binding.logicRegistry.register(Logic,{group,resource:'gramlot:charts'});scripts.set(binding,`${group}.tick`);
|
|
20
|
+
}
|
|
21
|
+
return scripts.get(binding);
|
|
22
|
+
}
|
|
23
|
+
export const ChartTimeline=defineComponent({
|
|
24
|
+
name:'chartTimeline',tag:'gramlot-chart-timeline',base:Container,sourceContext:true,bagStore:true,
|
|
25
|
+
parameters:{storepath:{dtype:'T'},rowMode:{dtype:'T'},configpath:{dtype:'T'},timeField:{dtype:'T',binding:'read'},timeStep:{dtype:'T',binding:'read'},timeIndex:{dtype:'R',binding:'read'}},
|
|
26
|
+
implementation:Base=>class extends Base{
|
|
27
|
+
#context;#bag;#store;#release;#active=false;#syncing=false;#selection;#minimum;#profile;#field;
|
|
28
|
+
constructor(){super();const style=this.ownerDocument.createElement('style');style.textContent=':host{display:none}';this.shadowRoot.append(style);}
|
|
29
|
+
setSourceContext(context){this.#context=context;}
|
|
30
|
+
setStoreBag(bag){this.#bag=bag;}
|
|
31
|
+
projectAttributes(attrs,adapt){const result=super.projectAttributes(attrs,adapt);if(this.#active)this.#connect();return result;}
|
|
32
|
+
connectedCallback(){this.#active=true;this.#connect();}
|
|
33
|
+
#connect(){
|
|
34
|
+
const store=this.#context.sourceNode.rootBuilder.binding.collectionStore(this.#bag,this.parameters.rowMode);
|
|
35
|
+
if(store!==this.#store){this.#release?.();this.#store=store;this.#profile=null;this.#release=store.subscribe(()=>{this.#profile=null;this.#sync();});}
|
|
36
|
+
this.#sync();
|
|
37
|
+
}
|
|
38
|
+
#sync(){
|
|
39
|
+
if(this.#syncing)return;this.#syncing=true;
|
|
40
|
+
try{
|
|
41
|
+
const node=this.#context.sourceNode,path=this.parameters.configpath,config=node.getRelativeData(path);
|
|
42
|
+
const put=(key,value)=>{const old=config.getItem(key);if(old instanceof Date&&value instanceof Date?old.getTime()!==value.getTime():old!==value)node.setRelativeData(`${path}.${key}`,value);};
|
|
43
|
+
const {timeField:field,timeStep:requested}=this.parameters;
|
|
44
|
+
if(!this.#profile||field!==this.#field){this.#profile=timeProfile(this.#store,field);this.#field=field;}
|
|
45
|
+
const profile=this.#profile,step=requested==='auto'?profile.suggested:requested;
|
|
46
|
+
put('timeHasClock',profile.hasClock);put('timeUnit',step);
|
|
47
|
+
const selection=JSON.stringify([field,step]);
|
|
48
|
+
let index=config.getItem('timeIndex');
|
|
49
|
+
const changed=this.#selection!==undefined&&selection!==this.#selection;
|
|
50
|
+
if(changed){index=0;put('timePlaying',false);}
|
|
51
|
+
this.#selection=selection;
|
|
52
|
+
const extent=field&&profile.first?{min:timePeriod(profile.first,step),max:timePeriod(profile.last,step)}:null;
|
|
53
|
+
if(!changed&&extent&&this.#minimum!==undefined&&extent.min!==this.#minimum&&config.getItem('timeValue') instanceof Date)index=timePeriod(config.getItem('timeValue'),step)-extent.min;
|
|
54
|
+
this.#minimum=extent?.min;
|
|
55
|
+
const max=extent?extent.max-extent.min:0;
|
|
56
|
+
if(!Number.isInteger(index))throw new TypeError('Time index requires an integer');
|
|
57
|
+
index=Math.max(0,Math.min(max,index));
|
|
58
|
+
const value=extent?timeDate(extent.min+index,step):null;
|
|
59
|
+
put('timeMax',max);put('timeIndex',index);put('timeValue',value);
|
|
60
|
+
put('timeLabel',value?timeLabel(value,step):'No temporal data');
|
|
61
|
+
if(!extent||max===0)put('timePlaying',false);
|
|
62
|
+
}finally{this.#syncing=false;}
|
|
63
|
+
}
|
|
64
|
+
disconnectedCallback(){
|
|
65
|
+
this.#active=false;this.#release?.();this.#release=null;this.#store=null;
|
|
66
|
+
const path=this.parameters.configpath;
|
|
67
|
+
this.#context.sourceNode.setRelativeData(`${path}.timePlaying`,false);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import bar from './bar.js';
|
|
2
|
+
import line from './line.js';
|
|
3
|
+
import area from './area.js';
|
|
4
|
+
import stackedBar from './stackedBar.js';
|
|
5
|
+
import stackedArea from './stackedArea.js';
|
|
6
|
+
import horizontalBar from './horizontalBar.js';
|
|
7
|
+
import pie from './pie.js';
|
|
8
|
+
import donut from './donut.js';
|
|
9
|
+
import scatter from './scatter.js';
|
|
10
|
+
import bar3D from './bar3D.js';
|
|
11
|
+
import line3D from './line3D.js';
|
|
12
|
+
import scatter3D from './scatter3D.js';
|
|
13
|
+
import surface from './surface.js';
|
|
14
|
+
import map from './map.js';
|
|
15
|
+
import mapBar3D from './mapBar3D.js';
|
|
16
|
+
import map3D from './map3D.js';
|
|
17
|
+
import lines3D from './lines3D.js';
|
|
18
|
+
import polygons3D from './polygons3D.js';
|
|
19
|
+
|
|
20
|
+
export const chartTypes = [bar,line,area,stackedBar,stackedArea,horizontalBar,pie,donut,scatter,bar3D,line3D,scatter3D,surface,map,mapBar3D,map3D,lines3D,polygons3D];
|
|
21
|
+
const types=new Map(chartTypes.map(type=>[type.id,type]));
|
|
22
|
+
export function chartType(id) {
|
|
23
|
+
const type=types.get(id);
|
|
24
|
+
if(!type)throw new TypeError('Choose a supported chart type');
|
|
25
|
+
return type;
|
|
26
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import {ChartTimeView,timeLabel} from './chart-time.js';
|
|
2
|
+
import {ChartTimeline} from './chart-timeline.js';
|
|
3
|
+
import {ChartPane} from './chart-pane.js';
|
|
4
|
+
import {Bag} from '@gramlot/gramlot';
|
|
5
|
+
import {defineCollection, defineComponent} from '@gramlot/gramlot/components';
|
|
6
|
+
import {Container} from './container.js';
|
|
7
|
+
import {gridSearch} from './grid-search.js';
|
|
8
|
+
import {ChartSampleView} from './chart-sample-view.js';
|
|
9
|
+
import {ChartDataView} from './chart-data-view.js';
|
|
10
|
+
import {ChartGeoJSON} from './chart-geojson.js';
|
|
11
|
+
import {ChartFields} from './chart-fields.js';
|
|
12
|
+
import {ChartRenderer} from './chart-renderer.js';
|
|
13
|
+
|
|
14
|
+
const ChartView = defineComponent({
|
|
15
|
+
name:'chartView', tag:'gramlot-chart-view', base:Container, sourceContext:true, bagStore:true,
|
|
16
|
+
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'},
|
|
17
|
+
chartType:{dtype:'T',binding:'read'}, captionField:{dtype:'T',binding:'read'}, valueFields:{dtype:'T',nullable:true,binding:'read'}},
|
|
18
|
+
implementation:Base => class extends Base {
|
|
19
|
+
#sampleView; #timeView; #revision=0; #active=false; #message; #context; #store; #grid; #releaseGrid; #view; #releaseView; #renderer; #resize; #options; #optionsSubscription = Symbol('chart-options');
|
|
20
|
+
constructor() {
|
|
21
|
+
super();
|
|
22
|
+
this.control.replaceChildren();
|
|
23
|
+
const style = this.ownerDocument.createElement('style');
|
|
24
|
+
style.textContent = ':host{height:100%;min-height:0}.control-box{height:100%;min-height:0;overflow:hidden}';
|
|
25
|
+
this.shadowRoot.append(style);
|
|
26
|
+
this.#message = this.ownerDocument.createElement('div');
|
|
27
|
+
this.#message.setAttribute('role','alert'); this.#message.hidden = true;
|
|
28
|
+
this.#message.style.cssText = 'padding:20px;white-space:normal';
|
|
29
|
+
this.control = this.ownerDocument.createElement('div');
|
|
30
|
+
this.controlBox.append(this.#message, this.control);
|
|
31
|
+
this.controlBox.style.backgroundColor = '#fff';
|
|
32
|
+
this.#message.style.color = '#333';
|
|
33
|
+
this.control.style.cssText = 'width:100%;height:100%;min-width:0;background:#fff';
|
|
34
|
+
this.#resize = new this.ownerDocument.defaultView.ResizeObserver(() => this.#renderer?.resize());
|
|
35
|
+
}
|
|
36
|
+
setSourceContext(context) { this.#context = context; }
|
|
37
|
+
setStoreBag(bag) {
|
|
38
|
+
if (bag != null && !(bag instanceof Bag) && !Array.isArray(bag)) throw new TypeError('Chart requires a Data Bag or sample array');
|
|
39
|
+
this.#store = bag;
|
|
40
|
+
}
|
|
41
|
+
projectAttributes(attrs, adapt) {
|
|
42
|
+
const rest = super.projectAttributes(attrs,adapt);
|
|
43
|
+
this.#bindOptions();
|
|
44
|
+
if (this.#active) { this.#connectStore(); this.#render(); }
|
|
45
|
+
return rest;
|
|
46
|
+
}
|
|
47
|
+
#bindOptions() {
|
|
48
|
+
const options = this.parameters.seriesOptions;
|
|
49
|
+
if (!(options instanceof Bag)) throw new TypeError('seriesOptions requires a Bag');
|
|
50
|
+
if (options === this.#options) return;
|
|
51
|
+
this.#options?.unsubscribe(this.#optionsSubscription,{any:true});
|
|
52
|
+
this.#options = options;
|
|
53
|
+
options.subscribe(this.#optionsSubscription,{any:() => this.#render()});
|
|
54
|
+
}
|
|
55
|
+
connectedCallback() {
|
|
56
|
+
this.#active = true;
|
|
57
|
+
this.#bindOptions();
|
|
58
|
+
const binding = this.#context.sourceNode.rootBuilder.binding;
|
|
59
|
+
if (this.parameters.gridId) {
|
|
60
|
+
const target = binding.nodeIds.get(this.parameters.gridId);
|
|
61
|
+
if (!target || target.nodeTag !== 'grid') throw new TypeError('gridId requires an existing grid nodeId');
|
|
62
|
+
if (target.absDatapath(target.getAttr('storepath')) !== this.#context.sourceNode.absDatapath(this.parameters.storepath)) {
|
|
63
|
+
throw new TypeError('Chart and grid must use the same storepath');
|
|
64
|
+
}
|
|
65
|
+
this.#grid = gridSearch(target);
|
|
66
|
+
this.#releaseGrid = this.#grid.subscribe(() => this.#syncGrid());
|
|
67
|
+
}
|
|
68
|
+
this.#connectStore();
|
|
69
|
+
this.#render();
|
|
70
|
+
this.#resize.observe(this.control);
|
|
71
|
+
}
|
|
72
|
+
#connectStore() {
|
|
73
|
+
if (this.parameters.rowMode === 'samples') {
|
|
74
|
+
if (this.parameters.gridId || this.parameters.timeField) throw new TypeError('Sample charts do not use grid filters or temporal playback');
|
|
75
|
+
if (!this.#sampleView) {
|
|
76
|
+
this.#releaseView?.(); this.#releaseView = null;
|
|
77
|
+
this.#view?.dispose(); this.#view = null;
|
|
78
|
+
this.#renderer?.dispose(); this.#renderer = null;
|
|
79
|
+
this.#sampleView = new ChartSampleView();
|
|
80
|
+
}
|
|
81
|
+
this.#sampleView.bind(this.#store ?? [], this.parameters.sampleStep, this.parameters.sampleStart,
|
|
82
|
+
this.parameters.captionField, this.parameters.valueFields);
|
|
83
|
+
if (!this.#renderer) {
|
|
84
|
+
this.#timeView = new ChartTimeView(this.#sampleView);
|
|
85
|
+
this.#renderer = new ChartRenderer(this.control, this.#timeView, {renderer:'svg', domains:context=>this.#sampleView.domains(context,this.parameters.sampleMin,this.parameters.sampleMax)});
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (this.#sampleView) {
|
|
90
|
+
this.#renderer.dispose(); this.#renderer = null; this.#sampleView = null;
|
|
91
|
+
}
|
|
92
|
+
const store = this.#context.sourceNode.rootBuilder.binding.collectionStore(this.#store,this.parameters.rowMode);
|
|
93
|
+
if (!this.#view) {
|
|
94
|
+
this.#view = new ChartDataView(store);
|
|
95
|
+
this.#timeView = new ChartTimeView(this.#view.view);
|
|
96
|
+
this.#renderer = new ChartRenderer(this.control,this.#timeView,{renderer:'svg',domains:context=>this.#timeView.domains(context),onTerritorySelect:name=>this.#context.writeParameter('selectedTerritory',name)});
|
|
97
|
+
this.#releaseView = this.#view.view.subscribe(() => {this.#timeView.invalidateDomains();this.#render();});
|
|
98
|
+
} else if (this.#view.view.bag !== this.#store) this.#view.bindStore(store);
|
|
99
|
+
if (this.#grid) this.#syncGrid();
|
|
100
|
+
}
|
|
101
|
+
#syncGrid() {
|
|
102
|
+
const gridView = this.#grid.view;
|
|
103
|
+
if (!gridView) { this.#view?.detach(); return; }
|
|
104
|
+
// Grid and chart receive the same Data replacement independently.
|
|
105
|
+
// Follow only once both consumers refer to that replacement Bag.
|
|
106
|
+
if (!this.#view || gridView.bag !== this.#store) return;
|
|
107
|
+
this.#view.follow(gridView);
|
|
108
|
+
this.#render();
|
|
109
|
+
}
|
|
110
|
+
async #render() {
|
|
111
|
+
if (!this.#renderer) return;
|
|
112
|
+
const {engine,chartType:typeId,captionField,valueFields,secondCaptionField,geometryField,geoJSON,mapValueField,mapLabelField,mapLabelMode,mapBarScale} = this.parameters;
|
|
113
|
+
const revision=++this.#revision;
|
|
114
|
+
this.#renderer.invalidate();
|
|
115
|
+
try {
|
|
116
|
+
this.#timeView.setPeriod(this.parameters.timeField,this.parameters.timeValue,this.parameters.timeStep,this.parameters.timeEmpty);
|
|
117
|
+
const rows=this.#timeView.getRows(),snapshot=this.#timeView.snapshotDate;
|
|
118
|
+
if(this.parameters.configpath){
|
|
119
|
+
const node=this.#context.sourceNode,path=`${this.parameters.configpath}.timeSnapshotLabel`;
|
|
120
|
+
const label=snapshot&&snapshot.getTime()!==this.parameters.timeValue.getTime()?`Showing: ${timeLabel(snapshot,this.parameters.timeStep)}`:'';
|
|
121
|
+
if(node.getRelativeData(path)!==label)node.setRelativeData(path,label);
|
|
122
|
+
}
|
|
123
|
+
if (!rows.length && !(this.parameters.timeField && this.#view.view.getRows().some(row=>this.#view.view.value(row,this.parameters.timeField)!=null))) {
|
|
124
|
+
this.control.hidden = true;
|
|
125
|
+
this.#message.setAttribute('role','status');
|
|
126
|
+
this.#message.textContent = 'No data to display'; this.#message.hidden = false;
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
await this.#renderer.prepare(engine,typeId);
|
|
130
|
+
if(revision!==this.#revision || !this.#renderer)return;
|
|
131
|
+
this.control.hidden = false;
|
|
132
|
+
const structure=new Bag({engine,chartType:typeId,captionField,valueFields,secondCaptionField,geometryField,mapValueField,mapLabelField,mapLabelMode,mapBarScale});
|
|
133
|
+
structure.setItem('geoJSON',geoJSON);
|
|
134
|
+
await this.#renderer.update(structure, this.#options);
|
|
135
|
+
if(revision!==this.#revision || !this.#renderer)return;
|
|
136
|
+
this.#message.setAttribute('role','alert'); this.#message.hidden = true; this.#message.textContent = '';
|
|
137
|
+
this.#renderer.resize();
|
|
138
|
+
}
|
|
139
|
+
catch (error) { if(revision!==this.#revision || !this.#renderer)return; this.control.hidden = true; this.#message.setAttribute('role','alert'); this.#message.textContent = error.message; this.#message.hidden = false; }
|
|
140
|
+
}
|
|
141
|
+
disconnectedCallback() {
|
|
142
|
+
this.#active = false;
|
|
143
|
+
this.#revision++;
|
|
144
|
+
this.#options?.unsubscribe(this.#optionsSubscription,{any:true}); this.#options = null;
|
|
145
|
+
this.#resize.disconnect(); this.#releaseGrid?.(); this.#releaseView?.();
|
|
146
|
+
this.#view?.dispose(); this.#renderer?.dispose();
|
|
147
|
+
this.#sampleView = null;
|
|
148
|
+
this.#grid = this.#view = this.#renderer = this.#releaseGrid = this.#releaseView = null;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
export default defineCollection({name:'charts',assets:{echartsGlLicense:new URL('./licenses/echarts-gl.txt',import.meta.url),clayglLicense:new URL('./licenses/claygl.txt',import.meta.url),plotlyLicense:new URL('./licenses/plotly.txt',import.meta.url),vegaLicense:new URL('./licenses/vega.txt',import.meta.url),uplotLicense:new URL('./licenses/uplot.txt',import.meta.url)},components:[ChartPane,ChartView,ChartFields,ChartGeoJSON,ChartTimeline]});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Text projection for checkBoxText. Codes remain the field value; drafts belong to Source. */
|
|
2
|
+
export class CheckBoxTextEditor {
|
|
3
|
+
constructor(owner) {
|
|
4
|
+
this.owner = owner;
|
|
5
|
+
const doc = owner.ownerDocument;
|
|
6
|
+
this.input = doc.createElement('input');
|
|
7
|
+
this.input.type = 'text'; this.input.className = 'summary';
|
|
8
|
+
this.input.placeholder = 'Select options'; this.input.autocomplete = 'off';
|
|
9
|
+
this.input.setAttribute('aria-label', 'Selected descriptions');
|
|
10
|
+
this.list = doc.createElement('datalist'); this.list.id = 'description-options';
|
|
11
|
+
this.input.setAttribute('list', this.list.id);
|
|
12
|
+
this.toggle = doc.createElement('button'); this.toggle.type = 'button';
|
|
13
|
+
this.toggle.className = 'choice-toggle'; this.toggle.setAttribute('aria-label', 'Show options');
|
|
14
|
+
this.element = doc.createElement('div'); this.element.className = 'summary-row choice-field';
|
|
15
|
+
this.element.append(this.input, this.toggle, this.list);
|
|
16
|
+
this.toggle.addEventListener('click', () => owner.openChoices());
|
|
17
|
+
this.input.addEventListener('input', event => {
|
|
18
|
+
if (this.locked) return;
|
|
19
|
+
owner.cancelValidation();
|
|
20
|
+
this.state.draft = {text:this.input.value, value:owner.readControlValue()};
|
|
21
|
+
owner.pageContext?.formSelectionError('Confirm the edited selection.');
|
|
22
|
+
if (!event.isComposing) { owner.closeChoices(); this.suggest(); }
|
|
23
|
+
});
|
|
24
|
+
this.input.addEventListener('compositionend', () => this.suggest());
|
|
25
|
+
this.input.addEventListener('change', () => this.commit());
|
|
26
|
+
this.input.addEventListener('keydown', event => {
|
|
27
|
+
if (event.isComposing || this.locked) return;
|
|
28
|
+
if (event.key === 'Enter') { event.preventDefault(); this.commit(); }
|
|
29
|
+
if (event.key === 'Escape') { event.preventDefault(); owner.cancelValidation(); this.clear(); owner.closeChoices(); owner.updateSummary(); }
|
|
30
|
+
});
|
|
31
|
+
owner.control.addEventListener('change', event => {
|
|
32
|
+
if (event.target !== owner.control) this.clear();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
get state() { return this.source.checkBoxTextState; }
|
|
36
|
+
get locked() { return this.input.disabled || this.input.readOnly || !this.owner.pageContext?.isActive(); }
|
|
37
|
+
attach(source) { this.source = source; source.checkBoxTextState ??= {draft:null}; }
|
|
38
|
+
clear() {
|
|
39
|
+
if (this.source) this.state.draft = null;
|
|
40
|
+
this.owner.pageContext?.formSelectionError('');
|
|
41
|
+
this.input.setCustomValidity(''); this.input.setAttribute('aria-invalid','false');
|
|
42
|
+
this.owner.error('');
|
|
43
|
+
}
|
|
44
|
+
project(value, caption) {
|
|
45
|
+
if (this.source && this.state.draft && !Object.is(this.state.draft.value, value)) this.clear();
|
|
46
|
+
const text = this.source && this.state.draft ? this.state.draft.text : caption ?? '';
|
|
47
|
+
if (this.input.value !== text) this.input.value = text;
|
|
48
|
+
this.toggle.disabled = this.input.disabled;
|
|
49
|
+
this.element.hidden = this.input.hidden;
|
|
50
|
+
this.suggest();
|
|
51
|
+
}
|
|
52
|
+
suggest() {
|
|
53
|
+
const text = this.input.value, end = text.lastIndexOf(',') + 1;
|
|
54
|
+
const prefix = text.slice(0,end), query = text.slice(end).trim().toLocaleLowerCase();
|
|
55
|
+
const options = this.owner.textOptions();
|
|
56
|
+
const used = new Set(prefix.split(',').map(s => s.trim().toLocaleLowerCase()));
|
|
57
|
+
this.list.replaceChildren(...options.filter(row => !row.disabled && !used.has(row.caption.toLocaleLowerCase()) &&
|
|
58
|
+
row.caption.toLocaleLowerCase().includes(query)).map(row => {
|
|
59
|
+
const option = this.owner.ownerDocument.createElement('option');
|
|
60
|
+
option.value = prefix + row.caption; option.label = row.id; return option;
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
candidate() {
|
|
64
|
+
if (!this.source || !this.state.draft) return {value:this.owner.readControlValue()};
|
|
65
|
+
const text = this.state.draft.text.trim();
|
|
66
|
+
if (!text) return {value:null};
|
|
67
|
+
const rows = this.owner.textOptions(), codes = [];
|
|
68
|
+
const old = (this.state.draft.value || '').split(',');
|
|
69
|
+
for (const token of text.split(',').map(s => s.trim())) {
|
|
70
|
+
const matches = rows.filter(row => !row.disabled && row.caption.toLocaleLowerCase() === token.toLocaleLowerCase());
|
|
71
|
+
if (matches.length !== 1) {
|
|
72
|
+
// A missing code already present in Data may remain until options load.
|
|
73
|
+
if (token && old.includes(token) && !rows.some(row => row.id === token)) { codes.push(token); continue; }
|
|
74
|
+
return {error:matches.length > 1 ? 'Ambiguous description: choose its checkbox.' : 'Choose a description from the options.'};
|
|
75
|
+
}
|
|
76
|
+
if (!codes.includes(matches[0].id)) codes.push(matches[0].id);
|
|
77
|
+
}
|
|
78
|
+
return {value:codes.join(',') || null};
|
|
79
|
+
}
|
|
80
|
+
commit() {
|
|
81
|
+
if (this.locked || !this.state.draft) return;
|
|
82
|
+
this.owner.control.dispatchEvent(new this.owner.ownerDocument.defaultView.Event('change', {bubbles:true}));
|
|
83
|
+
}
|
|
84
|
+
reject(message) {
|
|
85
|
+
this.input.setCustomValidity(message); this.input.setAttribute('aria-invalid','true');
|
|
86
|
+
this.owner.error(message); this.owner.pageContext?.formSelectionError(message);
|
|
87
|
+
}
|
|
88
|
+
}
|