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,464 @@
1
+ // A form for OpEx requests of the department picked in the filter bar. It adds the amount to the cell of the
2
+ // department's Budget 2026 the form names, on top of what is there. Every list on the form comes from the model.
3
+ // IMPORT_PnL is the input the model's own P&L sheets write; a request goes to one month, never a year.
4
+ // Tile size: w24 h10; w14 h15 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 and the form
102
+ const bar = picks(['Entity', 'Year to date', 'Department']);
103
+ // the department's cost centres: the list follows the Department picked in the filter bar (a cost centre links to
104
+ // its department), the numbers are the full-year budget whatever the bar's period
105
+ const centres = readTable({
106
+ includeDashboardFilters: false,
107
+ rows: { table: 'Cost centre', includeDashboardFilters: true },
108
+ columns: [{ label: 'PL', formula: 'sum("OpEx", "Versions">"Budget 2026", "Reporting period">"Current year")', numberFormat: '#,##0,' }],
109
+ });
110
+ // the OpEx accounts are the ones with an OpEx budget
111
+ const accounts = readTable({
112
+ includeDashboardFilters: false,
113
+ rows: { table: 'P&L account' },
114
+ columns: [{ label: 'PL', formula: 'sum("OpEx", "Versions">"Budget 2026", "Reporting period">"Current year")' }],
115
+ });
116
+ const companies = ctx.query([{ type: 'DTABLE', table: 'Entity' }], { includeDashboardFilters: false, includeDashboardTimeline: false });
117
+ // the cell a request goes to: one month of Budget 2026, the input the model's P&L sheets write
118
+ const cellOf = (f) => `sum("IMPORT_PnL", "Versions">"Budget 2026", "Years">"Y2026", "Months">${quote(f.month)}, "Entity">${quote(f.entity)}, "Cost centre">${quote(f.centre)}, "P&L account">${quote(f.account)})`;
119
+ // the last request: reading the cell, then its write handle (ctx.write redraws the tile when it starts and settles)
120
+ let sent = null;
121
+ // --- The Farseer look (echarts-look.md, design.md): the same block in every tile ---
122
+ // AC: the dashboards' AC colour (SKILL.md section 2, The AC colour): #323232, or the company's
123
+ // darkest brand colour when it is dark enough, never an example's. AC_LIGHT is its PY tint.
124
+ // Everything else below is derived from them, so nothing else needs changing.
125
+ const AC = '#323232';
126
+ const AC_LIGHT = '#A6A6A6';
127
+ // mixes a colour with white: share 1 is the colour itself, 0 is white
128
+ function tint(hex, share) {
129
+ const n = parseInt(hex.slice(1), 16);
130
+ const mix = (c) => Math.round(c * share + 255 * (1 - share)).toString(16).padStart(2, '0');
131
+ return `#${mix(n >> 16)}${mix((n >> 8) & 255)}${mix(n & 255)}`.toUpperCase();
132
+ }
133
+ // a colour with almost no hue (graphite, grey): its ramp would turn a map grey, so magnitude takes Farseer blue
134
+ 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; };
135
+ const PALETTE = [AC, '#ED7D16', '#1BB5D7', '#8A2FE5', '#BFA812', '#E52FCD']; // identity: AC first, then distinct hues
136
+ const FILL = [AC_LIGHT, '#F5B87F', '#82D6E9', '#BF8DF1', '#DCCF7D', '#F18DE4']; // the light step, for large areas
137
+ // magnitude (maps, heatmaps), light to dark: steps of AC, or Farseer blue when AC is a grey
138
+ const RAMP = isGrey(AC) ? ['#81A9FF', '#457DFF', '#0D4BC2', '#043288'] : [0.45, 0.65, 0.8, 1].map((s) => tint(AC, s));
139
+ // light tints of AC for large areas that need ink text (treemap groups), clearly apart from each other
140
+ // (from Farseer blue when AC is a grey, as the ramp: grey tints would make a grey block)
141
+ const TINTS = [0.52, 0.37, 0.24, 0.11].map((s) => tint(isGrey(AC) ? '#043288' : AC, s));
142
+ const TRACK = tint(AC, 0.12); // the unfilled part of a gauge
143
+ const PRIMARY = '#1A66FF'; // Farseer's own primary button, not a data colour
144
+ const GOOD = '#0CB955';
145
+ const BAD = '#E21E09';
146
+ const INK = () => ctx.theme.tokens?.text ?? '#020810';
147
+ const MUTED = () => ctx.theme.tokens?.muted ?? '#687C95';
148
+ const LINE = () => ctx.theme.tokens?.border ?? '#E6EBF2';
149
+ const SURFACE = () => ctx.theme.tokens?.background ?? '#FFFFFF';
150
+ const FONT = 'Inter, system-ui, sans-serif';
151
+ let drawnOnce = false;
152
+ // draws one echarts chart in the look; the first chart that draws ends the entrance animation for the rest
153
+ function drawChart(element, option) {
154
+ ctx.charts.echarts(element, option);
155
+ drawnOnce = true;
156
+ }
157
+ // the chart tile's look, measured from it: square bars, 12 px ink labels with a surface-coloured halo, an ink
158
+ // category axis with ticks, no value axis or gridlines, the legend at the bottom, its tooltip and margins
159
+ const LABEL = { show: true, fontFamily: FONT, fontSize: 12, color: INK(), textBorderColor: SURFACE(), textBorderWidth: 4 };
160
+ function look() {
161
+ return {
162
+ animation: !drawnOnce,
163
+ animationDuration: 500,
164
+ textStyle: { fontFamily: FONT, fontSize: 12, color: INK() },
165
+ grid: { left: 10, right: 10, top: 20, bottom: 10, containLabel: true },
166
+ legend: { bottom: 0, textStyle: { fontFamily: FONT, color: INK() } },
167
+ tooltip: {
168
+ trigger: 'item', confine: true, backgroundColor: SURFACE(), borderColor: '#EDF2F7', borderWidth: 1,
169
+ padding: [6, 10], textStyle: { color: INK(), fontSize: 12, fontFamily: FONT },
170
+ extraCssText: 'border-radius:6px;box-shadow:0 4px 16px rgba(107,131,160,0.15)',
171
+ },
172
+ categoryAxis: {
173
+ axisLine: { show: true, lineStyle: { color: INK(), width: 1 } },
174
+ axisTick: { show: false },
175
+ axisLabel: { color: INK(), fontFamily: FONT, fontSize: 12, hideOverlap: true },
176
+ splitLine: { show: false },
177
+ },
178
+ valueAxis: { show: false, splitLine: { show: false } },
179
+ };
180
+ }
181
+ function merge(base, extra) {
182
+ if (Array.isArray(extra) || typeof extra !== 'object' || extra === null) return extra;
183
+ const out = { ...base };
184
+ for (const [key, value] of Object.entries(extra)) {
185
+ out[key] = typeof value === 'object' && value !== null && !Array.isArray(value) && typeof base?.[key] === 'object' ? merge(base[key], value) : value;
186
+ }
187
+ return out;
188
+ }
189
+ // form controls and buttons in Farseer's toolbar look: 28 px high, 12 px text, the focus ring drawn inside the
190
+ // control (so a control at the tile's edge never loses it), button text that never wraps, a long choice ending in …
191
+ // Farseer's own form controls and buttons (the app's input, select and button), the same in every tile
192
+ const CONTROL_CSS = `
193
+ .fs-control { font: 400 12px/20px ${FONT}; height: 32px; padding: 0 8px; border: 1px solid #EDF2F7; border-radius: 8px;
194
+ background-color: #EDF2F7; color: var(--code-tile-text); min-width: 0; max-width: 100%; box-sizing: border-box; outline: none;
195
+ overflow: hidden; white-space: nowrap; text-overflow: ellipsis; transition: border-color 100ms; }
196
+ select.fs-control { appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer;
197
+ 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");
198
+ background-repeat: no-repeat; background-position: right 8px center; background-size: 16px 16px; }
199
+ .fs-control:hover { border-color: #C1CEDE; }
200
+ .fs-control:focus, .fs-control:focus-visible { border-color: #1966FF; outline: 1px solid #1966FF; outline-offset: 0; }
201
+ .fs-control.fs-empty, .fs-control::placeholder { color: var(--code-tile-muted); }
202
+ .fs-control:disabled { background-color: var(--code-tile-background); color: var(--code-tile-muted); cursor: not-allowed; }
203
+ .fs-button { font: 500 12px/14px ${FONT}; height: 32px; min-width: 32px; padding: 0 12px; white-space: nowrap; flex: none; border: none;
204
+ border-radius: 8px; cursor: pointer; background-color: #1966FF; color: #FFFFFF; transition: background-color 100ms, color 100ms; }
205
+ .fs-button:hover { background-color: #0942B2; }
206
+ .fs-button.fs-secondary { background-color: #E8F0FF; color: #1966FF; }
207
+ .fs-button.fs-secondary:hover { background-color: #C5D9FF; }
208
+ .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; }
209
+ .fs-button.fs-tertiary:hover { background-color: #EDF2F7; }
210
+ .fs-button:disabled, .fs-button:disabled:hover { background-color: var(--code-tile-border); color: var(--code-tile-muted); box-shadow: none; cursor: not-allowed; }
211
+ .fs-button:focus-visible { outline: 1px solid var(--code-tile-text); outline-offset: 1px; }
212
+ .fs-button { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
213
+ .fs-chevron { width: 16px; height: 16px; flex: none; background-color: currentColor; -webkit-mask: center / 16px no-repeat; mask: center / 16px no-repeat; }
214
+ .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"); }
215
+ .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"); }
216
+ .fs-button.fs-icon-only { padding: 0; width: 32px; }`;
217
+ function control(tag, className = 'fs-control') {
218
+ if (!document.getElementById('fs-control-style')) {
219
+ const style = document.createElement('style');
220
+ style.id = 'fs-control-style';
221
+ style.textContent = CONTROL_CSS;
222
+ document.head.append(style);
223
+ }
224
+ const node = document.createElement(tag);
225
+ node.className = className;
226
+ return node;
227
+ }
228
+ // Farseer's table look (farseer-table.md): the same font, row height, header and rules as a table tile
229
+ const TABLE_CSS = `
230
+ .fs-table-wrap { width: fit-content; max-width: 100%; overflow: hidden; }
231
+ .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; }
232
+ .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; }
233
+ .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; }
234
+ .fs-table th:first-child, .fs-table td:first-child { text-align: left; }
235
+ .fs-table td:first-child { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
236
+ .fs-table tr.fs-total td { font-weight: 700; background-image: linear-gradient(var(--code-tile-text), var(--code-tile-text)); }
237
+ .fs-table tbody tr:hover td { background-color: color-mix(in srgb, var(--code-tile-muted) 8%, transparent); }
238
+ .fs-table .fs-good { color: ${GOOD}; } .fs-table .fs-bad { color: ${BAD}; } .fs-table .fs-muted { color: var(--code-tile-muted); }
239
+ .fs-table .fs-key { display: inline-block; width: 8px; height: 8px; margin-right: 8px; vertical-align: 0; }
240
+ .fs-table th.fs-AC, .fs-table tr:last-child td.fs-AC { background: linear-gradient(${AC}, ${AC}) bottom / 100% 3px no-repeat; }
241
+ .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; }
242
+ .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; }
243
+ .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; }`;
244
+ function farseerTable(head, rows) {
245
+ // head: [{ label, key?, scenario?: 'AC' | 'PL' | 'PY' | 'FC' }] (a scenario column gets the table tile's rule
246
+ // under its header and its last row: AC thick, PL double, PY light, FC dotted);
247
+ // rows: [{ cells: [text or node, …], total?, tone?: [null | 'good' | 'bad' | 'muted', …] }]
248
+ if (!document.getElementById('fs-table-style')) {
249
+ const style = document.createElement('style');
250
+ style.id = 'fs-table-style';
251
+ style.textContent = TABLE_CSS;
252
+ document.head.append(style);
253
+ }
254
+ const table = el('table');
255
+ table.className = 'fs-table';
256
+ const tr = table.createTHead().insertRow();
257
+ for (const h of head) {
258
+ const th = el('th');
259
+ if (h.scenario) th.className = `fs-${h.scenario}`;
260
+ if (h.key) th.append(h.key);
261
+ th.append(h.label);
262
+ tr.append(th);
263
+ }
264
+ const body = table.createTBody();
265
+ for (const row of rows) {
266
+ const line = body.insertRow();
267
+ if (row.total) line.className = 'fs-total';
268
+ row.cells.forEach((cell, i) => {
269
+ const td = line.insertCell();
270
+ const classes = [row.tone?.[i] ? `fs-${row.tone[i]}` : '', head[i]?.scenario ? `fs-${head[i].scenario}` : ''].filter(Boolean);
271
+ if (classes.length) td.className = classes.join(' ');
272
+ if (cell instanceof Node) td.append(cell);
273
+ else td.textContent = cell ?? '';
274
+ if (i === 0 && typeof cell === 'string') td.title = cell;
275
+ });
276
+ }
277
+ // 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
278
+ const box = el('div');
279
+ box.className = 'fs-table-wrap';
280
+ box.append(table);
281
+ return box;
282
+ }
283
+ // a variance number in a table, as the table tile shows it: red when it hurts, ink when it helps
284
+ const tone = (delta, costLine) => (delta === null || delta === undefined ? 'muted' : (costLine ? delta > 0 : delta < 0) ? 'bad' : null);
285
+ // small HTML helpers for titles, notes and states, all in the theme's ink
286
+ function el(tag, css, text) {
287
+ const node = document.createElement(tag);
288
+ if (css) node.style.cssText = css;
289
+ if (text !== undefined) node.textContent = text;
290
+ return node;
291
+ }
292
+ // the tile header exactly as Farseer draws a chart or table tile's name: 12 px ink, regular, 10 px above the content;
293
+ // a note under it in the footnote style (11 px muted). The frame already sits inside the card's 8 px padding, so the
294
+ // tile's own content has no outer padding of its own
295
+ const TITLE = 'font-size:12px;font-weight:400;line-height:1.25;color:var(--code-tile-text)';
296
+ const NOTE = 'font-size:11px;line-height:1.35;color:var(--code-tile-muted)'; // footnotes and units only
297
+ const PAGE = 'display:grid;gap:10px;height:100%;padding:0;align-content:start';
298
+ const MESSAGE = 'display:grid;place-items:center;height:100%;font-size:13px;color:var(--code-tile-muted)';
299
+ // one title line, the way Farseer names tiles ("Net sales by region, year to date (kEUR)"); the scope only when the
300
+ // filter bar narrows it. A note the reader needs goes to the bottom in the footnote style, never under the title
301
+ // a value that rounds to zero carries no sign: "-0,0%" and "+0" become "0,0%" and "0"
302
+ const unsigned0 = (text) => String(text).replace(/^[+\-−](?=0(?:[.,]0+)?(?:\s?%|\s?pp)?$)/, '');
303
+ function heading(wrap, title) {
304
+ wrap.append(el('div', TITLE, title));
305
+ }
306
+ function footnote(wrap, text) {
307
+ wrap.append(el('div', `${NOTE};padding-top:2px`, text));
308
+ }
309
+ // the scope the filter bar sets, for titles: nothing for the whole group, the company, or "2 companies"
310
+ // (bar is the picks() the body opened for the tables a title names)
311
+ function scope(table, all, one) {
312
+ const pick = bar.current[table];
313
+ if (!pick || pick.all) return all;
314
+ if (pick.members.length === 1) return pick.members[0];
315
+ return `${pick.members.length} ${one}`;
316
+ }
317
+ function period() {
318
+ const ytd = bar.current['Year to date'];
319
+ const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
320
+ if (!ytd || ytd.all || ytd.members.length !== 1) return 'year to date';
321
+ const m = Number(ytd.members[0].replace('M', ''));
322
+ return m === 1 ? 'January' : `January to ${MONTHS[m - 1]}`;
323
+ }
324
+ // --- end of the look ---
325
+ const form = ctx.snapshot('form', { centre: '', account: '', entity: '', month: '', amount: '' });
326
+ const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
327
+ const withValue = (result, column) => {
328
+ const i = result.columns.findIndex((c) => c.label === column);
329
+ return i < 0 ? [] : result.rows.filter((row) => row.cells[i]?.value !== null && row.cells[i]?.value !== undefined).map((row) => ({ name: row.label, value: row.cells[i].value }));
330
+ };
331
+
332
+ let refresh = () => {};
333
+ // every field the status line asks for is required, so the button and the hint always agree
334
+ // a number the viewer typed, read in their own locale (en-US "13,000.5", de-DE "13.000,5"); null when the field is empty
335
+ function parseNumber(text) {
336
+ const parts = new Intl.NumberFormat(ctx.theme.numberLocale || 'en-US').formatToParts(12345.6);
337
+ const group = parts.find((p) => p.type === 'group')?.value ?? ',';
338
+ const decimal = parts.find((p) => p.type === 'decimal')?.value ?? '.';
339
+ const clean = String(text).trim().split(group).join('').replace(/\s/g, '').replace(decimal, '.');
340
+ return clean === '' ? null : Number(clean);
341
+ }
342
+ const ready = (f) => Boolean(f.centre && f.account && f.entity && f.month && parseNumber(f.amount) > 0);
343
+
344
+ // form controls in the tile's look: one height, a quiet border, a muted prompt until something is chosen
345
+ const FORM_CSS = `
346
+ .fs-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px 12px; }
347
+ .fs-form label { display: grid; gap: 4px; font-size: 12px; font-weight: 400; color: var(--code-tile-text); min-width: 0; }
348
+ .fs-form .fs-control { width: 100%; }
349
+ .fs-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px 12px; }`;
350
+ function style() {
351
+ if (document.getElementById('fs-form-style')) return;
352
+ const node = document.createElement('style');
353
+ node.id = 'fs-form-style';
354
+ node.textContent = FORM_CSS;
355
+ document.head.append(node);
356
+ }
357
+ function field(label, control) {
358
+ const box = el('label');
359
+ box.append(label, control);
360
+ return box;
361
+ }
362
+ function select(options, key, prompt) {
363
+ const s = control('select');
364
+ s.id = `field-${key}`;
365
+ s.add(new Option(prompt, ''));
366
+ for (const [value, text] of options) s.add(new Option(text, value, false, value === form.value[key]));
367
+ s.classList.toggle('fs-empty', !form.value[key]);
368
+ s.title = s.selectedOptions[0]?.text ?? '';
369
+ s.onchange = () => {
370
+ form.set({ ...form.value, [key]: s.value });
371
+ ctx.render();
372
+ };
373
+ return s;
374
+ }
375
+ function input(key, placeholder, mode) {
376
+ const i = control('input');
377
+ i.id = `field-${key}`;
378
+ i.value = form.value[key];
379
+ i.placeholder = placeholder;
380
+ if (mode) i.inputMode = mode;
381
+ // typing must not redraw (that drops the focus); only the button follows
382
+ i.oninput = () => {
383
+ form.set({ ...form.value, [key]: i.value });
384
+ refresh();
385
+ };
386
+ return i;
387
+ }
388
+
389
+ // what the status line says about the last request, or what is still missing
390
+ function said(f) {
391
+ if (sent?.failed) return `The request was not added: ${sent.failed}`;
392
+ if (sent?.reading) return 'Reading the current budget…';
393
+ if (sent?.handle?.loading) return 'Adding the request…';
394
+ if (sent?.handle?.error) return `The request was not added: ${sent.handle.error.message}`;
395
+ if (sent?.handle) return `Added: ${ctx.format(sent.before, '#,##0')} + ${ctx.format(sent.amount, '#,##0')} = ${ctx.format(sent.before + sent.amount, '#,##0')} EUR in ${MONTHS[Number(sent.f.month.slice(1)) - 1]} 2026, ${sent.f.centre}, ${sent.f.account}.`;
396
+ return ready(f) ? '' : 'Fill in every field to add the request';
397
+ }
398
+
399
+ return (element) => {
400
+ style();
401
+ const wrap = el('div', 'display:grid;gap:12px;padding:0;align-content:start');
402
+ const pick = bar.current.Department;
403
+ const department = pick && !pick.all && pick.members.length === 1 ? pick.members[0] : null;
404
+ heading(wrap, department ? `OpEx request for ${department}, Budget 2026` : 'OpEx request, Budget 2026');
405
+ if (!department) {
406
+ wrap.append(el('div', 'font-size:13px;color:var(--code-tile-muted)', bar.loading ? '' : 'Pick one department in the filter bar to request OpEx for it.'));
407
+ element.replaceChildren(wrap);
408
+ return;
409
+ }
410
+ const own = withValue(centres.current, 'PL');
411
+ // the form and its budget table wrap: the table goes under the form when both don't fit side by side
412
+ const layout = el('div', 'display:flex;flex-wrap:wrap;gap:16px 24px;align-items:flex-start');
413
+ const left = el('div', 'display:grid;gap:12px;flex:1 1 340px;min-width:0');
414
+ const grid = el('div');
415
+ grid.className = 'fs-form';
416
+ grid.append(
417
+ field('Cost centre', select(own.map((c) => [c.name, c.name]), 'centre', 'Choose a cost centre')),
418
+ field('Account', select(withValue(accounts.current, 'PL').map((a) => [a.name, a.name]), 'account', 'Choose an account')),
419
+ field('Company', select(namesOf(companies.current[0]).map((c) => [c, c]), 'entity', 'Choose a company')),
420
+ field('Month', select(MONTHS.map((m, i) => [`M${i + 1}`, `${m} 2026`]), 'month', 'Choose a month')),
421
+ field('Amount (EUR)', input('amount', 'Amount in EUR', 'decimal')),
422
+ );
423
+ const busy = Boolean(sent?.reading || sent?.handle?.loading);
424
+ const actions = el('div');
425
+ actions.className = 'fs-actions';
426
+ const status = el('span', 'font-size:12px;color:var(--code-tile-muted)', said(form.value));
427
+ status.setAttribute('role', 'status');
428
+ const button = control('button', 'fs-button');
429
+ button.textContent = 'Add to the budget';
430
+ refresh = () => {
431
+ button.disabled = busy || !ready(form.value);
432
+ status.textContent = said(form.value);
433
+ };
434
+ refresh();
435
+ button.onclick = () => {
436
+ const f = form.value;
437
+ if (!ready(f)) return;
438
+ const amount = parseNumber(f.amount);
439
+ const formula = cellOf(f);
440
+ sent = { reading: true, f, amount };
441
+ refresh();
442
+ // read the cell in the click, right before the write, so the request adds to what is there now
443
+ ctx.read([{ type: 'VARIABLE', formula }], { includeDashboardFilters: false, includeDashboardTimeline: false }).then(
444
+ ([cell]) => {
445
+ const before = cell.value ?? 0;
446
+ sent = { f, amount, before, handle: ctx.write({ type: 'VARIABLE', formula, value: before + amount }) };
447
+ form.set({ ...f, amount: '' });
448
+ },
449
+ (failure) => {
450
+ sent = { failed: failure.message };
451
+ ctx.render();
452
+ },
453
+ );
454
+ };
455
+ actions.append(status, button);
456
+ left.append(grid, actions);
457
+ // the budget the request adds to, per cost centre, in Farseer's table look
458
+ const context = el('div', 'display:grid;gap:6px;flex:0 0 auto;max-width:100%');
459
+ context.append(farseerTable([{ label: 'Full-year budget' }, { label: 'PL', scenario: 'PL' }], own.map((c) => ({ cells: [c.name, ctx.format(c.value, '#,##0,')] }))));
460
+ layout.append(left, context);
461
+ wrap.append(layout);
462
+ element.replaceChildren(wrap);
463
+ };
464
+ }
@@ -0,0 +1,98 @@
1
+ # Tables in the Farseer look
2
+
3
+ A table whose job is to be read on its own belongs in a table tile (`farseer-dashboards`): it has the client's formats, sorting, drill and export, and nobody needs code to change it. Propose that first. A table goes into a Code tile only beside something a table tile can't hold: a chart with a fixed colour per member, a button, a form.
4
+
5
+ There it must look exactly like a table tile, not like a table someone styled by eye. These are the table tile's own values, measured from it in the app:
6
+
7
+ | Part | Table tile |
8
+ |---|---|
9
+ | Font | Inter 12 px, line height 1.2, weight 400; ink `--code-tile-text` |
10
+ | Row | 24 px high, no vertical padding, text centred vertically |
11
+ | Header | the column name in 12 px weight 400 (not bold, not uppercase), a 1 px ink line under it |
12
+ | Rules | a 1 px line under every row in `--code-tile-border`; under a total row the line is ink and the row is bold |
13
+ | Columns | the name left, every number right; columns separated by a 12 px gap that the lines also break at; no column wider than its content |
14
+ | Numbers | the column's own format through `ctx.format`; aligned figures |
15
+ | Scenario columns | the table tile marks a scenario column with a rule under its header and its last row: AC a 3 px line in the AC colour, PL a double line, PY a 3 px line in AC light, FC dotted. `head[i].scenario` does it. The rules are painted as backgrounds, not borders, so a thick rule doesn't push its header text up out of line with the other headers |
16
+ | Variances | red when the variance hurts (by the line's polarity), ink when it helps; green only on marks (bars, pins), not on table text |
17
+ | Width | the table is as wide as its content (`width: max-content`), never stretched across a wide tile |
18
+ | Hover | the row behind the pointer takes a faint wash |
19
+
20
+ Paste this into the body once and call `farseerTable` wherever a table is drawn. It writes its own `<style>` into the frame the first time (`FONT`, `GOOD` and `BAD` are the constants from `echarts-look.md` and `design.md`; `el` is the small element helper the examples carry):
21
+
22
+ ```js
23
+ // Farseer's table look (farseer-table.md): the same font, row height, header and rules as a table tile
24
+ const TABLE_CSS = `
25
+ .fs-table-wrap { width: fit-content; max-width: 100%; overflow: hidden; }
26
+ .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; }
27
+ .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; }
28
+ .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; }
29
+ .fs-table th:first-child, .fs-table td:first-child { text-align: left; }
30
+ .fs-table td:first-child { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
31
+ .fs-table tr.fs-total td { font-weight: 700; background-image: linear-gradient(var(--code-tile-text), var(--code-tile-text)); }
32
+ .fs-table tbody tr:hover td { background-color: color-mix(in srgb, var(--code-tile-muted) 8%, transparent); }
33
+ .fs-table .fs-good { color: ${GOOD}; } .fs-table .fs-bad { color: ${BAD}; } .fs-table .fs-muted { color: var(--code-tile-muted); }
34
+ .fs-table .fs-key { display: inline-block; width: 8px; height: 8px; margin-right: 8px; vertical-align: 0; }
35
+ .fs-table th.fs-AC, .fs-table tr:last-child td.fs-AC { background: linear-gradient(${AC}, ${AC}) bottom / 100% 3px no-repeat; }
36
+ .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; }
37
+ .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; }
38
+ .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; }`;
39
+ function farseerTable(head, rows) {
40
+ // head: [{ label, key?, scenario?: 'AC' | 'PL' | 'PY' | 'FC' }] (a scenario column gets the table tile's rule
41
+ // under its header and its last row: AC thick, PL double, PY light, FC dotted);
42
+ // rows: [{ cells: [text or node, …], total?, tone?: [null | 'good' | 'bad' | 'muted', …] }]
43
+ if (!document.getElementById('fs-table-style')) {
44
+ const style = document.createElement('style');
45
+ style.id = 'fs-table-style';
46
+ style.textContent = TABLE_CSS;
47
+ document.head.append(style);
48
+ }
49
+ const table = el('table');
50
+ table.className = 'fs-table';
51
+ const tr = table.createTHead().insertRow();
52
+ for (const h of head) {
53
+ const th = el('th');
54
+ if (h.scenario) th.className = `fs-${h.scenario}`;
55
+ if (h.key) th.append(h.key);
56
+ th.append(h.label);
57
+ tr.append(th);
58
+ }
59
+ const body = table.createTBody();
60
+ for (const row of rows) {
61
+ const line = body.insertRow();
62
+ if (row.total) line.className = 'fs-total';
63
+ row.cells.forEach((cell, i) => {
64
+ const td = line.insertCell();
65
+ const classes = [row.tone?.[i] ? `fs-${row.tone[i]}` : '', head[i]?.scenario ? `fs-${head[i].scenario}` : ''].filter(Boolean);
66
+ if (classes.length) td.className = classes.join(' ');
67
+ if (cell instanceof Node) td.append(cell);
68
+ else td.textContent = cell ?? '';
69
+ if (i === 0 && typeof cell === 'string') td.title = cell;
70
+ });
71
+ }
72
+ // 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
73
+ const box = el('div');
74
+ box.className = 'fs-table-wrap';
75
+ box.append(table);
76
+ return box;
77
+ }
78
+ // a variance number in a table, as the table tile shows it: red when it hurts, ink when it helps
79
+ const tone = (delta, costLine) => (delta === null || delta === undefined ? 'muted' : (costLine ? delta > 0 : delta < 0) ? 'bad' : null);
80
+ ```
81
+
82
+ Use it like this:
83
+
84
+ ```js
85
+ wrap.append(farseerTable(
86
+ [{ label: 'kEUR' }, { label: 'AC' }, { label: 'PL' }, { label: 'ΔPL' }],
87
+ rows.map((row) => ({
88
+ total: row.label === 'EBITDA',
89
+ cells: [row.label, ctx.format(ac, '#,##0,'), ctx.format(pl, '#,##0,'), ctx.format(ac - pl, '+#,##0,;-#,##0,')],
90
+ tone: [null, null, null, tone(ac - pl, isCostLine)],
91
+ })),
92
+ ));
93
+ ```
94
+
95
+ - A cell can be a node: a swatch and a name (`el('span')` with a coloured 8 px square before the text) keys a member's colour to the charts beside the table.
96
+ - Every scenario column takes `scenario: 'AC' | 'PL' | 'PY' | 'FC'` in its header entry, so it carries the table tile's notation; a variance column (ΔPL, ΔPY) keeps the thin ink rule. The row-label column's header is empty; the unit is in the tile's title.
97
+ - Bars inside a table are not drawn in HTML. Draw the ranking as a chart (`ctx.charts.farseer`, `BAR_CHART` with `layout: 'VERTICAL'`) beside the table, with the rows in the same order, or leave the bars out.
98
+ - Size the tile from the rows: 24 px a row, plus the header, the title and 24 px, divided by 30 and rounded up.