farseer-cli 1.24.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 (75) 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/sheets.js +5 -3
  11. package/dist/commands/sheets.js.map +1 -1
  12. package/dist/commands/whoami.js +12 -5
  13. package/dist/commands/whoami.js.map +1 -1
  14. package/dist/mcp/tools/authTools.js +2 -1
  15. package/dist/mcp/tools/authTools.js.map +1 -1
  16. package/dist/mcp/tools/dashboardTools.js +3 -1
  17. package/dist/mcp/tools/dashboardTools.js.map +1 -1
  18. package/dist/mcp/tools/runTools.js +2 -3
  19. package/dist/mcp/tools/runTools.js.map +1 -1
  20. package/dist/mcp/utils/helpers.js +8 -6
  21. package/dist/mcp/utils/helpers.js.map +2 -2
  22. package/dist/mcp/utils/session.js +6 -2
  23. package/dist/mcp/utils/session.js.map +1 -1
  24. package/dist/operations/dashboards.js +1 -1
  25. package/dist/operations/dashboards.js.map +1 -1
  26. package/dist/pipeline/generated-reference.json +8 -8
  27. package/dist/services/codefirst/layoutReadback.js +95 -0
  28. package/dist/services/codefirst/layoutReadback.js.map +2 -2
  29. package/dist/services/configService.js +33 -18
  30. package/dist/services/configService.js.map +1 -1
  31. package/dist/services/credentials.js +26 -11
  32. package/dist/services/credentials.js.map +1 -1
  33. package/dist/services/farseerService.js +34 -32
  34. package/dist/services/farseerService.js.map +1 -1
  35. package/dist/services/keycloak.js +44 -0
  36. package/dist/services/keycloak.js.map +6 -0
  37. package/dist/services/preflight.js +1 -2
  38. package/dist/services/preflight.js.map +1 -1
  39. package/dist/services/realms.js +67 -15
  40. package/dist/services/realms.js.map +1 -1
  41. package/dist/utils/serverUrl.js +42 -0
  42. package/dist/utils/serverUrl.js.map +6 -0
  43. package/docs/pipeline-reference.md +13 -3
  44. package/package.json +2 -2
  45. package/skills/farseer-build-model/SKILL.md +1 -1
  46. package/skills/farseer-code-tiles/SKILL.md +153 -0
  47. package/skills/farseer-code-tiles/anti-patterns.md +183 -0
  48. package/skills/farseer-code-tiles/api.md +237 -0
  49. package/skills/farseer-code-tiles/check-tile.mjs +521 -0
  50. package/skills/farseer-code-tiles/design.md +159 -0
  51. package/skills/farseer-code-tiles/echarts-look.md +110 -0
  52. package/skills/farseer-code-tiles/examples/board-deck.js +695 -0
  53. package/skills/farseer-code-tiles/examples/data-checks.js +475 -0
  54. package/skills/farseer-code-tiles/examples/kpi-cards.js +374 -0
  55. package/skills/farseer-code-tiles/examples/map-countries.js +377 -0
  56. package/skills/farseer-code-tiles/examples/month-plan.js +443 -0
  57. package/skills/farseer-code-tiles/examples/new-location.js +581 -0
  58. package/skills/farseer-code-tiles/examples/open-forecast.js +598 -0
  59. package/skills/farseer-code-tiles/examples/pl-sankey.js +402 -0
  60. package/skills/farseer-code-tiles/examples/ranked-bars.js +337 -0
  61. package/skills/farseer-code-tiles/examples/request-form.js +464 -0
  62. package/skills/farseer-code-tiles/farseer-table.md +98 -0
  63. package/skills/farseer-code-tiles/known-mistakes.md +178 -0
  64. package/skills/farseer-code-tiles/maps/europe.geo.json +1 -0
  65. package/skills/farseer-code-tiles/maps/pick-map.mjs +59 -0
  66. package/skills/farseer-code-tiles/maps/world.geo.json +1 -0
  67. package/skills/farseer-dashboards/SKILL.md +3 -2
  68. package/skills/farseer-dashboards/check.md +3 -2
  69. package/skills/farseer-dashboards/measures.md +3 -1
  70. package/skills/farseer-dashboards/reporting-period.md +1 -1
  71. package/skills/farseer-modify-model/SKILL.md +1 -1
  72. package/skills/farseer-modify-model/model-validation-pattern.md +3 -3
  73. package/skills/farseer-optimize-model/SKILL.md +9 -1
  74. package/skills/farseer-pnl/SKILL.md +3 -3
  75. package/skills/pipeline-authoring/SKILL.md +2 -2
@@ -0,0 +1,337 @@
1
+ // Net sales by region, ranked. The skill's maps hold countries only, so the model's sales regions
2
+ // have no outlines. A ranked bar chart is a standard chart type, so it is drawn by the chart tile's own code
3
+ // (ctx.charts.farseer); a plain chart tile could show the same, and the subtitle says why there is no map.
4
+ // Tile size: w18 h10 for ten regions (one row is about 28 px); w14 h10 when narrow.
5
+ export default function (ctx) {
6
+ // readTable: a table of numbers from the model, in the shape ctx.charts.farseer draws
7
+ // ({ columns: [{ label, numberFormat }], rows: [{ label, cells: [{ value }] }] }). Call it in the body.
8
+ // rows: { table: 'Entity' } every member of a table, listed live by name
9
+ // rows: { table, includeDashboardFilters: true } the members the filter bar leaves, even when the numbers ignore it
10
+ // rows: { table: 'Months', members: ['M1', …] } the members named here, in this order
11
+ // rows: [{ label, formula, numberFormat }] one line per formula (a P&L)
12
+ // no rows one row, labelled '', for KPIs
13
+ // columns: [{ label, formula, numberFormat }] with member rows, [{ label, filter }] with formula lines
14
+ // Member rows and every number follow the filter bar and timeline, unless the spec turns them off.
15
+ const quote = (name) => `"${String(name).replace(/(["\\])/g, '\\$1')}"`;
16
+ // a table's members from a DTABLE answer, by name, without its NULL member
17
+ const namesOf = (answer) => (answer?.value ?? []).map(String).filter((name) => !name.startsWith('NULL ('));
18
+ function withFilter(formula, filter) {
19
+ let out = '', depth = [], quoted = false;
20
+ for (let i = 0; i < formula.length; i++) {
21
+ const c = formula[i];
22
+ if (c === '"' && formula[i - 1] !== '\\') quoted = !quoted;
23
+ if (!quoted && c === '(') depth.push(/sum\s*$/i.test(formula.slice(0, i)));
24
+ if (!quoted && c === ')' && depth.pop()) out += `, ${filter}`;
25
+ out += c;
26
+ }
27
+ return out;
28
+ }
29
+ function readTable(spec) {
30
+ // includeDashboardFilters: false / includeDashboardTimeline: false in the spec leave one out (say so on the tile)
31
+ const options = { includeDashboardFilters: spec.includeDashboardFilters !== false, includeDashboardTimeline: spec.includeDashboardTimeline !== false };
32
+ const { columns } = spec;
33
+ const rows = spec.rows ?? [{ label: '' }];
34
+ const memberRows = !Array.isArray(rows);
35
+ const listOptions = { ...options, ...(memberRows && rows.includeDashboardFilters !== undefined ? { includeDashboardFilters: rows.includeDashboardFilters } : {}) };
36
+ const list = memberRows && !rows.members ? ctx.query([{ type: 'DTABLE', table: rows.table }], listOptions) : null;
37
+ let names = memberRows ? rows.members ?? null : null;
38
+ let listed = null;
39
+ let values = null;
40
+ const open = () => {
41
+ values?.close();
42
+ const formulas = memberRows
43
+ ? names.flatMap((name) => columns.map((c) => withFilter(c.formula, `${quote(rows.table)}>${quote(name)}`)))
44
+ : rows.flatMap((r) => columns.map((c) => (r.formula ? withFilter(r.formula, c.filter) : c.formula)));
45
+ values = formulas.length ? ctx.query(formulas.map((formula) => ({ type: 'VARIABLE', formula })), options) : null;
46
+ };
47
+ if (!list) open();
48
+ const refresh = () => {
49
+ if (list.loading && !list.current.length) return;
50
+ const now = namesOf(list.current[0]);
51
+ const key = now.join('\u0001');
52
+ if (key !== listed) {
53
+ listed = key;
54
+ names = now;
55
+ open();
56
+ }
57
+ };
58
+ return {
59
+ get loading() {
60
+ if (list) refresh();
61
+ return (list?.loading ?? false) || (values?.loading ?? false);
62
+ },
63
+ get error() {
64
+ return list?.error ?? values?.error ?? null;
65
+ },
66
+ get current() {
67
+ if (list) refresh();
68
+ const cells = values?.current ?? [];
69
+ const labels = memberRows ? names ?? [] : rows.map((r) => r.label);
70
+ return {
71
+ columns: columns.map((c) => ({ label: c.label, numberFormat: c.numberFormat ?? (memberRows ? null : rows[0]?.numberFormat) ?? null })),
72
+ rows: labels.map((label, j) => ({
73
+ label,
74
+ numberFormat: memberRows ? null : rows[j].numberFormat ?? null,
75
+ cells: columns.map((_, i) => ({ value: cells[j * columns.length + i]?.value ?? null })),
76
+ })),
77
+ };
78
+ },
79
+ };
80
+ }
81
+ // picks(['Entity', 'Year to date']): what the filter bar picked on these tables, for a title or a form.
82
+ // current.Entity is { members: ['Acme Croatia'], all: false }; all is true when the bar doesn't narrow that table.
83
+ function picks(tables) {
84
+ const picked = ctx.query(tables.map((table) => ({ type: 'DTABLE', table })));
85
+ const every = ctx.query(tables.map((table) => ({ type: 'DTABLE', table })), { includeDashboardFilters: false, includeDashboardTimeline: false });
86
+ return {
87
+ get loading() {
88
+ return picked.loading || every.loading;
89
+ },
90
+ get error() {
91
+ return picked.error ?? every.error ?? null;
92
+ },
93
+ get current() {
94
+ return Object.fromEntries(tables.map((table, i) => {
95
+ const members = namesOf(picked.current[i]);
96
+ return [table, { members, all: members.length === namesOf(every.current[i]).length }];
97
+ }));
98
+ },
99
+ };
100
+ }
101
+ // what the filter bar picked, for the title
102
+ const bar = picks(['Entity', 'Year to date']);
103
+ const regions = readTable({
104
+ rows: { table: 'Region' },
105
+ columns: [{ label: 'AC', formula: 'sum("Revenue", "Versions">"Actual", "Reporting period">"Current year")', numberFormat: '#,##0,' }],
106
+ });
107
+ // --- The Farseer look (echarts-look.md, design.md): the same block in every tile ---
108
+ // AC: the dashboards' AC colour (SKILL.md section 2, The AC colour): #323232, or the company's
109
+ // darkest brand colour when it is dark enough, never an example's. AC_LIGHT is its PY tint.
110
+ // Everything else below is derived from them, so nothing else needs changing.
111
+ const AC = '#323232';
112
+ const AC_LIGHT = '#A6A6A6';
113
+ // mixes a colour with white: share 1 is the colour itself, 0 is white
114
+ function tint(hex, share) {
115
+ const n = parseInt(hex.slice(1), 16);
116
+ const mix = (c) => Math.round(c * share + 255 * (1 - share)).toString(16).padStart(2, '0');
117
+ return `#${mix(n >> 16)}${mix((n >> 8) & 255)}${mix(n & 255)}`.toUpperCase();
118
+ }
119
+ // a colour with almost no hue (graphite, grey): its ramp would turn a map grey, so magnitude takes Farseer blue
120
+ 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; };
121
+ const PALETTE = [AC, '#ED7D16', '#1BB5D7', '#8A2FE5', '#BFA812', '#E52FCD']; // identity: AC first, then distinct hues
122
+ const FILL = [AC_LIGHT, '#F5B87F', '#82D6E9', '#BF8DF1', '#DCCF7D', '#F18DE4']; // the light step, for large areas
123
+ // magnitude (maps, heatmaps), light to dark: steps of AC, or Farseer blue when AC is a grey
124
+ const RAMP = isGrey(AC) ? ['#81A9FF', '#457DFF', '#0D4BC2', '#043288'] : [0.45, 0.65, 0.8, 1].map((s) => tint(AC, s));
125
+ // light tints of AC for large areas that need ink text (treemap groups), clearly apart from each other
126
+ // (from Farseer blue when AC is a grey, as the ramp: grey tints would make a grey block)
127
+ const TINTS = [0.52, 0.37, 0.24, 0.11].map((s) => tint(isGrey(AC) ? '#043288' : AC, s));
128
+ const TRACK = tint(AC, 0.12); // the unfilled part of a gauge
129
+ const PRIMARY = '#1A66FF'; // Farseer's own primary button, not a data colour
130
+ const GOOD = '#0CB955';
131
+ const BAD = '#E21E09';
132
+ const INK = () => ctx.theme.tokens?.text ?? '#020810';
133
+ const MUTED = () => ctx.theme.tokens?.muted ?? '#687C95';
134
+ const LINE = () => ctx.theme.tokens?.border ?? '#E6EBF2';
135
+ const SURFACE = () => ctx.theme.tokens?.background ?? '#FFFFFF';
136
+ const FONT = 'Inter, system-ui, sans-serif';
137
+ let drawnOnce = false;
138
+ // draws one echarts chart in the look; the first chart that draws ends the entrance animation for the rest
139
+ function drawChart(element, option) {
140
+ ctx.charts.echarts(element, option);
141
+ drawnOnce = true;
142
+ }
143
+ // the chart tile's look, measured from it: square bars, 12 px ink labels with a surface-coloured halo, an ink
144
+ // category axis with ticks, no value axis or gridlines, the legend at the bottom, its tooltip and margins
145
+ const LABEL = { show: true, fontFamily: FONT, fontSize: 12, color: INK(), textBorderColor: SURFACE(), textBorderWidth: 4 };
146
+ function look() {
147
+ return {
148
+ animation: !drawnOnce,
149
+ animationDuration: 500,
150
+ textStyle: { fontFamily: FONT, fontSize: 12, color: INK() },
151
+ grid: { left: 10, right: 10, top: 20, bottom: 10, containLabel: true },
152
+ legend: { bottom: 0, textStyle: { fontFamily: FONT, color: INK() } },
153
+ tooltip: {
154
+ trigger: 'item', confine: true, backgroundColor: SURFACE(), borderColor: '#EDF2F7', borderWidth: 1,
155
+ padding: [6, 10], textStyle: { color: INK(), fontSize: 12, fontFamily: FONT },
156
+ extraCssText: 'border-radius:6px;box-shadow:0 4px 16px rgba(107,131,160,0.15)',
157
+ },
158
+ categoryAxis: {
159
+ axisLine: { show: true, lineStyle: { color: INK(), width: 1 } },
160
+ axisTick: { show: false },
161
+ axisLabel: { color: INK(), fontFamily: FONT, fontSize: 12, hideOverlap: true },
162
+ splitLine: { show: false },
163
+ },
164
+ valueAxis: { show: false, splitLine: { show: false } },
165
+ };
166
+ }
167
+ function merge(base, extra) {
168
+ if (Array.isArray(extra) || typeof extra !== 'object' || extra === null) return extra;
169
+ const out = { ...base };
170
+ for (const [key, value] of Object.entries(extra)) {
171
+ out[key] = typeof value === 'object' && value !== null && !Array.isArray(value) && typeof base?.[key] === 'object' ? merge(base[key], value) : value;
172
+ }
173
+ return out;
174
+ }
175
+ // form controls and buttons in Farseer's toolbar look: 28 px high, 12 px text, the focus ring drawn inside the
176
+ // control (so a control at the tile's edge never loses it), button text that never wraps, a long choice ending in …
177
+ // Farseer's own form controls and buttons (the app's input, select and button), the same in every tile
178
+ const CONTROL_CSS = `
179
+ .fs-control { font: 400 12px/20px ${FONT}; height: 32px; padding: 0 8px; border: 1px solid #EDF2F7; border-radius: 8px;
180
+ background-color: #EDF2F7; color: var(--code-tile-text); min-width: 0; max-width: 100%; box-sizing: border-box; outline: none;
181
+ overflow: hidden; white-space: nowrap; text-overflow: ellipsis; transition: border-color 100ms; }
182
+ select.fs-control { appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer;
183
+ 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");
184
+ background-repeat: no-repeat; background-position: right 8px center; background-size: 16px 16px; }
185
+ .fs-control:hover { border-color: #C1CEDE; }
186
+ .fs-control:focus, .fs-control:focus-visible { border-color: #1966FF; outline: 1px solid #1966FF; outline-offset: 0; }
187
+ .fs-control.fs-empty, .fs-control::placeholder { color: var(--code-tile-muted); }
188
+ .fs-control:disabled { background-color: var(--code-tile-background); color: var(--code-tile-muted); cursor: not-allowed; }
189
+ .fs-button { font: 500 12px/14px ${FONT}; height: 32px; min-width: 32px; padding: 0 12px; white-space: nowrap; flex: none; border: none;
190
+ border-radius: 8px; cursor: pointer; background-color: #1966FF; color: #FFFFFF; transition: background-color 100ms, color 100ms; }
191
+ .fs-button:hover { background-color: #0942B2; }
192
+ .fs-button.fs-secondary { background-color: #E8F0FF; color: #1966FF; }
193
+ .fs-button.fs-secondary:hover { background-color: #C5D9FF; }
194
+ .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; }
195
+ .fs-button.fs-tertiary:hover { background-color: #EDF2F7; }
196
+ .fs-button:disabled, .fs-button:disabled:hover { background-color: var(--code-tile-border); color: var(--code-tile-muted); box-shadow: none; cursor: not-allowed; }
197
+ .fs-button:focus-visible { outline: 1px solid var(--code-tile-text); outline-offset: 1px; }
198
+ .fs-button { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
199
+ .fs-chevron { width: 16px; height: 16px; flex: none; background-color: currentColor; -webkit-mask: center / 16px no-repeat; mask: center / 16px no-repeat; }
200
+ .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"); }
201
+ .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"); }
202
+ .fs-button.fs-icon-only { padding: 0; width: 32px; }`;
203
+ function control(tag, className = 'fs-control') {
204
+ if (!document.getElementById('fs-control-style')) {
205
+ const style = document.createElement('style');
206
+ style.id = 'fs-control-style';
207
+ style.textContent = CONTROL_CSS;
208
+ document.head.append(style);
209
+ }
210
+ const node = document.createElement(tag);
211
+ node.className = className;
212
+ return node;
213
+ }
214
+ // Farseer's table look (farseer-table.md): the same font, row height, header and rules as a table tile
215
+ const TABLE_CSS = `
216
+ .fs-table-wrap { width: fit-content; max-width: 100%; overflow: hidden; }
217
+ .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; }
218
+ .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; }
219
+ .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; }
220
+ .fs-table th:first-child, .fs-table td:first-child { text-align: left; }
221
+ .fs-table td:first-child { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
222
+ .fs-table tr.fs-total td { font-weight: 700; background-image: linear-gradient(var(--code-tile-text), var(--code-tile-text)); }
223
+ .fs-table tbody tr:hover td { background-color: color-mix(in srgb, var(--code-tile-muted) 8%, transparent); }
224
+ .fs-table .fs-good { color: ${GOOD}; } .fs-table .fs-bad { color: ${BAD}; } .fs-table .fs-muted { color: var(--code-tile-muted); }
225
+ .fs-table .fs-key { display: inline-block; width: 8px; height: 8px; margin-right: 8px; vertical-align: 0; }
226
+ .fs-table th.fs-AC, .fs-table tr:last-child td.fs-AC { background: linear-gradient(${AC}, ${AC}) bottom / 100% 3px no-repeat; }
227
+ .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; }
228
+ .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; }
229
+ .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; }`;
230
+ function farseerTable(head, rows) {
231
+ // head: [{ label, key?, scenario?: 'AC' | 'PL' | 'PY' | 'FC' }] (a scenario column gets the table tile's rule
232
+ // under its header and its last row: AC thick, PL double, PY light, FC dotted);
233
+ // rows: [{ cells: [text or node, …], total?, tone?: [null | 'good' | 'bad' | 'muted', …] }]
234
+ if (!document.getElementById('fs-table-style')) {
235
+ const style = document.createElement('style');
236
+ style.id = 'fs-table-style';
237
+ style.textContent = TABLE_CSS;
238
+ document.head.append(style);
239
+ }
240
+ const table = el('table');
241
+ table.className = 'fs-table';
242
+ const tr = table.createTHead().insertRow();
243
+ for (const h of head) {
244
+ const th = el('th');
245
+ if (h.scenario) th.className = `fs-${h.scenario}`;
246
+ if (h.key) th.append(h.key);
247
+ th.append(h.label);
248
+ tr.append(th);
249
+ }
250
+ const body = table.createTBody();
251
+ for (const row of rows) {
252
+ const line = body.insertRow();
253
+ if (row.total) line.className = 'fs-total';
254
+ row.cells.forEach((cell, i) => {
255
+ const td = line.insertCell();
256
+ const classes = [row.tone?.[i] ? `fs-${row.tone[i]}` : '', head[i]?.scenario ? `fs-${head[i].scenario}` : ''].filter(Boolean);
257
+ if (classes.length) td.className = classes.join(' ');
258
+ if (cell instanceof Node) td.append(cell);
259
+ else td.textContent = cell ?? '';
260
+ if (i === 0 && typeof cell === 'string') td.title = cell;
261
+ });
262
+ }
263
+ // 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
264
+ const box = el('div');
265
+ box.className = 'fs-table-wrap';
266
+ box.append(table);
267
+ return box;
268
+ }
269
+ // a variance number in a table, as the table tile shows it: red when it hurts, ink when it helps
270
+ const tone = (delta, costLine) => (delta === null || delta === undefined ? 'muted' : (costLine ? delta > 0 : delta < 0) ? 'bad' : null);
271
+ // small HTML helpers for titles, notes and states, all in the theme's ink
272
+ function el(tag, css, text) {
273
+ const node = document.createElement(tag);
274
+ if (css) node.style.cssText = css;
275
+ if (text !== undefined) node.textContent = text;
276
+ return node;
277
+ }
278
+ // the tile header exactly as Farseer draws a chart or table tile's name: 12 px ink, regular, 10 px above the content;
279
+ // a note under it in the footnote style (11 px muted). The frame already sits inside the card's 8 px padding, so the
280
+ // tile's own content has no outer padding of its own
281
+ const TITLE = 'font-size:12px;font-weight:400;line-height:1.25;color:var(--code-tile-text)';
282
+ const NOTE = 'font-size:11px;line-height:1.35;color:var(--code-tile-muted)'; // footnotes and units only
283
+ const PAGE = 'display:grid;gap:10px;height:100%;padding:0;align-content:start';
284
+ const MESSAGE = 'display:grid;place-items:center;height:100%;font-size:13px;color:var(--code-tile-muted)';
285
+ // one title line, the way Farseer names tiles ("Net sales by region, year to date (kEUR)"); the scope only when the
286
+ // filter bar narrows it. A note the reader needs goes to the bottom in the footnote style, never under the title
287
+ // a value that rounds to zero carries no sign: "-0,0%" and "+0" become "0,0%" and "0"
288
+ const unsigned0 = (text) => String(text).replace(/^[+\-−](?=0(?:[.,]0+)?(?:\s?%|\s?pp)?$)/, '');
289
+ function heading(wrap, title) {
290
+ wrap.append(el('div', TITLE, title));
291
+ }
292
+ function footnote(wrap, text) {
293
+ wrap.append(el('div', `${NOTE};padding-top:2px`, text));
294
+ }
295
+ // the scope the filter bar sets, for titles: nothing for the whole group, the company, or "2 companies"
296
+ // (bar is the picks() the body opened for the tables a title names)
297
+ function scope(table, all, one) {
298
+ const pick = bar.current[table];
299
+ if (!pick || pick.all) return all;
300
+ if (pick.members.length === 1) return pick.members[0];
301
+ return `${pick.members.length} ${one}`;
302
+ }
303
+ function period() {
304
+ const ytd = bar.current['Year to date'];
305
+ const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
306
+ if (!ytd || ytd.all || ytd.members.length !== 1) return 'year to date';
307
+ const m = Number(ytd.members[0].replace('M', ''));
308
+ return m === 1 ? 'January' : `January to ${MONTHS[m - 1]}`;
309
+ }
310
+ // --- end of the look ---
311
+ return (element) => {
312
+ const wrap = el('div', 'display:grid;grid-template-rows:auto 1fr auto;gap:10px;height:100%;padding:0');
313
+ heading(wrap, `Net sales by region, ${period()}${scope('Entity', '', 'companies') ? `, ${scope('Entity', '', 'companies')}` : ''} (kEUR)`);
314
+ const chart = el('div', 'min-height:0');
315
+ wrap.append(chart);
316
+ element.replaceChildren(wrap);
317
+ const result = regions.current;
318
+ const ac = result.columns.findIndex((c) => c.label === 'AC');
319
+ // largest first; the result keeps its shape, so the chart tile's code draws it as it would its own rows
320
+ const rows = result.rows.filter((r) => (r.cells[ac]?.value ?? 0) > 0).sort((a, b) => b.cells[ac].value - a.cells[ac].value);
321
+ if (rows.length === 0) {
322
+ chart.replaceChildren(el('div', MESSAGE, regions.loading ? '' : regions.error?.message ?? 'No data for this selection'));
323
+ return;
324
+ }
325
+ chart.style.height = `${Math.min(element.clientHeight - 56, rows.length * 28 + 16)}px`;
326
+ footnote(wrap, 'No map: sales regions have no outlines.');
327
+ ctx.charts.farseer({ ...result, rows }, chart, {
328
+ type: 'BAR_CHART',
329
+ layout: 'VERTICAL', // horizontal bars, one per region
330
+ series: { transposeData: true }, // regions on the axis, the AC column as the one series
331
+ display: { showLegend: false, showValueAxis: false },
332
+ labels: { showLabels: true },
333
+ spacing: { marginRight: 56, marginTop: 4, marginBottom: 4 }, // room for the largest value's label
334
+ rowVisualizationByPath: { AC: { color: { solid: AC, pattern: 'SOLID' } } },
335
+ });
336
+ };
337
+ }