@sybilion/uilib 1.3.102 → 1.3.104

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.
@@ -6,18 +6,22 @@ import 'recharts';
6
6
  import '../../../Chart/Chart.context.js';
7
7
  import '../../../Chart/Chart.styl.js';
8
8
  import { useDebounceCallback } from '../../../../../hooks/useDebounceCallback.js';
9
+ import useElemDrag from '../../../../../hooks/useDragElem.js';
9
10
  import { ChevronsLeftRight } from 'lucide-react';
10
11
  import S from '../../ChartAreaInteractive.styl.js';
11
12
  import { useChartYRange } from '../useChartYRange.js';
12
13
  import S$1 from './PinOverlay.styl.js';
13
14
 
14
- function PinOverlay({ baseChartProps, pinMonth, onPinMonthChange, onPreviewMonthChange: _onPreviewMonthChange, className, }) {
15
+ function PinOverlay({ baseChartProps, pinMonth, onPinMonthChange, onPreviewMonthChange, className, }) {
15
16
  const { chartData } = baseChartProps;
16
17
  const chartRef = useRef(null);
17
18
  const pinRef = useRef(null);
18
19
  const pinPlaceholderRef = useRef(null);
19
20
  const pinContainerRef = useRef(null);
21
+ const containerRectRef = useRef(null);
20
22
  const [isPinHovered, setIsPinHovered] = useState(false);
23
+ const [isDraggingPin, setIsDraggingPin] = useState(false);
24
+ const [isPinAnimating, setIsPinAnimating] = useState(true);
21
25
  const pinPosRef = useRef(0);
22
26
  const currPinMonthRef = useRef(pinMonth);
23
27
  const debouncedOnPinMonthChange = useDebounceCallback((...args) => onPinMonthChange?.(args[0]), 500, [onPinMonthChange]);
@@ -97,6 +101,57 @@ function PinOverlay({ baseChartProps, pinMonth, onPinMonthChange, onPreviewMonth
97
101
  currPinMonthRef.current = pinMonth;
98
102
  }
99
103
  }, [pinMonth, chartData]);
104
+ const clearPinTransforms = () => {
105
+ if (pinRef.current) {
106
+ pinRef.current.style.transform = '';
107
+ pinRef.current.style.transition = '';
108
+ }
109
+ if (pinPlaceholderRef.current) {
110
+ pinPlaceholderRef.current.style.transform = '';
111
+ pinPlaceholderRef.current.style.transition = '';
112
+ }
113
+ };
114
+ useElemDrag({
115
+ elem: pinPlaceholderRef,
116
+ isActive: chartData.length > 0,
117
+ onDragStart: e => {
118
+ e.stopPropagation();
119
+ setIsDraggingPin(true);
120
+ setIsPinAnimating(false);
121
+ containerRectRef.current =
122
+ pinContainerRef.current?.getBoundingClientRect() ?? null;
123
+ if (pinRef.current)
124
+ pinRef.current.style.transition = 'none';
125
+ if (pinPlaceholderRef.current) {
126
+ pinPlaceholderRef.current.style.transition = 'none';
127
+ }
128
+ },
129
+ onDrag: (_delta, e) => {
130
+ const containerRect = containerRectRef.current;
131
+ if (!containerRect)
132
+ return;
133
+ const pinCurrentLeft = (pinPosRef.current / 100) * containerRect.width;
134
+ const relativeX = e.clientX - containerRect.left;
135
+ const clampedX = Math.max(0, Math.min(containerRect.width, relativeX));
136
+ const translateX = clampedX - pinCurrentLeft;
137
+ const transform = `translateX(${translateX}px)`;
138
+ if (pinRef.current)
139
+ pinRef.current.style.transform = transform;
140
+ if (pinPlaceholderRef.current) {
141
+ pinPlaceholderRef.current.style.transform = transform;
142
+ }
143
+ const previewPercent = containerRect.width > 0 ? (clampedX / containerRect.width) * 100 : 0;
144
+ onPreviewMonthChange?.(getPinMonthAndYear(previewPercent) ?? undefined);
145
+ },
146
+ onDragEnd: e => {
147
+ e.stopPropagation();
148
+ setIsDraggingPin(false);
149
+ setTimeout(() => setIsPinAnimating(true), 200);
150
+ containerRectRef.current = null;
151
+ clearPinTransforms();
152
+ snapPinToPosition(e.clientX, true, true);
153
+ },
154
+ });
100
155
  const onChartClick = (e) => {
101
156
  if (e.button !== 0)
102
157
  return;
@@ -105,8 +160,8 @@ function PinOverlay({ baseChartProps, pinMonth, onPinMonthChange, onPreviewMonth
105
160
  return;
106
161
  snapPinToPosition(e.clientX, true, false);
107
162
  };
108
- const overlay = (jsxs(Fragment, { children: [jsx("div", { className: cn(S.overlay, S$1.pinContainer), ref: pinContainerRef, children: jsx("div", { className: S$1.pinLineBase, style: { left: `${pinPosRef.current}%` }, ref: pinRef, children: jsx("div", { className: S$1.pinButton, "aria-label": "News pin", title: `Current month: ${getPinMonthAndYear() || 'Loading...'}`, children: jsx(ChevronsLeftRight, { className: S$1.pinIcon, "aria-hidden": "true" }) }) }) }), jsx("div", { className: S$1.pinPlaceholder, style: { left: `${pinPosRef.current}%` }, ref: pinPlaceholderRef, onPointerEnter: () => setIsPinHovered(true), onPointerLeave: () => setIsPinHovered(false) })] }));
109
- return (jsx("div", { className: cn(className, S$1.root, S$1.pinAnimating, isPinHovered && S$1.pinHovered), onClick: onChartClick, ref: chartRef, children: jsx(BaseChartWrapper, { ...baseChartProps, yMin: yMin, yMax: yMax, autoScaleYAxis: false, overlayElements: overlay }) }));
163
+ const overlay = (jsxs(Fragment, { children: [jsx("div", { className: cn(S.overlay, S$1.pinContainer), ref: pinContainerRef, children: jsx("div", { className: S$1.pinLineBase, style: { left: `${pinPosRef.current}%` }, ref: pinRef, children: jsx("div", { className: S$1.pinButton, "aria-label": "News pin", title: `Current month: ${getPinMonthAndYear() || 'Loading...'}`, children: jsx(ChevronsLeftRight, { className: S$1.pinIcon, "aria-hidden": "true" }) }) }) }), jsx("div", { className: cn(S.overlay, S$1.pinPlaceholderHost), children: jsx("div", { className: S$1.pinPlaceholder, style: { left: `${pinPosRef.current}%` }, ref: pinPlaceholderRef, onPointerEnter: () => setIsPinHovered(true), onPointerLeave: () => setIsPinHovered(false) }) })] }));
164
+ return (jsx("div", { className: cn(className, S$1.root, isPinAnimating && S$1.pinAnimating, isPinHovered && S$1.pinHovered, isDraggingPin && S$1.pinDragging), onClick: onChartClick, ref: chartRef, children: jsx(BaseChartWrapper, { ...baseChartProps, yMin: yMin, yMax: yMax, autoScaleYAxis: false, showTooltip: !isDraggingPin, overlayElements: overlay }) }));
110
165
  }
111
166
 
112
167
  export { PinOverlay };
@@ -1,7 +1,7 @@
1
1
  import styleInject from 'style-inject';
2
2
 
3
- var css_248z = ".PinOverlay_root__RUZxO{touch-action:pan-y}.PinOverlay_pinContainer__6sc1J{height:calc(var(--chart-height) - 70px);inset:0;margin:var(--p-5) var(--p-8) var(--p-24) var(--p-12);pointer-events:none;position:absolute;touch-action:pan-y;transition:transform .2s ease-out,z-index 0ms;-webkit-user-select:none;-moz-user-select:none;user-select:none;z-index:2}.PinOverlay_pinHovered__cGPjN .PinOverlay_pinContainer__6sc1J{z-index:10}.PinOverlay_pinLineBase__0BWsD{height:100%;pointer-events:none;position:absolute;width:3px}.PinOverlay_pinLineBase__0BWsD:before{border-radius:50%;box-shadow:0 4px 6px -1px var(--shadow-color);content:\"\";height:36px;left:-16px;position:absolute;top:-8px;width:36px;z-index:-1}.PinOverlay_pinLineBase__0BWsD:after{background-color:var(--background);border-radius:12px;bottom:0;content:\"\";left:0;position:absolute;top:0;transform:translate3d(.5px,0,0);transition:background-color .3s ease-out;width:100%;z-index:1}.PinOverlay_pinAnimating__5XMJG .PinOverlay_pinLineBase__0BWsD{transition:left .3s ease-out}.PinOverlay_pinButton__cnV1K{position:absolute;--offset:-8px;align-items:center;background-color:var(--background);border-radius:9999px;cursor:pointer;display:flex;justify-content:center;left:-8px;left:var(--offset);margin-left:-8px;margin-left:var(--offset);padding:10px;pointer-events:auto;top:-18px;touch-action:none;transition:transform .2s ease-out;-webkit-user-select:none;-moz-user-select:none;user-select:none}.PinOverlay_pinHovered__cGPjN .PinOverlay_pinButton__cnV1K{transform:scale(1.1)}.PinOverlay_pinButton__cnV1K:active{cursor:grabbing}.PinOverlay_pinIcon__s7Ze0{color:var(--foreground);height:16px;width:16px}.PinOverlay_pinPlaceholder__JhKcQ{cursor:pointer;height:72px;margin-left:-40px;margin-top:-40px;pointer-events:auto;position:absolute;top:var(--p-5);touch-action:none;width:72px;z-index:20}.PinOverlay_pinAnimating__5XMJG .PinOverlay_pinPlaceholder__JhKcQ{transition:left .3s ease-out}.PinOverlay_pinPlaceholder__JhKcQ:active{cursor:grabbing}";
4
- var S = {"root":"PinOverlay_root__RUZxO","pinContainer":"PinOverlay_pinContainer__6sc1J","pinHovered":"PinOverlay_pinHovered__cGPjN","pinLineBase":"PinOverlay_pinLineBase__0BWsD","pinAnimating":"PinOverlay_pinAnimating__5XMJG","pinButton":"PinOverlay_pinButton__cnV1K","pinIcon":"PinOverlay_pinIcon__s7Ze0","pinPlaceholder":"PinOverlay_pinPlaceholder__JhKcQ"};
3
+ var css_248z = ".PinOverlay_root__RUZxO{touch-action:pan-y}.PinOverlay_pinDragging__gu3xp .PinOverlay_pinLineBase__0BWsD{opacity:.8}.PinOverlay_pinDragging__gu3xp .PinOverlay_pinButton__cnV1K,.PinOverlay_pinDragging__gu3xp .PinOverlay_pinPlaceholder__JhKcQ{transition:none}.PinOverlay_pinContainer__6sc1J{height:calc(var(--chart-height) - 70px);inset:0;margin:var(--p-5) var(--p-8) var(--p-24) var(--p-12);pointer-events:none;position:absolute;touch-action:pan-y;transition:transform .2s ease-out,z-index 0ms;-webkit-user-select:none;-moz-user-select:none;user-select:none;z-index:2}.PinOverlay_pinHovered__cGPjN .PinOverlay_pinContainer__6sc1J{z-index:10}.PinOverlay_pinLineBase__0BWsD{height:100%;pointer-events:none;position:absolute;width:3px}.PinOverlay_pinLineBase__0BWsD:before{border-radius:50%;box-shadow:0 4px 6px -1px var(--shadow-color);content:\"\";height:36px;left:-16px;position:absolute;top:-8px;width:36px;z-index:-1}.PinOverlay_pinLineBase__0BWsD:after{background-color:var(--background);border-radius:12px;bottom:0;content:\"\";left:0;position:absolute;top:0;transform:translate3d(.5px,0,0);transition:background-color .3s ease-out;width:100%;z-index:1}.PinOverlay_pinAnimating__5XMJG .PinOverlay_pinLineBase__0BWsD{transition:left .3s ease-out}.PinOverlay_pinButton__cnV1K{position:absolute;--offset:-8px;align-items:center;background-color:var(--background);border-radius:9999px;cursor:pointer;display:flex;justify-content:center;left:-8px;left:var(--offset);margin-left:-8px;margin-left:var(--offset);padding:10px;pointer-events:none;top:-18px;touch-action:none;transition:transform .2s ease-out;-webkit-user-select:none;-moz-user-select:none;user-select:none}.PinOverlay_pinHovered__cGPjN .PinOverlay_pinButton__cnV1K{transform:scale(1.1)}.PinOverlay_pinButton__cnV1K:active{cursor:grabbing}.PinOverlay_pinIcon__s7Ze0{color:var(--foreground);height:16px;width:16px}.PinOverlay_pinPlaceholderHost__oiZxE{pointer-events:none;z-index:20}.PinOverlay_pinPlaceholder__JhKcQ{cursor:pointer;height:72px;margin-left:-36px;margin-top:-36px;pointer-events:auto;position:absolute;top:0;touch-action:none;width:72px}.PinOverlay_pinAnimating__5XMJG .PinOverlay_pinPlaceholder__JhKcQ{transition:left .3s ease-out}.PinOverlay_pinPlaceholder__JhKcQ:active{cursor:grabbing}";
4
+ var S = {"root":"PinOverlay_root__RUZxO","pinDragging":"PinOverlay_pinDragging__gu3xp","pinLineBase":"PinOverlay_pinLineBase__0BWsD","pinButton":"PinOverlay_pinButton__cnV1K","pinPlaceholder":"PinOverlay_pinPlaceholder__JhKcQ","pinContainer":"PinOverlay_pinContainer__6sc1J","pinHovered":"PinOverlay_pinHovered__cGPjN","pinAnimating":"PinOverlay_pinAnimating__5XMJG","pinIcon":"PinOverlay_pinIcon__s7Ze0","pinPlaceholderHost":"PinOverlay_pinPlaceholderHost__oiZxE"};
5
5
  styleInject(css_248z);
6
6
 
7
7
  export { S as default };
@@ -83,7 +83,7 @@ function DriverCard({ selectedDriver, isLoading, inQueue = false, driverSelector
83
83
  const directionText = direction > 0 ? 'Positive' : 'Negative';
84
84
  const DirectionIcon = direction > 0 ? TrendUpIcon : TrendDownIcon;
85
85
  const nameElem = (jsx("h4", { className: `${S.driverTitle} ${S.truncated}`, children: name }));
86
- return (jsx(Card, { className: S.root, paddingSize: "l", children: jsx(CardContent, { noScroll: true, children: jsxs("div", { className: S.cardContent, children: [jsx("div", { className: S.driverHeader, children: jsxs("div", { className: S.headerContent, children: [jsxs("div", { className: S.topHeader, children: [jsxs("p", { className: S.categoryInfo, children: [jsx("span", { className: S.categoryIcon, children: getCategoryIcon(category) }), jsx("span", { className: S.categoryText, children: category })] }), driverSelector] }), name.length > 60 ? (jsxs(Tooltip, { children: [jsx(LabelWithId, { id: id, label: jsx(TooltipTrigger, { asChild: true, children: nameElem }) }), jsx(TooltipContent, { side: "left", className: S.tooltipContent, overTrigger: true, children: jsx("div", { className: S.tooltipTitle, children: name }) })] })) : (jsx(LabelWithId, { id: id, label: nameElem })), jsx("p", { className: S.regionDisplay, children: regionDisplay })] }) }), jsx("div", { className: S.metricsSection, children: jsx("div", { className: S.importanceScore, children: importanceDisplay }) }), jsxs("div", { className: S.directionLagSection, children: [jsxs(Badge, { variant: direction > 0 ? 'green' : 'red', className: S.directionBadge, children: [jsx(DirectionIcon, { className: S.trendIcon }), directionText, " correlation"] }), jsxs("span", { className: S.lagInfo, children: ["Lag: ", lag] })] }), jsx(DriverPerformanceChart, { driver: selectedDriver }), jsx("p", { className: S.description, children: summary ?? '' })] }) }) }));
86
+ return (jsx(Card, { className: S.root, paddingSize: "l", radiusSize: "xl", children: jsx(CardContent, { noScroll: true, children: jsxs("div", { className: S.cardContent, children: [jsx("div", { className: S.driverHeader, children: jsxs("div", { className: S.headerContent, children: [jsxs("div", { className: S.topHeader, children: [jsxs("p", { className: S.categoryInfo, children: [jsx("span", { className: S.categoryIcon, children: getCategoryIcon(category) }), jsx("span", { className: S.categoryText, children: category })] }), driverSelector] }), name.length > 60 ? (jsxs(Tooltip, { children: [jsx(LabelWithId, { id: id, label: jsx(TooltipTrigger, { asChild: true, children: nameElem }) }), jsx(TooltipContent, { side: "left", className: S.tooltipContent, overTrigger: true, children: jsx("div", { className: S.tooltipTitle, children: name }) })] })) : (jsx(LabelWithId, { id: id, label: nameElem })), jsx("p", { className: S.regionDisplay, children: regionDisplay })] }) }), jsx("div", { className: S.metricsSection, children: jsx("div", { className: S.importanceScore, children: importanceDisplay }) }), jsxs("div", { className: S.directionLagSection, children: [jsxs(Badge, { variant: direction > 0 ? 'green' : 'red', className: S.directionBadge, children: [jsx(DirectionIcon, { className: S.trendIcon }), directionText, " correlation"] }), jsxs("span", { className: S.lagInfo, children: ["Lag: ", lag] })] }), jsx(DriverPerformanceChart, { driver: selectedDriver }), jsx("p", { className: S.description, children: summary ?? '' })] }) }) }));
87
87
  }
88
88
 
89
89
  export { DriverCard };
@@ -6,5 +6,5 @@ interface PinOverlayProps {
6
6
  onPreviewMonthChange?: (month: string | undefined) => void;
7
7
  className?: string;
8
8
  }
9
- export declare function PinOverlay({ baseChartProps, pinMonth, onPinMonthChange, onPreviewMonthChange: _onPreviewMonthChange, className, }: PinOverlayProps): import("react/jsx-runtime").JSX.Element;
9
+ export declare function PinOverlay({ baseChartProps, pinMonth, onPinMonthChange, onPreviewMonthChange, className, }: PinOverlayProps): import("react/jsx-runtime").JSX.Element;
10
10
  export {};
@@ -17,6 +17,35 @@ function hasForecastValue(point, id) {
17
17
  const v = point[forecastSeriesKey(id)];
18
18
  return v !== null && v !== undefined && typeof v === 'number';
19
19
  }
20
+ /**
21
+ * First forecast month for bridge logic — skips synthetic connection rows already
22
+ * injected upstream (forecast equals historical on the month before the next forecast).
23
+ */
24
+ function findFirstForecastDateForBridge(rows, id) {
25
+ const dataKey = forecastSeriesKey(id);
26
+ const withForecast = rows
27
+ .filter(row => hasForecastValue(row, id))
28
+ .sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime());
29
+ for (let i = 0; i < withForecast.length; i++) {
30
+ const row = withForecast[i];
31
+ const next = withForecast[i + 1];
32
+ if (!next) {
33
+ return row.date;
34
+ }
35
+ const expectedBridgeDate = normalizeToMonthStart(getPreviousMonth(next.date));
36
+ const forecastVal = row[dataKey];
37
+ const isSyntheticBridge = normalizeToMonthStart(row.date) === expectedBridgeDate &&
38
+ row.historical != null &&
39
+ typeof forecastVal === 'number' &&
40
+ forecastVal === row.historical;
41
+ if (!isSyntheticBridge) {
42
+ return row.date;
43
+ }
44
+ }
45
+ return withForecast.length > 0
46
+ ? withForecast[withForecast.length - 1].date
47
+ : null;
48
+ }
20
49
  /**
21
50
  * Injects `forecast_{id}` on the row before each series’ first forecast month (historical value)
22
51
  * so dashed forecast lines meet the historical line. Matches sybilion-client bridge behavior.
@@ -36,16 +65,11 @@ function ensureChartForecastBridge(chartData, options) {
36
65
  const rows = sorted.map(p => ({ ...p }));
37
66
  for (const id of seriesIds) {
38
67
  const dataKey = forecastSeriesKey(id);
39
- let firstForecastDate = null;
40
- for (const row of rows) {
41
- if (hasForecastValue(row, id)) {
42
- firstForecastDate = row.date;
43
- break;
44
- }
45
- }
68
+ const firstForecastDate = findFirstForecastDateForBridge(rows, id);
46
69
  if (!firstForecastDate)
47
70
  continue;
48
- const prevMonthNorm = normalizeToMonthStart(getPreviousMonth(firstForecastDate));
71
+ const prevMonthRaw = getPreviousMonth(firstForecastDate);
72
+ const prevMonthNorm = normalizeToMonthStart(prevMonthRaw);
49
73
  const prevMonthIdx = rows.findIndex(row => normalizeToMonthStart(row.date) === prevMonthNorm);
50
74
  if (prevMonthIdx >= 0) {
51
75
  const existing = rows[prevMonthIdx][dataKey];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sybilion/uilib",
3
- "version": "1.3.102",
3
+ "version": "1.3.104",
4
4
  "description": "Sybilion Design System — React UI components (Webpack + Stylus)",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -1,6 +1,16 @@
1
1
  .root
2
2
  touch-action pan-y
3
3
 
4
+ .pinDragging
5
+ .pinLineBase
6
+ opacity 0.8
7
+
8
+ .pinButton
9
+ transition none
10
+
11
+ .pinPlaceholder
12
+ transition none
13
+
4
14
  // Chart overlay and pin styles
5
15
  .pinContainer
6
16
  position absolute
@@ -64,7 +74,7 @@
64
74
  background-color var(--background)
65
75
  cursor pointer
66
76
  user-select none
67
- pointer-events auto
77
+ pointer-events none
68
78
  touch-action none
69
79
 
70
80
  .pinHovered &
@@ -80,19 +90,20 @@
80
90
 
81
91
 
82
92
  // Hover placeholder for better pin access - rendered on top of all chart layers
93
+ .pinPlaceholderHost
94
+ pointer-events none
95
+ z-index 20
96
+
83
97
  .pinPlaceholder
84
98
  position absolute
85
- top var(--p-5)
99
+ top 0
86
100
  width 72px
87
101
  height 72px
88
- margin-left -40px
89
- margin-top -40px
90
- z-index 20
102
+ margin-left -36px
103
+ margin-top -36px
91
104
  pointer-events auto
92
105
  cursor pointer
93
106
  touch-action none
94
- // Debug: uncomment to visualize
95
- // background-color rgba(255, 0, 0, 0.1)
96
107
 
97
108
  .pinAnimating &
98
109
  transition left 300ms ease-out
@@ -4,10 +4,12 @@ interface CssExports {
4
4
  'pinAnimating': string;
5
5
  'pinButton': string;
6
6
  'pinContainer': string;
7
+ 'pinDragging': string;
7
8
  'pinHovered': string;
8
9
  'pinIcon': string;
9
10
  'pinLineBase': string;
10
11
  'pinPlaceholder': string;
12
+ 'pinPlaceholderHost': string;
11
13
  'root': string;
12
14
  }
13
15
  export const cssExports: CssExports;
@@ -4,6 +4,7 @@ import { useEffect, useRef, useState } from 'react';
4
4
  import { BaseChartWrapper } from '#uilib/components/ui/Chart/components';
5
5
  import { BaseChartWrapperProps } from '#uilib/components/ui/Chart/components/BaseChartWrapper';
6
6
  import { useDebounceCallback } from '#uilib/hooks/useDebounceCallback';
7
+ import useElemDrag from '#uilib/hooks/useDragElem';
7
8
  import { ChevronsLeftRight } from 'lucide-react';
8
9
 
9
10
  import CAS from '../../ChartAreaInteractive.styl';
@@ -22,7 +23,7 @@ export function PinOverlay({
22
23
  baseChartProps,
23
24
  pinMonth,
24
25
  onPinMonthChange,
25
- onPreviewMonthChange: _onPreviewMonthChange,
26
+ onPreviewMonthChange,
26
27
  className,
27
28
  }: PinOverlayProps) {
28
29
  const { chartData } = baseChartProps;
@@ -30,8 +31,11 @@ export function PinOverlay({
30
31
  const pinRef = useRef<HTMLDivElement>(null);
31
32
  const pinPlaceholderRef = useRef<HTMLDivElement>(null);
32
33
  const pinContainerRef = useRef<HTMLDivElement>(null);
34
+ const containerRectRef = useRef<DOMRect | null>(null);
33
35
 
34
36
  const [isPinHovered, setIsPinHovered] = useState(false);
37
+ const [isDraggingPin, setIsDraggingPin] = useState(false);
38
+ const [isPinAnimating, setIsPinAnimating] = useState(true);
35
39
 
36
40
  const pinPosRef = useRef<number>(0);
37
41
  const currPinMonthRef = useRef<string | undefined>(pinMonth);
@@ -135,6 +139,60 @@ export function PinOverlay({
135
139
  }
136
140
  }, [pinMonth, chartData]);
137
141
 
142
+ const clearPinTransforms = () => {
143
+ if (pinRef.current) {
144
+ pinRef.current.style.transform = '';
145
+ pinRef.current.style.transition = '';
146
+ }
147
+ if (pinPlaceholderRef.current) {
148
+ pinPlaceholderRef.current.style.transform = '';
149
+ pinPlaceholderRef.current.style.transition = '';
150
+ }
151
+ };
152
+
153
+ useElemDrag({
154
+ elem: pinPlaceholderRef,
155
+ isActive: chartData.length > 0,
156
+ onDragStart: e => {
157
+ e.stopPropagation();
158
+ setIsDraggingPin(true);
159
+ setIsPinAnimating(false);
160
+ containerRectRef.current =
161
+ pinContainerRef.current?.getBoundingClientRect() ?? null;
162
+ if (pinRef.current) pinRef.current.style.transition = 'none';
163
+ if (pinPlaceholderRef.current) {
164
+ pinPlaceholderRef.current.style.transition = 'none';
165
+ }
166
+ },
167
+ onDrag: (_delta, e) => {
168
+ const containerRect = containerRectRef.current;
169
+ if (!containerRect) return;
170
+
171
+ const pinCurrentLeft = (pinPosRef.current / 100) * containerRect.width;
172
+ const relativeX = e.clientX - containerRect.left;
173
+ const clampedX = Math.max(0, Math.min(containerRect.width, relativeX));
174
+ const translateX = clampedX - pinCurrentLeft;
175
+ const transform = `translateX(${translateX}px)`;
176
+
177
+ if (pinRef.current) pinRef.current.style.transform = transform;
178
+ if (pinPlaceholderRef.current) {
179
+ pinPlaceholderRef.current.style.transform = transform;
180
+ }
181
+
182
+ const previewPercent =
183
+ containerRect.width > 0 ? (clampedX / containerRect.width) * 100 : 0;
184
+ onPreviewMonthChange?.(getPinMonthAndYear(previewPercent) ?? undefined);
185
+ },
186
+ onDragEnd: e => {
187
+ e.stopPropagation();
188
+ setIsDraggingPin(false);
189
+ setTimeout(() => setIsPinAnimating(true), 200);
190
+ containerRectRef.current = null;
191
+ clearPinTransforms();
192
+ snapPinToPosition(e.clientX, true, true);
193
+ },
194
+ });
195
+
138
196
  const onChartClick = (e: React.MouseEvent<HTMLDivElement>) => {
139
197
  if (e.button !== 0) return;
140
198
  const target = e.target as HTMLElement;
@@ -159,13 +217,15 @@ export function PinOverlay({
159
217
  </div>
160
218
  </div>
161
219
  </div>
162
- <div
163
- className={S.pinPlaceholder}
164
- style={{ left: `${pinPosRef.current}%` }}
165
- ref={pinPlaceholderRef}
166
- onPointerEnter={() => setIsPinHovered(true)}
167
- onPointerLeave={() => setIsPinHovered(false)}
168
- />
220
+ <div className={cn(CAS.overlay, S.pinPlaceholderHost)}>
221
+ <div
222
+ className={S.pinPlaceholder}
223
+ style={{ left: `${pinPosRef.current}%` }}
224
+ ref={pinPlaceholderRef}
225
+ onPointerEnter={() => setIsPinHovered(true)}
226
+ onPointerLeave={() => setIsPinHovered(false)}
227
+ />
228
+ </div>
169
229
  </>
170
230
  );
171
231
 
@@ -174,8 +234,9 @@ export function PinOverlay({
174
234
  className={cn(
175
235
  className,
176
236
  S.root,
177
- S.pinAnimating,
237
+ isPinAnimating && S.pinAnimating,
178
238
  isPinHovered && S.pinHovered,
239
+ isDraggingPin && S.pinDragging,
179
240
  )}
180
241
  onClick={onChartClick}
181
242
  ref={chartRef}
@@ -185,6 +246,7 @@ export function PinOverlay({
185
246
  yMin={yMin}
186
247
  yMax={yMax}
187
248
  autoScaleYAxis={false}
249
+ showTooltip={!isDraggingPin}
188
250
  overlayElements={overlay}
189
251
  />
190
252
  </div>
@@ -154,7 +154,7 @@ export function DriverCard({
154
154
  );
155
155
 
156
156
  return (
157
- <Card className={S.root} paddingSize="l">
157
+ <Card className={S.root} paddingSize="l" radiusSize="xl">
158
158
  <CardContent noScroll>
159
159
  <div className={S.cardContent}>
160
160
  {/* Driver Header */}
@@ -36,6 +36,46 @@ function hasForecastValue(point: ChartDataPoint, id: number): boolean {
36
36
  return v !== null && v !== undefined && typeof v === 'number';
37
37
  }
38
38
 
39
+ /**
40
+ * First forecast month for bridge logic — skips synthetic connection rows already
41
+ * injected upstream (forecast equals historical on the month before the next forecast).
42
+ */
43
+ function findFirstForecastDateForBridge(
44
+ rows: ChartDataPoint[],
45
+ id: number,
46
+ ): string | null {
47
+ const dataKey = forecastSeriesKey(id);
48
+ const withForecast = rows
49
+ .filter(row => hasForecastValue(row, id))
50
+ .sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime());
51
+
52
+ for (let i = 0; i < withForecast.length; i++) {
53
+ const row = withForecast[i];
54
+ const next = withForecast[i + 1];
55
+ if (!next) {
56
+ return row.date;
57
+ }
58
+
59
+ const expectedBridgeDate = normalizeToMonthStart(
60
+ getPreviousMonth(next.date),
61
+ );
62
+ const forecastVal = row[dataKey];
63
+ const isSyntheticBridge =
64
+ normalizeToMonthStart(row.date) === expectedBridgeDate &&
65
+ row.historical != null &&
66
+ typeof forecastVal === 'number' &&
67
+ forecastVal === row.historical;
68
+
69
+ if (!isSyntheticBridge) {
70
+ return row.date;
71
+ }
72
+ }
73
+
74
+ return withForecast.length > 0
75
+ ? withForecast[withForecast.length - 1].date
76
+ : null;
77
+ }
78
+
39
79
  /**
40
80
  * Injects `forecast_{id}` on the row before each series’ first forecast month (historical value)
41
81
  * so dashed forecast lines meet the historical line. Matches sybilion-client bridge behavior.
@@ -65,18 +105,11 @@ export function ensureChartForecastBridge(
65
105
 
66
106
  for (const id of seriesIds) {
67
107
  const dataKey = forecastSeriesKey(id);
68
- let firstForecastDate: string | null = null;
69
- for (const row of rows) {
70
- if (hasForecastValue(row, id)) {
71
- firstForecastDate = row.date;
72
- break;
73
- }
74
- }
108
+ const firstForecastDate = findFirstForecastDateForBridge(rows, id);
75
109
  if (!firstForecastDate) continue;
76
110
 
77
- const prevMonthNorm = normalizeToMonthStart(
78
- getPreviousMonth(firstForecastDate),
79
- );
111
+ const prevMonthRaw = getPreviousMonth(firstForecastDate);
112
+ const prevMonthNorm = normalizeToMonthStart(prevMonthRaw);
80
113
 
81
114
  const prevMonthIdx = rows.findIndex(
82
115
  row => normalizeToMonthStart(row.date) === prevMonthNorm,