awesome-timeline-react 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -749,6 +749,9 @@ export declare class SceneStore {
749
749
  */
750
750
  setLabelMinHeights(heights: Map<string, number>): void;
751
751
  getRowHeight(rowId: string, windowStart: number, windowEnd: number): number;
752
+ /** Extra top offset for a row's lanes: when a tall label grows the row past what its lanes need,
753
+ * the lanes sit centred in it rather than hugging the top with the surplus all below. */
754
+ getLaneInset(rowId: string, windowStart: number, windowEnd: number): number;
752
755
  /**
753
756
  * y offset of each row's top edge (content coordinates, before scroll) plus
754
757
  * the total content height — drives both drawing and the scroll spacer.
@@ -996,6 +999,12 @@ declare type TimelineProps = {
996
999
  /** fires whenever the selection changes (click, group-click, clear, or the
997
1000
  * imperative handle) */
998
1001
  onSelectionChange?: (eventIds: string[]) => void;
1002
+ /** fires whenever the visible time window changes (pan, zoom, a startDate/endDate refit, or the
1003
+ * imperative handle) and once on mount, in unix seconds — the same range `getVisibleRange` returns */
1004
+ onWindowChange?: (range: {
1005
+ startTime: number;
1006
+ endTime: number;
1007
+ }) => void;
999
1008
  /** rows collapsed initially (uncontrolled). After mount, collapse state lives
1000
1009
  * in the scene and survives every data update — streaming patches,
1001
1010
  * `setEvents`, and `events`-prop resets never change it; only a user caret
@@ -1120,6 +1129,15 @@ declare type TimelineType = TimelineProps;
1120
1129
  export { TimelineType }
1121
1130
  export { TimelineType as TimelineType_alias_1 }
1122
1131
 
1132
+ /**
1133
+ * `onWindowChange`: the visible window reported on every pan, zoom and refit. Two consumers here —
1134
+ * the readout a date picker would show, and a strip below the board that draws each event's span
1135
+ * against the reported window, the way a coupled chart follows the timeline. Drag the background to
1136
+ * pan, ctrl/cmd + wheel to zoom; the strip and the readout must move with the bars. The inputs set
1137
+ * `startDate`/`endDate`, which refits the board and reports the new window through the same callback.
1138
+ */
1139
+ export declare const TimelineWindowSync: () => React_2.JSX.Element;
1140
+
1123
1141
  export declare const timeToWidth: (startTime: number, endTime: number, tick: number) => number;
1124
1142
 
1125
1143
  export declare const timeToX: (time: number, windowStart: number, tick: number) => number;
@@ -749,6 +749,9 @@ export declare class SceneStore {
749
749
  */
750
750
  setLabelMinHeights(heights: Map<string, number>): void;
751
751
  getRowHeight(rowId: string, windowStart: number, windowEnd: number): number;
752
+ /** Extra top offset for a row's lanes: when a tall label grows the row past what its lanes need,
753
+ * the lanes sit centred in it rather than hugging the top with the surplus all below. */
754
+ getLaneInset(rowId: string, windowStart: number, windowEnd: number): number;
752
755
  /**
753
756
  * y offset of each row's top edge (content coordinates, before scroll) plus
754
757
  * the total content height — drives both drawing and the scroll spacer.
@@ -996,6 +999,12 @@ declare type TimelineProps = {
996
999
  /** fires whenever the selection changes (click, group-click, clear, or the
997
1000
  * imperative handle) */
998
1001
  onSelectionChange?: (eventIds: string[]) => void;
1002
+ /** fires whenever the visible time window changes (pan, zoom, a startDate/endDate refit, or the
1003
+ * imperative handle) and once on mount, in unix seconds — the same range `getVisibleRange` returns */
1004
+ onWindowChange?: (range: {
1005
+ startTime: number;
1006
+ endTime: number;
1007
+ }) => void;
999
1008
  /** rows collapsed initially (uncontrolled). After mount, collapse state lives
1000
1009
  * in the scene and survives every data update — streaming patches,
1001
1010
  * `setEvents`, and `events`-prop resets never change it; only a user caret
@@ -1120,6 +1129,15 @@ declare type TimelineType = TimelineProps;
1120
1129
  export { TimelineType }
1121
1130
  export { TimelineType as TimelineType_alias_1 }
1122
1131
 
1132
+ /**
1133
+ * `onWindowChange`: the visible window reported on every pan, zoom and refit. Two consumers here —
1134
+ * the readout a date picker would show, and a strip below the board that draws each event's span
1135
+ * against the reported window, the way a coupled chart follows the timeline. Drag the background to
1136
+ * pan, ctrl/cmd + wheel to zoom; the strip and the readout must move with the bars. The inputs set
1137
+ * `startDate`/`endDate`, which refits the board and reports the new window through the same callback.
1138
+ */
1139
+ export declare const TimelineWindowSync: () => React_2.JSX.Element;
1140
+
1123
1141
  export declare const timeToWidth: (startTime: number, endTime: number, tick: number) => number;
1124
1142
 
1125
1143
  export declare const timeToX: (time: number, windowStart: number, tick: number) => number;
package/dist/index.js CHANGED
@@ -1043,6 +1043,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
1043
1043
  if (rowY + rowHeight < 0) continue;
1044
1044
  if (rowY > view.height) break;
1045
1045
  const lanes = scene.getLanes(rowId, windowStart, windowEnd);
1046
+ const inset = scene.getLaneInset(rowId, windowStart, windowEnd);
1046
1047
  const rowStatics = cullToWindow(
1047
1048
  scene.getRowStaticEvents(rowId),
1048
1049
  windowStart,
@@ -1055,7 +1056,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
1055
1056
  roundedRect(
1056
1057
  ctx,
1057
1058
  x,
1058
- rowY + geometry.laneTopOffset,
1059
+ rowY + inset + geometry.laneTopOffset,
1059
1060
  width,
1060
1061
  staticEventHeight(lanes.highestLane, geometry),
1061
1062
  geometry.barRadius
@@ -1071,7 +1072,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
1071
1072
  let width = timeToWidth(event.startTime, event.endTime, tick);
1072
1073
  const y = rowY + animator.eventTop(
1073
1074
  event.id,
1074
- laneTop(lanes.laneOf.get(event.id), geometry)
1075
+ inset + laneTop(lanes.laneOf.get(event.id), geometry)
1075
1076
  );
1076
1077
  const resize = view.resizePreview;
1077
1078
  const resizing = resize !== null && resize.eventId === event.id;
@@ -1231,7 +1232,7 @@ var hitTest = (scene, view, x, y) => {
1231
1232
  }
1232
1233
  if (rowId === null) return null;
1233
1234
  const lanes = scene.getLanes(rowId, windowStart, windowEnd);
1234
- const rowY = rowTop - scrollTop;
1235
+ const lanesY = rowTop - scrollTop + scene.getLaneInset(rowId, windowStart, windowEnd);
1235
1236
  const events = cullToWindow(
1236
1237
  scene.getRowEvents(rowId),
1237
1238
  windowStart,
@@ -1241,7 +1242,7 @@ var hitTest = (scene, view, x, y) => {
1241
1242
  const event = events[i];
1242
1243
  const rect = {
1243
1244
  x: timeToX(event.startTime, windowStart, tick),
1244
- y: rowY + laneTop(lanes.laneOf.get(event.id), geometry),
1245
+ y: lanesY + laneTop(lanes.laneOf.get(event.id), geometry),
1245
1246
  width: timeToWidth(event.startTime, event.endTime, tick),
1246
1247
  height: geometry.barHeight
1247
1248
  };
@@ -1258,7 +1259,7 @@ var hitTest = (scene, view, x, y) => {
1258
1259
  const event = statics[i];
1259
1260
  const rect = {
1260
1261
  x: timeToX(event.startTime, windowStart, tick),
1261
- y: rowY + geometry.laneTopOffset,
1262
+ y: lanesY + geometry.laneTopOffset,
1262
1263
  width: timeToWidth(event.startTime, event.endTime, tick),
1263
1264
  height: staticEventHeight(lanes.highestLane, geometry)
1264
1265
  };
@@ -2645,6 +2646,17 @@ var SceneStore = class {
2645
2646
  const labelHeight = (_a = this.labelMinHeights.get(rowId)) != null ? _a : 0;
2646
2647
  return Math.max(laneHeight, labelHeight);
2647
2648
  }
2649
+ /** Extra top offset for a row's lanes: when a tall label grows the row past what its lanes need,
2650
+ * the lanes sit centred in it rather than hugging the top with the surplus all below. */
2651
+ getLaneInset(rowId, windowStart, windowEnd) {
2652
+ var _a;
2653
+ const laneHeight = rowMinHeight(
2654
+ this.getLanes(rowId, windowStart, windowEnd).highestLane,
2655
+ this.geometry
2656
+ );
2657
+ const labelHeight = (_a = this.labelMinHeights.get(rowId)) != null ? _a : 0;
2658
+ return labelHeight > laneHeight ? Math.floor((labelHeight - laneHeight) / 2) : 0;
2659
+ }
2648
2660
  /**
2649
2661
  * y offset of each row's top edge (content coordinates, before scroll) plus
2650
2662
  * the total content height — drives both drawing and the scroll spacer.
@@ -2814,6 +2826,7 @@ var Timeline = (0, import_react7.forwardRef)(
2814
2826
  selectable = false,
2815
2827
  defaultSelectedEventIds,
2816
2828
  onSelectionChange,
2829
+ onWindowChange,
2817
2830
  defaultCollapsedRowIds,
2818
2831
  startDate,
2819
2832
  endDate,
@@ -2918,6 +2931,12 @@ var Timeline = (0, import_react7.forwardRef)(
2918
2931
  }, [scene, defaultCollapsedRowIds]);
2919
2932
  const windowTimeRef = (0, import_react7.useRef)(windowTime);
2920
2933
  windowTimeRef.current = windowTime;
2934
+ const onWindowChangeRef = (0, import_react7.useRef)(onWindowChange);
2935
+ onWindowChangeRef.current = onWindowChange;
2936
+ (0, import_react7.useEffect)(() => {
2937
+ var _a;
2938
+ (_a = onWindowChangeRef.current) == null ? void 0 : _a.call(onWindowChangeRef, { startTime: windowTime[0], endTime: windowTime[1] });
2939
+ }, [windowTime[0], windowTime[1]]);
2921
2940
  (0, import_react7.useImperativeHandle)(
2922
2941
  handleRef,
2923
2942
  () => ({