@sybilion/uilib 1.4.17 → 1.4.19

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.
@@ -1,6 +1,6 @@
1
1
  import styleInject from 'style-inject';
2
2
 
3
- var css_248z = "@media (max-width:768px){:root{--page-x-padding:var(--p-6);--page-y-padding:var(--p-6)}}.GridLayout_root__VF9sR{display:grid;min-width:0;width:100%}.GridLayout_root__VF9sR>*{min-width:300px}";
3
+ var css_248z = "@media (max-width:768px){:root{--page-x-padding:var(--p-6);--page-y-padding:var(--p-6)}}.GridLayout_root__VF9sR{display:grid;min-width:0;width:100%}";
4
4
  var S = {"root":"GridLayout_root__VF9sR"};
5
5
  styleInject(css_248z);
6
6
 
@@ -53,7 +53,7 @@ import { Table, TableHeader, TableRow, TableHead, TableCellValue, TableBody, Tab
53
53
  import { TextShimmer } from '../../ui/TextShimmer/TextShimmer.js';
54
54
  import { TIME_RANGES } from '../../ui/TimeRangeControls/TimeRangeControls.constants.js';
55
55
  import S from './DriversComparisonChart.styl.js';
56
- import { applyDriversComparisonViewToPayload, mergeBacktestsChartData, mergeDatasetHistoricalWithBacktestsChartData, computeDriversComparisonHistoricalWindowFloor, DRIVER_FORECAST_ID_BASE, getLagDisplayForView, resolveDriverLagLabel, INITIAL_VISIBLE_SERIES_COUNT, buildDriversComparisonChartData, formatSeriesImportance } from './driversComparisonChart.helpers.js';
56
+ import { applyDriversComparisonViewToPayload, getDriversWithDataSortedByImportance, mergeBacktestsChartData, mergeDatasetHistoricalWithBacktestsChartData, DRIVER_FORECAST_ID_BASE, computeDriversComparisonHistoricalWindowFloor, getLagDisplayForView, resolveDriverLagLabel, INITIAL_VISIBLE_SERIES_COUNT, buildDriversComparisonChartData, formatSeriesImportance } from './driversComparisonChart.helpers.js';
57
57
 
58
58
  const ALL_TIME_RANGE = TIME_RANGES[TIME_RANGES.length - 1];
59
59
  function toForecastDataKey(id) {
@@ -105,24 +105,13 @@ function DriversComparisonChart({ payload, datasetHistorical = [], loading = fal
105
105
  });
106
106
  }, [setHiddenSeries]);
107
107
  const payloadForView = useMemo(() => applyDriversComparisonViewToPayload(payload, viewTab), [payload, viewTab]);
108
- const sortedDriversWithData = useMemo(() => {
109
- const driversList = payloadForView?.drivers ?? [];
110
- if (!driversList.length)
111
- return [];
112
- return [...driversList]
113
- .filter(d => d.normalized_series &&
114
- Object.keys(d.normalized_series).some(key => d.normalized_series[key] != null))
115
- .sort((a, b) => String(a.id).localeCompare(String(b.id)));
116
- }, [payloadForView?.drivers]);
108
+ const sortedDriversWithData = useMemo(() => getDriversWithDataSortedByImportance(payloadForView?.drivers), [payloadForView?.drivers]);
117
109
  const mergedChartData = useMemo(() => mergeBacktestsChartData(payloadForView), [payloadForView]);
118
110
  const mergedWithHistorical = useMemo(() => mergeDatasetHistoricalWithBacktestsChartData(datasetHistorical, mergedChartData), [datasetHistorical, mergedChartData]);
119
111
  const historicalWindowFloor = useMemo(() => {
120
112
  const laggedMerged = mergeBacktestsChartData(payload);
121
113
  const merged = mergeDatasetHistoricalWithBacktestsChartData(datasetHistorical, laggedMerged);
122
- const sortedDrivers = [...(payload?.drivers ?? [])]
123
- .filter(d => d.normalized_series &&
124
- Object.keys(d.normalized_series).some(key => d.normalized_series[key] != null))
125
- .sort((a, b) => String(a.id).localeCompare(String(b.id)));
114
+ const sortedDrivers = getDriversWithDataSortedByImportance(payload?.drivers);
126
115
  const forecastIds = sortedDrivers.map((_, idx) => DRIVER_FORECAST_ID_BASE + idx);
127
116
  return computeDriversComparisonHistoricalWindowFloor(merged, forecastIds);
128
117
  }, [payload, datasetHistorical]);
@@ -145,8 +134,7 @@ function DriversComparisonChart({ payload, datasetHistorical = [], loading = fal
145
134
  const tableSeriesRows = useMemo(() => {
146
135
  if (sortedDriversWithData.length === 0)
147
136
  return [];
148
- return sortedDriversWithData
149
- .map((driver, idx) => {
137
+ return sortedDriversWithData.map((driver, idx) => {
150
138
  const raw = driver.importance;
151
139
  const importance = typeof raw === 'number' && Number.isFinite(raw) ? raw : null;
152
140
  const lagSource = originalDriversById.get(String(driver.id)) ?? driver;
@@ -157,8 +145,7 @@ function DriversComparisonChart({ payload, datasetHistorical = [], loading = fal
157
145
  importance,
158
146
  lag: getLagDisplayForView(resolveDriverLagLabel(lagSource), viewTab),
159
147
  };
160
- })
161
- .sort((a, b) => b.importance - a.importance);
148
+ });
162
149
  }, [originalDriversById, sortedDriversWithData, viewTab]);
163
150
  const seriesInitKeyResolved = seriesInitKey ?? `${tableSeriesRows.map(r => r.id).join(',') || 'none'}`;
164
151
  const backtestsSeriesInitKeyRef = useRef('');
@@ -1,6 +1,6 @@
1
1
  import styleInject from 'style-inject';
2
2
 
3
- var css_248z = "@media (max-width:768px){:root{--page-x-padding:var(--p-6);--page-y-padding:var(--p-6)}}.DriversComparisonChart_root__GLnlF{display:flex;flex-direction:column;gap:var(--p-4);width:100%}.DriversComparisonChart_chartShell__0AzAz{position:relative;width:100%}.DriversComparisonChart_chartShellLoading__wTLod .DriversComparisonChart_chartSlot__WKe6N{opacity:.3;pointer-events:none}.DriversComparisonChart_chartShellLoading__wTLod .recharts-line-dots{display:none}.DriversComparisonChart_chartSlot__WKe6N{width:100%}.DriversComparisonChart_loadingLayer__HlEmA{inset:0;pointer-events:none;position:absolute;z-index:10}.DriversComparisonChart_loadingMessage__Li3S7{color:var(--foreground);display:block;left:0;position:absolute;text-align:center;top:calc(50% - 4em);width:100%;z-index:1}.DriversComparisonChart_loadingText__0y3Ms{backdrop-filter:blur(10px);border-radius:var(--p-4);box-shadow:0 0 0 2px var(--page-color);color:var(--foreground);font-size:16px;font-weight:500;padding:0 var(--p-3)}.DriversComparisonChart_chartWithOverlay__SMToK{position:relative;width:100%}.DriversComparisonChart_chartInteractiveLayer__0aquh{transition:opacity .2s ease-out;width:100%}.DriversComparisonChart_chartInteractiveDimmed__us1dv{opacity:.3;pointer-events:none}.DriversComparisonChart_chartInteractiveDimmed__us1dv .recharts-line-dots{display:none}.DriversComparisonChart_chartEmptyOverlay__eXqzk{align-items:center;display:flex;inset:0;justify-content:center;padding:var(--p-4);pointer-events:none;position:absolute;z-index:6}.DriversComparisonChart_chartEmptyBlurb__Tjy9E{max-width:42rem;padding:0 var(--p-3)}.DriversComparisonChart_seriesEmptyWrap__RyRs5{display:flex;justify-content:center;padding:var(--p-8) var(--p-4)}.DriversComparisonChart_seriesSection__yrf4I{width:100%}.DriversComparisonChart_seriesTableWrapper__oredC{margin:0 calc(var(--page-x-padding)*-1);position:relative}.DriversComparisonChart_seriesTableContainer__dhfXK{overflow-x:auto;position:relative;width:100%}.DriversComparisonChart_seriesScrollbar__2jgk6{bottom:calc(var(--p-7)*-1 + 2px)!important}.DriversComparisonChart_seriesTable__NybPR{max-width:100%;table-layout:auto;width:100%}.DriversComparisonChart_seriesTable__NybPR tr{cursor:pointer;position:relative}.DriversComparisonChart_seriesTable__NybPR td:not(:first-child),.DriversComparisonChart_seriesTable__NybPR th:not(:first-child){text-align:right}.DriversComparisonChart_seriesColSeries__--0mj{text-align:left;vertical-align:middle}.DriversComparisonChart_rowHidden__Fwhna{opacity:.4}.DriversComparisonChart_colorSwatch__o3ZVr{border-radius:2px;display:inline-flex;flex-shrink:0;height:10px;margin-right:var(--p-2);width:10px}.DriversComparisonChart_seriesLabel__Aidof{display:-webkit-box;-webkit-line-clamp:3;max-width:60vw;min-width:0;-webkit-box-orient:vertical;white-space:break-spaces}.DriversComparisonChart_chartContainer__1eM-O{margin-left:calc(var(--page-x-padding)*-1 + 26px);max-width:calc(100% + 60px);transition:opacity .3s ease-out;width:calc(100% + 60px)}.DriversComparisonChart_chartContainer__1eM-O .recharts-yAxis-tick-labels{display:none}@media (max-width:768px){.DriversComparisonChart_chartContainer__1eM-O{margin-left:calc(var(--page-x-padding)*-1 + 10px);width:calc(100% + 30px)}}";
3
+ var css_248z = "@media (max-width:768px){:root{--page-x-padding:var(--p-6);--page-y-padding:var(--p-6)}}.DriversComparisonChart_root__GLnlF{display:flex;flex-direction:column;gap:var(--p-4);width:100%}.DriversComparisonChart_chartShell__0AzAz{position:relative;width:100%}.DriversComparisonChart_chartShellLoading__wTLod .DriversComparisonChart_chartSlot__WKe6N{opacity:.3;pointer-events:none}.DriversComparisonChart_chartShellLoading__wTLod .recharts-line-dots{display:none}.DriversComparisonChart_chartSlot__WKe6N{width:100%}.DriversComparisonChart_loadingLayer__HlEmA{inset:0;pointer-events:none;position:absolute;z-index:10}.DriversComparisonChart_loadingMessage__Li3S7{color:var(--foreground);display:block;left:0;position:absolute;text-align:center;top:calc(50% - 4em);width:100%;z-index:1}.DriversComparisonChart_loadingText__0y3Ms{backdrop-filter:blur(10px);border-radius:var(--p-4);box-shadow:0 0 0 2px var(--page-color);color:var(--foreground);font-size:16px;font-weight:500;padding:0 var(--p-3)}.DriversComparisonChart_chartWithOverlay__SMToK{position:relative;width:100%}.DriversComparisonChart_chartInteractiveLayer__0aquh{transition:opacity .2s ease-out;width:100%}.DriversComparisonChart_chartInteractiveDimmed__us1dv{opacity:.3;pointer-events:none}.DriversComparisonChart_chartInteractiveDimmed__us1dv .recharts-line-dots{display:none}.DriversComparisonChart_chartEmptyOverlay__eXqzk{align-items:center;display:flex;inset:0;justify-content:center;padding:var(--p-4);pointer-events:none;position:absolute;z-index:6}.DriversComparisonChart_chartEmptyBlurb__Tjy9E{max-width:42rem;padding:0 var(--p-3)}.DriversComparisonChart_seriesEmptyWrap__RyRs5{display:flex;justify-content:center;padding:var(--p-8) var(--p-4)}.DriversComparisonChart_seriesSection__yrf4I{width:100%}.DriversComparisonChart_seriesTableWrapper__oredC{margin:0 calc(var(--page-x-padding)*-1);position:relative}.DriversComparisonChart_seriesTableContainer__dhfXK{overflow-x:auto;position:relative;width:100%}.DriversComparisonChart_seriesScrollbar__2jgk6{bottom:calc(var(--p-7)*-1 + 2px)!important}.DriversComparisonChart_seriesTable__NybPR{max-width:100%;table-layout:auto;width:100%}.DriversComparisonChart_seriesTable__NybPR tr{cursor:pointer;position:relative}.DriversComparisonChart_seriesTable__NybPR th:not(:first-child)>caption{justify-content:flex-end}.DriversComparisonChart_seriesTable__NybPR td:not(:first-child){text-align:right}.DriversComparisonChart_seriesColSeries__--0mj{text-align:left;vertical-align:middle}.DriversComparisonChart_rowHidden__Fwhna{opacity:.4}.DriversComparisonChart_colorSwatch__o3ZVr{border-radius:2px;display:inline-flex;flex-shrink:0;height:10px;margin-right:var(--p-2);width:10px}.DriversComparisonChart_seriesLabel__Aidof{display:-webkit-box;-webkit-line-clamp:3;max-width:60vw;min-width:0;-webkit-box-orient:vertical;white-space:break-spaces}.DriversComparisonChart_chartContainer__1eM-O{margin-left:calc(var(--page-x-padding)*-1 + 26px);max-width:calc(100% + 60px);transition:opacity .3s ease-out;width:calc(100% + 60px)}.DriversComparisonChart_chartContainer__1eM-O .recharts-yAxis-tick-labels{display:none}@media (max-width:768px){.DriversComparisonChart_chartContainer__1eM-O{margin-left:calc(var(--page-x-padding)*-1 + 10px);width:calc(100% + 30px)}}";
4
4
  var S = {"root":"DriversComparisonChart_root__GLnlF","chartShell":"DriversComparisonChart_chartShell__0AzAz","chartShellLoading":"DriversComparisonChart_chartShellLoading__wTLod","chartSlot":"DriversComparisonChart_chartSlot__WKe6N","loadingLayer":"DriversComparisonChart_loadingLayer__HlEmA","loadingMessage":"DriversComparisonChart_loadingMessage__Li3S7","loadingText":"DriversComparisonChart_loadingText__0y3Ms","chartWithOverlay":"DriversComparisonChart_chartWithOverlay__SMToK","chartInteractiveLayer":"DriversComparisonChart_chartInteractiveLayer__0aquh","chartInteractiveDimmed":"DriversComparisonChart_chartInteractiveDimmed__us1dv","chartEmptyOverlay":"DriversComparisonChart_chartEmptyOverlay__eXqzk","chartEmptyBlurb":"DriversComparisonChart_chartEmptyBlurb__Tjy9E","seriesEmptyWrap":"DriversComparisonChart_seriesEmptyWrap__RyRs5","seriesSection":"DriversComparisonChart_seriesSection__yrf4I","seriesTableWrapper":"DriversComparisonChart_seriesTableWrapper__oredC","seriesTableContainer":"DriversComparisonChart_seriesTableContainer__dhfXK","seriesScrollbar":"DriversComparisonChart_seriesScrollbar__2jgk6","seriesTable":"DriversComparisonChart_seriesTable__NybPR","seriesColSeries":"DriversComparisonChart_seriesColSeries__--0mj","rowHidden":"DriversComparisonChart_rowHidden__Fwhna","colorSwatch":"DriversComparisonChart_colorSwatch__o3ZVr","seriesLabel":"DriversComparisonChart_seriesLabel__Aidof","chartContainer":"DriversComparisonChart_chartContainer__1eM-O"};
5
5
  styleInject(css_248z);
6
6
 
@@ -11,6 +11,26 @@ function formatSeriesImportance(value) {
11
11
  return '—';
12
12
  return `${value.toFixed(1)}%`;
13
13
  }
14
+ function driverImportanceSortKey(importance) {
15
+ return typeof importance === 'number' && Number.isFinite(importance)
16
+ ? importance
17
+ : -Infinity;
18
+ }
19
+ /** Higher importance first; ties broken by driver id for stable ordering. */
20
+ function compareDriversByImportance(a, b) {
21
+ const importanceDelta = driverImportanceSortKey(b.importance) -
22
+ driverImportanceSortKey(a.importance);
23
+ if (importanceDelta !== 0)
24
+ return importanceDelta;
25
+ return String(a.id).localeCompare(String(b.id));
26
+ }
27
+ function sortDriversByImportance(drivers) {
28
+ return [...drivers].sort(compareDriversByImportance);
29
+ }
30
+ function getDriversWithDataSortedByImportance(drivers) {
31
+ return sortDriversByImportance((drivers ?? []).filter(d => d.normalized_series &&
32
+ Object.keys(d.normalized_series).some(key => d.normalized_series[key] != null)));
33
+ }
14
34
  function resolveDriverLagLabel(driver) {
15
35
  if (typeof driver.lag === 'string' && driver.lag.trim()) {
16
36
  return driver.lag;
@@ -132,10 +152,7 @@ function mergeBacktestsChartData(payload) {
132
152
  map.set(k, existing);
133
153
  });
134
154
  if (payload.drivers?.length) {
135
- const sorted = [...payload.drivers]
136
- .filter(d => d.normalized_series &&
137
- Object.keys(d.normalized_series).some(key => d.normalized_series[key] != null))
138
- .sort((a, b) => String(a.id).localeCompare(String(b.id)));
155
+ const sorted = getDriversWithDataSortedByImportance(payload.drivers);
139
156
  sorted.forEach((driver, idx) => {
140
157
  const fid = DRIVER_FORECAST_ID_BASE + idx;
141
158
  const series = driver.normalized_series;
@@ -271,4 +288,4 @@ function buildDriversComparisonChartData(mergedWithHistorical, datasetHistorical
271
288
  return withLead.filter(p => normalizeToMonthStart(p.date) >= xMin);
272
289
  }
273
290
 
274
- export { DRIVER_COMPARISON_CHART_LEAD_MONTHS, DRIVER_FORECAST_ID_BASE, INITIAL_VISIBLE_SERIES_COUNT, applyDriversComparisonViewToPayload, buildDriversComparisonChartData, computeDriversComparisonHistoricalWindowFloor, formatLagMonthsLabel, formatSeriesImportance, getLagDisplayForView, getZoomAnchorMonthFromDriverMaterialStarts, mergeBacktestsChartData, mergeDatasetHistoricalWithBacktestsChartData, parseLagMonthsFromLabel, prependHistoricalLeadFromDataset, resolveDriverLagLabel, shiftNormalizedSeriesBackward, shiftNormalizedSeriesForward, subtractMonthsFromMonthStart };
291
+ export { DRIVER_COMPARISON_CHART_LEAD_MONTHS, DRIVER_FORECAST_ID_BASE, INITIAL_VISIBLE_SERIES_COUNT, applyDriversComparisonViewToPayload, buildDriversComparisonChartData, compareDriversByImportance, computeDriversComparisonHistoricalWindowFloor, formatLagMonthsLabel, formatSeriesImportance, getDriversWithDataSortedByImportance, getLagDisplayForView, getZoomAnchorMonthFromDriverMaterialStarts, mergeBacktestsChartData, mergeDatasetHistoricalWithBacktestsChartData, parseLagMonthsFromLabel, prependHistoricalLeadFromDataset, resolveDriverLagLabel, shiftNormalizedSeriesBackward, shiftNormalizedSeriesForward, sortDriversByImportance, subtractMonthsFromMonthStart };
@@ -6,6 +6,16 @@ export declare const INITIAL_VISIBLE_SERIES_COUNT = 3;
6
6
  export declare const DRIVER_COMPARISON_CHART_LEAD_MONTHS = 6;
7
7
  export type DriversComparisonViewTab = 'overlapped' | 'lagged';
8
8
  export declare function formatSeriesImportance(value: number | null): string;
9
+ /** Higher importance first; ties broken by driver id for stable ordering. */
10
+ export declare function compareDriversByImportance<T extends {
11
+ id?: string | number;
12
+ importance?: number | null;
13
+ }>(a: T, b: T): number;
14
+ export declare function sortDriversByImportance<T extends {
15
+ id?: string | number;
16
+ importance?: number | null;
17
+ }>(drivers: T[]): T[];
18
+ export declare function getDriversWithDataSortedByImportance(drivers: BacktestsComponentPayload['drivers'] | undefined): NonNullable<BacktestsComponentPayload['drivers']>;
9
19
  export declare function resolveDriverLagLabel(driver: {
10
20
  lag?: string | null;
11
21
  overall_lag?: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sybilion/uilib",
3
- "version": "1.4.17",
3
+ "version": "1.4.19",
4
4
  "description": "Sybilion Design System — React UI components (Webpack + Stylus)",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -4,6 +4,3 @@
4
4
  display grid
5
5
  width 100%
6
6
  min-width 0
7
-
8
- > *
9
- min-width 300px
@@ -104,10 +104,10 @@
104
104
  position relative
105
105
  cursor pointer
106
106
 
107
- td
108
- th
109
- &:not(:first-child)
110
- text-align right
107
+ th:not(:first-child) > caption
108
+ justify-content flex-end
109
+ td:not(:first-child)
110
+ text-align right
111
111
 
112
112
  .seriesColSeries
113
113
  text-align left
@@ -37,6 +37,7 @@ import {
37
37
  buildDriversComparisonChartData,
38
38
  computeDriversComparisonHistoricalWindowFloor,
39
39
  formatSeriesImportance,
40
+ getDriversWithDataSortedByImportance,
40
41
  getLagDisplayForView,
41
42
  mergeBacktestsChartData,
42
43
  mergeDatasetHistoricalWithBacktestsChartData,
@@ -158,19 +159,10 @@ export function DriversComparisonChart({
158
159
  [payload, viewTab],
159
160
  );
160
161
 
161
- const sortedDriversWithData = useMemo(() => {
162
- const driversList = payloadForView?.drivers ?? [];
163
- if (!driversList.length) return [];
164
- return [...driversList]
165
- .filter(
166
- d =>
167
- d.normalized_series &&
168
- Object.keys(d.normalized_series).some(
169
- key => d.normalized_series![key] != null,
170
- ),
171
- )
172
- .sort((a, b) => String(a.id).localeCompare(String(b.id)));
173
- }, [payloadForView?.drivers]);
162
+ const sortedDriversWithData = useMemo(
163
+ () => getDriversWithDataSortedByImportance(payloadForView?.drivers),
164
+ [payloadForView?.drivers],
165
+ );
174
166
 
175
167
  const mergedChartData = useMemo(
176
168
  () => mergeBacktestsChartData(payloadForView),
@@ -192,15 +184,9 @@ export function DriversComparisonChart({
192
184
  datasetHistorical,
193
185
  laggedMerged,
194
186
  );
195
- const sortedDrivers = [...(payload?.drivers ?? [])]
196
- .filter(
197
- d =>
198
- d.normalized_series &&
199
- Object.keys(d.normalized_series).some(
200
- key => d.normalized_series![key] != null,
201
- ),
202
- )
203
- .sort((a, b) => String(a.id).localeCompare(String(b.id)));
187
+ const sortedDrivers = getDriversWithDataSortedByImportance(
188
+ payload?.drivers,
189
+ );
204
190
  const forecastIds = sortedDrivers.map(
205
191
  (_, idx) => DRIVER_FORECAST_ID_BASE + idx,
206
192
  );
@@ -226,21 +212,19 @@ export function DriversComparisonChart({
226
212
 
227
213
  const tableSeriesRows = useMemo(() => {
228
214
  if (sortedDriversWithData.length === 0) return [];
229
- return sortedDriversWithData
230
- .map((driver, idx) => {
231
- const raw = driver.importance;
232
- const importance =
233
- typeof raw === 'number' && Number.isFinite(raw) ? raw : null;
234
- const lagSource = originalDriversById.get(String(driver.id)) ?? driver;
235
- return {
236
- id: DRIVER_FORECAST_ID_BASE + idx,
237
- name: driver.name || String(driver.id),
238
- color: getForecastColor(idx + 1),
239
- importance,
240
- lag: getLagDisplayForView(resolveDriverLagLabel(lagSource), viewTab),
241
- };
242
- })
243
- .sort((a, b) => b.importance - a.importance);
215
+ return sortedDriversWithData.map((driver, idx) => {
216
+ const raw = driver.importance;
217
+ const importance =
218
+ typeof raw === 'number' && Number.isFinite(raw) ? raw : null;
219
+ const lagSource = originalDriversById.get(String(driver.id)) ?? driver;
220
+ return {
221
+ id: DRIVER_FORECAST_ID_BASE + idx,
222
+ name: driver.name || String(driver.id),
223
+ color: getForecastColor(idx + 1),
224
+ importance,
225
+ lag: getLagDisplayForView(resolveDriverLagLabel(lagSource), viewTab),
226
+ };
227
+ });
244
228
  }, [originalDriversById, sortedDriversWithData, viewTab]);
245
229
 
246
230
  const seriesInitKeyResolved =
@@ -5,8 +5,10 @@ import {
5
5
  DRIVER_FORECAST_ID_BASE,
6
6
  applyDriversComparisonViewToPayload,
7
7
  buildDriversComparisonChartData,
8
+ compareDriversByImportance,
8
9
  computeDriversComparisonHistoricalWindowFloor,
9
10
  formatLagMonthsLabel,
11
+ getDriversWithDataSortedByImportance,
10
12
  getLagDisplayForView,
11
13
  mergeBacktestsChartData,
12
14
  mergeDatasetHistoricalWithBacktestsChartData,
@@ -14,9 +16,56 @@ import {
14
16
  resolveDriverLagLabel,
15
17
  shiftNormalizedSeriesBackward,
16
18
  shiftNormalizedSeriesForward,
19
+ sortDriversByImportance,
17
20
  subtractMonthsFromMonthStart,
18
21
  } from './driversComparisonChart.helpers';
19
22
 
23
+ describe('sortDriversByImportance', () => {
24
+ it('orders drivers by importance descending before id tie-break', () => {
25
+ const drivers = [
26
+ { id: 'b', importance: 50, normalized_series: { '2015-01-01': 1 } },
27
+ { id: 'a', importance: 100, normalized_series: { '2015-01-01': 1 } },
28
+ { id: 'c', importance: 100, normalized_series: { '2015-01-01': 1 } },
29
+ ];
30
+ expect(sortDriversByImportance(drivers).map(d => d.id)).toEqual([
31
+ 'a',
32
+ 'c',
33
+ 'b',
34
+ ]);
35
+ });
36
+
37
+ it('puts drivers without importance last', () => {
38
+ const drivers = [
39
+ {
40
+ id: 'z',
41
+ name: 'Z',
42
+ importance: null,
43
+ normalized_series: { '2015-01-01': 1 },
44
+ },
45
+ {
46
+ id: 'a',
47
+ name: 'A',
48
+ importance: 10,
49
+ normalized_series: { '2015-01-01': 1 },
50
+ },
51
+ ];
52
+ expect(
53
+ getDriversWithDataSortedByImportance(drivers).map(d => d.id),
54
+ ).toEqual(['a', 'z']);
55
+ });
56
+ });
57
+
58
+ describe('compareDriversByImportance', () => {
59
+ it('breaks equal importance ties by id', () => {
60
+ expect(
61
+ compareDriversByImportance(
62
+ { id: 'b', importance: 100 },
63
+ { id: 'a', importance: 100 },
64
+ ),
65
+ ).toBeGreaterThan(0);
66
+ });
67
+ });
68
+
20
69
  describe('parseLagMonthsFromLabel', () => {
21
70
  it('uses max month for ranges', () => {
22
71
  expect(parseLagMonthsFromLabel('9 to 12 month(s)')).toBe(12);
@@ -21,6 +21,45 @@ export function formatSeriesImportance(value: number | null): string {
21
21
  return `${value.toFixed(1)}%`;
22
22
  }
23
23
 
24
+ function driverImportanceSortKey(
25
+ importance: number | null | undefined,
26
+ ): number {
27
+ return typeof importance === 'number' && Number.isFinite(importance)
28
+ ? importance
29
+ : -Infinity;
30
+ }
31
+
32
+ /** Higher importance first; ties broken by driver id for stable ordering. */
33
+ export function compareDriversByImportance<
34
+ T extends { id?: string | number; importance?: number | null },
35
+ >(a: T, b: T): number {
36
+ const importanceDelta =
37
+ driverImportanceSortKey(b.importance) -
38
+ driverImportanceSortKey(a.importance);
39
+ if (importanceDelta !== 0) return importanceDelta;
40
+ return String(a.id).localeCompare(String(b.id));
41
+ }
42
+
43
+ export function sortDriversByImportance<
44
+ T extends { id?: string | number; importance?: number | null },
45
+ >(drivers: T[]): T[] {
46
+ return [...drivers].sort(compareDriversByImportance);
47
+ }
48
+
49
+ export function getDriversWithDataSortedByImportance(
50
+ drivers: BacktestsComponentPayload['drivers'] | undefined,
51
+ ): NonNullable<BacktestsComponentPayload['drivers']> {
52
+ return sortDriversByImportance(
53
+ (drivers ?? []).filter(
54
+ d =>
55
+ d.normalized_series &&
56
+ Object.keys(d.normalized_series).some(
57
+ key => d.normalized_series![key] != null,
58
+ ),
59
+ ),
60
+ );
61
+ }
62
+
24
63
  export function resolveDriverLagLabel(driver: {
25
64
  lag?: string | null;
26
65
  overall_lag?: string | null;
@@ -165,15 +204,7 @@ export function mergeBacktestsChartData(
165
204
  });
166
205
 
167
206
  if (payload.drivers?.length) {
168
- const sorted = [...payload.drivers]
169
- .filter(
170
- d =>
171
- d.normalized_series &&
172
- Object.keys(d.normalized_series).some(
173
- key => d.normalized_series![key] != null,
174
- ),
175
- )
176
- .sort((a, b) => String(a.id).localeCompare(String(b.id)));
207
+ const sorted = getDriversWithDataSortedByImportance(payload.drivers);
177
208
 
178
209
  sorted.forEach((driver, idx) => {
179
210
  const fid = DRIVER_FORECAST_ID_BASE + idx;
@@ -1,4 +1,3 @@
1
- import { Button } from '#uilib/components/ui/Button';
2
1
  import {
3
2
  Card,
4
3
  CardContent,
@@ -8,13 +7,14 @@ import {
8
7
  CardTitle,
9
8
  LinkCard,
10
9
  } from '#uilib/components/ui/Card';
11
- import CardGuidance from '#uilib/components/ui/Card/AGENT.md';
12
- import { PageContentSection } from '#uilib/components/ui/Page';
13
- import { PackageIcon } from '@phosphor-icons/react';
14
10
 
15
11
  import { AppPageHeader } from '../components/AppPageHeader/AppPageHeader';
12
+ import { Button } from '#uilib/components/ui/Button';
13
+ import CardGuidance from '#uilib/components/ui/Card/AGENT.md';
16
14
  import { DocsGuidance } from '../components/DocsGuidance/DocsGuidance';
17
15
  import { DocsHeaderActions } from '../docsHeaderActions';
16
+ import { PackageIcon } from '@phosphor-icons/react';
17
+ import { PageContentSection } from '#uilib/components/ui/Page';
18
18
 
19
19
  const PADDING_SIZES = ['s', 'm', 'l'] as const;
20
20
  const RADIUS_SIZES = ['s', 'm', 'l', 'xl'] as const;
@@ -95,9 +95,11 @@ export default function CardPage() {
95
95
  <thead>
96
96
  <tr>
97
97
  <th style={{ textAlign: 'left', padding: '0.5rem' }}>
98
- composition
98
+ Composition
99
+ </th>
100
+ <th style={{ textAlign: 'left', padding: '0.5rem' }}>
101
+ Preview
99
102
  </th>
100
- <th style={{ padding: '0.5rem' }}>preview</th>
101
103
  </tr>
102
104
  </thead>
103
105
  <tbody>