@gramlot/gramlot 0.3.31 → 0.3.33
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/dist/components/charts/__init__.py +1 -1
- package/dist/components/charts/assets/collection.js +36 -21
- package/dist/components/charts/assets/index.js +1 -1
- package/dist/components/charts/grammar.json +15482 -232
- package/dist/components/grid/__init__.py +1 -1
- package/dist/components/grid/assets/collection.js +5 -5
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/gramlot.js +22 -10
- package/dist/gramlot.min.js +2 -2
- package/dist/standard-collections.js +1 -1
- package/package.json +1 -1
- package/src/components/chart-boxplot-options.js +22 -0
- package/src/components/chart-candlestick-options.js +27 -0
- package/src/components/chart-controls.js +28 -6
- package/src/components/chart-domains.js +1 -1
- package/src/components/chart-engines/echarts.js +18 -0
- package/src/components/chart-fields.js +11 -1
- package/src/components/chart-funnel-options.js +19 -0
- package/src/components/chart-gauge-options.js +98 -0
- package/src/components/chart-gauge.js +105 -0
- package/src/components/chart-heatmap-options.js +29 -0
- package/src/components/chart-notice.js +126 -0
- package/src/components/chart-pane.js +7 -1
- package/src/components/chart-parallel-options.js +24 -0
- package/src/components/chart-radar-options.js +29 -0
- package/src/components/chart-renderer.js +2 -8
- package/src/components/chart-sankey-options.js +43 -0
- package/src/components/chart-sunburst-options.js +12 -0
- package/src/components/chart-syntax.js +82 -0
- package/src/components/chart-time.js +2 -1
- package/src/components/chart-treemap-options.js +16 -0
- package/src/components/chart-type-data.js +62 -0
- package/src/components/chart-types/area.js +6 -1
- package/src/components/chart-types/bar.js +6 -1
- package/src/components/chart-types/bar3D.js +7 -1
- package/src/components/chart-types/boxplot.js +11 -0
- package/src/components/chart-types/candlestick.js +10 -0
- package/src/components/chart-types/donut.js +6 -1
- package/src/components/chart-types/funnel.js +7 -0
- package/src/components/chart-types/heatmap.js +8 -0
- package/src/components/chart-types/horizontalBar.js +6 -1
- package/src/components/chart-types/index.js +21 -1
- package/src/components/chart-types/line.js +6 -1
- package/src/components/chart-types/line3D.js +7 -1
- package/src/components/chart-types/lines3D.js +7 -1
- package/src/components/chart-types/map.js +7 -1
- package/src/components/chart-types/map3D.js +6 -1
- package/src/components/chart-types/mapBar3D.js +6 -1
- package/src/components/chart-types/parallel.js +7 -0
- package/src/components/chart-types/pie.js +6 -1
- package/src/components/chart-types/polygons3D.js +7 -1
- package/src/components/chart-types/radar.js +7 -0
- package/src/components/chart-types/sankey.js +8 -0
- package/src/components/chart-types/scatter.js +6 -1
- package/src/components/chart-types/scatter3D.js +7 -1
- package/src/components/chart-types/stackedArea.js +6 -1
- package/src/components/chart-types/stackedBar.js +6 -1
- package/src/components/chart-types/sunburst.js +7 -0
- package/src/components/chart-types/surface.js +7 -1
- package/src/components/chart-types/treemap.js +7 -0
- package/src/components/charts.js +60 -13
- package/src/components/grid-selection.js +10 -3
- package/src/components/registry.js +9 -5
- package/src/page-store-connection.js +15 -5
- package/themes/gramlot-base/theme.css +2 -0
package/package.json
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {chartCell,chartName,chartCaption} from './chart-type-data.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One box per row. `valueFields` is read as min, q1, median, q3, max; the statistics belong to the host, raw data is not accepted.
|
|
5
|
+
* A row with an empty value is skipped; a row whose five values decrease is an error naming its caption.
|
|
6
|
+
*/
|
|
7
|
+
export function chartBoxplotOptions({view,category,fields,seriesOptions}) {
|
|
8
|
+
const names=[],data=[];
|
|
9
|
+
for(const row of view.getRows()) {
|
|
10
|
+
const values=fields.map(field=>chartCell(view,row,field));
|
|
11
|
+
if(values.some(value=>value===null))continue;
|
|
12
|
+
const name=chartName(view.value(row,category),category);
|
|
13
|
+
if(values.some((value,index)=>index>0&&value<values[index-1]))throw new TypeError(`Boxplot row ${name} must satisfy min <= q1 <= median <= q3 <= max.`);
|
|
14
|
+
names.push(name);
|
|
15
|
+
data.push(values);
|
|
16
|
+
}
|
|
17
|
+
return {backgroundColor:'#ffffff',tooltip:{trigger:'item'},
|
|
18
|
+
grid:{left:60,right:30,top:30,bottom:50},
|
|
19
|
+
xAxis:{type:'category',data:names,name:category,boundaryGap:true},
|
|
20
|
+
yAxis:{type:'value',scale:true},
|
|
21
|
+
series:[{id:fields[0],name:chartCaption(seriesOptions,fields[0]),type:'boxplot',data}]};
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {chartCell,chartName,chartCaption,chartSeriesText} from './chart-type-data.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One candle per row in store order. `valueFields` is read as open, high, low, close; ECharts wants open, close, low, high.
|
|
5
|
+
* A row with an empty value among the four is skipped, never drawn as zero.
|
|
6
|
+
* Colors: `upColor` and `downColor` in the series options of the first measure (open); ECharts defaults otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export function chartCandlestickOptions({view,category,fields,seriesOptions}) {
|
|
9
|
+
const [open,high,low,close]=fields;
|
|
10
|
+
const names=[],data=[];
|
|
11
|
+
for(const row of view.getRows()) {
|
|
12
|
+
const values=fields.map(field=>chartCell(view,row,field));
|
|
13
|
+
if(values.some(value=>value===null))continue;
|
|
14
|
+
names.push(chartName(view.value(row,category),category));
|
|
15
|
+
data.push([values[0],values[3],values[2],values[1]]);
|
|
16
|
+
}
|
|
17
|
+
const up=chartSeriesText(seriesOptions,open,'upColor'),down=chartSeriesText(seriesOptions,open,'downColor');
|
|
18
|
+
const itemStyle={};
|
|
19
|
+
if(up){itemStyle.color=up;itemStyle.borderColor=up;}
|
|
20
|
+
if(down){itemStyle.color0=down;itemStyle.borderColor0=down;}
|
|
21
|
+
return {backgroundColor:'#ffffff',tooltip:{trigger:'axis',axisPointer:{type:'cross'}},
|
|
22
|
+
grid:{left:60,right:30,top:30,bottom:70},
|
|
23
|
+
xAxis:{type:'category',data:names,name:category,boundaryGap:true},
|
|
24
|
+
yAxis:{type:'value',scale:true},
|
|
25
|
+
dataZoom:[{type:'inside'}],
|
|
26
|
+
series:[{id:open,name:chartCaption(seriesOptions,open),type:'candlestick',data,itemStyle}]};
|
|
27
|
+
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {chartEngines,chartCapabilities} from './chart-engines/index.js';
|
|
2
|
-
import {chartTypes} from './chart-types/index.js';
|
|
2
|
+
import {chartTypes,chartRoles,chartFixedMeasures} from './chart-types/index.js';
|
|
3
3
|
|
|
4
4
|
/** Standard Source sections, reused by the type descriptors. No chart state lives here. */
|
|
5
5
|
export function chartControls(config, {configpath,storepath,rowMode,prefix}) {
|
|
6
6
|
const refs={};
|
|
7
|
-
function select(parent,label,key,choices,reference) {
|
|
8
|
-
const id=`${prefix}-${key}`;
|
|
7
|
+
function select(parent,label,key,choices,reference,id=`${prefix}-${key}`) {
|
|
9
8
|
parent.html_label(label,{for:id});
|
|
10
9
|
const attrs={id,value:`^${configpath}.${key}`};
|
|
11
10
|
if(reference) { attrs.nodeId=`${prefix}_${reference}`;refs[reference]=attrs.nodeId; }
|
|
@@ -74,10 +73,33 @@ export function chartControls(config, {configpath,storepath,rowMode,prefix}) {
|
|
|
74
73
|
columns.column({field:'axis',name:'Axis',width:'30%',edit:{tag:'filteringSelect',values:'left:Left,right:Right',validate_select:true}});
|
|
75
74
|
}
|
|
76
75
|
};
|
|
76
|
+
// Column sections follow the syntax of the types; geoJSON and mapBarScale are the non-column sections they declare.
|
|
77
|
+
const declares={
|
|
78
|
+
category:type=>chartRoles(type,'captionField').length>0,
|
|
79
|
+
secondDimension:type=>chartRoles(type,'secondCaptionField').length>0,
|
|
80
|
+
geometry:type=>chartRoles(type,'geometryField').length>0,
|
|
81
|
+
mapMeasure:type=>chartRoles(type,'mapValueField').length>0,
|
|
82
|
+
measures:type=>chartRoles(type,'valueFields').some(role=>role.count==='many'),
|
|
83
|
+
geoJSON:type=>type.controls.includes('geoJSON'),
|
|
84
|
+
mapBarScale:type=>type.controls.includes('mapBarScale')
|
|
85
|
+
};
|
|
86
|
+
const shown=types=>`^${configpath}.chartType:=${JSON.stringify(types)}.includes({}) ? "grid" : "none"`;
|
|
77
87
|
for(const [name,compose] of Object.entries(sections)) {
|
|
78
|
-
const
|
|
79
|
-
const section=config.div({display:`^${configpath}.chartType:=${JSON.stringify(types)}.includes({}) ? "grid" : "none"`,gap:'4px'});
|
|
88
|
+
const section=config.div({display:shown(chartTypes.filter(declares[name]).map(type=>type.id)),gap:'4px'});
|
|
80
89
|
compose(section);
|
|
81
90
|
}
|
|
82
|
-
|
|
91
|
+
// One select per fixed measure role (value, open … close, min … max), shared by the types that declare it.
|
|
92
|
+
const fixed=new Map();
|
|
93
|
+
for(const type of chartTypes)for(const name of chartFixedMeasures(type)) {
|
|
94
|
+
if(!fixed.has(name))fixed.set(name,{role:chartRoles(type,'valueFields').find(role=>role.name===name),types:[]});
|
|
95
|
+
fixed.get(name).types.push(type.id);
|
|
96
|
+
}
|
|
97
|
+
const measureRoleIds=[];
|
|
98
|
+
for(const [name,{role,types}] of fixed) {
|
|
99
|
+
const section=config.div({display:shown(types),gap:'4px'});
|
|
100
|
+
select(section,role.caption,`measureRoles.${name}`,[['','Choose a column']],`measureRole_${name}`,`${prefix}-role-${name}`);
|
|
101
|
+
measureRoleIds.push(refs[`measureRole_${name}`]);
|
|
102
|
+
delete refs[`measureRole_${name}`];
|
|
103
|
+
}
|
|
104
|
+
config.chartFields({storepath,rowMode,configpath,measureRoleIds:measureRoleIds.join(','),...refs});
|
|
83
105
|
}
|
|
@@ -26,7 +26,7 @@ export function chartDomains(view,{category,fields,settings,structure,type}) {
|
|
|
26
26
|
}
|
|
27
27
|
axes[side]=chartRange(values,true);
|
|
28
28
|
}
|
|
29
|
-
const secondField=type.
|
|
29
|
+
const secondField=type.syntax.some(role=>role.parameter==='secondCaptionField')?structure.getItem('secondCaptionField'):null;
|
|
30
30
|
const second=secondField?chartData(view,secondField,[]):null;
|
|
31
31
|
const dimensions=[dimension,...(second?[{kind:second.kind,values:[...new Set(second.source.map(row=>row[0]))],range:chartRange(second.source.map(row=>row[0]))}]:[])];
|
|
32
32
|
const mapField=type.id==='map'?structure.getItem('mapValueField'):null;
|
|
@@ -7,6 +7,15 @@ import {chartSpatialOptions} from '../chart-spatial-options.js';
|
|
|
7
7
|
import {chartGeographicOptions,chartPolygonGeoJSON} from '../chart-geographic-options.js';
|
|
8
8
|
import {chartMapBar3DOptions} from '../chart-map-bar3d-options.js';
|
|
9
9
|
import {chartMapOptions} from '../chart-map-options.js';
|
|
10
|
+
import {chartFunnelOptions} from '../chart-funnel-options.js';
|
|
11
|
+
import {chartRadarOptions} from '../chart-radar-options.js';
|
|
12
|
+
import {chartParallelOptions} from '../chart-parallel-options.js';
|
|
13
|
+
import {chartHeatmapOptions} from '../chart-heatmap-options.js';
|
|
14
|
+
import {chartSankeyOptions} from '../chart-sankey-options.js';
|
|
15
|
+
import {chartCandlestickOptions} from '../chart-candlestick-options.js';
|
|
16
|
+
import {chartBoxplotOptions} from '../chart-boxplot-options.js';
|
|
17
|
+
import {chartTreemapOptions} from '../chart-treemap-options.js';
|
|
18
|
+
import {chartSunburstOptions} from '../chart-sunburst-options.js';
|
|
10
19
|
|
|
11
20
|
let glLoading;
|
|
12
21
|
export class EChartsAdapter {
|
|
@@ -76,6 +85,15 @@ export class EChartsAdapter {
|
|
|
76
85
|
const option=chartGeographicOptions(view,type,category,structure.getItem('geometryField'),fields,settings,this.#mapName,geoJSON);
|
|
77
86
|
this.#map(geoJSON);return option;
|
|
78
87
|
}
|
|
88
|
+
render_funnel(context) { return chartFunnelOptions(context); }
|
|
89
|
+
render_radar(context) { return chartRadarOptions(context); }
|
|
90
|
+
render_parallel(context) { return chartParallelOptions(context); }
|
|
91
|
+
render_heatmap(context) { return chartHeatmapOptions(context); }
|
|
92
|
+
render_sankey(context) { return chartSankeyOptions(context); }
|
|
93
|
+
render_candlestick(context) { return chartCandlestickOptions(context); }
|
|
94
|
+
render_boxplot(context) { return chartBoxplotOptions(context); }
|
|
95
|
+
render_treemap(context) { return chartTreemapOptions(context); }
|
|
96
|
+
render_sunburst(context) { return chartSunburstOptions(context); }
|
|
79
97
|
svg() { return this.#chart.renderToSVGString(); }
|
|
80
98
|
resize() { this.#chart.resize(); }
|
|
81
99
|
dispose() { this.#chart.dispose();if(this.#mapData)echarts.registerMap(this.#mapName,{type:'FeatureCollection',features:[]}); }
|
|
@@ -2,6 +2,7 @@ import {Bag} from '@gramlot/gramlot';
|
|
|
2
2
|
import {defineComponent} from '@gramlot/gramlot/components';
|
|
3
3
|
import {randomId} from '../random-id.js';
|
|
4
4
|
import {Container} from './container.js';
|
|
5
|
+
import {chartTypes,chartFixedMeasures} from './chart-types/index.js';
|
|
5
6
|
|
|
6
7
|
const chartLogic = new WeakMap();
|
|
7
8
|
function measureAction(binding) {
|
|
@@ -34,7 +35,7 @@ export function chartFields(store) {
|
|
|
34
35
|
|
|
35
36
|
export const ChartFields = defineComponent({
|
|
36
37
|
name:'chartFields',tag:'gramlot-chart-fields',base:Container,sourceContext:true,bagStore:true,
|
|
37
|
-
parameters:{timeFieldId:{dtype:'T'},storepath:{dtype:'T'},rowMode:{dtype:'T'},configpath:{dtype:'T'},categoryId:{dtype:'T'},mapMeasureId:{dtype:'T'},mapLabelId:{dtype:'T'},secondCategoryId:{dtype:'T'},geometryId:{dtype:'T'},measureMenuId:{dtype:'T'}},
|
|
38
|
+
parameters:{timeFieldId:{dtype:'T'},storepath:{dtype:'T'},rowMode:{dtype:'T'},configpath:{dtype:'T'},categoryId:{dtype:'T'},mapMeasureId:{dtype:'T'},mapLabelId:{dtype:'T'},secondCategoryId:{dtype:'T'},geometryId:{dtype:'T'},measureMenuId:{dtype:'T'},measureRoleIds:{dtype:'T'}},
|
|
38
39
|
implementation:Base => class extends Base {
|
|
39
40
|
#context; #bag; #store; #release; #signature; #active=false;
|
|
40
41
|
constructor() { super(); const style=this.ownerDocument.createElement('style');style.textContent=':host{display:none}';this.shadowRoot.append(style); }
|
|
@@ -92,6 +93,15 @@ export const ChartFields = defineComponent({
|
|
|
92
93
|
if(!measures.includes(config.getItem('mapValueField')))config.setItem('mapValueField',measures.find(field=>options.getItem(field).getItem('selected')) ?? measures[0] ?? '');
|
|
93
94
|
if(!fields.includes(config.getItem('mapLabelField')))config.setItem('mapLabelField',fields.includes(config.getItem('captionField'))?config.getItem('captionField'):fields[0] ?? '');
|
|
94
95
|
reconcile(binding.nodeIds.get(this.parameters.geometryId),fields);
|
|
96
|
+
// Fixed measure roles: each select offers the numeric columns; an empty or vanished role takes the
|
|
97
|
+
// measure at its position in the column order, so a type change shows a complete assignment.
|
|
98
|
+
for(const id of this.parameters.measureRoleIds.split(','))
|
|
99
|
+
reconcile(binding.nodeIds.get(id),['',...measures],field=>field?options.getItem(field).getItem('caption'):'Choose a column');
|
|
100
|
+
if(!(config.getItem('measureRoles') instanceof Bag))config.setItem('measureRoles',new Bag());
|
|
101
|
+
const roles=config.getItem('measureRoles');
|
|
102
|
+
for(const type of chartTypes)chartFixedMeasures(type).forEach((name,index)=>{
|
|
103
|
+
if(!measures.includes(roles.getItem(name)))roles.setItem(name,measures[index] ?? '');
|
|
104
|
+
});
|
|
95
105
|
reconcile(binding.nodeIds.get(this.parameters.secondCategoryId),fields);
|
|
96
106
|
for(const child of [...menu.value.getNodes()])menu.value.popNode(child.label);
|
|
97
107
|
measures.forEach((field,index)=>{
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {chartPalette} from './chart-domains.js';
|
|
2
|
+
import {chartCell,chartName,chartCaption} from './chart-type-data.js';
|
|
3
|
+
|
|
4
|
+
/** Funnel stages in store order. Empty measures are skipped, never drawn as zero. */
|
|
5
|
+
export function chartFunnelOptions({view,category,fields,seriesOptions}) {
|
|
6
|
+
const [field]=fields;
|
|
7
|
+
const data=[];
|
|
8
|
+
for(const row of view.getRows()) {
|
|
9
|
+
const value=chartCell(view,row,field);
|
|
10
|
+
if(value===null)continue;
|
|
11
|
+
if(value<0)throw new TypeError('Funnel requires nonnegative values.');
|
|
12
|
+
const name=chartName(view.value(row,category),category);
|
|
13
|
+
data.push({name,value,itemStyle:{color:chartPalette[data.length%chartPalette.length]}});
|
|
14
|
+
}
|
|
15
|
+
return {backgroundColor:'#ffffff',tooltip:{trigger:'item',formatter:'{b}: {c}'},
|
|
16
|
+
legend:{show:true,type:'scroll',orient:'horizontal',left:12,right:12,bottom:10,height:24,data:data.map(item=>item.name)},
|
|
17
|
+
series:[{id:field,name:chartCaption(seriesOptions,field),type:'funnel',top:20,bottom:64,left:'10%',width:'80%',
|
|
18
|
+
sort:'none',gap:2,label:{show:true,position:'inside'},data}]};
|
|
19
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** Engine-side options of the `gauge` element: one value on a dial, a ring or an arc. */
|
|
2
|
+
|
|
3
|
+
export const GAUGE_PRESENTATIONS = ['needle', 'ring', 'arc'];
|
|
4
|
+
|
|
5
|
+
/** The node text of a gauge as a number; empty text is no value, never zero. */
|
|
6
|
+
export function gaugeValue(text) {
|
|
7
|
+
if (text == null || text === '') return null;
|
|
8
|
+
const value = Number(text);
|
|
9
|
+
if (!Number.isFinite(value)) throw new TypeError(`gauge requires a number, received '${text}'`);
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* `'65:#e6a23c,85:#c23531'` as `[{value:65,color:'#e6a23c'},{value:85,color:'#c23531'}]`, ascending.
|
|
15
|
+
* A color is a name or a hex code: it cannot contain a comma.
|
|
16
|
+
*/
|
|
17
|
+
export function parseThresholds(text) {
|
|
18
|
+
if (text == null || text === '') return [];
|
|
19
|
+
if (typeof text !== 'string') throw new TypeError('gauge thresholds requires a string of value:color pairs');
|
|
20
|
+
const items = text.split(',').map(part => {
|
|
21
|
+
const match = /^\s*(-?\d+(?:\.\d+)?)\s*:\s*(\S+)\s*$/.exec(part);
|
|
22
|
+
if (!match) throw new TypeError(`Invalid gauge threshold '${part.trim()}': use value:color`);
|
|
23
|
+
return {value: Number(match[1]), color: match[2]};
|
|
24
|
+
}).sort((a, b) => a.value - b.value);
|
|
25
|
+
for (let i = 1; i < items.length; i++) {
|
|
26
|
+
if (items[i].value === items[i - 1].value) throw new TypeError(`Duplicate gauge threshold ${items[i].value}`);
|
|
27
|
+
}
|
|
28
|
+
return items;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The color of the band that holds `value`: the last threshold reached, else the accent. */
|
|
32
|
+
export function gaugeBandColor(thresholds, value, accent) {
|
|
33
|
+
let color = accent;
|
|
34
|
+
for (const threshold of thresholds) if (value >= threshold.value) color = threshold.color;
|
|
35
|
+
return color;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Color stops of the dial: each band ends where the next threshold starts. */
|
|
39
|
+
export function gaugeBands(thresholds, min, max, accent) {
|
|
40
|
+
const colors = [accent, ...thresholds.map(item => item.color)];
|
|
41
|
+
const ends = [...thresholds.map(item => Math.min(1, Math.max(0, (item.value - min) / (max - min)))), 1];
|
|
42
|
+
const stops = [];
|
|
43
|
+
colors.forEach((color, index) => {
|
|
44
|
+
if (ends[index] > (stops.at(-1)?.[0] ?? 0)) stops.push([ends[index], color]);
|
|
45
|
+
});
|
|
46
|
+
return stops;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The text under the dial: the real value, rounded to two decimals, inside the mask. */
|
|
50
|
+
export function gaugeText(value, mask) {
|
|
51
|
+
const text = String(Math.round(value * 100) / 100);
|
|
52
|
+
return (mask ?? '{}').replaceAll('{}', () => text);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const LAYOUT = {
|
|
56
|
+
needle: {startAngle: 225, endAngle: -45, center: ['50%', '52%'], radius: '78%', width: 14,
|
|
57
|
+
detail: [0, '58%'], title: [0, '82%']},
|
|
58
|
+
ring: {startAngle: 90, endAngle: -270, center: ['50%', '50%'], radius: '88%', width: 16,
|
|
59
|
+
detail: [0, '-6%'], title: [0, '28%']},
|
|
60
|
+
arc: {startAngle: 180, endAngle: 0, center: ['50%', '72%'], radius: '112%', width: 16,
|
|
61
|
+
detail: [0, '-22%'], title: [0, '14%']},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* ECharts option for one gauge. `palette` carries the theme colors: accent, ink, muted, track.
|
|
66
|
+
* Every presentation sets the same keys, so a merge into the previous option leaves nothing behind.
|
|
67
|
+
*/
|
|
68
|
+
export function gaugeOption({value, min, max, mask, thresholds, presentation, caption, palette}) {
|
|
69
|
+
if (!GAUGE_PRESENTATIONS.includes(presentation)) {
|
|
70
|
+
throw new TypeError(`gauge presentation must be one of ${GAUGE_PRESENTATIONS.join(', ')}`);
|
|
71
|
+
}
|
|
72
|
+
if (!(Number.isFinite(min) && Number.isFinite(max) && min < max)) throw new TypeError('gauge requires min lower than max');
|
|
73
|
+
if (value != null && !Number.isFinite(value)) throw new TypeError('gauge requires a finite number');
|
|
74
|
+
const layout = LAYOUT[presentation], needle = presentation === 'needle';
|
|
75
|
+
const shown = value == null ? null : Math.min(max, Math.max(min, value));
|
|
76
|
+
const text = value == null ? '' : gaugeText(value, mask);
|
|
77
|
+
return {
|
|
78
|
+
animationDuration: 300,
|
|
79
|
+
series: [{
|
|
80
|
+
id: 'gauge', type: 'gauge', min, max,
|
|
81
|
+
startAngle: layout.startAngle, endAngle: layout.endAngle, center: layout.center, radius: layout.radius,
|
|
82
|
+
splitNumber: 5,
|
|
83
|
+
pointer: {show: needle, length: '62%', width: 5, itemStyle: {color: palette.ink}},
|
|
84
|
+
anchor: {show: needle, size: 10, showAbove: true, itemStyle: {color: palette.ink}},
|
|
85
|
+
progress: {show: !needle, width: layout.width, roundCap: true,
|
|
86
|
+
itemStyle: {color: value == null ? palette.accent : gaugeBandColor(thresholds, value, palette.accent)}},
|
|
87
|
+
axisLine: {roundCap: !needle, lineStyle: {width: layout.width,
|
|
88
|
+
color: needle ? gaugeBands(thresholds, min, max, palette.accent) : [[1, palette.track]]}},
|
|
89
|
+
axisTick: {show: needle, distance: -layout.width - 4, length: 4, lineStyle: {color: palette.muted, width: 1}},
|
|
90
|
+
splitLine: {show: needle, distance: -layout.width - 6, length: 8, lineStyle: {color: palette.muted, width: 2}},
|
|
91
|
+
axisLabel: {show: needle, distance: layout.width + 6, color: palette.muted, fontSize: 11},
|
|
92
|
+
title: {show: true, offsetCenter: layout.title, color: palette.muted, fontSize: 13},
|
|
93
|
+
detail: {show: true, offsetCenter: layout.detail, color: palette.ink, fontSize: 22, fontWeight: 'bold',
|
|
94
|
+
valueAnimation: false, formatter: () => text},
|
|
95
|
+
data: shown === null ? [] : [{value: shown, name: caption ?? ''}],
|
|
96
|
+
}],
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as echarts from 'echarts/dist/echarts.js';
|
|
2
|
+
import {defineComponent} from './registry.js';
|
|
3
|
+
import {Container} from './container.js';
|
|
4
|
+
import {gaugeOption, gaugeValue, parseThresholds} from './chart-gauge-options.js';
|
|
5
|
+
import {ChartNotice, CHART_NOTICE_STYLE} from './chart-notice.js';
|
|
6
|
+
|
|
7
|
+
const GAUGE_SECTIONS = [
|
|
8
|
+
{title:'What a gauge shows', paragraphs:['One number on a dial, a ring or an arc, between min and max. The number is the value of the gauge node.']},
|
|
9
|
+
{title:'Parameters', table:[['Parameter','Description'],
|
|
10
|
+
['value','The node value: a finite number. Empty is no value, never zero.'],
|
|
11
|
+
['min, max','The range of the scale; defaults 0 and 100.'],
|
|
12
|
+
['mask','The text of the value, with {} for the number rounded to two decimals; default {}.'],
|
|
13
|
+
['thresholds','Ascending bands as value:color pairs, for example 65:#e6a23c,85:#c23531; a color is a name or a hex code.'],
|
|
14
|
+
['presentation','needle, ring or arc.'],
|
|
15
|
+
['caption','A label under the value.']]}
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const LIGHT = {accent: '#235db2', ink: '#202936', muted: '#526174', track: '#e9edf2'};
|
|
19
|
+
const DARK = {accent: '#6ea8fe', ink: '#e8edf3', muted: '#a3b0c0', track: '#3a4554'};
|
|
20
|
+
|
|
21
|
+
/** One value on a dial, a ring or an arc. The node value is the value; it never writes Data. */
|
|
22
|
+
export const Gauge = defineComponent({
|
|
23
|
+
name: 'gauge', tag: 'gramlot-gauge', base: Container,
|
|
24
|
+
parameters: {
|
|
25
|
+
min: {dtype: 'R', default: 0, binding: 'read'}, max: {dtype: 'R', default: 100, binding: 'read'},
|
|
26
|
+
mask: {dtype: 'T', default: '{}', binding: 'read'}, thresholds: {dtype: 'T', default: '', nullable: true, binding: 'read'},
|
|
27
|
+
presentation: {dtype: 'T', default: 'needle', binding: 'read'}, caption: {dtype: 'T', default: '', nullable: true, binding: 'read'}
|
|
28
|
+
},
|
|
29
|
+
implementation: Base => class extends Base {
|
|
30
|
+
#chart; #surface; #notice; #resize; #text; #theme; #dark; #active = false;
|
|
31
|
+
constructor() {
|
|
32
|
+
super();
|
|
33
|
+
const doc = this.ownerDocument;
|
|
34
|
+
this.control.replaceChildren();
|
|
35
|
+
const style = doc.createElement('style');
|
|
36
|
+
style.textContent = ':host{height:100%;min-height:160px}.control-box{height:100%;min-height:160px;overflow:hidden}' + CHART_NOTICE_STYLE;
|
|
37
|
+
this.shadowRoot.append(style);
|
|
38
|
+
this.#notice = new ChartNotice(doc);
|
|
39
|
+
this.#surface = doc.createElement('div');
|
|
40
|
+
this.#surface.style.cssText = 'width:100%;height:100%;min-height:160px';
|
|
41
|
+
this.control.append(this.#notice.element, this.#surface);
|
|
42
|
+
const view = doc.defaultView;
|
|
43
|
+
this.#resize = new view.ResizeObserver(() => this.#chart?.resize());
|
|
44
|
+
this.#text = new view.MutationObserver(() => this.#render());
|
|
45
|
+
this.#theme = new view.MutationObserver(() => this.#render());
|
|
46
|
+
this.#dark = view.matchMedia('(prefers-color-scheme: dark)');
|
|
47
|
+
}
|
|
48
|
+
projectAttributes(attrs, adapt) {
|
|
49
|
+
const rest = super.projectAttributes(attrs, adapt);
|
|
50
|
+
if (this.#active) this.#render();
|
|
51
|
+
return rest;
|
|
52
|
+
}
|
|
53
|
+
connectedCallback() {
|
|
54
|
+
this.#active = true;
|
|
55
|
+
this.#chart = echarts.init(this.#surface, null, {renderer: 'svg'});
|
|
56
|
+
// The node text is where the renderer writes the resolved node value.
|
|
57
|
+
this.#text.observe(this, {childList: true, subtree: true, characterData: true});
|
|
58
|
+
this.#theme.observe(this.ownerDocument.documentElement, {attributes: true, attributeFilter: ['data-theme', 'class']});
|
|
59
|
+
this.#dark.addEventListener('change', this.#onTheme);
|
|
60
|
+
this.#resize.observe(this.#surface);
|
|
61
|
+
this.#render();
|
|
62
|
+
}
|
|
63
|
+
#onTheme = () => this.#render();
|
|
64
|
+
#palette() {
|
|
65
|
+
const dark = this.#isDark();
|
|
66
|
+
const base = dark ? DARK : LIGHT;
|
|
67
|
+
const style = this.ownerDocument.defaultView.getComputedStyle(this);
|
|
68
|
+
const read = (name, fallback) => style.getPropertyValue(name).trim() || fallback;
|
|
69
|
+
return {accent: read('--gramlot-brand-blue', base.accent), ink: read('--gramlot-ink', base.ink),
|
|
70
|
+
muted: read('--gramlot-text-secondary', base.muted), track: read('--gramlot-surface-subtle', base.track)};
|
|
71
|
+
}
|
|
72
|
+
#isDark() {
|
|
73
|
+
const theme = this.ownerDocument.documentElement.getAttribute('data-theme');
|
|
74
|
+
return theme ? theme === 'dark' : this.#dark.matches;
|
|
75
|
+
}
|
|
76
|
+
#render() {
|
|
77
|
+
if (!this.#chart) return;
|
|
78
|
+
try {
|
|
79
|
+
const {min, max, mask, thresholds, presentation, caption} = this.parameters;
|
|
80
|
+
const value = gaugeValue(this.textContent);
|
|
81
|
+
const option = gaugeOption({value, min, max, mask,
|
|
82
|
+
thresholds: parseThresholds(thresholds), presentation, caption, palette: this.#palette()});
|
|
83
|
+
if (value === null) {
|
|
84
|
+
this.#surface.hidden = true;
|
|
85
|
+
this.#notice.info('No value', 'Gauge: no value', [{title:'Why there is no value',
|
|
86
|
+
paragraphs:['The gauge node is empty. A missing value is shown as no value, never as zero.',
|
|
87
|
+
'Bind the node to a number, for example gauge("^.cpu").']}, ...GAUGE_SECTIONS]);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
this.#notice.hide(); this.#surface.hidden = false;
|
|
91
|
+
this.#chart.setOption(option, {replaceMerge: ['series']});
|
|
92
|
+
} catch (error) {
|
|
93
|
+
this.#surface.hidden = true;
|
|
94
|
+
this.#notice.error(error.message, 'Gauge: the value cannot be shown',
|
|
95
|
+
[{title:'What is wrong', paragraphs:[error.message]}, ...GAUGE_SECTIONS]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
disconnectedCallback() {
|
|
99
|
+
this.#active = false;
|
|
100
|
+
this.#text.disconnect(); this.#theme.disconnect(); this.#resize.disconnect();
|
|
101
|
+
this.#dark.removeEventListener('change', this.#onTheme);
|
|
102
|
+
this.#chart?.dispose(); this.#chart = null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {chartCell,chartName,chartCaption} from './chart-type-data.js';
|
|
2
|
+
|
|
3
|
+
/** X categories from `captionField`, Y categories from `secondCaptionField`, one measure as cell color. */
|
|
4
|
+
export function chartHeatmapOptions({view,category,structure,fields,settings,seriesOptions}) {
|
|
5
|
+
const second=structure.getItem('secondCaptionField');
|
|
6
|
+
const [field]=fields;
|
|
7
|
+
const xs=[],ys=[],xIndex=new Map(),yIndex=new Map(),seen=new Set(),data=[];
|
|
8
|
+
const index=(list,map,name)=>{if(!map.has(name)){map.set(name,list.length);list.push(name);}return map.get(name);};
|
|
9
|
+
for(const row of view.getRows()) {
|
|
10
|
+
const x=index(xs,xIndex,chartName(view.value(row,category),category));
|
|
11
|
+
const y=index(ys,yIndex,chartName(view.value(row,second),second));
|
|
12
|
+
const value=chartCell(view,row,field);
|
|
13
|
+
if(value===null)continue;
|
|
14
|
+
const key=`${x}:${y}`;
|
|
15
|
+
if(seen.has(key))throw new TypeError(`Heatmap has two cells for ${xs[x]} / ${ys[y]}. Prepare one row per pair upstream.`);
|
|
16
|
+
seen.add(key);
|
|
17
|
+
data.push([x,y,value]);
|
|
18
|
+
}
|
|
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
|
+
if(min===max){min-=1;max+=1;}
|
|
21
|
+
const name=chartCaption(seriesOptions,field);
|
|
22
|
+
return {backgroundColor:'#ffffff',tooltip:{trigger:'item',position:'top'},
|
|
23
|
+
grid:{left:80,right:40,top:36,bottom:110},
|
|
24
|
+
xAxis:{type:'category',data:xs,name:category,splitArea:{show:true}},
|
|
25
|
+
yAxis:{type:'category',data:ys,name:second,splitArea:{show:true}},
|
|
26
|
+
visualMap:{type:'continuous',min,max,calculable:true,orient:'horizontal',left:'center',bottom:10,
|
|
27
|
+
inRange:{color:['#f3f6fb',settings[0].color]}},
|
|
28
|
+
series:[{id:field,name,type:'heatmap',data,emphasis:{itemStyle:{borderColor:'#333',borderWidth:1}}}]};
|
|
29
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import {ChartSyntaxError} from './chart-syntax.js';
|
|
2
|
+
import {chartTypes} from './chart-types/index.js';
|
|
3
|
+
|
|
4
|
+
// The icon is a styled glyph, not an svg: the svg inside a chart view is always the chart.
|
|
5
|
+
const ICONS = {error:'!', info:'i'};
|
|
6
|
+
|
|
7
|
+
/** Shadow-root styles of the notice; colours follow the `--gramlot-*` theme variables. */
|
|
8
|
+
export const CHART_NOTICE_STYLE = `
|
|
9
|
+
.chart-notice{display:flex;align-items:flex-start;gap:10px;padding:16px 20px;font:13px/1.45 var(--gramlot-font-ui,system-ui,sans-serif);color:var(--gramlot-ink,#243449)}
|
|
10
|
+
.chart-notice[hidden]{display:none}
|
|
11
|
+
.chart-notice-icon{flex:none;display:grid;place-items:center;inline-size:20px;block-size:20px;border-radius:50%;font:700 13px/1 var(--gramlot-font-ui,system-ui,sans-serif);color:var(--gramlot-surface,#fff)}
|
|
12
|
+
.chart-notice[data-kind=error] .chart-notice-icon{background:var(--gramlot-error,#b13d48)}
|
|
13
|
+
.chart-notice[data-kind=info] .chart-notice-icon{background:var(--gramlot-text-secondary,#566579)}
|
|
14
|
+
.chart-notice-text{flex:1;min-inline-size:0;white-space:normal;overflow-wrap:anywhere}
|
|
15
|
+
.chart-notice button{flex:none;font:inherit;padding:2px 10px;border:1px solid var(--gramlot-border-control,#a9b4c2);border-radius:var(--gramlot-radius-sm,4px);background:var(--gramlot-surface,#fff);color:inherit;cursor:pointer}
|
|
16
|
+
.chart-notice-dialog{max-inline-size:min(640px,calc(100vw - 32px));border:1px solid var(--gramlot-border,#d5dce5);border-radius:var(--gramlot-radius,6px);padding:20px 24px;background:var(--gramlot-surface,#fff);color:var(--gramlot-ink,#243449);font:13px/1.5 var(--gramlot-font-ui,system-ui,sans-serif)}
|
|
17
|
+
.chart-notice-dialog h2{margin:0 0 12px;font-size:16px}
|
|
18
|
+
.chart-notice-dialog h3{margin:14px 0 4px;font-size:13px}
|
|
19
|
+
.chart-notice-dialog p{margin:0 0 6px}
|
|
20
|
+
.chart-notice-dialog table{border-collapse:collapse;inline-size:100%}
|
|
21
|
+
.chart-notice-dialog th,.chart-notice-dialog td{border-block-end:1px solid var(--gramlot-border,#d5dce5);padding:4px 6px;text-align:start;vertical-align:top}
|
|
22
|
+
.chart-notice-dialog code{font-family:var(--gramlot-font-code,ui-monospace,monospace)}
|
|
23
|
+
.chart-notice-dialog form{margin-block-start:16px;text-align:end}`;
|
|
24
|
+
|
|
25
|
+
function roleParameter(role, roles) {
|
|
26
|
+
if (role.parameter !== 'valueFields' || role.count === 'many') return role.parameter;
|
|
27
|
+
const fixed = roles.filter(item => item.parameter === 'valueFields');
|
|
28
|
+
return fixed.length === 1 ? 'valueFields' : `valueFields, position ${fixed.indexOf(role) + 1}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The sections that explain a chart type: what it shows and the columns it reads. */
|
|
32
|
+
export function chartTypeSections(type) {
|
|
33
|
+
return [
|
|
34
|
+
{title:`What ${type.label.toLowerCase()} shows`, paragraphs:[type.doc]},
|
|
35
|
+
{title:'Columns it reads', table:[['Column','Parameter','Required','Description'],
|
|
36
|
+
...type.syntax.map(role => [role.caption, roleParameter(role, type.syntax), role.required ? 'yes' : 'no',
|
|
37
|
+
role.count === 'many' ? `One or more. ${role.doc}` : role.doc])]}
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The sections that explain a chart error; `type` is null when the chart type itself is unknown. */
|
|
42
|
+
export function chartErrorSections(error, type) {
|
|
43
|
+
if (error instanceof ChartSyntaxError) {
|
|
44
|
+
const {expected, received, fix} = error.diagnosis;
|
|
45
|
+
return [
|
|
46
|
+
{title:'What is wrong', paragraphs:[error.message]},
|
|
47
|
+
{title:'Expected', paragraphs:[expected]},
|
|
48
|
+
{title:'Received', paragraphs:[received]},
|
|
49
|
+
{title:'How to fix it', paragraphs:[fix]},
|
|
50
|
+
...chartTypeSections(type)
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
if (!type) return [
|
|
54
|
+
{title:'What is wrong', paragraphs:[error.message]},
|
|
55
|
+
{title:'Supported chart types', paragraphs:[chartTypes.map(item => `${item.id} (${item.label})`).join(', ')]}
|
|
56
|
+
];
|
|
57
|
+
return [{title:'What is wrong', paragraphs:[error.message]}, ...chartTypeSections(type)];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The notice shown in place of a chart that is not drawn: an icon, one line and "More info",
|
|
62
|
+
* which opens a dialog with the explanation. `error` uses role alert, `info` role status.
|
|
63
|
+
*/
|
|
64
|
+
export class ChartNotice {
|
|
65
|
+
#box; #icon; #text; #dialog; #sections = [];
|
|
66
|
+
constructor(doc) {
|
|
67
|
+
this.#box = doc.createElement('div');
|
|
68
|
+
this.#box.className = 'chart-notice'; this.#box.hidden = true;
|
|
69
|
+
this.#icon = doc.createElement('span');
|
|
70
|
+
this.#icon.className = 'chart-notice-icon'; this.#icon.setAttribute('aria-hidden', 'true');
|
|
71
|
+
this.#text = doc.createElement('div'); this.#text.className = 'chart-notice-text'; this.#text.hidden = true;
|
|
72
|
+
this.#text.setAttribute('role', 'alert');
|
|
73
|
+
const more = doc.createElement('button');
|
|
74
|
+
more.type = 'button'; more.textContent = 'More info';
|
|
75
|
+
more.addEventListener('click', () => this.open());
|
|
76
|
+
this.#dialog = doc.createElement('dialog');
|
|
77
|
+
this.#dialog.className = 'chart-notice-dialog';
|
|
78
|
+
this.#box.append(this.#icon, this.#text, more, this.#dialog);
|
|
79
|
+
}
|
|
80
|
+
get element() { return this.#box; }
|
|
81
|
+
get hidden() { return this.#box.hidden; }
|
|
82
|
+
get dialog() { return this.#dialog; }
|
|
83
|
+
get text() { return this.#text; }
|
|
84
|
+
|
|
85
|
+
error(message, title, sections) { this.#show('error', 'alert', message, title, sections); }
|
|
86
|
+
info(message, title, sections) { this.#show('info', 'status', message, title, sections); }
|
|
87
|
+
hide() {
|
|
88
|
+
this.#box.hidden = this.#text.hidden = true; this.#text.textContent = '';
|
|
89
|
+
if (this.#dialog.open) this.#dialog.close();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Fill and open the dialog with the explanation of the current notice. */
|
|
93
|
+
open() {
|
|
94
|
+
const doc = this.#dialog.ownerDocument;
|
|
95
|
+
const heading = doc.createElement('h2'); heading.textContent = this.#sections.title;
|
|
96
|
+
const parts = [heading];
|
|
97
|
+
for (const section of this.#sections.items) {
|
|
98
|
+
const title = doc.createElement('h3'); title.textContent = section.title; parts.push(title);
|
|
99
|
+
for (const text of section.paragraphs ?? []) { const p = doc.createElement('p'); p.textContent = text; parts.push(p); }
|
|
100
|
+
if (section.table) {
|
|
101
|
+
const table = doc.createElement('table');
|
|
102
|
+
section.table.forEach((cells, index) => {
|
|
103
|
+
const row = table.insertRow();
|
|
104
|
+
for (const value of cells) {
|
|
105
|
+
const cell = doc.createElement(index ? 'td' : 'th'); cell.textContent = value; row.append(cell);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
parts.push(table);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const form = doc.createElement('form'); form.method = 'dialog';
|
|
112
|
+
const close = doc.createElement('button'); close.textContent = 'Close'; form.append(close);
|
|
113
|
+
parts.push(form);
|
|
114
|
+
this.#dialog.replaceChildren(...parts);
|
|
115
|
+
this.#dialog.showModal();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
#show(kind, role, message, title, sections) {
|
|
119
|
+
this.#box.dataset.kind = kind;
|
|
120
|
+
this.#text.setAttribute('role', role);
|
|
121
|
+
this.#icon.textContent = ICONS[kind];
|
|
122
|
+
this.#text.textContent = message;
|
|
123
|
+
this.#sections = {title, items:sections};
|
|
124
|
+
this.#box.hidden = this.#text.hidden = false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -4,6 +4,7 @@ import {Container} from './container.js';
|
|
|
4
4
|
import {randomId} from '../random-id.js';
|
|
5
5
|
import {chartTimeLogic} from './chart-timeline.js';
|
|
6
6
|
import {chartControls} from './chart-controls.js';
|
|
7
|
+
import {chartTypes,chartFixedMeasures} from './chart-types/index.js';
|
|
7
8
|
|
|
8
9
|
/** One shared Source composition for Python and JavaScript callers. */
|
|
9
10
|
export const ChartPane = defineComponent({
|
|
@@ -39,10 +40,15 @@ export const ChartPane = defineComponent({
|
|
|
39
40
|
const defaults={mapLabelMode:'value',mapBarScale:'zero',selectedTerritory:'',timeField:'',timeEmpty:'previous',timeSnapshotLabel:'',timeStep:'auto',timeUnit:'month',timeHasClock:false,timeIndex:0,timeMax:0,timeAtEnd:true,timeValue:null,timeLabel:'',timePlaying:false,timeSpeed:0.8,engine:'echarts',chartType:'bar',captionField:'',secondCaptionField:'',geometryField:'',mapValueField:'',mapLabelField:'',geoJSON:null,drawer:'close'};
|
|
40
41
|
for(const [key,value] of Object.entries(defaults))if(!configuration.getNode(key))configuration.setItem(key,value);
|
|
41
42
|
if(!configuration.getNode('seriesOptions'))configuration.setItem('seriesOptions',new Bag());
|
|
43
|
+
if(!configuration.getNode('measureRoles'))configuration.setItem('measureRoles',new Bag());
|
|
42
44
|
if(!(configuration.getItem('seriesOptions') instanceof Bag))throw new TypeError('seriesOptions must be a Bag');
|
|
43
45
|
const fragment=new node.builder.source.constructor(null,node.builder);
|
|
44
46
|
const frame=node.builder.wrapSource(fragment).framePane({node_label:'frame',height:'100%'});
|
|
45
|
-
|
|
47
|
+
// A type with fixed measures reads them from its roles, in reading order; the others from the selected measures.
|
|
48
|
+
const fixed=JSON.stringify(Object.fromEntries(chartTypes.map(type=>[type.id,chartFixedMeasures(type)]).filter(([,names])=>names.length)));
|
|
49
|
+
frame.dataFormula({result_path:`${configpath}.valueFields`,
|
|
50
|
+
formula:`(${fixed}[type] ?? null) ? ${fixed}[type].map(name => roles.getItem(name) || '').filter(Boolean).join(',') : options.getNodes().filter(n => n.getValue().getItem('selected')).map(n => n.label).join(',')`,
|
|
51
|
+
options:`^${configpath}.seriesOptions`,roles:`^${configpath}.measureRoles`,type:`^${configpath}.chartType`,_onBuilt:true});
|
|
46
52
|
const toolbar=frame.top.contentPane({display:'flex',justify_content:'flex-end',align_items:'center',padding:'2px 6px'});
|
|
47
53
|
const path=JSON.stringify(`${configpath}.drawer`);
|
|
48
54
|
toolbar.button({icon:'⚙',aria_label:'Chart settings',title:'Chart settings',action:`this.SET(${path},this.GET(${path}) === 'close' ? true : 'close');`});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {chartPalette} from './chart-domains.js';
|
|
2
|
+
import {chartCell,chartName,chartCaption,chartSeriesNumber} from './chart-type-data.js';
|
|
3
|
+
|
|
4
|
+
/** One vertical axis per measure and one polyline per row; `captionField` names the row. */
|
|
5
|
+
export function chartParallelOptions({view,category,fields,seriesOptions}) {
|
|
6
|
+
const rows=[];
|
|
7
|
+
for(const row of view.getRows()) {
|
|
8
|
+
const values=fields.map(field=>chartCell(view,row,field));
|
|
9
|
+
if(values.every(value=>value===null))continue;
|
|
10
|
+
rows.push({name:chartName(view.value(row,category),category),values});
|
|
11
|
+
}
|
|
12
|
+
const parallelAxis=fields.map((field,dim)=>{
|
|
13
|
+
const axis={dim,name:chartCaption(seriesOptions,field)};
|
|
14
|
+
const min=chartSeriesNumber(seriesOptions,field,'min'),max=chartSeriesNumber(seriesOptions,field,'max');
|
|
15
|
+
if(min!==null)axis.min=min;
|
|
16
|
+
if(max!==null)axis.max=max;
|
|
17
|
+
return axis;
|
|
18
|
+
});
|
|
19
|
+
return {backgroundColor:'#ffffff',tooltip:{trigger:'item'},
|
|
20
|
+
parallel:{left:60,right:60,top:60,bottom:40,parallelAxisDefault:{type:'value',nameLocation:'start',nameGap:20}},
|
|
21
|
+
parallelAxis,
|
|
22
|
+
series:[{type:'parallel',lineStyle:{width:2,opacity:0.7},emphasis:{lineStyle:{width:4,opacity:1}},
|
|
23
|
+
data:rows.map((row,index)=>({name:row.name,value:row.values,lineStyle:{color:chartPalette[index%chartPalette.length]}}))}]};
|
|
24
|
+
}
|