farseer-cli 1.25.0 → 1.26.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 (69) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/dashboards.js +2 -0
  3. package/dist/commands/dashboards.js.map +1 -1
  4. package/dist/commands/login.js +18 -7
  5. package/dist/commands/login.js.map +1 -1
  6. package/dist/commands/logout.js +28 -12
  7. package/dist/commands/logout.js.map +1 -1
  8. package/dist/commands/run.js +2 -3
  9. package/dist/commands/run.js.map +1 -1
  10. package/dist/commands/whoami.js +12 -5
  11. package/dist/commands/whoami.js.map +1 -1
  12. package/dist/mcp/tools/authTools.js +2 -1
  13. package/dist/mcp/tools/authTools.js.map +1 -1
  14. package/dist/mcp/tools/dashboardTools.js +3 -1
  15. package/dist/mcp/tools/dashboardTools.js.map +1 -1
  16. package/dist/mcp/tools/runTools.js +2 -3
  17. package/dist/mcp/tools/runTools.js.map +1 -1
  18. package/dist/mcp/utils/helpers.js +8 -6
  19. package/dist/mcp/utils/helpers.js.map +2 -2
  20. package/dist/mcp/utils/session.js +6 -2
  21. package/dist/mcp/utils/session.js.map +1 -1
  22. package/dist/operations/dashboards.js +1 -1
  23. package/dist/operations/dashboards.js.map +1 -1
  24. package/dist/pipeline/generated-reference.json +8 -8
  25. package/dist/services/codefirst/layoutReadback.js +95 -0
  26. package/dist/services/codefirst/layoutReadback.js.map +2 -2
  27. package/dist/services/configService.js +33 -18
  28. package/dist/services/configService.js.map +1 -1
  29. package/dist/services/credentials.js +26 -11
  30. package/dist/services/credentials.js.map +1 -1
  31. package/dist/services/farseerService.js +34 -32
  32. package/dist/services/farseerService.js.map +1 -1
  33. package/dist/services/keycloak.js +44 -0
  34. package/dist/services/keycloak.js.map +6 -0
  35. package/dist/services/preflight.js +1 -2
  36. package/dist/services/preflight.js.map +1 -1
  37. package/dist/services/realms.js +67 -15
  38. package/dist/services/realms.js.map +1 -1
  39. package/dist/utils/serverUrl.js +42 -0
  40. package/dist/utils/serverUrl.js.map +6 -0
  41. package/docs/pipeline-reference.md +13 -3
  42. package/package.json +1 -1
  43. package/skills/farseer-code-tiles/SKILL.md +153 -0
  44. package/skills/farseer-code-tiles/anti-patterns.md +183 -0
  45. package/skills/farseer-code-tiles/api.md +237 -0
  46. package/skills/farseer-code-tiles/check-tile.mjs +521 -0
  47. package/skills/farseer-code-tiles/design.md +159 -0
  48. package/skills/farseer-code-tiles/echarts-look.md +110 -0
  49. package/skills/farseer-code-tiles/examples/board-deck.js +695 -0
  50. package/skills/farseer-code-tiles/examples/data-checks.js +475 -0
  51. package/skills/farseer-code-tiles/examples/kpi-cards.js +374 -0
  52. package/skills/farseer-code-tiles/examples/map-countries.js +377 -0
  53. package/skills/farseer-code-tiles/examples/month-plan.js +443 -0
  54. package/skills/farseer-code-tiles/examples/new-location.js +581 -0
  55. package/skills/farseer-code-tiles/examples/open-forecast.js +598 -0
  56. package/skills/farseer-code-tiles/examples/pl-sankey.js +402 -0
  57. package/skills/farseer-code-tiles/examples/ranked-bars.js +337 -0
  58. package/skills/farseer-code-tiles/examples/request-form.js +464 -0
  59. package/skills/farseer-code-tiles/farseer-table.md +98 -0
  60. package/skills/farseer-code-tiles/known-mistakes.md +178 -0
  61. package/skills/farseer-code-tiles/maps/europe.geo.json +1 -0
  62. package/skills/farseer-code-tiles/maps/pick-map.mjs +59 -0
  63. package/skills/farseer-code-tiles/maps/world.geo.json +1 -0
  64. package/skills/farseer-dashboards/SKILL.md +3 -2
  65. package/skills/farseer-dashboards/check.md +3 -2
  66. package/skills/farseer-dashboards/measures.md +3 -1
  67. package/skills/farseer-optimize-model/SKILL.md +9 -1
  68. package/skills/farseer-pnl/SKILL.md +3 -3
  69. package/skills/pipeline-authoring/SKILL.md +2 -2
@@ -0,0 +1,377 @@
1
+ // Net sales by company on a map of the countries the companies sell in. Real outlines from the
2
+ // skill's maps folder (Natural Earth, public domain), zoomed to the countries with data, the values listed in its corner.
3
+ // Tile size: w18 h12; w14 h11 when narrow.
4
+ export default function (ctx) {
5
+ // readTable: a table of numbers from the model, in the shape ctx.charts.farseer draws
6
+ // ({ columns: [{ label, numberFormat }], rows: [{ label, cells: [{ value }] }] }). Call it in the body.
7
+ // rows: { table: 'Entity' } every member of a table, listed live by name
8
+ // rows: { table, includeDashboardFilters: true } the members the filter bar leaves, even when the numbers ignore it
9
+ // rows: { table: 'Months', members: ['M1', …] } the members named here, in this order
10
+ // rows: [{ label, formula, numberFormat }] one line per formula (a P&L)
11
+ // no rows one row, labelled '', for KPIs
12
+ // columns: [{ label, formula, numberFormat }] with member rows, [{ label, filter }] with formula lines
13
+ // Member rows and every number follow the filter bar and timeline, unless the spec turns them off.
14
+ const quote = (name) => `"${String(name).replace(/(["\\])/g, '\\$1')}"`;
15
+ // a table's members from a DTABLE answer, by name, without its NULL member
16
+ const namesOf = (answer) => (answer?.value ?? []).map(String).filter((name) => !name.startsWith('NULL ('));
17
+ function withFilter(formula, filter) {
18
+ let out = '', depth = [], quoted = false;
19
+ for (let i = 0; i < formula.length; i++) {
20
+ const c = formula[i];
21
+ if (c === '"' && formula[i - 1] !== '\\') quoted = !quoted;
22
+ if (!quoted && c === '(') depth.push(/sum\s*$/i.test(formula.slice(0, i)));
23
+ if (!quoted && c === ')' && depth.pop()) out += `, ${filter}`;
24
+ out += c;
25
+ }
26
+ return out;
27
+ }
28
+ function readTable(spec) {
29
+ // includeDashboardFilters: false / includeDashboardTimeline: false in the spec leave one out (say so on the tile)
30
+ const options = { includeDashboardFilters: spec.includeDashboardFilters !== false, includeDashboardTimeline: spec.includeDashboardTimeline !== false };
31
+ const { columns } = spec;
32
+ const rows = spec.rows ?? [{ label: '' }];
33
+ const memberRows = !Array.isArray(rows);
34
+ const listOptions = { ...options, ...(memberRows && rows.includeDashboardFilters !== undefined ? { includeDashboardFilters: rows.includeDashboardFilters } : {}) };
35
+ const list = memberRows && !rows.members ? ctx.query([{ type: 'DTABLE', table: rows.table }], listOptions) : null;
36
+ let names = memberRows ? rows.members ?? null : null;
37
+ let listed = null;
38
+ let values = null;
39
+ const open = () => {
40
+ values?.close();
41
+ const formulas = memberRows
42
+ ? names.flatMap((name) => columns.map((c) => withFilter(c.formula, `${quote(rows.table)}>${quote(name)}`)))
43
+ : rows.flatMap((r) => columns.map((c) => (r.formula ? withFilter(r.formula, c.filter) : c.formula)));
44
+ values = formulas.length ? ctx.query(formulas.map((formula) => ({ type: 'VARIABLE', formula })), options) : null;
45
+ };
46
+ if (!list) open();
47
+ const refresh = () => {
48
+ if (list.loading && !list.current.length) return;
49
+ const now = namesOf(list.current[0]);
50
+ const key = now.join('\u0001');
51
+ if (key !== listed) {
52
+ listed = key;
53
+ names = now;
54
+ open();
55
+ }
56
+ };
57
+ return {
58
+ get loading() {
59
+ if (list) refresh();
60
+ return (list?.loading ?? false) || (values?.loading ?? false);
61
+ },
62
+ get error() {
63
+ return list?.error ?? values?.error ?? null;
64
+ },
65
+ get current() {
66
+ if (list) refresh();
67
+ const cells = values?.current ?? [];
68
+ const labels = memberRows ? names ?? [] : rows.map((r) => r.label);
69
+ return {
70
+ columns: columns.map((c) => ({ label: c.label, numberFormat: c.numberFormat ?? (memberRows ? null : rows[0]?.numberFormat) ?? null })),
71
+ rows: labels.map((label, j) => ({
72
+ label,
73
+ numberFormat: memberRows ? null : rows[j].numberFormat ?? null,
74
+ cells: columns.map((_, i) => ({ value: cells[j * columns.length + i]?.value ?? null })),
75
+ })),
76
+ };
77
+ },
78
+ };
79
+ }
80
+ // picks(['Entity', 'Year to date']): what the filter bar picked on these tables, for a title or a form.
81
+ // current.Entity is { members: ['Acme Croatia'], all: false }; all is true when the bar doesn't narrow that table.
82
+ function picks(tables) {
83
+ const picked = ctx.query(tables.map((table) => ({ type: 'DTABLE', table })));
84
+ const every = ctx.query(tables.map((table) => ({ type: 'DTABLE', table })), { includeDashboardFilters: false, includeDashboardTimeline: false });
85
+ return {
86
+ get loading() {
87
+ return picked.loading || every.loading;
88
+ },
89
+ get error() {
90
+ return picked.error ?? every.error ?? null;
91
+ },
92
+ get current() {
93
+ return Object.fromEntries(tables.map((table, i) => {
94
+ const members = namesOf(picked.current[i]);
95
+ return [table, { members, all: members.length === namesOf(every.current[i]).length }];
96
+ }));
97
+ },
98
+ };
99
+ }
100
+ // what the filter bar picked, for the title
101
+ const bar = picks(['Entity', 'Year to date']);
102
+ const sales = readTable({
103
+ rows: { table: 'Entity' },
104
+ columns: [{ label: 'AC', formula: 'sum("Net sales", "Versions">"Actual", "Reporting period">"Current year")' }],
105
+ });
106
+ // --- The Farseer look (echarts-look.md, design.md): the same block in every tile ---
107
+ // AC: the dashboards' AC colour (SKILL.md section 2, The AC colour): #323232, or the company's
108
+ // darkest brand colour when it is dark enough, never an example's. AC_LIGHT is its PY tint.
109
+ // Everything else below is derived from them, so nothing else needs changing.
110
+ const AC = '#323232';
111
+ const AC_LIGHT = '#A6A6A6';
112
+ // mixes a colour with white: share 1 is the colour itself, 0 is white
113
+ function tint(hex, share) {
114
+ const n = parseInt(hex.slice(1), 16);
115
+ const mix = (c) => Math.round(c * share + 255 * (1 - share)).toString(16).padStart(2, '0');
116
+ return `#${mix(n >> 16)}${mix((n >> 8) & 255)}${mix(n & 255)}`.toUpperCase();
117
+ }
118
+ // a colour with almost no hue (graphite, grey): its ramp would turn a map grey, so magnitude takes Farseer blue
119
+ const isGrey = (hex) => { const n = parseInt(hex.slice(1), 16); const c = [n >> 16, (n >> 8) & 255, n & 255]; return Math.max(...c) - Math.min(...c) < 24; };
120
+ const PALETTE = [AC, '#ED7D16', '#1BB5D7', '#8A2FE5', '#BFA812', '#E52FCD']; // identity: AC first, then distinct hues
121
+ const FILL = [AC_LIGHT, '#F5B87F', '#82D6E9', '#BF8DF1', '#DCCF7D', '#F18DE4']; // the light step, for large areas
122
+ // magnitude (maps, heatmaps), light to dark: steps of AC, or Farseer blue when AC is a grey
123
+ const RAMP = isGrey(AC) ? ['#81A9FF', '#457DFF', '#0D4BC2', '#043288'] : [0.45, 0.65, 0.8, 1].map((s) => tint(AC, s));
124
+ // light tints of AC for large areas that need ink text (treemap groups), clearly apart from each other
125
+ // (from Farseer blue when AC is a grey, as the ramp: grey tints would make a grey block)
126
+ const TINTS = [0.52, 0.37, 0.24, 0.11].map((s) => tint(isGrey(AC) ? '#043288' : AC, s));
127
+ const TRACK = tint(AC, 0.12); // the unfilled part of a gauge
128
+ const PRIMARY = '#1A66FF'; // Farseer's own primary button, not a data colour
129
+ const GOOD = '#0CB955';
130
+ const BAD = '#E21E09';
131
+ const INK = () => ctx.theme.tokens?.text ?? '#020810';
132
+ const MUTED = () => ctx.theme.tokens?.muted ?? '#687C95';
133
+ const LINE = () => ctx.theme.tokens?.border ?? '#E6EBF2';
134
+ const SURFACE = () => ctx.theme.tokens?.background ?? '#FFFFFF';
135
+ const FONT = 'Inter, system-ui, sans-serif';
136
+ let drawnOnce = false;
137
+ // draws one echarts chart in the look; the first chart that draws ends the entrance animation for the rest
138
+ function drawChart(element, option) {
139
+ ctx.charts.echarts(element, option);
140
+ drawnOnce = true;
141
+ }
142
+ // the chart tile's look, measured from it: square bars, 12 px ink labels with a surface-coloured halo, an ink
143
+ // category axis with ticks, no value axis or gridlines, the legend at the bottom, its tooltip and margins
144
+ const LABEL = { show: true, fontFamily: FONT, fontSize: 12, color: INK(), textBorderColor: SURFACE(), textBorderWidth: 4 };
145
+ function look() {
146
+ return {
147
+ animation: !drawnOnce,
148
+ animationDuration: 500,
149
+ textStyle: { fontFamily: FONT, fontSize: 12, color: INK() },
150
+ grid: { left: 10, right: 10, top: 20, bottom: 10, containLabel: true },
151
+ legend: { bottom: 0, textStyle: { fontFamily: FONT, color: INK() } },
152
+ tooltip: {
153
+ trigger: 'item', confine: true, backgroundColor: SURFACE(), borderColor: '#EDF2F7', borderWidth: 1,
154
+ padding: [6, 10], textStyle: { color: INK(), fontSize: 12, fontFamily: FONT },
155
+ extraCssText: 'border-radius:6px;box-shadow:0 4px 16px rgba(107,131,160,0.15)',
156
+ },
157
+ categoryAxis: {
158
+ axisLine: { show: true, lineStyle: { color: INK(), width: 1 } },
159
+ axisTick: { show: false },
160
+ axisLabel: { color: INK(), fontFamily: FONT, fontSize: 12, hideOverlap: true },
161
+ splitLine: { show: false },
162
+ },
163
+ valueAxis: { show: false, splitLine: { show: false } },
164
+ };
165
+ }
166
+ function merge(base, extra) {
167
+ if (Array.isArray(extra) || typeof extra !== 'object' || extra === null) return extra;
168
+ const out = { ...base };
169
+ for (const [key, value] of Object.entries(extra)) {
170
+ out[key] = typeof value === 'object' && value !== null && !Array.isArray(value) && typeof base?.[key] === 'object' ? merge(base[key], value) : value;
171
+ }
172
+ return out;
173
+ }
174
+ // form controls and buttons in Farseer's toolbar look: 28 px high, 12 px text, the focus ring drawn inside the
175
+ // control (so a control at the tile's edge never loses it), button text that never wraps, a long choice ending in …
176
+ // Farseer's own form controls and buttons (the app's input, select and button), the same in every tile
177
+ const CONTROL_CSS = `
178
+ .fs-control { font: 400 12px/20px ${FONT}; height: 32px; padding: 0 8px; border: 1px solid #EDF2F7; border-radius: 8px;
179
+ background-color: #EDF2F7; color: var(--code-tile-text); min-width: 0; max-width: 100%; box-sizing: border-box; outline: none;
180
+ overflow: hidden; white-space: nowrap; text-overflow: ellipsis; transition: border-color 100ms; }
181
+ select.fs-control { appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer;
182
+ background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23020810' fill-rule='evenodd' d='M4.17 6.124a.5.5 0 01.706.047L8 9.74l3.124-3.57a.5.5 0 01.752.658l-3.5 4a.5.5 0 01-.752 0l-3.5-4a.5.5 0 01.047-.705z'/%3E%3C/svg%3E");
183
+ background-repeat: no-repeat; background-position: right 8px center; background-size: 16px 16px; }
184
+ .fs-control:hover { border-color: #C1CEDE; }
185
+ .fs-control:focus, .fs-control:focus-visible { border-color: #1966FF; outline: 1px solid #1966FF; outline-offset: 0; }
186
+ .fs-control.fs-empty, .fs-control::placeholder { color: var(--code-tile-muted); }
187
+ .fs-control:disabled { background-color: var(--code-tile-background); color: var(--code-tile-muted); cursor: not-allowed; }
188
+ .fs-button { font: 500 12px/14px ${FONT}; height: 32px; min-width: 32px; padding: 0 12px; white-space: nowrap; flex: none; border: none;
189
+ border-radius: 8px; cursor: pointer; background-color: #1966FF; color: #FFFFFF; transition: background-color 100ms, color 100ms; }
190
+ .fs-button:hover { background-color: #0942B2; }
191
+ .fs-button.fs-secondary { background-color: #E8F0FF; color: #1966FF; }
192
+ .fs-button.fs-secondary:hover { background-color: #C5D9FF; }
193
+ .fs-button.fs-tertiary { background-color: transparent; color: var(--code-tile-text); font-weight: 400; box-shadow: 0 0 0 1px var(--code-tile-border) inset; }
194
+ .fs-button.fs-tertiary:hover { background-color: #EDF2F7; }
195
+ .fs-button:disabled, .fs-button:disabled:hover { background-color: var(--code-tile-border); color: var(--code-tile-muted); box-shadow: none; cursor: not-allowed; }
196
+ .fs-button:focus-visible { outline: 1px solid var(--code-tile-text); outline-offset: 1px; }
197
+ .fs-button { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
198
+ .fs-chevron { width: 16px; height: 16px; flex: none; background-color: currentColor; -webkit-mask: center / 16px no-repeat; mask: center / 16px no-repeat; }
199
+ .fs-chevron-left { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M10.376 4.67a.5.5 0 01-.047.706L6.76 8.5l3.57 3.124a.5.5 0 11-.658.752l-4-3.5a.5.5 0 010-.752l4-3.5a.5.5 0 01.705.047z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M10.376 4.67a.5.5 0 01-.047.706L6.76 8.5l3.57 3.124a.5.5 0 11-.658.752l-4-3.5a.5.5 0 010-.752l4-3.5a.5.5 0 01.705.047z'/%3E%3C/svg%3E"); }
200
+ .fs-chevron-right { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M5.624 12.33a.5.5 0 01.047-.706L9.24 8.5 5.67 5.376a.5.5 0 11.658-.752l4 3.5a.5.5 0 010 .752l-4 3.5a.5.5 0 01-.705-.047z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M5.624 12.33a.5.5 0 01.047-.706L9.24 8.5 5.67 5.376a.5.5 0 11.658-.752l4 3.5a.5.5 0 010 .752l-4 3.5a.5.5 0 01-.705-.047z'/%3E%3C/svg%3E"); }
201
+ .fs-button.fs-icon-only { padding: 0; width: 32px; }`;
202
+ function control(tag, className = 'fs-control') {
203
+ if (!document.getElementById('fs-control-style')) {
204
+ const style = document.createElement('style');
205
+ style.id = 'fs-control-style';
206
+ style.textContent = CONTROL_CSS;
207
+ document.head.append(style);
208
+ }
209
+ const node = document.createElement(tag);
210
+ node.className = className;
211
+ return node;
212
+ }
213
+ // Farseer's table look (farseer-table.md): the same font, row height, header and rules as a table tile
214
+ const TABLE_CSS = `
215
+ .fs-table-wrap { width: fit-content; max-width: 100%; overflow: hidden; }
216
+ .fs-table { width: max-content; max-width: calc(100% + 12px); border-collapse: separate; border-spacing: 12px 0; margin: 0 0 0 -12px; font: 12px/1.2 ${FONT}; color: var(--code-tile-text); font-variant-numeric: tabular-nums; }
217
+ .fs-table th { height: 24px; padding: 0 0 5px; font-weight: 400; text-align: right; vertical-align: bottom; white-space: nowrap; background: linear-gradient(var(--code-tile-text), var(--code-tile-text)) bottom / 100% 1px no-repeat; }
218
+ .fs-table td { height: 24px; padding: 0; text-align: right; white-space: nowrap; background: linear-gradient(var(--code-tile-border), var(--code-tile-border)) bottom / 100% 1px no-repeat; }
219
+ .fs-table th:first-child, .fs-table td:first-child { text-align: left; }
220
+ .fs-table td:first-child { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
221
+ .fs-table tr.fs-total td { font-weight: 700; background-image: linear-gradient(var(--code-tile-text), var(--code-tile-text)); }
222
+ .fs-table tbody tr:hover td { background-color: color-mix(in srgb, var(--code-tile-muted) 8%, transparent); }
223
+ .fs-table .fs-good { color: ${GOOD}; } .fs-table .fs-bad { color: ${BAD}; } .fs-table .fs-muted { color: var(--code-tile-muted); }
224
+ .fs-table .fs-key { display: inline-block; width: 8px; height: 8px; margin-right: 8px; vertical-align: 0; }
225
+ .fs-table th.fs-AC, .fs-table tr:last-child td.fs-AC { background: linear-gradient(${AC}, ${AC}) bottom / 100% 3px no-repeat; }
226
+ .fs-table th.fs-PY, .fs-table tr:last-child td.fs-PY { background: linear-gradient(${AC_LIGHT}, ${AC_LIGHT}) bottom / 100% 3px no-repeat; }
227
+ .fs-table th.fs-PL, .fs-table tr:last-child td.fs-PL { background: linear-gradient(${AC}, ${AC}) bottom / 100% 1px no-repeat, linear-gradient(${AC}, ${AC}) 0 calc(100% - 3px) / 100% 1px no-repeat; }
228
+ .fs-table th.fs-FC, .fs-table tr:last-child td.fs-FC { background: repeating-linear-gradient(90deg, ${AC} 0 3px, transparent 3px 5px) bottom / 100% 3px no-repeat; }`;
229
+ function farseerTable(head, rows) {
230
+ // head: [{ label, key?, scenario?: 'AC' | 'PL' | 'PY' | 'FC' }] (a scenario column gets the table tile's rule
231
+ // under its header and its last row: AC thick, PL double, PY light, FC dotted);
232
+ // rows: [{ cells: [text or node, …], total?, tone?: [null | 'good' | 'bad' | 'muted', …] }]
233
+ if (!document.getElementById('fs-table-style')) {
234
+ const style = document.createElement('style');
235
+ style.id = 'fs-table-style';
236
+ style.textContent = TABLE_CSS;
237
+ document.head.append(style);
238
+ }
239
+ const table = el('table');
240
+ table.className = 'fs-table';
241
+ const tr = table.createTHead().insertRow();
242
+ for (const h of head) {
243
+ const th = el('th');
244
+ if (h.scenario) th.className = `fs-${h.scenario}`;
245
+ if (h.key) th.append(h.key);
246
+ th.append(h.label);
247
+ tr.append(th);
248
+ }
249
+ const body = table.createTBody();
250
+ for (const row of rows) {
251
+ const line = body.insertRow();
252
+ if (row.total) line.className = 'fs-total';
253
+ row.cells.forEach((cell, i) => {
254
+ const td = line.insertCell();
255
+ const classes = [row.tone?.[i] ? `fs-${row.tone[i]}` : '', head[i]?.scenario ? `fs-${head[i].scenario}` : ''].filter(Boolean);
256
+ if (classes.length) td.className = classes.join(' ');
257
+ if (cell instanceof Node) td.append(cell);
258
+ else td.textContent = cell ?? '';
259
+ if (i === 0 && typeof cell === 'string') td.title = cell;
260
+ });
261
+ }
262
+ // the first column gap reaches 12 px past the left edge, so the text lines up with the title; a clipping box keeps it inside the tile
263
+ const box = el('div');
264
+ box.className = 'fs-table-wrap';
265
+ box.append(table);
266
+ return box;
267
+ }
268
+ // a variance number in a table, as the table tile shows it: red when it hurts, ink when it helps
269
+ const tone = (delta, costLine) => (delta === null || delta === undefined ? 'muted' : (costLine ? delta > 0 : delta < 0) ? 'bad' : null);
270
+ // small HTML helpers for titles, notes and states, all in the theme's ink
271
+ function el(tag, css, text) {
272
+ const node = document.createElement(tag);
273
+ if (css) node.style.cssText = css;
274
+ if (text !== undefined) node.textContent = text;
275
+ return node;
276
+ }
277
+ // the tile header exactly as Farseer draws a chart or table tile's name: 12 px ink, regular, 10 px above the content;
278
+ // a note under it in the footnote style (11 px muted). The frame already sits inside the card's 8 px padding, so the
279
+ // tile's own content has no outer padding of its own
280
+ const TITLE = 'font-size:12px;font-weight:400;line-height:1.25;color:var(--code-tile-text)';
281
+ const NOTE = 'font-size:11px;line-height:1.35;color:var(--code-tile-muted)'; // footnotes and units only
282
+ const PAGE = 'display:grid;gap:10px;height:100%;padding:0;align-content:start';
283
+ const MESSAGE = 'display:grid;place-items:center;height:100%;font-size:13px;color:var(--code-tile-muted)';
284
+ // one title line, the way Farseer names tiles ("Net sales by region, year to date (kEUR)"); the scope only when the
285
+ // filter bar narrows it. A note the reader needs goes to the bottom in the footnote style, never under the title
286
+ // a value that rounds to zero carries no sign: "-0,0%" and "+0" become "0,0%" and "0"
287
+ const unsigned0 = (text) => String(text).replace(/^[+\-−](?=0(?:[.,]0+)?(?:\s?%|\s?pp)?$)/, '');
288
+ function heading(wrap, title) {
289
+ wrap.append(el('div', TITLE, title));
290
+ }
291
+ function footnote(wrap, text) {
292
+ wrap.append(el('div', `${NOTE};padding-top:2px`, text));
293
+ }
294
+ // the scope the filter bar sets, for titles: nothing for the whole group, the company, or "2 companies"
295
+ // (bar is the picks() the body opened for the tables a title names)
296
+ function scope(table, all, one) {
297
+ const pick = bar.current[table];
298
+ if (!pick || pick.all) return all;
299
+ if (pick.members.length === 1) return pick.members[0];
300
+ return `${pick.members.length} ${one}`;
301
+ }
302
+ function period() {
303
+ const ytd = bar.current['Year to date'];
304
+ const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
305
+ if (!ytd || ytd.all || ytd.members.length !== 1) return 'year to date';
306
+ const m = Number(ytd.members[0].replace('M', ''));
307
+ return m === 1 ? 'January' : `January to ${MONTHS[m - 1]}`;
308
+ }
309
+ // --- end of the look ---
310
+ const MAP = {"type":"FeatureCollection","features":[{"type":"Feature","properties":{"name":"SK","context":true},"geometry":{"type":"MultiPolygon","coordinates":[[[[22.54,49.07],[22.3,48.69],[22.14,48.57],[22.11,48.39],[21.72,48.35],[21.45,48.55],[20.49,48.53],[20.33,48.3],[19.95,48.15],[19.63,48.22],[19.47,48.11],[18.79,48],[18.72,47.79],[17.64,47.81],[17.32,47.99],[17.09,48.04],[16.87,48.39],[16.99,48.68],[17.14,48.84],[17.76,48.89],[18.09,49.07],[18.16,49.26],[18.6,49.49],[18.94,49.5],[18.97,49.4],[19.15,49.4],[19.44,49.6],[19.63,49.41],[19.77,49.37],[19.76,49.2],[19.8,49.19],[20.06,49.18],[20.16,49.32],[20.36,49.39],[20.95,49.32],[21.08,49.42],[21.35,49.43],[21.89,49.34],[22.02,49.21],[22.54,49.07]]]]}},{"type":"Feature","properties":{"name":"SI"},"geometry":{"type":"MultiPolygon","coordinates":[[[[16.52,46.5],[16.32,46.53],[16.24,46.48],[16.23,46.37],[16.07,46.37],[15.64,46.2],[15.59,46.14],[15.67,46.05],[15.65,45.86],[15.28,45.73],[15.35,45.66],[15.28,45.58],[15.34,45.47],[15.24,45.44],[14.79,45.48],[14.57,45.66],[14.37,45.48],[13.99,45.51],[13.88,45.43],[13.62,45.48],[13.58,45.52],[13.87,45.61],[13.58,45.81],[13.6,45.98],[13.49,45.99],[13.63,46.18],[13.38,46.26],[13.7,46.52],[14.55,46.4],[14.89,46.61],[15.44,46.63],[15.77,46.71],[15.96,46.68],[15.98,46.8],[16.09,46.86],[16.28,46.86],[16.52,46.5]]]]}},{"type":"Feature","properties":{"name":"RS"},"geometry":{"type":"MultiPolygon","coordinates":[[[[21.36,44.83],[21.91,44.67],[22.09,44.54],[22.5,44.71],[22.72,44.61],[22.5,44.49],[22.53,44.38],[22.71,44.24],[22.63,44.19],[22.6,44.08],[22.42,44.01],[22.37,43.78],[22.55,43.45],[22.98,43.19],[22.71,42.88],[22.47,42.84],[22.44,42.63],[22.53,42.48],[22.42,42.33],[22.24,42.36],[21.56,42.25],[21.52,42.33],[21.61,42.39],[21.75,42.67],[21.39,42.75],[21.4,42.83],[21.06,43.09],[20.84,43.17],[20.8,43.26],[20.62,43.2],[20.62,43.03],[20.48,42.95],[20.47,42.86],[20.34,42.83],[20.27,42.94],[19.61,43.17],[19.22,43.45],[19.19,43.53],[19.25,43.58],[19.45,43.56],[19.5,43.64],[19.25,43.97],[19.55,43.99],[19.58,44.04],[19.12,44.36],[19.35,44.88],[19,44.9],[19.09,44.93],[19.06,45.14],[19.14,45.2],[19.4,45.21],[19,45.4],[19.06,45.51],[18.92,45.6],[18.95,45.66],[18.84,45.84],[19.07,46.01],[19.28,46],[19.53,46.16],[20.21,46.13],[20.71,45.74],[20.77,45.75],[20.79,45.47],[21.49,45.15],[21.35,45.01],[21.53,44.9],[21.36,44.83]]]]}},{"type":"Feature","properties":{"name":"RO","context":true},"geometry":{"type":"MultiPolygon","coordinates":[[[[28.21,45.45],[28.45,45.29],[28.76,45.23],[28.78,45.31],[29.4,45.42],[29.71,45.26],[29.56,44.84],[29.05,44.76],[29.1,44.98],[28.98,44.99],[28.89,44.92],[28.93,44.81],[28.81,44.57],[28.89,44.57],[28.65,44.3],[28.66,43.98],[28.59,43.74],[28.22,43.77],[28.05,43.82],[27.88,43.99],[27.74,43.96],[27.43,44.02],[27.09,44.17],[26.22,44.01],[25.82,43.77],[25.5,43.67],[23.22,43.87],[22.92,43.83],[22.87,43.95],[23.03,44.08],[22.69,44.25],[22.49,44.44],[22.55,44.54],[22.72,44.61],[22.5,44.71],[22.09,44.54],[21.91,44.67],[21.36,44.83],[21.53,44.9],[21.35,45.01],[21.49,45.15],[20.79,45.47],[20.77,45.75],[20.71,45.74],[20.24,46.11],[20.51,46.17],[20.61,46.13],[20.76,46.25],[21.12,46.28],[21.26,46.41],[21.32,46.61],[21.5,46.7],[21.66,47.04],[22,47.4],[22,47.51],[22.29,47.73],[22.61,47.77],[23.14,48.09],[23.41,47.99],[24.18,47.91],[24.58,47.93],[24.89,47.72],[25.46,47.91],[26.16,47.99],[26.31,48.2],[26.71,48.26],[26.98,48.16],[27.61,47.34],[28.07,46.98],[28.24,46.64],[28.24,46.45],[28.1,45.97],[28.16,45.65],[28.07,45.6],[28.21,45.45]]]]}},{"type":"Feature","properties":{"name":"ME","context":true},"geometry":{"type":"MultiPolygon","coordinates":[[[[19.19,43.53],[19.22,43.45],[19.61,43.17],[19.94,43.08],[20.35,42.85],[20.19,42.75],[20.05,42.76],[20.07,42.56],[19.94,42.51],[19.79,42.48],[19.73,42.63],[19.65,42.63],[19.28,42.17],[19.36,42.07],[19.34,41.87],[19.19,41.95],[18.89,42.25],[18.63,42.38],[18.65,42.44],[18.52,42.43],[18.44,42.52],[18.55,42.64],[18.47,42.78],[18.46,43],[18.62,43.03],[18.67,43.23],[18.85,43.35],[19.03,43.29],[18.95,43.53],[19.19,43.53]]]]}},{"type":"Feature","properties":{"name":"MK","context":true},"geometry":{"type":"MultiPolygon","coordinates":[[[[21.56,42.25],[22.24,42.36],[22.58,42.1],[22.8,42.03],[23,41.74],[22.93,41.36],[22.78,41.33],[22.72,41.18],[22.6,41.14],[21.99,41.13],[21.58,40.87],[21.4,40.91],[20.96,40.85],[20.93,40.9],[20.74,40.91],[20.49,41.27],[20.45,41.52],[20.52,41.57],[20.55,41.86],[20.73,41.87],[20.78,42.07],[21.06,42.17],[21.29,42.1],[21.39,42.22],[21.56,42.25]]]]}},{"type":"Feature","properties":{"name":"XK","context":true},"geometry":{"type":"MultiPolygon","coordinates":[[[[20.34,42.83],[20.47,42.86],[20.48,42.95],[20.62,43.03],[20.62,43.2],[20.8,43.26],[20.84,43.17],[21.06,43.09],[21.4,42.83],[21.39,42.75],[21.75,42.65],[21.52,42.33],[21.56,42.25],[21.39,42.22],[21.29,42.1],[21.06,42.17],[20.78,42.07],[20.73,41.87],[20.58,41.87],[20.49,42.22],[20.24,42.34],[20.06,42.55],[20.05,42.76],[20.34,42.83]]]]}},{"type":"Feature","properties":{"name":"IT","context":true},"geometry":{"type":"MultiPolygon","coordinates":[[[[7.02,45.93],[7.13,45.88],[7.54,45.98],[7.79,45.92],[7.99,46.02],[8.13,46.16],[8.1,46.27],[8.42,46.45],[8.46,46.25],[8.64,46.11],[8.82,46.08],[8.78,46],[8.95,45.83],[9.02,45.85],[9,46.01],[9.25,46.29],[9.3,46.5],[9.43,46.48],[9.53,46.31],[9.94,46.36],[10.08,46.23],[10.15,46.25],[10.04,46.48],[10.09,46.6],[10.43,46.55],[10.4,46.67],[10.45,46.86],[10.99,46.78],[11.24,46.98],[11.78,46.99],[12.17,47.08],[12.15,46.94],[12.39,46.7],[13.7,46.52],[13.38,46.26],[13.63,46.18],[13.49,45.99],[13.6,45.98],[13.58,45.81],[13.87,45.61],[13.72,45.59],[13.78,45.63],[13.63,45.77],[13.47,45.71],[13.21,45.77],[13.03,45.64],[12.43,45.47],[12.54,45.54],[12.49,45.55],[12.27,45.45],[12.23,45.24],[12.52,44.97],[12.38,44.8],[12.28,44.83],[12.25,44.72],[12.4,44.22],[12.69,43.99],[13.56,43.57],[14.01,42.69],[14.54,42.24],[15.17,41.93],[16.16,41.9],[16.15,41.76],[15.91,41.62],[15.9,41.51],[17.1,41.06],[17.47,40.84],[17.95,40.66],[18.46,40.22],[18.49,40.1],[18.39,39.9],[18.34,39.82],[18.08,39.94],[17.87,40.28],[17.4,40.34],[17.18,40.5],[16.93,40.46],[16.67,40.14],[16.52,39.75],[16.6,39.64],[16.82,39.58],[17.11,39.38],[17.17,39],[17.1,38.92],[16.95,38.94],[16.62,38.8],[16.56,38.71],[16.55,38.41],[16.28,38.25],[16.06,37.94],[15.72,37.94],[15.65,38.03],[15.64,38.18],[15.82,38.3],[15.93,38.67],[16.2,38.76],[16.21,38.94],[16.11,39.02],[16.02,39.35],[15.69,39.99],[15.59,40.05],[15.29,40.07],[14.95,40.24],[14.95,40.47],[14.77,40.67],[14.34,40.6],[14.46,40.73],[14.31,40.81],[14.04,40.81],[13.73,41.24],[13.25,41.29],[13.09,41.24],[12.85,41.41],[12.63,41.47],[12.08,41.94],[11.81,42.08],[11.64,42.29],[11.3,42.42],[11.1,42.42],[11.18,42.46],[11.17,42.54],[10.71,42.94],[10.51,42.97],[10.52,43.2],[10.32,43.51],[10.25,43.85],[10.05,44.02],[9.73,44.1],[9.29,44.32],[8.77,44.42],[8.55,44.35],[8,43.88],[7.49,43.77],[7.48,43.86],[7.68,44.08],[7.64,44.16],[7.32,44.14],[6.9,44.34],[6.84,44.51],[7.03,44.72],[6.99,44.83],[6.74,44.92],[6.63,45.07],[6.69,45.14],[6.84,45.14],[7.08,45.24],[7.15,45.38],[6.79,45.74],[6.8,45.81],[7.02,45.93]],[[12.49,43.9],[12.5,43.99],[12.4,43.93],[12.49,43.9]]],[[[10.4,42.86],[10.42,42.71],[10.11,42.79],[10.4,42.86]]],[[[13.94,40.71],[13.87,40.71],[13.87,40.76],[13.96,40.74],[13.94,40.71]]],[[[15.58,38.22],[15.23,37.78],[15.1,37.46],[15.12,37.33],[15.23,37.24],[15.17,37.21],[15.3,37.06],[15.12,36.84],[15.11,36.69],[14.5,36.8],[14.26,37.05],[13.8,37.14],[12.92,37.57],[12.64,37.59],[12.44,37.82],[12.55,38.05],[12.73,38.18],[12.9,38.03],[13.16,38.19],[13.29,38.19],[13.79,37.98],[14.51,38.05],[14.79,38.17],[15.12,38.15],[15.5,38.29],[15.63,38.27],[15.58,38.22]]],[[[9.63,40.88],[9.81,40.5],[9.64,40.27],[9.71,40.02],[9.56,39.17],[9.06,39.24],[8.97,38.96],[8.88,38.91],[8.65,38.93],[8.42,39.21],[8.4,39.48],[8.45,39.72],[8.54,39.73],[8.55,39.84],[8.41,39.92],[8.47,40.29],[8.19,40.65],[8.22,40.91],[8.36,40.85],[8.57,40.85],[8.82,40.95],[9.23,41.26],[9.62,41.02],[9.55,40.93],[9.63,40.88]]],[[[8.48,39.07],[8.42,38.97],[8.36,39.1],[8.48,39.07]]],[[[8.29,41.04],[8.21,41],[8.32,41.12],[8.29,41.04]]]]}},{"type":"Feature","properties":{"name":"HU","context":true},"geometry":{"type":"MultiPolygon","coordinates":[[[[22.13,48.41],[22.25,48.41],[22.35,48.26],[22.58,48.13],[22.77,48.11],[22.88,47.95],[22.61,47.77],[22.29,47.73],[22,47.51],[22,47.4],[21.66,47.04],[21.5,46.7],[21.32,46.61],[21.26,46.41],[21.04,46.24],[20.84,46.26],[20.61,46.13],[20.51,46.17],[20.24,46.11],[19.61,46.17],[19.28,46],[19.09,46.02],[18.93,45.93],[18.67,45.91],[18.44,45.77],[17.96,45.77],[17.31,46],[16.87,46.34],[16.52,46.5],[16.28,46.86],[16.09,46.86],[16.25,46.97],[16.45,47.01],[16.49,47.12],[16.42,47.22],[16.44,47.4],[16.62,47.45],[16.68,47.54],[16.64,47.61],[16.42,47.67],[16.59,47.75],[16.79,47.68],[17.07,47.71],[17.03,47.84],[17.15,48.01],[17.32,47.99],[17.76,47.77],[18.72,47.79],[18.79,48],[19.47,48.11],[19.63,48.22],[19.95,48.15],[20.33,48.3],[20.49,48.53],[21.45,48.55],[21.72,48.35],[22.13,48.41]]]]}},{"type":"Feature","properties":{"name":"HR"},"geometry":{"type":"MultiPolygon","coordinates":[[[[13.58,45.52],[13.88,45.43],[13.99,45.51],[14.37,45.48],[14.57,45.66],[14.79,45.48],[15.34,45.47],[15.28,45.58],[15.35,45.66],[15.28,45.73],[15.65,45.86],[15.61,46.17],[16.07,46.37],[16.23,46.37],[16.24,46.48],[16.32,46.53],[16.75,46.42],[17.31,46],[17.81,45.79],[18.36,45.75],[18.53,45.8],[18.67,45.91],[18.91,45.93],[18.84,45.84],[18.95,45.66],[18.92,45.6],[19.06,45.51],[19,45.4],[19.4,45.19],[19.14,45.2],[19.06,45.14],[19.09,44.93],[18.94,44.87],[18.79,44.91],[18.66,45.08],[18,45.14],[17.81,45.08],[17.65,45.16],[17.5,45.12],[17.13,45.17],[16.92,45.28],[16.79,45.2],[16.53,45.22],[16.29,45.01],[16.03,45.19],[15.79,45.18],[15.74,44.77],[16.1,44.52],[16.3,44.12],[17.08,43.52],[17.27,43.45],[17.29,43.31],[17.65,43.01],[17.59,42.94],[16.9,43.39],[16.39,43.54],[15.99,43.52],[15.94,43.66],[15.5,43.91],[15.19,44.17],[15.12,44.26],[15.47,44.27],[14.98,44.6],[14.9,44.71],[14.85,45.08],[14.55,45.3],[14.31,45.34],[13.97,44.84],[13.86,44.84],[13.63,45.11],[13.52,45.48],[13.58,45.52]]],[[[16.65,43],[17.19,42.92],[16.85,42.9],[16.65,43]]],[[[17.19,43.13],[16.68,43.12],[16.38,43.21],[17.19,43.13]]],[[[16.79,43.27],[16.42,43.32],[16.45,43.39],[16.89,43.31],[16.79,43.27]]],[[[14.81,44.98],[14.69,44.96],[14.44,45.1],[14.57,45.22],[14.81,44.98]]],[[[14.83,44.76],[14.86,44.71],[14.66,44.8],[14.75,44.84],[14.83,44.76]]],[[[15.19,44.34],[14.91,44.49],[14.74,44.7],[15.24,44.35],[15.19,44.34]]],[[[15.19,43.92],[15.14,43.91],[14.87,44.17],[15.19,43.92]]],[[[15.37,43.97],[15.44,43.9],[15.27,44.01],[15.37,43.97]]],[[[14.49,44.66],[14.42,44.67],[14.31,44.9],[14.34,45.02],[14.29,45.14],[14.33,45.16],[14.47,44.97],[14.49,44.66]]],[[[17.61,42.77],[17.74,42.7],[17.34,42.79],[17.61,42.77]]],[[[18.44,42.56],[18.52,42.43],[17.82,42.8],[17.05,43.01],[17.22,43.03],[17.72,42.85],[17.67,42.9],[17.8,42.9],[18.44,42.56]]]]}},{"type":"Feature","properties":{"name":"BG","context":true},"geometry":{"type":"MultiPolygon","coordinates":[[[[28.01,41.97],[27.53,41.92],[27.24,42.09],[26.62,41.96],[26.32,41.72],[26.11,41.73],[26.07,41.67],[26.14,41.39],[25.92,41.31],[25.25,41.24],[24.99,41.36],[24.77,41.36],[24.49,41.56],[24.06,41.53],[24.01,41.46],[23.64,41.39],[22.92,41.34],[23,41.74],[22.84,41.99],[22.58,42.1],[22.34,42.31],[22.52,42.44],[22.44,42.63],[22.47,42.84],[22.71,42.88],[22.98,43.19],[22.5,43.52],[22.37,43.78],[22.4,43.97],[22.6,44.08],[22.63,44.19],[22.71,44.24],[23.03,44.08],[22.87,43.95],[22.92,43.83],[23.22,43.87],[25.5,43.67],[25.82,43.77],[26.22,44.01],[27.09,44.17],[27.43,44.02],[27.74,43.96],[27.88,43.99],[28.05,43.82],[28.22,43.77],[28.59,43.74],[28.56,43.5],[28.47,43.39],[28.13,43.4],[27.93,43.19],[27.89,42.75],[27.75,42.71],[27.48,42.47],[27.71,42.35],[28.01,41.97]]]]}},{"type":"Feature","properties":{"name":"BA","context":true},"geometry":{"type":"MultiPolygon","coordinates":[[[[19.35,44.88],[19.12,44.36],[19.58,44.04],[19.55,43.99],[19.25,43.97],[19.49,43.7],[19.48,43.6],[18.95,43.53],[19.03,43.29],[18.85,43.35],[18.67,43.23],[18.62,43.03],[18.44,42.97],[18.55,42.64],[18.44,42.56],[17.8,42.9],[17.59,42.94],[17.65,43.01],[17.29,43.31],[17.27,43.45],[17.08,43.52],[16.3,44.12],[16.1,44.52],[15.74,44.77],[15.82,45.2],[16.03,45.19],[16.29,45.01],[16.53,45.22],[16.79,45.2],[16.92,45.28],[17.13,45.17],[17.5,45.12],[17.65,45.16],[17.81,45.08],[18,45.14],[18.66,45.08],[18.84,44.88],[19.35,44.88]]]]}},{"type":"Feature","properties":{"name":"AT","context":true},"geometry":{"type":"MultiPolygon","coordinates":[[[[9.53,47.27],[9.63,47.47],[9.52,47.52],[9.75,47.58],[10.2,47.36],[10.18,47.28],[10.37,47.37],[10.44,47.55],[10.87,47.52],[11.04,47.39],[11.72,47.58],[12.19,47.62],[12.21,47.72],[12.48,47.64],[12.69,47.67],[12.77,47.64],[12.81,47.54],[13.01,47.48],[13.05,47.66],[12.9,47.72],[12.95,47.89],[12.76,48.08],[12.81,48.16],[13.37,48.36],[13.49,48.58],[13.72,48.54],[13.79,48.59],[13.81,48.77],[14.05,48.6],[14.69,48.6],[14.79,48.75],[14.92,48.77],[14.99,49],[15.83,48.86],[16.06,48.75],[16.37,48.74],[16.54,48.8],[16.88,48.7],[16.95,48.6],[16.87,48.39],[17.15,48.01],[17.03,47.84],[17.07,47.71],[16.79,47.68],[16.59,47.75],[16.42,47.67],[16.64,47.61],[16.68,47.54],[16.62,47.45],[16.44,47.4],[16.46,47.02],[16.04,46.84],[15.96,46.68],[15.77,46.71],[15.44,46.63],[14.89,46.61],[14.55,46.4],[12.48,46.67],[12.15,46.94],[12.17,47.08],[11.78,46.99],[11.24,46.98],[10.93,46.77],[10.45,46.86],[10.35,46.98],[10.13,46.85],[9.88,46.94],[9.85,47.01],[9.58,47.06],[9.61,47.11],[9.53,47.27]]]]}},{"type":"Feature","properties":{"name":"AL","context":true},"geometry":{"type":"MultiPolygon","coordinates":[[[[19.34,41.87],[19.36,42.07],[19.28,42.17],[19.7,42.65],[19.79,42.48],[20.06,42.55],[20.24,42.34],[20.52,42.17],[20.58,41.92],[20.52,41.57],[20.45,41.52],[20.49,41.27],[20.71,40.93],[20.93,40.9],[21.03,40.62],[20.95,40.49],[20.81,40.45],[20.66,40.12],[20.31,39.98],[20.38,39.8],[20.31,39.8],[20.21,39.65],[20,39.71],[19.85,40.04],[19.48,40.21],[19.32,40.41],[19.46,40.41],[19.34,40.66],[19.46,40.93],[19.44,41.42],[19.58,41.64],[19.58,41.79],[19.34,41.87]]]]}}]};
311
+ // Natural Earth (public domain). Countries: SI, RS, HR. 14037 characters.
312
+ ctx.charts.registerMap('acme', MAP);
313
+ // the model's companies and the country each one sells in
314
+ const ISO = { 'Acme Croatia': 'HR', 'Acme Serbia': 'RS', 'Acme Slovenia': 'SI' };
315
+ const COUNTRY = { HR: 'Croatia', RS: 'Serbia', SI: 'Slovenia' };
316
+
317
+ // the view: the countries with data and a margin around them, so the map fills the tile instead of the region
318
+ const BOX = (() => {
319
+ let [w, s, e, n] = [180, 90, -180, -90];
320
+ for (const f of MAP.features) {
321
+ if (f.properties.context) continue;
322
+ for (const poly of f.geometry.coordinates) for (const [x, y] of poly[0]) [w, s, e, n] = [Math.min(w, x), Math.min(s, y), Math.max(e, x), Math.max(n, y)];
323
+ }
324
+ const [dx, dy] = [(e - w) * 0.12, (n - s) * 0.12];
325
+ return [[w - dx, n + dy], [e + dx, s - dy]];
326
+ })();
327
+
328
+ return (element) => {
329
+ const wrap = el('div', `display:grid;grid-template-rows:auto 1fr${element.clientWidth < 480 ? ' auto' : ''};gap:8px;height:100%;padding:0`);
330
+ heading(wrap, `Net sales by country, ${period()} (kEUR)`);
331
+ const area = el('div', 'position:relative;min-height:0');
332
+ // the map fades into the tile at every edge instead of being cut off straight; the scale and the values sit in
333
+ // the faded margin, outside the mask, so they stay crisp and never lie over an outline
334
+ const FADE = 'linear-gradient(to right, transparent, #000 14%, #000 86%, transparent), linear-gradient(to bottom, transparent, #000 14%, #000 86%, transparent)';
335
+ const chart = el('div', `min-height:0;-webkit-mask-image:${FADE};mask-image:${FADE};-webkit-mask-composite:source-in;mask-composite:intersect`);
336
+ const key = el('div', 'position:absolute;left:0;top:0;display:grid;gap:4px;font-size:11px;color:var(--code-tile-muted);font-variant-numeric:tabular-nums');
337
+ const narrowMap = element.clientWidth < 480;
338
+ const values = el('div', `${narrowMap ? 'position:static;display:flex;gap:16px;flex-wrap:wrap' : 'position:absolute;left:0;top:34px;display:grid;gap:2px'};font-size:12px;font-variant-numeric:tabular-nums;color:var(--code-tile-text)`);
339
+ area.append(chart, key);
340
+ wrap.append(area);
341
+ if (narrowMap) wrap.append(values); else area.append(values);
342
+ element.replaceChildren(wrap);
343
+ const result = sales.current;
344
+ const ac = result.columns.findIndex((c) => c.label === 'AC');
345
+ const rows = result.rows.filter((r) => ISO[r.label] && (r.cells[ac]?.value ?? null) !== null);
346
+ if (rows.length === 0) {
347
+ chart.replaceChildren(el('div', MESSAGE, sales.loading ? '' : sales.error?.message ?? 'No data for this selection'));
348
+ return;
349
+ }
350
+ const max = Math.max(...rows.map((r) => r.cells[ac].value));
351
+ // the exact values beside the map, largest first, in the empty corner under the scale
352
+ for (const r of [...rows].sort((a, b) => b.cells[ac].value - a.cells[ac].value)) {
353
+ const line = el('div', `display:flex;gap:${narrowMap ? 6 : 10}px;justify-content:space-between${narrowMap ? '' : ';min-width:130px'}`);
354
+ line.append(el('span', '', COUNTRY[ISO[r.label]]), el('span', 'font-weight:600', ctx.format(r.cells[ac].value, '#,##0,')));
355
+ values.append(line);
356
+ }
357
+ // the colour scale as a small key: the ramp from 0 to the largest value
358
+ const ramp = el('div', `width:96px;height:8px;background:linear-gradient(90deg,${RAMP.join(',')})`);
359
+ const ends = el('div', 'display:flex;justify-content:space-between;width:96px');
360
+ ends.append(el('span', '', '0'), el('span', '', ctx.format(max, '#,##0,')));
361
+ key.append(ramp, ends);
362
+ chart.style.height = `${element.clientHeight - 46}px`;
363
+ drawChart(chart, merge({ textStyle: look().textStyle, tooltip: look().tooltip }, {
364
+ tooltip: { formatter: (p) => (p.value > 0 ? `<b>${ctx.format(p.value, '#,##0,')} kEUR</b><br>${COUNTRY[p.name] ?? p.name}` : '') },
365
+ // the colour mapping; its own legend is hidden because it would fade with the map (the key above replaces it)
366
+ visualMap: { type: 'continuous', show: false, min: 0, max, inRange: { color: RAMP }, seriesIndex: 0 },
367
+ series: [{
368
+ type: 'map', map: 'acme', roam: false, boundingCoords: BOX, layoutCenter: ['55%', '50%'], layoutSize: '100%', selectedMode: false,
369
+ aspectScale: 0.72,
370
+ label: { show: false },
371
+ itemStyle: { areaColor: LINE(), borderColor: SURFACE(), borderWidth: 1 },
372
+ emphasis: { label: { show: false }, itemStyle: { areaColor: RAMP[3] } },
373
+ data: rows.map((r) => ({ name: ISO[r.label], value: r.cells[ac].value })),
374
+ }],
375
+ }));
376
+ };
377
+ }