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,402 @@
1
+ // Where net sales go, from net sales through each cost down to net profit, as the dashboard is filtered.
2
+ // Results flow on in the AC colour; costs leave the flow in its light tint. Costs are stored positive in this model.
3
+ // Tile size: w36 h10 (the flow and the EBITDA-to-net-profit table beside it). Below 640 px the parts become ranked
4
+ // bars (w14 h12).
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 pl = readTable({
104
+ rows: [
105
+ { label: 'Net sales', formula: 'sum("Net sales")' },
106
+ { label: 'COGS', formula: 'sum("COGS")' },
107
+ { label: 'Gross profit', formula: 'sum("Gross profit")' },
108
+ { label: 'Personnel costs', formula: 'sum("Personnel costs")' },
109
+ { label: 'Rent and facilities', formula: 'sum("Rent and facilities")' },
110
+ { label: 'Marketing', formula: 'sum("Marketing")' },
111
+ { label: 'Other OpEx', formula: 'sum("Other OpEx")' },
112
+ { label: 'EBITDA', formula: 'sum("EBITDA")' },
113
+ { label: 'D&A', formula: 'sum("D&A")' },
114
+ { label: 'EBIT', formula: 'sum("EBIT")' },
115
+ { label: 'Financial result', formula: 'sum("Financial result")' },
116
+ { label: 'Profit before tax', formula: 'sum("Profit before tax")' },
117
+ { label: 'Income tax', formula: 'sum("Income tax")' },
118
+ { label: 'Net profit', formula: 'sum("Net profit")' },
119
+ ],
120
+ columns: [{ label: 'AC', filter: '"Versions">"Actual", "Reporting period">"Current year"' }],
121
+ });
122
+ // --- The Farseer look (echarts-look.md, design.md): the same block in every tile ---
123
+ // AC: the dashboards' AC colour (SKILL.md section 2, The AC colour): #323232, or the company's
124
+ // darkest brand colour when it is dark enough, never an example's. AC_LIGHT is its PY tint.
125
+ // Everything else below is derived from them, so nothing else needs changing.
126
+ const AC = '#323232';
127
+ const AC_LIGHT = '#A6A6A6';
128
+ // mixes a colour with white: share 1 is the colour itself, 0 is white
129
+ function tint(hex, share) {
130
+ const n = parseInt(hex.slice(1), 16);
131
+ const mix = (c) => Math.round(c * share + 255 * (1 - share)).toString(16).padStart(2, '0');
132
+ return `#${mix(n >> 16)}${mix((n >> 8) & 255)}${mix(n & 255)}`.toUpperCase();
133
+ }
134
+ // a colour with almost no hue (graphite, grey): its ramp would turn a map grey, so magnitude takes Farseer blue
135
+ 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; };
136
+ const PALETTE = [AC, '#ED7D16', '#1BB5D7', '#8A2FE5', '#BFA812', '#E52FCD']; // identity: AC first, then distinct hues
137
+ const FILL = [AC_LIGHT, '#F5B87F', '#82D6E9', '#BF8DF1', '#DCCF7D', '#F18DE4']; // the light step, for large areas
138
+ // magnitude (maps, heatmaps), light to dark: steps of AC, or Farseer blue when AC is a grey
139
+ const RAMP = isGrey(AC) ? ['#81A9FF', '#457DFF', '#0D4BC2', '#043288'] : [0.45, 0.65, 0.8, 1].map((s) => tint(AC, s));
140
+ // light tints of AC for large areas that need ink text (treemap groups), clearly apart from each other
141
+ // (from Farseer blue when AC is a grey, as the ramp: grey tints would make a grey block)
142
+ const TINTS = [0.52, 0.37, 0.24, 0.11].map((s) => tint(isGrey(AC) ? '#043288' : AC, s));
143
+ const TRACK = tint(AC, 0.12); // the unfilled part of a gauge
144
+ const PRIMARY = '#1A66FF'; // Farseer's own primary button, not a data colour
145
+ const GOOD = '#0CB955';
146
+ const BAD = '#E21E09';
147
+ const INK = () => ctx.theme.tokens?.text ?? '#020810';
148
+ const MUTED = () => ctx.theme.tokens?.muted ?? '#687C95';
149
+ const LINE = () => ctx.theme.tokens?.border ?? '#E6EBF2';
150
+ const SURFACE = () => ctx.theme.tokens?.background ?? '#FFFFFF';
151
+ const FONT = 'Inter, system-ui, sans-serif';
152
+ let drawnOnce = false;
153
+ // draws one echarts chart in the look; the first chart that draws ends the entrance animation for the rest
154
+ function drawChart(element, option) {
155
+ ctx.charts.echarts(element, option);
156
+ drawnOnce = true;
157
+ }
158
+ // the chart tile's look, measured from it: square bars, 12 px ink labels with a surface-coloured halo, an ink
159
+ // category axis with ticks, no value axis or gridlines, the legend at the bottom, its tooltip and margins
160
+ const LABEL = { show: true, fontFamily: FONT, fontSize: 12, color: INK(), textBorderColor: SURFACE(), textBorderWidth: 4 };
161
+ function look() {
162
+ return {
163
+ animation: !drawnOnce,
164
+ animationDuration: 500,
165
+ textStyle: { fontFamily: FONT, fontSize: 12, color: INK() },
166
+ grid: { left: 10, right: 10, top: 20, bottom: 10, containLabel: true },
167
+ legend: { bottom: 0, textStyle: { fontFamily: FONT, color: INK() } },
168
+ tooltip: {
169
+ trigger: 'item', confine: true, backgroundColor: SURFACE(), borderColor: '#EDF2F7', borderWidth: 1,
170
+ padding: [6, 10], textStyle: { color: INK(), fontSize: 12, fontFamily: FONT },
171
+ extraCssText: 'border-radius:6px;box-shadow:0 4px 16px rgba(107,131,160,0.15)',
172
+ },
173
+ categoryAxis: {
174
+ axisLine: { show: true, lineStyle: { color: INK(), width: 1 } },
175
+ axisTick: { show: false },
176
+ axisLabel: { color: INK(), fontFamily: FONT, fontSize: 12, hideOverlap: true },
177
+ splitLine: { show: false },
178
+ },
179
+ valueAxis: { show: false, splitLine: { show: false } },
180
+ };
181
+ }
182
+ function merge(base, extra) {
183
+ if (Array.isArray(extra) || typeof extra !== 'object' || extra === null) return extra;
184
+ const out = { ...base };
185
+ for (const [key, value] of Object.entries(extra)) {
186
+ out[key] = typeof value === 'object' && value !== null && !Array.isArray(value) && typeof base?.[key] === 'object' ? merge(base[key], value) : value;
187
+ }
188
+ return out;
189
+ }
190
+ // form controls and buttons in Farseer's toolbar look: 28 px high, 12 px text, the focus ring drawn inside the
191
+ // control (so a control at the tile's edge never loses it), button text that never wraps, a long choice ending in …
192
+ // Farseer's own form controls and buttons (the app's input, select and button), the same in every tile
193
+ const CONTROL_CSS = `
194
+ .fs-control { font: 400 12px/20px ${FONT}; height: 32px; padding: 0 8px; border: 1px solid #EDF2F7; border-radius: 8px;
195
+ background-color: #EDF2F7; color: var(--code-tile-text); min-width: 0; max-width: 100%; box-sizing: border-box; outline: none;
196
+ overflow: hidden; white-space: nowrap; text-overflow: ellipsis; transition: border-color 100ms; }
197
+ select.fs-control { appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer;
198
+ 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");
199
+ background-repeat: no-repeat; background-position: right 8px center; background-size: 16px 16px; }
200
+ .fs-control:hover { border-color: #C1CEDE; }
201
+ .fs-control:focus, .fs-control:focus-visible { border-color: #1966FF; outline: 1px solid #1966FF; outline-offset: 0; }
202
+ .fs-control.fs-empty, .fs-control::placeholder { color: var(--code-tile-muted); }
203
+ .fs-control:disabled { background-color: var(--code-tile-background); color: var(--code-tile-muted); cursor: not-allowed; }
204
+ .fs-button { font: 500 12px/14px ${FONT}; height: 32px; min-width: 32px; padding: 0 12px; white-space: nowrap; flex: none; border: none;
205
+ border-radius: 8px; cursor: pointer; background-color: #1966FF; color: #FFFFFF; transition: background-color 100ms, color 100ms; }
206
+ .fs-button:hover { background-color: #0942B2; }
207
+ .fs-button.fs-secondary { background-color: #E8F0FF; color: #1966FF; }
208
+ .fs-button.fs-secondary:hover { background-color: #C5D9FF; }
209
+ .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; }
210
+ .fs-button.fs-tertiary:hover { background-color: #EDF2F7; }
211
+ .fs-button:disabled, .fs-button:disabled:hover { background-color: var(--code-tile-border); color: var(--code-tile-muted); box-shadow: none; cursor: not-allowed; }
212
+ .fs-button:focus-visible { outline: 1px solid var(--code-tile-text); outline-offset: 1px; }
213
+ .fs-button { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
214
+ .fs-chevron { width: 16px; height: 16px; flex: none; background-color: currentColor; -webkit-mask: center / 16px no-repeat; mask: center / 16px no-repeat; }
215
+ .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"); }
216
+ .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"); }
217
+ .fs-button.fs-icon-only { padding: 0; width: 32px; }`;
218
+ function control(tag, className = 'fs-control') {
219
+ if (!document.getElementById('fs-control-style')) {
220
+ const style = document.createElement('style');
221
+ style.id = 'fs-control-style';
222
+ style.textContent = CONTROL_CSS;
223
+ document.head.append(style);
224
+ }
225
+ const node = document.createElement(tag);
226
+ node.className = className;
227
+ return node;
228
+ }
229
+ // Farseer's table look (farseer-table.md): the same font, row height, header and rules as a table tile
230
+ const TABLE_CSS = `
231
+ .fs-table-wrap { width: fit-content; max-width: 100%; overflow: hidden; }
232
+ .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; }
233
+ .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; }
234
+ .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; }
235
+ .fs-table th:first-child, .fs-table td:first-child { text-align: left; }
236
+ .fs-table td:first-child { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
237
+ .fs-table tr.fs-total td { font-weight: 700; background-image: linear-gradient(var(--code-tile-text), var(--code-tile-text)); }
238
+ .fs-table tbody tr:hover td { background-color: color-mix(in srgb, var(--code-tile-muted) 8%, transparent); }
239
+ .fs-table .fs-good { color: ${GOOD}; } .fs-table .fs-bad { color: ${BAD}; } .fs-table .fs-muted { color: var(--code-tile-muted); }
240
+ .fs-table .fs-key { display: inline-block; width: 8px; height: 8px; margin-right: 8px; vertical-align: 0; }
241
+ .fs-table th.fs-AC, .fs-table tr:last-child td.fs-AC { background: linear-gradient(${AC}, ${AC}) bottom / 100% 3px no-repeat; }
242
+ .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; }
243
+ .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; }
244
+ .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; }`;
245
+ function farseerTable(head, rows) {
246
+ // head: [{ label, key?, scenario?: 'AC' | 'PL' | 'PY' | 'FC' }] (a scenario column gets the table tile's rule
247
+ // under its header and its last row: AC thick, PL double, PY light, FC dotted);
248
+ // rows: [{ cells: [text or node, …], total?, tone?: [null | 'good' | 'bad' | 'muted', …] }]
249
+ if (!document.getElementById('fs-table-style')) {
250
+ const style = document.createElement('style');
251
+ style.id = 'fs-table-style';
252
+ style.textContent = TABLE_CSS;
253
+ document.head.append(style);
254
+ }
255
+ const table = el('table');
256
+ table.className = 'fs-table';
257
+ const tr = table.createTHead().insertRow();
258
+ for (const h of head) {
259
+ const th = el('th');
260
+ if (h.scenario) th.className = `fs-${h.scenario}`;
261
+ if (h.key) th.append(h.key);
262
+ th.append(h.label);
263
+ tr.append(th);
264
+ }
265
+ const body = table.createTBody();
266
+ for (const row of rows) {
267
+ const line = body.insertRow();
268
+ if (row.total) line.className = 'fs-total';
269
+ row.cells.forEach((cell, i) => {
270
+ const td = line.insertCell();
271
+ const classes = [row.tone?.[i] ? `fs-${row.tone[i]}` : '', head[i]?.scenario ? `fs-${head[i].scenario}` : ''].filter(Boolean);
272
+ if (classes.length) td.className = classes.join(' ');
273
+ if (cell instanceof Node) td.append(cell);
274
+ else td.textContent = cell ?? '';
275
+ if (i === 0 && typeof cell === 'string') td.title = cell;
276
+ });
277
+ }
278
+ // 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
279
+ const box = el('div');
280
+ box.className = 'fs-table-wrap';
281
+ box.append(table);
282
+ return box;
283
+ }
284
+ // a variance number in a table, as the table tile shows it: red when it hurts, ink when it helps
285
+ const tone = (delta, costLine) => (delta === null || delta === undefined ? 'muted' : (costLine ? delta > 0 : delta < 0) ? 'bad' : null);
286
+ // small HTML helpers for titles, notes and states, all in the theme's ink
287
+ function el(tag, css, text) {
288
+ const node = document.createElement(tag);
289
+ if (css) node.style.cssText = css;
290
+ if (text !== undefined) node.textContent = text;
291
+ return node;
292
+ }
293
+ // the tile header exactly as Farseer draws a chart or table tile's name: 12 px ink, regular, 10 px above the content;
294
+ // a note under it in the footnote style (11 px muted). The frame already sits inside the card's 8 px padding, so the
295
+ // tile's own content has no outer padding of its own
296
+ const TITLE = 'font-size:12px;font-weight:400;line-height:1.25;color:var(--code-tile-text)';
297
+ const NOTE = 'font-size:11px;line-height:1.35;color:var(--code-tile-muted)'; // footnotes and units only
298
+ const PAGE = 'display:grid;gap:10px;height:100%;padding:0;align-content:start';
299
+ const MESSAGE = 'display:grid;place-items:center;height:100%;font-size:13px;color:var(--code-tile-muted)';
300
+ // one title line, the way Farseer names tiles ("Net sales by region, year to date (kEUR)"); the scope only when the
301
+ // filter bar narrows it. A note the reader needs goes to the bottom in the footnote style, never under the title
302
+ // a value that rounds to zero carries no sign: "-0,0%" and "+0" become "0,0%" and "0"
303
+ const unsigned0 = (text) => String(text).replace(/^[+\-−](?=0(?:[.,]0+)?(?:\s?%|\s?pp)?$)/, '');
304
+ function heading(wrap, title) {
305
+ wrap.append(el('div', TITLE, title));
306
+ }
307
+ function footnote(wrap, text) {
308
+ wrap.append(el('div', `${NOTE};padding-top:2px`, text));
309
+ }
310
+ // the scope the filter bar sets, for titles: nothing for the whole group, the company, or "2 companies"
311
+ // (bar is the picks() the body opened for the tables a title names)
312
+ function scope(table, all, one) {
313
+ const pick = bar.current[table];
314
+ if (!pick || pick.all) return all;
315
+ if (pick.members.length === 1) return pick.members[0];
316
+ return `${pick.members.length} ${one}`;
317
+ }
318
+ function period() {
319
+ const ytd = bar.current['Year to date'];
320
+ const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
321
+ if (!ytd || ytd.all || ytd.members.length !== 1) return 'year to date';
322
+ const m = Number(ytd.members[0].replace('M', ''));
323
+ return m === 1 ? 'January' : `January to ${MONTHS[m - 1]}`;
324
+ }
325
+ // --- end of the look ---
326
+ // two levels: net sales splits into COGS, each OpEx line and EBITDA; the way from EBITDA to net profit is a table
327
+ const OPEX = ['Personnel costs', 'Rent and facilities', 'Marketing', 'Other OpEx'];
328
+ const COST = AC_LIGHT; // costs leave the flow in the light AC tint
329
+
330
+ return (element) => {
331
+ const wrap = el('div', 'display:grid;grid-template-rows:auto 1fr;gap:10px;height:100%;padding:0');
332
+ heading(wrap, `Where net sales go, ${period()}${scope('Entity', '', 'companies') ? `, ${scope('Entity', '', 'companies')}` : ''} (kEUR)`);
333
+ const narrow = element.clientWidth < 640;
334
+ // the flow down to EBITDA, and the short chain from EBITDA to net profit as a table beside it, so the small
335
+ // part of the flow doesn't leave the right half of the tile empty
336
+ const body = el('div', `display:grid;grid-template-columns:${narrow ? 'minmax(0,1fr)' : 'minmax(0,620px) max-content'};justify-content:start;gap:32px;align-items:start;min-height:0`);
337
+ const chart = el('div', 'min-height:0');
338
+ const chain = el('div', 'display:grid;gap:6px');
339
+ body.append(chart, chain);
340
+ wrap.append(body);
341
+ element.replaceChildren(wrap);
342
+ const result = pl.current;
343
+ const ac = result.columns.findIndex((c) => c.label === 'AC');
344
+ const value = (label) => result.rows.find((r) => r.label === label)?.cells[ac]?.value ?? null;
345
+ if (result.rows.length === 0 || value('Net sales') === null) {
346
+ chart.replaceChildren(el('div', MESSAGE, pl.loading ? '' : pl.error?.message ?? 'No data for this selection'));
347
+ return;
348
+ }
349
+ const nodes = [];
350
+ const links = [];
351
+ const add = (name, value, color, depth, from) => {
352
+ if (value === null || value <= 0) return;
353
+ nodes.push({ name, value, depth, itemStyle: { color, borderWidth: 0 } });
354
+ if (from) links.push({ source: from, target: name, value });
355
+ };
356
+ add('Net sales', value('Net sales'), AC, 0);
357
+ add('EBITDA', value('EBITDA'), AC, 1, 'Net sales');
358
+ add('COGS', value('COGS'), COST, 1, 'Net sales');
359
+ for (const name of OPEX) add(name, value(name), COST, 1, 'Net sales');
360
+ // costs are stored positive; shown as what they take away
361
+ chain.append(farseerTable([{ label: '' }, { label: 'AC', scenario: 'AC' }], [
362
+ { cells: ['EBITDA', ctx.format(value('EBITDA'), '#,##0,')] },
363
+ { cells: ['D&A', ctx.format(-value('D&A'), '#,##0,')] },
364
+ { cells: ['Financial result', ctx.format(value('Financial result'), '#,##0,')] },
365
+ { cells: ['Income tax', ctx.format(-value('Income tax'), '#,##0,')] },
366
+ { total: true, cells: ['Net profit', ctx.format(value('Net profit'), '#,##0,')] },
367
+ ]));
368
+ if (narrow) chain.remove();
369
+ chart.style.height = `${element.clientHeight - 46}px`;
370
+ if (narrow) {
371
+ // too narrow for a flow whose labels stay apart: the same split as ranked bars, each part of net sales
372
+ const parts = nodes.filter((n) => !links.some((l) => l.source === n.name)).map((n) => ({ name: n.name, value: n.value, color: n.itemStyle.color }));
373
+ const { categoryAxis, valueAxis, ...base } = look();
374
+ drawChart(chart, merge(base, {
375
+ grid: { top: 4, right: 52 },
376
+ tooltip: { formatter: (p) => `<b>${ctx.format(p.value, '#,##0,')} kEUR</b><br>${p.name}` },
377
+ xAxis: merge(valueAxis, { type: 'value', axisLabel: { show: false }, splitLine: { show: false } }),
378
+ yAxis: merge(categoryAxis, { type: 'category', inverse: true, data: parts.map((p) => p.name), axisLabel: { color: INK(), fontSize: 12 } }),
379
+ series: [{
380
+ type: 'bar',
381
+ data: parts.map((p) => ({ value: p.value, itemStyle: { color: AC } })),
382
+ label: { ...LABEL, position: 'right', formatter: (p) => ctx.format(p.value, '#,##0,') },
383
+ }],
384
+ }));
385
+ return;
386
+ }
387
+ drawChart(chart, merge({ textStyle: look().textStyle, tooltip: look().tooltip }, {
388
+ tooltip: { formatter: (p) => `<b>${ctx.format(p.value, '#,##0,')} kEUR</b><br>${p.dataType === 'edge' ? `${p.data.source} → ${p.data.target}` : p.name}` },
389
+ series: [{
390
+ type: 'sankey', left: 0, right: 190, top: 4, bottom: 12, nodeAlign: 'justify', nodeWidth: 12, nodeGap: 14,
391
+ layoutIterations: 0, draggable: false, emphasis: { focus: 'adjacency' },
392
+ lineStyle: { color: 'target', opacity: 0.35, curveness: 0.5 },
393
+ label: {
394
+ color: INK(), fontSize: 11, formatter: (p) => `{name|${p.name}} {value|${ctx.format(p.value, '#,##0,')}}`,
395
+ rich: { name: { color: INK(), fontSize: 12 }, value: { color: INK(), fontSize: 12 } },
396
+ },
397
+ data: nodes,
398
+ links,
399
+ }],
400
+ }));
401
+ };
402
+ }