@masterteam/dashboard-builder 0.0.71 → 0.0.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,349 +1,398 @@
1
- # @masterteam/dashboard-builder
2
-
3
- Dashboard Builder components and services for Angular 21+ with Tailwind CSS 4.
4
- The package supports authoring, saving, loading, and rendering dashboards with
5
- charts, header widgets, topbar widgets, metadata-driven data sources, source
6
- links, and responsive ECharts output.
7
-
8
- ## Features
9
-
10
- - Multilingual dashboard item titles stored as `clientConfig.title.en/ar`.
11
- - Header, topbar, and chart item title editing in builder mode.
12
- - Host-interceptor-owned save messages, with automatic saves marked silent.
13
- - Registry-driven chart query schemas, including safe preview states for
14
- incomplete draft charts.
15
- - Stacked-bar query fields switch between auto-stack and manual-stack modes so
16
- only the relevant stack property selector is displayed and emitted.
17
- - Quick Manage style changes stay local in the drawer until Apply, with an
18
- isolated Preview tab for checking the edited chart config before the dashboard
19
- canvas is updated.
20
- - Chart header icons provide preset-based appearance and placement controls,
21
- including independent standalone/group visibility and grouped icon-only mode.
22
- - Timeline multi-level queries persist per-level `extraProperties` and still
23
- read legacy `extras` fields. Open timeline detail popovers close when the
24
- page, dashboard, or timeline scrolls outside the overlay, while the detail
25
- panel's own scrolling remains available.
26
- - PhaseGate Table uses a dedicated semantic-role editor and sends every
27
- configured runtime property in one deduplicated backend projection.
28
- - Ring Gauge with Formula accepts either `valueProperty` or `formula` for each
29
- series, exposes no Group By or Extra Properties controls, and renders legacy
30
- `values[].bars[]` responses through the concentric-ring gauge adapter.
31
- - Every GeneralQuery capability that includes `formula` exposes a visible
32
- per-series Show/Hide advanced settings action and a Formula Builder scoped to
33
- that series; formula availability is schema-driven rather than chart-specific.
34
- - Selected-property chips in dashboard query editors can be removed inline.
35
- - Properties/card-list items normalize null Percentage values to `0` with an
36
- empty progress track and never inherit a sibling card's runtime percentage.
37
- - Duplicated charts receive a new local dashboard identity, omit the source
38
- link/component IDs so the next save creates a new backend chart, and persist
39
- `duplicatedFrom` as provenance to the source dashboard identity.
40
- - Workspace-aware metadata loading for modules and properties.
41
- - A dedicated chart Filters action separates viewer-facing filter controls and
42
- built-in conditions from datasource configuration, using shared `mt-*` form
43
- fields throughout the condition editor.
44
- - Navigation actions expose a `Navigation Target` selector. Both page and
45
- entity navigation default to the current tab and can explicitly open in a
46
- new tab through `action.config.navigationTarget`.
47
- - Progress Update cards render activity HTML through ngx-quill's read-only
48
- renderer, preserving the rich-text size, color, font, alignment, direction,
49
- and semantic formatting configured in the source editor.
50
- - Persisted dashboards can be deleted from the page-settings drawer after a
51
- named, danger-styled confirmation; successful deletion returns the host to
52
- its dashboard list while standalone builders keep deletion unavailable.
53
- - Module multi-select serialized as selectors such as `Level:1,2,3`.
54
- - Source-link chaining with previous result fields, relationship fields, and the
55
- `Parent` option exposed to child-level configuration.
56
- - Distinct aggregation normalization from legacy `DisticntCount` to
57
- `DistinctCount`.
58
- - Container-aware ECharts option mapping for compact dashboard grid cells,
59
- including shared legend placement for donut, pie, bar, line, stacked bar, and
60
- other ECharts-based charts. Pie/donut radius, center, and slice-label geometry
61
- stay handler-owned to match the old dashboard builder; the shared EChart
62
- wrapper reserves the same chart area as the old wrapper and does not apply
63
- pie-specific responsive overrides. Native ECharts legend rendering stays
64
- authoritative; the wrapper maps legend dimensions before grid offsets and
65
- clamps saved percentage grid values against the current card pixels so stacked
66
- bar legends keep reserved space after resize. Donut slice labels are hidden so
67
- category names stay in the legend instead of being drawn over the ring. Pie
68
- legend vertical alignment applies only to left/right legends, so old saved
69
- vertical-align values do not move the default bottom legend into the chart
70
- body. Compact bar and line charts preserve their configured value-label
71
- visibility instead of hiding labels when the card height crosses a responsive
72
- breakpoint.
73
-
74
- ## Installation
75
-
76
- ```bash
77
- pnpm add @masterteam/dashboard-builder
78
- ```
79
-
80
- ## Usage
81
-
82
- ```typescript
83
- import { Component } from "@angular/core";
84
- import { DashboardBuilder } from "@masterteam/dashboard-builder";
85
-
86
- @Component({
87
- imports: [DashboardBuilder],
88
- template: ` <mt-dashboard-builder [services]="['pplus', 'splus']" (onSave)="saveDashboard()" /> `,
89
- })
90
- export class MyComponent {
91
- saveDashboard(): void {
92
- // React to a completed explicit save.
93
- }
94
- }
95
- ```
96
-
97
- ## Metadata Contract
98
-
99
- Hosts must provide the dashboard metadata endpoints used by
100
- `DashboardBuilderService`:
101
-
102
- - `GET metadata/workspaces` returns workspace options:
103
- `WorkspaceOption { id: string | number; name: string }`.
104
- - `GET metadata/modules/tree` accepts `services`, `workspaceId`, and
105
- `includeValues`. Returned module groups, items, and values may include
106
- `workspaceId` for client-side filtering.
107
- - `POST metadata/modules/properties` accepts `items` and optional
108
- `workspaceId`. Each request item may also include `workspaceId`.
109
-
110
- When a workspace changes, the builder clears selections and source links that no
111
- longer belong to the selected workspace.
112
-
113
- ## Snapshot Query Contract
114
-
115
- Snapshot charts distinguish the selected Level schema from the concrete Level
116
- record whose history is requested:
117
-
118
- ```typescript
119
- interface SnapshotQuery {
120
- workspaceSelector?: string | null;
121
- levelId: number; // schema id used to load record options
122
- levelDataId: number; // record id sent to GetSnapShotInfo
123
- snapshotTargetVersion: 2; // prevents schema ids from using the legacy fallback
124
- timeFrame: "yearly" | "monthly" | "weekly";
125
- year: number | "{{currentYear}}";
126
- getAveragePerPeriod?: boolean;
127
- selectedProperties: string[];
128
- }
129
- ```
130
-
131
- After a Level is selected, the builder requests its records through
132
- `POST fetch/query` with:
133
-
134
- ```typescript
135
- {
136
- contextKey: `level:${levelId}`;
137
- projection: "Card";
138
- display: {
139
- areas: ["card"];
140
- }
141
- }
142
- ```
143
-
144
- This authoring request deliberately omits `includeState`. Record options map
145
- directly from `data.records[].id/name`. Runtime calls
146
- `POST dashboards/{apiVersion}GetSnapShotInfo/{levelDataId}/{timeFrame}?year={year}`
147
- with `{ AvgPerPeriod, dashboardId }`; the schema `levelId` must not be used in
148
- that URL. Supported selected-property
149
- keys are `plannedProgress`, `actualProgress`, `budget`, `baselineProgress`,
150
- `spent`, `remaining`, and `paymentPlan`.
151
-
152
- ## Axis Label Wrapping Contract
153
-
154
- Bar and stacked-bar category labels preserve their original casing and wrap
155
- normal spaces, underscores, existing line breaks, and single tokens that exceed
156
- the selected character limit. Runtime keeps all generated lines visible and
157
- sets `hideOverlap: false`; the shared ECharts responsive layout still owns the
158
- available label width and grid containment.
159
-
160
- The persisted controls live under `clientConfig.barConfigOverride` and
161
- `clientConfig.stackBarConfigOverride`:
162
-
163
- ```typescript
164
- {
165
- axisLabelWrapMode: "characters" | "words" | "none";
166
- maxCharsPerLine?: 8 | 12 | 16 | 20 | 24 | 30 | 40;
167
- maxWordsPerLine?: 1 | 2 | 3 | 4 | 5 | 6;
168
- }
169
- ```
170
-
171
- Missing mode values use character wrapping, so old dashboards that only saved
172
- `maxCharsPerLine` remain compatible. The default is 20 characters per line;
173
- word mode defaults to three words per line. `none` normalizes separators but
174
- keeps the label on one line.
175
-
176
- ## Host Currency Settings Contract
177
-
178
- Dashboard currency labels, tooltips, and values read the host's canonical
179
- `systemSettings.settings` local-storage entry. The stored value must be a
180
- JSON-encoded array containing a case-sensitive `Currency` key whose `value`
181
- provides the currency code, localized units, and numeric format:
182
-
183
- ```typescript
184
- localStorage.setItem(
185
- "systemSettings.settings",
186
- JSON.stringify([
187
- {
188
- key: "Currency",
189
- value: {
190
- name: "OMR",
191
- unit: {
192
- en: "OMR",
193
- ar: "ريال عماني",
194
- },
195
- format: "{0:N3}",
196
- },
197
- },
198
- ]),
199
- );
200
- ```
201
-
202
- Runtime currency precedence is:
203
-
204
- 1. The valid `Currency` entry in `systemSettings.settings`.
205
- 2. The legacy JSON object stored under `currency` (its `unit` string).
206
- 3. The built-in SAR unit and legacy number formatting.
207
-
208
- Arabic dashboards (including regional language codes such as `ar-SA`) use
209
- `value.unit.ar`; every other language uses `value.unit.en`. Supported system
210
- formats include decimal/grouping patterns such as `{0:#,0.00}`, compact
211
- thousands such as `{0:#,0, K}`, and named decimal patterns such as `{0:N3}`.
212
- The host currency format is authoritative; a chart's legacy decimal option does
213
- not override its decimal count.
214
-
215
- The showcase's opt-in offline dashboard fixture
216
- (`showcase-mock-dashboard-builder=1`) appends the OMR example above only when
217
- the settings array has no `Currency` entry, so an existing host choice remains
218
- authoritative.
219
-
220
- ## PhaseGate Table Query Contract
221
-
222
- `2-table-view` does not use the generic table pivot/aggregation query. Its
223
- canonical service query is:
224
-
225
- ```typescript
226
- {
227
- rowIdentityProperty: string;
228
- phaseNameProperty: string;
229
- phaseIdProperty: string;
230
- phaseOrderProperty: string;
231
- phaseStatusProperty: string;
232
- phaseProgressProperty: string;
233
- phaseIsCurrentProperty: string;
234
- phaseIsCompletedProperty: string;
235
- phaseAllItemsCompletedProperty: string;
236
- baseProperties: string[];
237
- properties: string[];
238
- selectedProperties: string[];
239
- }
240
- ```
241
-
242
- `baseProperties` is the ordered multi-select of visible business columns. Both
243
- `properties` and `selectedProperties` are rebuilt before save/request as the
244
- same deduplicated union of those columns and every non-empty semantic role, so
245
- the chart service receives all fields needed by the renderer.
246
-
247
- The runtime resolves configured roles by property identity, matching the row
248
- object key or wrapper `key`, `normalizedKey`, `label`, or `name` without
249
- depending on response order. Consequently a visible project Status and the
250
- phase Status can coexist safely. Dynamic phase headers use the configured
251
- phase property's runtime value rather than its schema/metadata label, and an
252
- empty `phaseProgressProperty` does not render a zero-value progress track.
253
- Legacy generic-table configs are still read;
254
- `lookupProperty` becomes the phase-status role, with conservative runtime
255
- fallbacks until the remaining roles are configured and saved.
256
-
257
- ## Runtime Filter Contract
258
-
259
- Dashboard filters have two independent scopes:
260
-
261
- - Page/general filter definitions live in the dashboard configuration's
262
- `filters` collection. The viewer supplies their applied values to every item;
263
- request templates consume the keys they reference, and an item can explicitly
264
- ignore the page query-filter scope. The viewer opens a default-closed shared
265
- MT drawer from its in-flow Manage Filters action, so the host does not need a
266
- fixed sidebar or overlay CSS.
267
- - Chart filter definitions live canonically in
268
- `clientConfig.dynamicFilters`. Legacy
269
- `clientConfig.extraFilters.dynamicFilters` is read and migrated when the chart
270
- is edited. Runtime values are stored per widget identity and override a page
271
- value with the same key for that widget only.
272
- - Viewer `extraFilters` are host-owned context (for example, an informative
273
- workspace's `currentId`). They are merged after page and chart values, so a
274
- same-key runtime value cannot replace or clear the host's scope.
275
-
276
- Both drawers edit a private draft. Apply commits and refreshes the relevant
277
- scope; closing without Apply discards the draft. Clear replaces only the keys
278
- owned by that drawer's field set: optional values are removed, required
279
- non-date values remain selected, and static chart conditions plus the other
280
- runtime scope are preserved. `false` and `0` are valid applied values rather
281
- than empty values. Drawer ownership follows the viewer/widget lifecycle, so an
282
- open body-appended drawer is closed when its owner is destroyed and cannot
283
- commit into a stale chart store.
284
-
285
- Compatibility key mapping follows the original dashboard builder while keeping
286
- each scope's natural runtime types:
287
-
288
- - page/query values serialize multi-selects as comma-delimited strings, users
289
- as the id under `key` plus the display name under `<key>Name`, checkboxes as
290
- `"true"`/`"false"`, and quarters under `<key>S` plus `<key>E`;
291
- - chart item-store values keep multi-selects as arrays, checkboxes as booleans,
292
- users as `{ userId, displayName }` objects (or arrays of those objects), and
293
- quarters as the combined `start,end` value under the base key;
294
- - Clear owns every compatibility key for its field: users own `key` and
295
- `<key>Name`, while quarters own `key`, `<key>S`, and `<key>E`.
296
-
297
- Request substitution accepts both representations. Page values are merged
298
- first and a chart's typed item-store values win only for that widget.
299
-
300
- The parent report id (`pageId`) is the request execution context. A chart's
301
- `serviceConfig.dashboardId` remains its widget/store/cache identity and must not
302
- replace the report id. Route query parameters, including a legitimate filter
303
- named `id`, are never used as the report identity.
304
-
305
- Dialog actions retain that report id and expose the merged page/chart context
306
- both under `parentFilter` and as flat keys. This keeps current
307
- `{{parentFilter.year}}` templates and legacy `{{year}}` templates compatible.
308
-
309
- ## Compatibility Notes
310
-
311
- - Saved selectors remain backward-compatible with legacy `moduleType/moduleId`
312
- values and comma-based module ids.
313
- - Existing multilingual title objects are preserved. Plain string titles are
314
- normalized to the active title object shape.
315
- - The builder does not show save toasts directly. Save response messages belong
316
- to the host HTTP interceptor; automatic/internal save requests are sent with
317
- `noMessage: true`.
318
- - Aggregation requests normalize legacy `DisticntCount` values to
319
- `DistinctCount`; backends should accept both names and execute distinct-count
320
- semantics.
321
- - Table-card status legends support both grouped and flat label payloads,
322
- display legacy `label` text alongside the color indicator, and expose
323
- visibility plus per-entry order/color controls in Style Studio for Table,
324
- Dialog Table, and PhaseGate Table items.
325
- - `ChartDataService.clearCache(dashboardId?)` clears `LimitedHttpService`
326
- cache entries by chart item id (`serviceConfig.dashboardId`) when an id is
327
- passed, or clears all chart responses when omitted. Scoped clears also bypass
328
- matching in-flight requests so the next fetch cannot reuse stale data after a
329
- host create/edit/delete action.
330
- - `DashboardViewer.reloadPage()` is a host-facing mutation refresh API: it
331
- clears the dashboard chart HTTP cache before triggering all chart items, so
332
- calls such as `viewer()?.reloadPage()` always send fresh backend requests.
333
-
334
- ## Development
335
-
336
- ```bash
337
- # Build only the dashboard-builder package
338
- pnpm build:db
339
-
340
- # Focused tests for changed specs
341
- pnpm --filter @masterteam/dashboard-builder test -- --watch=false --include=<path>.spec.ts
342
- ```
343
-
344
- Do not use the full `@masterteam/components` build for routine component work
345
- unless the caller explicitly approves it.
346
-
347
- ## License
348
-
349
- MIT
1
+ # @masterteam/dashboard-builder
2
+
3
+ Dashboard Builder components and services for Angular 21+ with Tailwind CSS 4.
4
+ The package supports authoring, saving, loading, and rendering dashboards with
5
+ charts, header widgets, topbar widgets, metadata-driven data sources, source
6
+ links, and responsive ECharts output.
7
+
8
+ ## Features
9
+
10
+ - Multilingual dashboard item titles stored as `clientConfig.title.en/ar`.
11
+ - Header, topbar, and chart item title editing in builder mode.
12
+ - Host-interceptor-owned save messages, with automatic saves marked silent.
13
+ - Registry-driven chart query schemas, including safe preview states for
14
+ incomplete draft charts.
15
+ - Stacked-bar query fields switch between auto-stack and manual-stack modes so
16
+ only the relevant stack property selector is displayed and emitted.
17
+ - Quick Manage style changes stay local in the drawer until Apply, with an
18
+ isolated Preview tab for checking the edited chart config before the dashboard
19
+ canvas is updated.
20
+ - Chart header icons provide preset-based appearance and placement controls,
21
+ including independent standalone/group visibility and grouped icon-only mode.
22
+ - Timeline multi-level queries persist per-level `extraProperties` and still
23
+ read legacy `extras` fields. Open timeline detail popovers close when the
24
+ page, dashboard, or timeline scrolls outside the overlay, while the detail
25
+ panel's own scrolling remains available.
26
+ - PhaseGate Table uses a dedicated semantic-role editor and sends every
27
+ configured runtime property in one deduplicated backend projection.
28
+ - Ring Gauge with Formula accepts either `valueProperty` or `formula` for each
29
+ series, exposes no Group By or Extra Properties controls, and renders legacy
30
+ `values[].bars[]` responses through the concentric-ring gauge adapter. It
31
+ keeps each numeric detail visible (including `0`) without exposing the
32
+ generated series key as a gauge label or legend entry.
33
+ - Every GeneralQuery capability that includes `formula` exposes a visible
34
+ per-series Show/Hide advanced settings action and a Formula Builder scoped to
35
+ that series; formula availability is schema-driven rather than chart-specific.
36
+ Its function and operator catalogs preserve the complete P+4 Dashboard
37
+ Builder contract: all 26 labels map to their exact case-sensitive executable
38
+ keys, and raw keys are composed with the legacy punctuation operators.
39
+ - Selected-property chips in dashboard query editors can be removed inline.
40
+ - Properties/card-list items normalize null Percentage values to `0` with an
41
+ empty progress track and never inherit a sibling card's runtime percentage.
42
+ - Duplicated charts receive a new local dashboard identity, omit the source
43
+ link/component IDs so the next save creates a new backend chart, and persist
44
+ `duplicatedFrom` as provenance to the source dashboard identity.
45
+ - Workspace-aware metadata loading for modules and properties.
46
+ - A dedicated chart Filters action separates viewer-facing filter controls and
47
+ built-in conditions from datasource configuration, using shared `mt-*` form
48
+ fields throughout the condition editor.
49
+ - Navigation actions expose a `Navigation Target` selector. Both page and
50
+ entity navigation default to the current tab and can explicitly open in a
51
+ new tab through `action.config.navigationTarget`.
52
+ - Progress Update cards render activity HTML through ngx-quill's read-only
53
+ renderer, preserving the rich-text size, color, font, alignment, direction,
54
+ and semantic formatting configured in the source editor.
55
+ - Persisted dashboards can be deleted from the page-settings drawer after a
56
+ named, danger-styled confirmation; successful deletion returns the host to
57
+ its dashboard list while standalone builders keep deletion unavailable.
58
+ - Module multi-select serialized as selectors such as `Level:1,2,3`.
59
+ - Source-link chaining with previous result fields, relationship fields, and the
60
+ `Parent` option exposed to child-level configuration.
61
+ - Distinct aggregation normalization from legacy `DisticntCount` to
62
+ `DistinctCount`.
63
+ - Container-aware ECharts option mapping for compact dashboard grid cells,
64
+ including shared legend placement for donut, pie, bar, line, stacked bar, and
65
+ other ECharts-based charts. Pie/donut radius, center, and slice-label geometry
66
+ stay handler-owned to match the old dashboard builder; the shared EChart
67
+ wrapper reserves the same chart area as the old wrapper and does not apply
68
+ pie-specific responsive overrides. Native ECharts legend rendering stays
69
+ authoritative; the wrapper maps legend dimensions before grid offsets and
70
+ clamps saved percentage grid values against the current card pixels so stacked
71
+ bar legends keep reserved space after resize. Donut slice labels are hidden so
72
+ category names stay in the legend instead of being drawn over the ring. Pie
73
+ legend vertical alignment applies only to left/right legends, so old saved
74
+ vertical-align values do not move the default bottom legend into the chart
75
+ body. Compact bar and line charts preserve their configured value-label
76
+ visibility instead of hiding labels when the card height crosses a responsive
77
+ breakpoint.
78
+
79
+ ## Installation
80
+
81
+ ```bash
82
+ pnpm add @masterteam/dashboard-builder
83
+ ```
84
+
85
+ ## Usage
86
+
87
+ ```typescript
88
+ import { Component } from "@angular/core";
89
+ import { DashboardBuilder } from "@masterteam/dashboard-builder";
90
+
91
+ @Component({
92
+ imports: [DashboardBuilder],
93
+ template: ` <mt-dashboard-builder [services]="['pplus', 'splus']" (onSave)="saveDashboard()" /> `,
94
+ })
95
+ export class MyComponent {
96
+ saveDashboard(): void {
97
+ // React to a completed explicit save.
98
+ }
99
+ }
100
+ ```
101
+
102
+ ## Metadata Contract
103
+
104
+ Hosts must provide the dashboard metadata endpoints used by
105
+ `DashboardBuilderService`:
106
+
107
+ - `GET metadata/workspaces` returns workspace options:
108
+ `WorkspaceOption { id: string | number; name: string }`.
109
+ - `GET metadata/modules/tree` accepts `services`, `workspaceId`, and
110
+ `includeValues`. Returned module groups, items, and values may include
111
+ `workspaceId` for client-side filtering.
112
+ - `POST metadata/modules/properties` accepts `items` and optional
113
+ `workspaceId`. Each request item may also include `workspaceId`.
114
+
115
+ When a workspace changes, the builder clears selections and source links that no
116
+ longer belong to the selected workspace.
117
+
118
+ ## Table Query Editing Contract
119
+
120
+ The generic Table query editor persists ordered `selectedProperties`,
121
+ `PivotProperties`, `AggregationProperties`, and an optional `lookupProperty`.
122
+ Its ControlValueAccessor treats `writeValue` as silent model-to-view
123
+ synchronization: an equivalent value is ignored, and aggregation controls are
124
+ rebuilt with `emitEvent: false`. This is required because `DataSourceSettings`
125
+ immediately feeds each `ngModelChange` back into the editor; emitting during
126
+ that echo creates a synchronous loop that freezes the Properties picker
127
+ (#1284).
128
+
129
+ ## Snapshot Query Contract
130
+
131
+ Snapshot charts distinguish the selected Level schema from the concrete Level
132
+ record whose history is requested:
133
+
134
+ ```typescript
135
+ interface SnapshotQuery {
136
+ workspaceSelector?: string | null;
137
+ levelId: number; // schema id used to load record options
138
+ levelDataId: number; // record id sent to GetSnapShotInfo
139
+ snapshotTargetVersion: 2; // prevents schema ids from using the legacy fallback
140
+ timeFrame: "yearly" | "monthly" | "weekly";
141
+ year: number | "{{currentYear}}";
142
+ getAveragePerPeriod?: boolean;
143
+ selectedProperties: string[];
144
+ }
145
+ ```
146
+
147
+ After a Level is selected, the builder requests its records through
148
+ `POST fetch/query` with:
149
+
150
+ ```typescript
151
+ {
152
+ contextKey: `level:${levelId}`;
153
+ projection: "Card";
154
+ display: {
155
+ areas: ["card"];
156
+ }
157
+ }
158
+ ```
159
+
160
+ This authoring request deliberately omits `includeState`. Record options map
161
+ directly from `data.records[].id/name`. Runtime calls
162
+ `POST dashboards/{apiVersion}GetSnapShotInfo/{levelDataId}/{timeFrame}?year={year}`
163
+ with `{ AvgPerPeriod, dashboardId }`; the schema `levelId` must not be used in
164
+ that URL. Supported selected-property
165
+ keys are `plannedProgress`, `actualProgress`, `budget`, `baselineProgress`,
166
+ `spent`, `remaining`, and `paymentPlan`.
167
+
168
+ ## Axis Label Wrapping Contract
169
+
170
+ Bar and stacked-bar category labels preserve their original casing and wrap
171
+ normal spaces, underscores, existing line breaks, and single tokens that exceed
172
+ the selected character limit. Runtime keeps all generated lines visible and
173
+ sets `hideOverlap: false`; the shared ECharts responsive layout still owns the
174
+ available label width and grid containment.
175
+
176
+ The persisted controls live under `clientConfig.barConfigOverride` and
177
+ `clientConfig.stackBarConfigOverride`:
178
+
179
+ ```typescript
180
+ {
181
+ axisLabelWrapMode: "characters" | "words" | "none";
182
+ maxCharsPerLine?: 8 | 12 | 16 | 20 | 24 | 30 | 40;
183
+ maxWordsPerLine?: 1 | 2 | 3 | 4 | 5 | 6;
184
+ }
185
+ ```
186
+
187
+ Missing mode values use character wrapping, so old dashboards that only saved
188
+ `maxCharsPerLine` remain compatible. The default is 20 characters per line;
189
+ word mode defaults to three words per line. `none` normalizes separators but
190
+ keeps the label on one line.
191
+
192
+ ## Host Currency Settings Contract
193
+
194
+ Dashboard currency labels, tooltips, and values read the host's canonical
195
+ `systemSettings.settings` local-storage entry. The stored value must be a
196
+ JSON-encoded array containing a case-sensitive `Currency` key whose `value`
197
+ provides the currency code, localized units, and numeric format:
198
+
199
+ ```typescript
200
+ localStorage.setItem(
201
+ "systemSettings.settings",
202
+ JSON.stringify([
203
+ {
204
+ key: "Currency",
205
+ value: {
206
+ name: "OMR",
207
+ unit: {
208
+ en: "OMR",
209
+ ar: "ريال عماني",
210
+ },
211
+ format: "{0:N3}",
212
+ },
213
+ },
214
+ ]),
215
+ );
216
+ ```
217
+
218
+ Runtime currency precedence is:
219
+
220
+ 1. The valid `Currency` entry in `systemSettings.settings`.
221
+ 2. The legacy JSON object stored under `currency` (its `unit` string).
222
+ 3. The built-in SAR unit and legacy number formatting.
223
+
224
+ Arabic dashboards (including regional language codes such as `ar-SA`) use
225
+ `value.unit.ar`; every other language uses `value.unit.en`. Supported system
226
+ formats include decimal/grouping patterns such as `{0:#,0.00}`, compact
227
+ thousands such as `{0:#,0, K}`, and named decimal patterns such as `{0:N3}`.
228
+ The host currency format is authoritative; a chart's legacy decimal option does
229
+ not override its decimal count.
230
+
231
+ The showcase's opt-in offline dashboard fixture
232
+ (`showcase-mock-dashboard-builder=1`) appends the OMR example above only when
233
+ the settings array has no `Currency` entry, so an existing host choice remains
234
+ authoritative.
235
+
236
+ ## PhaseGate Table Query Contract
237
+
238
+ `2-table-view` does not use the generic table pivot/aggregation query. Its
239
+ canonical service query is:
240
+
241
+ ```typescript
242
+ {
243
+ rowIdentityProperty: string;
244
+ phaseNameProperty: string;
245
+ phaseIdProperty: string;
246
+ phaseOrderProperty: string;
247
+ phaseStatusProperty: string;
248
+ phaseProgressProperty: string;
249
+ phaseIsCurrentProperty: string;
250
+ phaseIsCompletedProperty: string;
251
+ phaseAllItemsCompletedProperty: string;
252
+ baseProperties: string[];
253
+ properties: string[];
254
+ selectedProperties: string[];
255
+ }
256
+ ```
257
+
258
+ `baseProperties` is the ordered multi-select of visible business columns. Both
259
+ `properties` and `selectedProperties` are rebuilt before save/request as the
260
+ same deduplicated union of those columns and every non-empty semantic role, so
261
+ the chart service receives all fields needed by the renderer.
262
+
263
+ The runtime resolves configured roles by property identity, matching the row
264
+ object key or wrapper `key`, `normalizedKey`, `label`, or `name` without
265
+ depending on response order. Consequently a visible project Status and the
266
+ phase Status can coexist safely. Dynamic phase headers use the configured
267
+ phase property's runtime value rather than its schema/metadata label, and an
268
+ empty `phaseProgressProperty` does not render a zero-value progress track.
269
+ Legacy generic-table configs are still read;
270
+ `lookupProperty` becomes the phase-status role, with conservative runtime
271
+ fallbacks until the remaining roles are configured and saved.
272
+
273
+ ## Runtime Filter Contract
274
+
275
+ Dashboard filters have two independent scopes:
276
+
277
+ - Page/general filter definitions live in the dashboard configuration's
278
+ `filters` collection. The viewer supplies their applied values to every item;
279
+ request templates consume the keys they reference, and an item can explicitly
280
+ ignore the page query-filter scope. The viewer opens a default-closed shared
281
+ MT drawer from its in-flow Manage Filters action, so the host does not need a
282
+ fixed sidebar or overlay CSS. Apply keeps the URL as the shareable source of
283
+ truth and re-fetches only charts whose service configuration references a
284
+ changed query key (including comma placeholders such as
285
+ `{{4,project_id}}` and page-filter relations).
286
+ - Chart filter definitions live canonically in
287
+ `clientConfig.dynamicFilters`. Legacy
288
+ `clientConfig.extraFilters.dynamicFilters` is read and migrated when the chart
289
+ is edited. Runtime values are stored per widget identity and override a page
290
+ value with the same key for that widget only.
291
+ - Viewer `extraFilters` are host-owned context (for example, an informative
292
+ workspace's `currentId`). They are merged after page and chart values, so a
293
+ same-key runtime value cannot replace or clear the host's scope.
294
+ - Builder and viewer hosts pass the same client-form metadata through
295
+ `[lookups]` and `[statuses]`. Lookup configuration labels are normalized from
296
+ the host lookup names, runtime Status options accept canonical nested status
297
+ definitions or legacy flat level statuses, and Status/Phase Gate schema
298
+ configuration is derived from the shared hierarchical metadata tree's
299
+ `Level` module.
300
+
301
+ Both drawers edit a private draft. Apply commits and refreshes the relevant
302
+ scope; closing without Apply discards the draft. Clear replaces only the keys
303
+ owned by that drawer's field set: optional values are removed, required
304
+ non-date values remain selected, and static chart conditions plus the other
305
+ runtime scope are preserved. `false` and `0` are valid applied values rather
306
+ than empty values. Drawer ownership follows the viewer/widget lifecycle, so an
307
+ open body-appended drawer is closed when its owner is destroyed and cannot
308
+ commit into a stale chart store.
309
+
310
+ Compatibility key mapping follows the original dashboard builder while keeping
311
+ each scope's natural runtime types:
312
+
313
+ - page/query values serialize multi-selects as comma-delimited strings, users
314
+ as the id under `key` plus the display name under `<key>Name`, checkboxes as
315
+ `"true"`/`"false"`, and quarters under `<key>S` plus `<key>E`;
316
+ - chart item-store values keep multi-selects as arrays, checkboxes as booleans,
317
+ users as `{ userId, displayName }` objects (or arrays of those objects), and
318
+ quarters as the combined `start,end` value under the base key;
319
+ - Clear owns every compatibility key for its field: users own `key` and
320
+ `<key>Name`, while quarters own `key`, `<key>S`, and `<key>E`.
321
+
322
+ Request substitution accepts both representations. Page values are merged
323
+ first and a chart's typed item-store values win only for that widget.
324
+
325
+ The parent report id (`pageId`) is the request execution context. A chart's
326
+ `serviceConfig.dashboardId` remains its widget/store/cache identity and must not
327
+ replace the report id. Route query parameters, including a legitimate filter
328
+ named `id`, are never used as the report identity.
329
+
330
+ Dialog actions retain that report id and expose the merged page/chart context
331
+ both under `parentFilter` and as flat keys. This keeps current
332
+ `{{parentFilter.year}}` templates and legacy `{{year}}` templates compatible.
333
+
334
+ ## Compatibility Notes
335
+
336
+ - Saved selectors remain backward-compatible with legacy `moduleType/moduleId`
337
+ values and comma-based module ids.
338
+ - Existing multilingual title objects are preserved. Plain string titles are
339
+ normalized to the active title object shape.
340
+ - Removing a persisted chart group unlinks its saved group container before
341
+ clearing the local group metadata. Its child charts remain on the dashboard
342
+ and the deleted empty group cannot return after Save and reload.
343
+ - Style Studio previews Header and Topbar draft styles before Apply by resolving
344
+ layout widgets without a `chartTypeId` through their registered
345
+ `clientConfig.componentName`. Cancel continues to discard the working draft.
346
+ - Style Studio preview/runtime parity includes bar and stacked-bar widths,
347
+ configured number precision and explicit currency visibility, pie legend
348
+ type/font controls, bilingual donut center labels, table/timeline legend
349
+ position and icon shape, and statistic-card icon placement. Stacked-bar
350
+ totals are emitted only when `configAsType.label.showTotalInTop` is true;
351
+ the generic data-label toggle cannot override that dedicated setting.
352
+ - Performance Gauge Card treats the `Status` wrapper returned in
353
+ `values.*.extraValues` as authoritative for the active status key, localized
354
+ label, and color. Component status ranges still define the gauge scale and
355
+ segments, and remain the fallback when the response has no status wrapper.
356
+ - The builder does not show save toasts directly. Save response messages belong
357
+ to the host HTTP interceptor; automatic/internal save requests are sent with
358
+ `noMessage: true`.
359
+ - Aggregation requests normalize legacy `DisticntCount` values to
360
+ `DistinctCount`; backends should accept both names and execute distinct-count
361
+ semantics.
362
+ - Table-card status legends support both grouped and flat label payloads,
363
+ display legacy `label` text alongside the color indicator, and expose
364
+ visibility plus per-entry order/color controls in Style Studio for Table,
365
+ Dialog Table, and PhaseGate Table items.
366
+ - Table and Dialog Table user cells resolve the canonical `photoUrl` value
367
+ before the legacy `image` and `avatar` aliases, then load the avatar through
368
+ the shared authenticated `secureImage` pipeline instead of binding the
369
+ backend value directly to `<img src>`.
370
+ - Manage Item filter value fields treat properties whose `normalizedKey` is
371
+ `Id` as literal identifiers. They do not call the finite-list
372
+ `property-items` endpoint for those properties; lookup and status properties
373
+ continue loading their selectable values normally.
374
+ - `ChartDataService.clearCache(dashboardId?)` clears `LimitedHttpService`
375
+ cache entries by chart item id (`serviceConfig.dashboardId`) when an id is
376
+ passed, or clears all chart responses when omitted. Scoped clears also bypass
377
+ matching in-flight requests so the next fetch cannot reuse stale data after a
378
+ host create/edit/delete action.
379
+ - `DashboardViewer.reloadPage()` is a host-facing mutation refresh API: it
380
+ clears the dashboard chart HTTP cache before triggering all chart items, so
381
+ calls such as `viewer()?.reloadPage()` always send fresh backend requests.
382
+
383
+ ## Development
384
+
385
+ ```bash
386
+ # Build only the dashboard-builder package
387
+ pnpm build:db
388
+
389
+ # Focused tests for changed specs
390
+ pnpm --filter @masterteam/dashboard-builder test -- --watch=false --include=<path>.spec.ts
391
+ ```
392
+
393
+ Do not use the full `@masterteam/components` build for routine component work
394
+ unless the caller explicitly approves it.
395
+
396
+ ## License
397
+
398
+ MIT