awesome-timeline-react 0.6.0 → 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.
package/dist/index.mjs CHANGED
@@ -691,36 +691,20 @@ var laneTop = (lane, g = DEFAULT_GEOMETRY) => g.laneTopOffset + g.laneHeight * l
691
691
  var rowMinHeight = (highestLane, g = DEFAULT_GEOMETRY) => g.rowBaseHeight + highestLane * g.laneHeight;
692
692
  var staticEventHeight = (highestLane, g = DEFAULT_GEOMETRY) => g.staticEventBaseHeight + highestLane * g.laneHeight;
693
693
  var assignLanes = (rowEvents, windowStart, windowEnd) => {
694
- let eventOrder = 0;
695
- const prevEvent = [];
696
- let highestEventOrder = 0;
694
+ const laneEnd = [];
697
695
  const laneOf = /* @__PURE__ */ new Map();
698
696
  for (const event of rowEvents) {
699
697
  if (!intersectsWindow(event, windowStart, windowEnd)) continue;
700
- let tempEventOrder = 0;
701
- let assignEventOrder = true;
702
- for (let i = 0; i <= eventOrder; i++) {
703
- if (prevEvent[i] && prevEvent[i].endTime > event.startTime) {
704
- tempEventOrder += 1;
705
- } else {
706
- if (eventOrder > highestEventOrder) {
707
- highestEventOrder = eventOrder;
708
- }
709
- eventOrder = 0;
710
- assignEventOrder = false;
711
- break;
712
- }
713
- }
714
- if (assignEventOrder) {
715
- eventOrder = tempEventOrder;
698
+ let lane = laneEnd.findIndex((end) => end <= event.startTime);
699
+ if (lane === -1) {
700
+ lane = laneEnd.length;
701
+ laneEnd.push(event.endTime);
702
+ } else if (event.endTime > laneEnd[lane]) {
703
+ laneEnd[lane] = event.endTime;
716
704
  }
717
- prevEvent[tempEventOrder] = event;
718
- laneOf.set(event.id, tempEventOrder);
705
+ laneOf.set(event.id, lane);
719
706
  }
720
- if (eventOrder > highestEventOrder) {
721
- highestEventOrder = eventOrder;
722
- }
723
- return { laneOf, highestLane: highestEventOrder };
707
+ return { laneOf, highestLane: Math.max(0, laneEnd.length - 1) };
724
708
  };
725
709
 
726
710
  // src/core/interactions.ts
@@ -1047,6 +1031,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
1047
1031
  if (rowY + rowHeight < 0) continue;
1048
1032
  if (rowY > view.height) break;
1049
1033
  const lanes = scene.getLanes(rowId, windowStart, windowEnd);
1034
+ const inset = scene.getLaneInset(rowId, windowStart, windowEnd);
1050
1035
  const rowStatics = cullToWindow(
1051
1036
  scene.getRowStaticEvents(rowId),
1052
1037
  windowStart,
@@ -1059,7 +1044,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
1059
1044
  roundedRect(
1060
1045
  ctx,
1061
1046
  x,
1062
- rowY + geometry.laneTopOffset,
1047
+ rowY + inset + geometry.laneTopOffset,
1063
1048
  width,
1064
1049
  staticEventHeight(lanes.highestLane, geometry),
1065
1050
  geometry.barRadius
@@ -1075,7 +1060,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
1075
1060
  let width = timeToWidth(event.startTime, event.endTime, tick);
1076
1061
  const y = rowY + animator.eventTop(
1077
1062
  event.id,
1078
- laneTop(lanes.laneOf.get(event.id), geometry)
1063
+ inset + laneTop(lanes.laneOf.get(event.id), geometry)
1079
1064
  );
1080
1065
  const resize = view.resizePreview;
1081
1066
  const resizing = resize !== null && resize.eventId === event.id;
@@ -1235,7 +1220,7 @@ var hitTest = (scene, view, x, y) => {
1235
1220
  }
1236
1221
  if (rowId === null) return null;
1237
1222
  const lanes = scene.getLanes(rowId, windowStart, windowEnd);
1238
- const rowY = rowTop - scrollTop;
1223
+ const lanesY = rowTop - scrollTop + scene.getLaneInset(rowId, windowStart, windowEnd);
1239
1224
  const events = cullToWindow(
1240
1225
  scene.getRowEvents(rowId),
1241
1226
  windowStart,
@@ -1245,7 +1230,7 @@ var hitTest = (scene, view, x, y) => {
1245
1230
  const event = events[i];
1246
1231
  const rect = {
1247
1232
  x: timeToX(event.startTime, windowStart, tick),
1248
- y: rowY + laneTop(lanes.laneOf.get(event.id), geometry),
1233
+ y: lanesY + laneTop(lanes.laneOf.get(event.id), geometry),
1249
1234
  width: timeToWidth(event.startTime, event.endTime, tick),
1250
1235
  height: geometry.barHeight
1251
1236
  };
@@ -1262,7 +1247,7 @@ var hitTest = (scene, view, x, y) => {
1262
1247
  const event = statics[i];
1263
1248
  const rect = {
1264
1249
  x: timeToX(event.startTime, windowStart, tick),
1265
- y: rowY + geometry.laneTopOffset,
1250
+ y: lanesY + geometry.laneTopOffset,
1266
1251
  width: timeToWidth(event.startTime, event.endTime, tick),
1267
1252
  height: staticEventHeight(lanes.highestLane, geometry)
1268
1253
  };
@@ -2649,6 +2634,17 @@ var SceneStore = class {
2649
2634
  const labelHeight = (_a = this.labelMinHeights.get(rowId)) != null ? _a : 0;
2650
2635
  return Math.max(laneHeight, labelHeight);
2651
2636
  }
2637
+ /** Extra top offset for a row's lanes: when a tall label grows the row past what its lanes need,
2638
+ * the lanes sit centred in it rather than hugging the top with the surplus all below. */
2639
+ getLaneInset(rowId, windowStart, windowEnd) {
2640
+ var _a;
2641
+ const laneHeight = rowMinHeight(
2642
+ this.getLanes(rowId, windowStart, windowEnd).highestLane,
2643
+ this.geometry
2644
+ );
2645
+ const labelHeight = (_a = this.labelMinHeights.get(rowId)) != null ? _a : 0;
2646
+ return labelHeight > laneHeight ? Math.floor((labelHeight - laneHeight) / 2) : 0;
2647
+ }
2652
2648
  /**
2653
2649
  * y offset of each row's top edge (content coordinates, before scroll) plus
2654
2650
  * the total content height — drives both drawing and the scroll spacer.
@@ -2818,6 +2814,7 @@ var Timeline = forwardRef3(
2818
2814
  selectable = false,
2819
2815
  defaultSelectedEventIds,
2820
2816
  onSelectionChange,
2817
+ onWindowChange,
2821
2818
  defaultCollapsedRowIds,
2822
2819
  startDate,
2823
2820
  endDate,
@@ -2922,6 +2919,12 @@ var Timeline = forwardRef3(
2922
2919
  }, [scene, defaultCollapsedRowIds]);
2923
2920
  const windowTimeRef = useRef7(windowTime);
2924
2921
  windowTimeRef.current = windowTime;
2922
+ const onWindowChangeRef = useRef7(onWindowChange);
2923
+ onWindowChangeRef.current = onWindowChange;
2924
+ useEffect6(() => {
2925
+ var _a;
2926
+ (_a = onWindowChangeRef.current) == null ? void 0 : _a.call(onWindowChangeRef, { startTime: windowTime[0], endTime: windowTime[1] });
2927
+ }, [windowTime[0], windowTime[1]]);
2925
2928
  useImperativeHandle2(
2926
2929
  handleRef,
2927
2930
  () => ({