@sybilion/uilib 1.4.11 → 1.4.13

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 (47) hide show
  1. package/dist/esm/components/ui/Button/Button.styl.js +1 -1
  2. package/dist/esm/components/ui/Chat/ChatSheet/ChatSheet.js +2 -2
  3. package/dist/esm/components/ui/Page/PageHeader/PageHeader.js +2 -2
  4. package/dist/esm/components/ui/Page/PageHeader/PageHeader.styl.js +2 -2
  5. package/dist/esm/components/ui/Renamer/Renamer.js +4 -4
  6. package/dist/esm/components/ui/Renamer/Renamer.styl.js +2 -2
  7. package/dist/esm/components/ui/Sidebar/Sidebar.js +20 -7
  8. package/dist/esm/components/ui/Sidebar/Sidebar.styl.js +2 -2
  9. package/dist/esm/components/ui/SmartTextTruncate/SmartTextTruncate.js +260 -67
  10. package/dist/esm/components/ui/SmartTextTruncate/SmartTextTruncate.styl.js +7 -0
  11. package/dist/esm/components/widgets/DriversComparisonChart/DriversComparisonChart.js +21 -5
  12. package/dist/esm/components/widgets/PerformanceChart/PerformanceChart.js +10 -3
  13. package/dist/esm/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.js +5 -5
  14. package/dist/esm/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.styl.js +2 -2
  15. package/dist/esm/index.js +1 -1
  16. package/dist/esm/types/src/components/ui/Chat/ChatSheet/ChatSheet.d.ts +2 -1
  17. package/dist/esm/types/src/components/ui/Page/PageHeader/PageHeader.d.ts +2 -1
  18. package/dist/esm/types/src/components/ui/Sidebar/Sidebar.d.ts +7 -2
  19. package/dist/esm/types/src/components/ui/SmartTextTruncate/SmartTextTruncate.d.ts +5 -3
  20. package/dist/esm/types/src/components/ui/SmartTextTruncate/index.d.ts +1 -1
  21. package/dist/esm/types/src/components/widgets/DriversComparisonChart/DriversComparisonChart.d.ts +3 -1
  22. package/dist/esm/types/src/components/widgets/PerformanceChart/PerformanceChart.d.ts +4 -1
  23. package/package.json +1 -1
  24. package/src/components/ui/Button/Button.styl +5 -10
  25. package/src/components/ui/Chat/ChatSheet/ChatSheet.tsx +5 -2
  26. package/src/components/ui/Page/PageHeader/PageHeader.styl +5 -0
  27. package/src/components/ui/Page/PageHeader/PageHeader.styl.d.ts +1 -0
  28. package/src/components/ui/Page/PageHeader/PageHeader.tsx +8 -1
  29. package/src/components/ui/Renamer/Renamer.styl +19 -4
  30. package/src/components/ui/Renamer/Renamer.tsx +8 -9
  31. package/src/components/ui/Sidebar/Sidebar.styl +61 -51
  32. package/src/components/ui/Sidebar/Sidebar.styl.d.ts +4 -0
  33. package/src/components/ui/Sidebar/Sidebar.tsx +66 -6
  34. package/src/components/ui/SmartTextTruncate/SmartTextTruncate.styl +34 -0
  35. package/src/components/ui/SmartTextTruncate/SmartTextTruncate.styl.d.ts +10 -0
  36. package/src/components/ui/SmartTextTruncate/SmartTextTruncate.tsx +335 -81
  37. package/src/components/ui/SmartTextTruncate/index.ts +5 -1
  38. package/src/components/widgets/DriversComparisonChart/DriversComparisonChart.tsx +53 -20
  39. package/src/components/widgets/PerformanceChart/PerformanceChart.tsx +21 -2
  40. package/src/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.styl +0 -24
  41. package/src/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.styl.d.ts +0 -2
  42. package/src/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.tsx +5 -11
  43. package/src/docs/components/DocsSidebar/DocsSidebar.tsx +3 -17
  44. package/src/docs/pages/SidebarDatasetsItemsGroupedPage.tsx +4 -1
  45. package/src/docs/pages/SmartTextTruncatePage.styl +22 -0
  46. package/src/docs/pages/SmartTextTruncatePage.styl.d.ts +2 -0
  47. package/src/docs/pages/SmartTextTruncatePage.tsx +21 -1
@@ -1,108 +1,371 @@
1
- import { useLayoutEffect, useRef, useState } from 'react';
1
+ import cn from 'classnames';
2
+ import { memo, useCallback, useLayoutEffect, useRef, useState } from 'react';
2
3
 
4
+ import S from './SmartTextTruncate.styl';
3
5
  import type { SmartTextTruncateProps } from './SmartTextTruncate.types';
4
6
 
5
7
  const ELLIPSIS = ' ... ';
6
8
  const END_CHARS_COUNT = 10;
9
+ const RESIZE_SETTLE_MS = 120;
10
+ const GLOBAL_KEY = '__sybilionSmartTextTruncate';
11
+ const RESIZE_ROOT_SELECTOR = '[data-smart-text-truncate-resize-root]';
12
+ const DRAG_THRESHOLD_PX = 3;
7
13
 
8
- function SmartTextTruncate({
14
+ type InteractionStore = {
15
+ isPanelDragging: boolean;
16
+ isResizeRootDragging: boolean;
17
+ };
18
+
19
+ type GlobalState = {
20
+ store: InteractionStore;
21
+ settleTimer: ReturnType<typeof setTimeout> | null;
22
+ resizeRafId: number;
23
+ recalcCallbacks: Set<() => void>;
24
+ resizeRootListenersInit: boolean;
25
+ panelDragActive: boolean;
26
+ };
27
+
28
+ type PendingResizeRootDrag = {
29
+ pointerId: number;
30
+ startX: number;
31
+ startY: number;
32
+ };
33
+
34
+ function getGlobalState(): GlobalState {
35
+ const w = window as Window & { [GLOBAL_KEY]?: GlobalState };
36
+ if (!w[GLOBAL_KEY]) {
37
+ w[GLOBAL_KEY] = {
38
+ store: {
39
+ isPanelDragging: false,
40
+ isResizeRootDragging: false,
41
+ },
42
+ settleTimer: null,
43
+ resizeRafId: 0,
44
+ recalcCallbacks: new Set(),
45
+ resizeRootListenersInit: false,
46
+ panelDragActive: false,
47
+ };
48
+ }
49
+ return w[GLOBAL_KEY];
50
+ }
51
+
52
+ let pendingResizeRootDrag: PendingResizeRootDrag | null = null;
53
+
54
+ function getIsFastMode(store: InteractionStore) {
55
+ return store.isPanelDragging || store.isResizeRootDragging;
56
+ }
57
+
58
+ function syncFastModeDom(store: InteractionStore) {
59
+ if (typeof document === 'undefined') {
60
+ return;
61
+ }
62
+ if (getIsFastMode(store)) {
63
+ document.documentElement.dataset.smartTextTruncateFast = '';
64
+ } else {
65
+ delete document.documentElement.dataset.smartTextTruncateFast;
66
+ }
67
+ }
68
+
69
+ function clearSettleTimer() {
70
+ const g = getGlobalState();
71
+ if (g.settleTimer) {
72
+ clearTimeout(g.settleTimer);
73
+ g.settleTimer = null;
74
+ }
75
+ }
76
+
77
+ function runSettleRecalc() {
78
+ getGlobalState().recalcCallbacks.forEach(recalc => recalc());
79
+ }
80
+
81
+ function scheduleSettle() {
82
+ const g = getGlobalState();
83
+ clearSettleTimer();
84
+
85
+ g.settleTimer = setTimeout(() => {
86
+ g.settleTimer = null;
87
+ runSettleRecalc();
88
+ }, RESIZE_SETTLE_MS);
89
+ }
90
+
91
+ function notifyContainerResize() {
92
+ const g = getGlobalState();
93
+ if (getIsFastMode(g.store)) {
94
+ return;
95
+ }
96
+ scheduleSettle();
97
+ }
98
+
99
+ function beginResizeRootDrag() {
100
+ const g = getGlobalState();
101
+ if (g.store.isResizeRootDragging) {
102
+ return;
103
+ }
104
+
105
+ clearSettleTimer();
106
+ g.store = { ...g.store, isResizeRootDragging: true };
107
+ syncFastModeDom(g.store);
108
+ }
109
+
110
+ function endResizeRootDrag() {
111
+ const g = getGlobalState();
112
+ pendingResizeRootDrag = null;
113
+
114
+ if (!g.store.isResizeRootDragging) {
115
+ return;
116
+ }
117
+
118
+ g.store = { ...g.store, isResizeRootDragging: false };
119
+ syncFastModeDom(g.store);
120
+ scheduleSettle();
121
+ }
122
+
123
+ function onResizeRootPointerDown(e: PointerEvent) {
124
+ if (e.button !== 0) {
125
+ return;
126
+ }
127
+
128
+ const root = (e.target as Element | null)?.closest(RESIZE_ROOT_SELECTOR);
129
+ if (!root) {
130
+ return;
131
+ }
132
+
133
+ clearSettleTimer();
134
+ pendingResizeRootDrag = {
135
+ pointerId: e.pointerId,
136
+ startX: e.clientX,
137
+ startY: e.clientY,
138
+ };
139
+ }
140
+
141
+ function onResizeRootPointerMove(e: PointerEvent) {
142
+ const pending = pendingResizeRootDrag;
143
+ if (!pending || e.pointerId !== pending.pointerId) {
144
+ return;
145
+ }
146
+
147
+ const dx = e.clientX - pending.startX;
148
+ const dy = e.clientY - pending.startY;
149
+ if (Math.hypot(dx, dy) < DRAG_THRESHOLD_PX) {
150
+ return;
151
+ }
152
+
153
+ beginResizeRootDrag();
154
+ }
155
+
156
+ function onResizeRootPointerUp(e: PointerEvent) {
157
+ const pending = pendingResizeRootDrag;
158
+ if (!pending || e.pointerId !== pending.pointerId) {
159
+ return;
160
+ }
161
+
162
+ endResizeRootDrag();
163
+ }
164
+
165
+ function ensureResizeRootListeners() {
166
+ const g = getGlobalState();
167
+ if (g.resizeRootListenersInit) {
168
+ return;
169
+ }
170
+ g.resizeRootListenersInit = true;
171
+ window.addEventListener('pointerdown', onResizeRootPointerDown);
172
+ window.addEventListener('pointermove', onResizeRootPointerMove);
173
+ window.addEventListener('pointerup', onResizeRootPointerUp);
174
+ window.addEventListener('pointercancel', onResizeRootPointerUp);
175
+ }
176
+
177
+ function scheduleContainerResize() {
178
+ const g = getGlobalState();
179
+ if (g.resizeRafId !== 0) {
180
+ return;
181
+ }
182
+ g.resizeRafId = requestAnimationFrame(() => {
183
+ g.resizeRafId = 0;
184
+ notifyContainerResize();
185
+ });
186
+ }
187
+
188
+ let sharedResizeObserver: ResizeObserver | null = null;
189
+ let widthProbe: Element | null = null;
190
+
191
+ function observeWidthProbe(container: Element) {
192
+ if (widthProbe) {
193
+ return;
194
+ }
195
+
196
+ if (!sharedResizeObserver) {
197
+ sharedResizeObserver = new ResizeObserver(() => {
198
+ const g = getGlobalState();
199
+ if (getIsFastMode(g.store)) {
200
+ return;
201
+ }
202
+ scheduleContainerResize();
203
+ });
204
+ }
205
+
206
+ widthProbe = container;
207
+ sharedResizeObserver.observe(container);
208
+ }
209
+
210
+ function unobserveWidthProbe(container: Element) {
211
+ if (widthProbe !== container) {
212
+ return;
213
+ }
214
+
215
+ sharedResizeObserver?.unobserve(container);
216
+ widthProbe = null;
217
+ }
218
+
219
+ /** Panel resize handle — call on first pointer move after press, not on pointer down. */
220
+ function notifyPanelWidthDragStart() {
221
+ const g = getGlobalState();
222
+ if (g.panelDragActive) {
223
+ return;
224
+ }
225
+
226
+ clearSettleTimer();
227
+ g.panelDragActive = true;
228
+ g.store = { ...g.store, isPanelDragging: true };
229
+ syncFastModeDom(g.store);
230
+ }
231
+
232
+ function notifyPanelWidthDragEnd() {
233
+ const g = getGlobalState();
234
+ if (!g.panelDragActive) {
235
+ return;
236
+ }
237
+
238
+ g.panelDragActive = false;
239
+ g.store = { ...g.store, isPanelDragging: false };
240
+ syncFastModeDom(g.store);
241
+ scheduleSettle();
242
+ }
243
+
244
+ function computeTruncatedText(
245
+ fullTextEl: HTMLSpanElement,
246
+ text: string,
247
+ containerWidth: number,
248
+ ): string {
249
+ if (text.length <= END_CHARS_COUNT) {
250
+ return text;
251
+ }
252
+
253
+ fullTextEl.textContent = text;
254
+ if (fullTextEl.scrollWidth <= containerWidth) {
255
+ return text;
256
+ }
257
+
258
+ const endPart = text.slice(-END_CHARS_COUNT);
259
+ let left = 0;
260
+ let right = text.length - END_CHARS_COUNT;
261
+ let bestStart = 0;
262
+
263
+ while (left <= right) {
264
+ const mid = Math.floor((left + right) / 2);
265
+ const startPart = text.slice(0, mid);
266
+ const truncated = startPart + ELLIPSIS + endPart;
267
+
268
+ fullTextEl.textContent = truncated;
269
+ if (fullTextEl.scrollWidth <= containerWidth) {
270
+ bestStart = mid;
271
+ left = mid + 1;
272
+ } else {
273
+ right = mid - 1;
274
+ }
275
+ }
276
+
277
+ if (bestStart === 0) {
278
+ fullTextEl.textContent = ELLIPSIS + endPart;
279
+ if (fullTextEl.scrollWidth <= containerWidth) {
280
+ return ELLIPSIS + endPart;
281
+ }
282
+ return endPart;
283
+ }
284
+
285
+ return text.slice(0, bestStart) + ELLIPSIS + endPart;
286
+ }
287
+
288
+ const SmartTextTruncate = memo(function SmartTextTruncate({
9
289
  children,
10
290
  className,
11
291
  ...props
12
292
  }: SmartTextTruncateProps) {
13
293
  const containerRef = useRef<HTMLSpanElement>(null);
14
294
  const fullTextRef = useRef<HTMLSpanElement>(null);
295
+ const lastMeasuredWidthRef = useRef(0);
296
+ const childrenRef = useRef(children);
297
+ childrenRef.current = children;
15
298
  const [displayText, setDisplayText] = useState<string>(
16
299
  typeof children === 'string' ? children : '',
17
300
  );
18
- const [resizeTrigger, setResizeTrigger] = useState(0);
301
+ const displayTextRef = useRef(displayText);
302
+ displayTextRef.current = displayText;
303
+
304
+ const recalc = useCallback(() => {
305
+ if (getIsFastMode(getGlobalState().store)) {
306
+ return;
307
+ }
19
308
 
20
- useLayoutEffect(() => {
21
309
  const container = containerRef.current;
22
310
  const fullText = fullTextRef.current;
311
+ const text = childrenRef.current;
23
312
 
24
- if (!container || !fullText || typeof children !== 'string') {
313
+ if (!container || !fullText || typeof text !== 'string') {
25
314
  return;
26
315
  }
27
316
 
28
- const text = children;
29
-
30
- // If text is shorter than END_CHARS_COUNT, no truncation needed
31
317
  if (text.length <= END_CHARS_COUNT) {
32
- setDisplayText(text);
318
+ if (displayTextRef.current !== text) {
319
+ setDisplayText(text);
320
+ }
33
321
  return;
34
322
  }
35
323
 
36
- // Measure container width
37
324
  const containerWidth = container.clientWidth;
38
325
  if (containerWidth === 0) {
39
- // Container not yet rendered, keep current text
40
326
  return;
41
327
  }
42
328
 
43
- // Measure full text width
44
- fullText.textContent = text;
45
- const fullTextWidth = fullText.scrollWidth;
46
-
47
- // If text fits, show full text
48
- if (fullTextWidth <= containerWidth) {
49
- setDisplayText(text);
329
+ if (
330
+ containerWidth === lastMeasuredWidthRef.current &&
331
+ lastMeasuredWidthRef.current !== 0
332
+ ) {
50
333
  return;
51
334
  }
52
335
 
53
- // Calculate truncated text: <start>...<last 10 chars>
54
- const endPart = text.slice(-END_CHARS_COUNT);
55
-
56
- // Binary search for optimal start length
57
- let left = 0;
58
- let right = text.length - END_CHARS_COUNT;
59
- let bestStart = 0;
336
+ lastMeasuredWidthRef.current = containerWidth;
337
+ const nextText = computeTruncatedText(fullText, text, containerWidth);
60
338
 
61
- while (left <= right) {
62
- const mid = Math.floor((left + right) / 2);
63
- const startPart = text.slice(0, mid);
64
- const truncated = startPart + ELLIPSIS + endPart;
65
-
66
- fullText.textContent = truncated;
67
- const truncatedWidth = fullText.scrollWidth;
68
-
69
- if (truncatedWidth <= containerWidth) {
70
- bestStart = mid;
71
- left = mid + 1;
72
- } else {
73
- right = mid - 1;
74
- }
339
+ if (nextText !== displayTextRef.current) {
340
+ setDisplayText(nextText);
75
341
  }
342
+ }, []);
76
343
 
77
- // Ensure we have at least some start text
78
- if (bestStart === 0) {
79
- // If even just ellipsis + end doesn't fit, show only end part
80
- fullText.textContent = ELLIPSIS + endPart;
81
- if (fullText.scrollWidth <= containerWidth) {
82
- setDisplayText(ELLIPSIS + endPart);
83
- } else {
84
- // Last resort: show only end part without ellipsis
85
- setDisplayText(endPart);
86
- }
87
- } else {
88
- setDisplayText(text.slice(0, bestStart) + ELLIPSIS + endPart);
89
- }
90
- }, [children, resizeTrigger]);
344
+ useLayoutEffect(() => {
345
+ lastMeasuredWidthRef.current = 0;
346
+ recalc();
347
+ }, [children, recalc]);
91
348
 
92
- // Handle ResizeObserver for container resizing
93
349
  useLayoutEffect(() => {
94
- const container = containerRef.current;
95
- if (!container) return;
350
+ ensureResizeRootListeners();
351
+ const g = getGlobalState();
352
+ g.recalcCallbacks.add(recalc);
353
+ return () => {
354
+ g.recalcCallbacks.delete(recalc);
355
+ };
356
+ }, [recalc]);
96
357
 
97
- const resizeObserver = new ResizeObserver(() => {
98
- // Trigger recalculation by updating resizeTrigger
99
- setResizeTrigger(prev => prev + 1);
100
- });
358
+ useLayoutEffect(() => {
359
+ ensureResizeRootListeners();
360
+ const container = containerRef.current;
361
+ if (!container) {
362
+ return;
363
+ }
101
364
 
102
- resizeObserver.observe(container);
365
+ observeWidthProbe(container);
103
366
 
104
367
  return () => {
105
- resizeObserver.disconnect();
368
+ unobserveWidthProbe(container);
106
369
  };
107
370
  }, []);
108
371
 
@@ -115,27 +378,18 @@ function SmartTextTruncate({
115
378
  }
116
379
 
117
380
  return (
118
- <span
119
- ref={containerRef}
120
- className={className}
121
- {...props}
122
- style={{ position: 'relative', ...props.style }}
123
- >
124
- {displayText}
125
- <span
126
- ref={fullTextRef}
127
- style={{
128
- position: 'absolute',
129
- visibility: 'hidden',
130
- whiteSpace: 'nowrap',
131
- top: '-9999px',
132
- }}
133
- aria-hidden="true"
134
- >
381
+ <span ref={containerRef} className={cn(S.root, className)} {...props}>
382
+ <span className={S.measuredLabel}>{displayText || children}</span>
383
+ <span className={S.liveLabel}>{children}</span>
384
+ <span ref={fullTextRef} className={S.fullText} aria-hidden="true">
135
385
  {children}
136
386
  </span>
137
387
  </span>
138
388
  );
139
- }
389
+ });
140
390
 
141
- export { SmartTextTruncate };
391
+ export {
392
+ SmartTextTruncate,
393
+ notifyPanelWidthDragStart,
394
+ notifyPanelWidthDragEnd,
395
+ };
@@ -1,2 +1,6 @@
1
- export { SmartTextTruncate } from './SmartTextTruncate';
1
+ export {
2
+ SmartTextTruncate,
3
+ notifyPanelWidthDragStart,
4
+ notifyPanelWidthDragEnd,
5
+ } from './SmartTextTruncate';
2
6
  export type { SmartTextTruncateProps } from './SmartTextTruncate.types';
@@ -66,6 +66,10 @@ export type DriversComparisonChartProps = {
66
66
  seriesInitKey?: string;
67
67
  viewTab?: DriversComparisonViewTab;
68
68
  onViewTabChange?: (tab: DriversComparisonViewTab) => void;
69
+ hiddenSeries?: Set<string>;
70
+ onHiddenSeriesChange?: (
71
+ update: Set<string> | ((prev: Set<string>) => Set<string>),
72
+ ) => void;
69
73
  };
70
74
 
71
75
  export type { DriversComparisonViewTab } from './driversComparisonChart.helpers';
@@ -85,14 +89,31 @@ export function DriversComparisonChart({
85
89
  seriesInitKey,
86
90
  viewTab: viewTabProp,
87
91
  onViewTabChange,
92
+ hiddenSeries: hiddenSeriesProp,
93
+ onHiddenSeriesChange,
88
94
  }: DriversComparisonChartProps) {
89
95
  const [internalTimeRange, setInternalTimeRange] =
90
96
  useState<string>(ALL_TIME_RANGE);
91
97
  const [internalViewTab, setInternalViewTab] =
92
98
  useState<DriversComparisonViewTab>('overlapped');
93
- const [hiddenSeries, setHiddenSeries] = useState<Set<string>>(new Set());
99
+ const [internalHiddenSeries, setInternalHiddenSeries] = useState<Set<string>>(
100
+ new Set(),
101
+ );
94
102
 
95
103
  const viewTab = viewTabProp ?? internalViewTab;
104
+ const hiddenSeriesControlled = hiddenSeriesProp !== undefined;
105
+ const hiddenSeries = hiddenSeriesProp ?? internalHiddenSeries;
106
+
107
+ const setHiddenSeries = useCallback(
108
+ (update: Set<string> | ((prev: Set<string>) => Set<string>)) => {
109
+ if (onHiddenSeriesChange) {
110
+ onHiddenSeriesChange(update);
111
+ return;
112
+ }
113
+ setInternalHiddenSeries(update);
114
+ },
115
+ [onHiddenSeriesChange],
116
+ );
96
117
 
97
118
  const timeRange = timeRangeProp ?? internalTimeRange;
98
119
  const handleTimeRangeChange = useCallback(
@@ -106,25 +127,31 @@ export function DriversComparisonChart({
106
127
  [onTimeRangeChange, timeRangeProp],
107
128
  );
108
129
 
109
- const toggleSeries = useCallback((id: number | string) => {
110
- const key = toForecastDataKey(id);
111
- setHiddenSeries(prev => {
112
- const next = new Set(prev);
113
- if (next.has(key)) next.delete(key);
114
- else next.add(key);
115
- return next;
116
- });
117
- }, []);
130
+ const toggleSeries = useCallback(
131
+ (id: number | string) => {
132
+ const key = toForecastDataKey(id);
133
+ setHiddenSeries(prev => {
134
+ const next = new Set(prev);
135
+ if (next.has(key)) next.delete(key);
136
+ else next.add(key);
137
+ return next;
138
+ });
139
+ },
140
+ [setHiddenSeries],
141
+ );
118
142
 
119
- const showSeries = useCallback((id: number | string) => {
120
- const key = toForecastDataKey(id);
121
- setHiddenSeries(prev => {
122
- if (!prev.has(key)) return prev;
123
- const next = new Set(prev);
124
- next.delete(key);
125
- return next;
126
- });
127
- }, []);
143
+ const showSeries = useCallback(
144
+ (id: number | string) => {
145
+ const key = toForecastDataKey(id);
146
+ setHiddenSeries(prev => {
147
+ if (!prev.has(key)) return prev;
148
+ const next = new Set(prev);
149
+ next.delete(key);
150
+ return next;
151
+ });
152
+ },
153
+ [setHiddenSeries],
154
+ );
128
155
 
129
156
  const payloadForView = useMemo(
130
157
  () => applyDriversComparisonViewToPayload(payload, viewTab),
@@ -222,6 +249,7 @@ export function DriversComparisonChart({
222
249
  const backtestsSeriesInitKeyRef = useRef<string>('');
223
250
 
224
251
  useEffect(() => {
252
+ if (hiddenSeriesControlled) return;
225
253
  if (tableSeriesRows.length === 0) return;
226
254
  const initKey = seriesInitKeyResolved;
227
255
  if (backtestsSeriesInitKeyRef.current === initKey) return;
@@ -237,7 +265,12 @@ export function DriversComparisonChart({
237
265
  });
238
266
  return next;
239
267
  });
240
- }, [seriesInitKeyResolved, tableSeriesRows]);
268
+ }, [
269
+ hiddenSeriesControlled,
270
+ seriesInitKeyResolved,
271
+ setHiddenSeries,
272
+ tableSeriesRows,
273
+ ]);
241
274
 
242
275
  const driversComparisonChartData = useMemo(
243
276
  () =>
@@ -134,6 +134,10 @@ export type PerformanceChartProps = {
134
134
  meta?: { viewTab: PerformanceViewTab },
135
135
  ) => void;
136
136
 
137
+ /** Controlled Per horizon / Spaghetti tab; omit for internal state. */
138
+ viewTab?: PerformanceViewTab;
139
+ onViewTabChange?: (tab: PerformanceViewTab) => void;
140
+
137
141
  isDarkTheme?: boolean;
138
142
  className?: string;
139
143
  seriesInitKey?: string;
@@ -177,6 +181,9 @@ export function PerformanceChart({
177
181
  timeRange: timeRangeProp,
178
182
  onTimeRangeChange,
179
183
 
184
+ viewTab: viewTabProp,
185
+ onViewTabChange,
186
+
180
187
  isDarkTheme = false,
181
188
  className,
182
189
  seriesInitKey,
@@ -192,7 +199,8 @@ export function PerformanceChart({
192
199
  onEnsureSeriesVisible,
193
200
  onHiddenSeriesChange,
194
201
  }: PerformanceChartProps) {
195
- const [viewTab, setViewTab] = useState<PerformanceViewTab>('perHorizon');
202
+ const [internalViewTab, setInternalViewTab] =
203
+ useState<PerformanceViewTab>('perHorizon');
196
204
  const [pinMonth, setPinMonth] = useState<string | undefined>(undefined);
197
205
  const [spaghettiTimeRange, setSpaghettiTimeRange] = useState<string>('All');
198
206
  const [perHorizonChartTimeRange, setPerHorizonChartTimeRange] =
@@ -212,6 +220,17 @@ export function PerformanceChart({
212
220
 
213
221
  const hiddenSeriesControlled = hiddenSeriesProp !== undefined;
214
222
  const hiddenSeries = hiddenSeriesProp ?? internalHiddenSeries;
223
+ const viewTab = viewTabProp ?? internalViewTab;
224
+
225
+ const handleViewTabChange = useCallback(
226
+ (tab: PerformanceViewTab) => {
227
+ onViewTabChange?.(tab);
228
+ if (viewTabProp === undefined) {
229
+ setInternalViewTab(tab);
230
+ }
231
+ },
232
+ [onViewTabChange, viewTabProp],
233
+ );
215
234
 
216
235
  const setHiddenSeries = useCallback(
217
236
  (update: Set<string> | ((prev: Set<string>) => Set<string>)) => {
@@ -1137,7 +1156,7 @@ export function PerformanceChart({
1137
1156
  value={viewTab}
1138
1157
  onValueChange={v => {
1139
1158
  if (v === 'perHorizon' || v === 'spaghetti') {
1140
- setViewTab(v);
1159
+ handleViewTabChange(v);
1141
1160
  }
1142
1161
  }}
1143
1162
  className={S.viewTabs}
@@ -1,29 +1,5 @@
1
- .chevronContainer
2
- margin-left auto
3
-
4
1
  .subMenuContainer
5
2
  position relative
6
3
 
7
- .subMenuBorder
8
- position absolute
9
- left var(--p-5)
10
- top 0
11
- bottom 26px
12
- width 1px
13
- background var(--sidebar-border)
14
-
15
4
  .subMenuItem
16
5
  position relative
17
- margin-left var(--p-6)
18
-
19
- &::before
20
- content ''
21
- position absolute
22
- left calc(var(--p-1) * -1)
23
- top var(--p-2)
24
- bottom 0
25
- width var(--p-3)
26
- height var(--p-3)
27
- border-left 1px solid var(--sidebar-border)
28
- border-bottom 1px solid var(--sidebar-border)
29
- border-bottom-left-radius var(--p-2)
@@ -1,8 +1,6 @@
1
1
  // This file is automatically generated.
2
2
  // Please do not change this file!
3
3
  interface CssExports {
4
- 'chevronContainer': string;
5
- 'subMenuBorder': string;
6
4
  'subMenuContainer': string;
7
5
  'subMenuItem': string;
8
6
  }