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/_tsup-dts-rollup.d.mts +50 -5
- package/dist/_tsup-dts-rollup.d.ts +50 -5
- package/dist/index.js +33 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -14,14 +14,24 @@ export declare type AnimationConfig = boolean | {
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Assigns a vertical lane (stacking order) to each window-visible event of a
|
|
17
|
-
* single row
|
|
18
|
-
*
|
|
17
|
+
* single row: interval partitioning, so a row opens exactly as many lanes as
|
|
18
|
+
* its peak concurrency and NO event is ever laid over another.
|
|
19
|
+
*
|
|
20
|
+
* Each event takes the lowest lane whose last event has already ended; if every
|
|
21
|
+
* lane is still busy it opens a new one. Semantics:
|
|
19
22
|
*
|
|
20
23
|
* - Events outside [windowStart, windowEnd] are skipped and do not influence
|
|
21
24
|
* lane assignment at all.
|
|
22
|
-
* -
|
|
23
|
-
*
|
|
24
|
-
* -
|
|
25
|
+
* - Touching events (prev.endTime === next.startTime) do not overlap, so they
|
|
26
|
+
* share a lane.
|
|
27
|
+
* - Lowest-free-lane means the assignment is deterministic, and a row with N
|
|
28
|
+
* concurrent events ends up exactly N lanes tall.
|
|
29
|
+
*
|
|
30
|
+
* Replaces the algorithm inlined in the original use-produce-content.tsx, whose
|
|
31
|
+
* occupancy scan was bounded by the previously-placed event's lane and reset
|
|
32
|
+
* whenever a lane freed: after a lane freed mid-row, later events were placed
|
|
33
|
+
* in lanes that had never been checked, and were drawn on top of the events
|
|
34
|
+
* still running there (visible on capacity rows with 3+ concurrent events).
|
|
25
35
|
*
|
|
26
36
|
* `rowEvents` must already be filtered to one row and sorted with
|
|
27
37
|
* helpers/sort-events (startTime asc, endTime asc).
|
|
@@ -739,6 +749,9 @@ export declare class SceneStore {
|
|
|
739
749
|
*/
|
|
740
750
|
setLabelMinHeights(heights: Map<string, number>): void;
|
|
741
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;
|
|
742
755
|
/**
|
|
743
756
|
* y offset of each row's top edge (content coordinates, before scroll) plus
|
|
744
757
|
* the total content height — drives both drawing and the scroll spacer.
|
|
@@ -931,6 +944,23 @@ declare type TimelineHandle = {
|
|
|
931
944
|
export { TimelineHandle }
|
|
932
945
|
export { TimelineHandle as TimelineHandle_alias_1 }
|
|
933
946
|
|
|
947
|
+
/**
|
|
948
|
+
* Lane stacking on a row whose events genuinely run in parallel (a shared pool / capacity row: one
|
|
949
|
+
* row, many concurrent bars). A row must open as many lanes as its peak concurrency so every bar is
|
|
950
|
+
* drawn in full — no bar may be laid over another.
|
|
951
|
+
*
|
|
952
|
+
* Both rows here are the same story with different data:
|
|
953
|
+
* - **Pool A** is the minimal case: four bars stack up, then lane 0's occupant ends and a new bar
|
|
954
|
+
* takes the freed lane, and the bars after it collide.
|
|
955
|
+
* - **Pool B** is the same failure in a realistic shape: a pool admitting a bar every 15 min, with
|
|
956
|
+
* runs of mixed length (one short "Hold"), so lane releases stop lining up with admissions.
|
|
957
|
+
*
|
|
958
|
+
* The panel above the board is computed by calling the SAME `assignLanes` the renderer uses, next to
|
|
959
|
+
* the peak concurrency the data actually needs — so it reports whether the layout is correct rather
|
|
960
|
+
* than asking you to eyeball it. `overlapping pairs` must be 0 and `lanes` must equal `needs`.
|
|
961
|
+
*/
|
|
962
|
+
export declare const TimelineLaneStacking: () => React_2.JSX.Element;
|
|
963
|
+
|
|
934
964
|
/**
|
|
935
965
|
* Long row labels: names that exceed the 100px header width wrap to multiple
|
|
936
966
|
* lines, stay centered, and grow the row height (and its canvas dividers) to
|
|
@@ -969,6 +999,12 @@ declare type TimelineProps = {
|
|
|
969
999
|
/** fires whenever the selection changes (click, group-click, clear, or the
|
|
970
1000
|
* imperative handle) */
|
|
971
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;
|
|
972
1008
|
/** rows collapsed initially (uncontrolled). After mount, collapse state lives
|
|
973
1009
|
* in the scene and survives every data update — streaming patches,
|
|
974
1010
|
* `setEvents`, and `events`-prop resets never change it; only a user caret
|
|
@@ -1093,6 +1129,15 @@ declare type TimelineType = TimelineProps;
|
|
|
1093
1129
|
export { TimelineType }
|
|
1094
1130
|
export { TimelineType as TimelineType_alias_1 }
|
|
1095
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
|
+
|
|
1096
1141
|
export declare const timeToWidth: (startTime: number, endTime: number, tick: number) => number;
|
|
1097
1142
|
|
|
1098
1143
|
export declare const timeToX: (time: number, windowStart: number, tick: number) => number;
|
|
@@ -14,14 +14,24 @@ export declare type AnimationConfig = boolean | {
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Assigns a vertical lane (stacking order) to each window-visible event of a
|
|
17
|
-
* single row
|
|
18
|
-
*
|
|
17
|
+
* single row: interval partitioning, so a row opens exactly as many lanes as
|
|
18
|
+
* its peak concurrency and NO event is ever laid over another.
|
|
19
|
+
*
|
|
20
|
+
* Each event takes the lowest lane whose last event has already ended; if every
|
|
21
|
+
* lane is still busy it opens a new one. Semantics:
|
|
19
22
|
*
|
|
20
23
|
* - Events outside [windowStart, windowEnd] are skipped and do not influence
|
|
21
24
|
* lane assignment at all.
|
|
22
|
-
* -
|
|
23
|
-
*
|
|
24
|
-
* -
|
|
25
|
+
* - Touching events (prev.endTime === next.startTime) do not overlap, so they
|
|
26
|
+
* share a lane.
|
|
27
|
+
* - Lowest-free-lane means the assignment is deterministic, and a row with N
|
|
28
|
+
* concurrent events ends up exactly N lanes tall.
|
|
29
|
+
*
|
|
30
|
+
* Replaces the algorithm inlined in the original use-produce-content.tsx, whose
|
|
31
|
+
* occupancy scan was bounded by the previously-placed event's lane and reset
|
|
32
|
+
* whenever a lane freed: after a lane freed mid-row, later events were placed
|
|
33
|
+
* in lanes that had never been checked, and were drawn on top of the events
|
|
34
|
+
* still running there (visible on capacity rows with 3+ concurrent events).
|
|
25
35
|
*
|
|
26
36
|
* `rowEvents` must already be filtered to one row and sorted with
|
|
27
37
|
* helpers/sort-events (startTime asc, endTime asc).
|
|
@@ -739,6 +749,9 @@ export declare class SceneStore {
|
|
|
739
749
|
*/
|
|
740
750
|
setLabelMinHeights(heights: Map<string, number>): void;
|
|
741
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;
|
|
742
755
|
/**
|
|
743
756
|
* y offset of each row's top edge (content coordinates, before scroll) plus
|
|
744
757
|
* the total content height — drives both drawing and the scroll spacer.
|
|
@@ -931,6 +944,23 @@ declare type TimelineHandle = {
|
|
|
931
944
|
export { TimelineHandle }
|
|
932
945
|
export { TimelineHandle as TimelineHandle_alias_1 }
|
|
933
946
|
|
|
947
|
+
/**
|
|
948
|
+
* Lane stacking on a row whose events genuinely run in parallel (a shared pool / capacity row: one
|
|
949
|
+
* row, many concurrent bars). A row must open as many lanes as its peak concurrency so every bar is
|
|
950
|
+
* drawn in full — no bar may be laid over another.
|
|
951
|
+
*
|
|
952
|
+
* Both rows here are the same story with different data:
|
|
953
|
+
* - **Pool A** is the minimal case: four bars stack up, then lane 0's occupant ends and a new bar
|
|
954
|
+
* takes the freed lane, and the bars after it collide.
|
|
955
|
+
* - **Pool B** is the same failure in a realistic shape: a pool admitting a bar every 15 min, with
|
|
956
|
+
* runs of mixed length (one short "Hold"), so lane releases stop lining up with admissions.
|
|
957
|
+
*
|
|
958
|
+
* The panel above the board is computed by calling the SAME `assignLanes` the renderer uses, next to
|
|
959
|
+
* the peak concurrency the data actually needs — so it reports whether the layout is correct rather
|
|
960
|
+
* than asking you to eyeball it. `overlapping pairs` must be 0 and `lanes` must equal `needs`.
|
|
961
|
+
*/
|
|
962
|
+
export declare const TimelineLaneStacking: () => React_2.JSX.Element;
|
|
963
|
+
|
|
934
964
|
/**
|
|
935
965
|
* Long row labels: names that exceed the 100px header width wrap to multiple
|
|
936
966
|
* lines, stay centered, and grow the row height (and its canvas dividers) to
|
|
@@ -969,6 +999,12 @@ declare type TimelineProps = {
|
|
|
969
999
|
/** fires whenever the selection changes (click, group-click, clear, or the
|
|
970
1000
|
* imperative handle) */
|
|
971
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;
|
|
972
1008
|
/** rows collapsed initially (uncontrolled). After mount, collapse state lives
|
|
973
1009
|
* in the scene and survives every data update — streaming patches,
|
|
974
1010
|
* `setEvents`, and `events`-prop resets never change it; only a user caret
|
|
@@ -1093,6 +1129,15 @@ declare type TimelineType = TimelineProps;
|
|
|
1093
1129
|
export { TimelineType }
|
|
1094
1130
|
export { TimelineType as TimelineType_alias_1 }
|
|
1095
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
|
+
|
|
1096
1141
|
export declare const timeToWidth: (startTime: number, endTime: number, tick: number) => number;
|
|
1097
1142
|
|
|
1098
1143
|
export declare const timeToX: (time: number, windowStart: number, tick: number) => number;
|
package/dist/index.js
CHANGED
|
@@ -703,36 +703,20 @@ var laneTop = (lane, g = DEFAULT_GEOMETRY) => g.laneTopOffset + g.laneHeight * l
|
|
|
703
703
|
var rowMinHeight = (highestLane, g = DEFAULT_GEOMETRY) => g.rowBaseHeight + highestLane * g.laneHeight;
|
|
704
704
|
var staticEventHeight = (highestLane, g = DEFAULT_GEOMETRY) => g.staticEventBaseHeight + highestLane * g.laneHeight;
|
|
705
705
|
var assignLanes = (rowEvents, windowStart, windowEnd) => {
|
|
706
|
-
|
|
707
|
-
const prevEvent = [];
|
|
708
|
-
let highestEventOrder = 0;
|
|
706
|
+
const laneEnd = [];
|
|
709
707
|
const laneOf = /* @__PURE__ */ new Map();
|
|
710
708
|
for (const event of rowEvents) {
|
|
711
709
|
if (!intersectsWindow(event, windowStart, windowEnd)) continue;
|
|
712
|
-
let
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
if (eventOrder > highestEventOrder) {
|
|
719
|
-
highestEventOrder = eventOrder;
|
|
720
|
-
}
|
|
721
|
-
eventOrder = 0;
|
|
722
|
-
assignEventOrder = false;
|
|
723
|
-
break;
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
if (assignEventOrder) {
|
|
727
|
-
eventOrder = tempEventOrder;
|
|
710
|
+
let lane = laneEnd.findIndex((end) => end <= event.startTime);
|
|
711
|
+
if (lane === -1) {
|
|
712
|
+
lane = laneEnd.length;
|
|
713
|
+
laneEnd.push(event.endTime);
|
|
714
|
+
} else if (event.endTime > laneEnd[lane]) {
|
|
715
|
+
laneEnd[lane] = event.endTime;
|
|
728
716
|
}
|
|
729
|
-
|
|
730
|
-
laneOf.set(event.id, tempEventOrder);
|
|
717
|
+
laneOf.set(event.id, lane);
|
|
731
718
|
}
|
|
732
|
-
|
|
733
|
-
highestEventOrder = eventOrder;
|
|
734
|
-
}
|
|
735
|
-
return { laneOf, highestLane: highestEventOrder };
|
|
719
|
+
return { laneOf, highestLane: Math.max(0, laneEnd.length - 1) };
|
|
736
720
|
};
|
|
737
721
|
|
|
738
722
|
// src/core/interactions.ts
|
|
@@ -1059,6 +1043,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
1059
1043
|
if (rowY + rowHeight < 0) continue;
|
|
1060
1044
|
if (rowY > view.height) break;
|
|
1061
1045
|
const lanes = scene.getLanes(rowId, windowStart, windowEnd);
|
|
1046
|
+
const inset = scene.getLaneInset(rowId, windowStart, windowEnd);
|
|
1062
1047
|
const rowStatics = cullToWindow(
|
|
1063
1048
|
scene.getRowStaticEvents(rowId),
|
|
1064
1049
|
windowStart,
|
|
@@ -1071,7 +1056,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
1071
1056
|
roundedRect(
|
|
1072
1057
|
ctx,
|
|
1073
1058
|
x,
|
|
1074
|
-
rowY + geometry.laneTopOffset,
|
|
1059
|
+
rowY + inset + geometry.laneTopOffset,
|
|
1075
1060
|
width,
|
|
1076
1061
|
staticEventHeight(lanes.highestLane, geometry),
|
|
1077
1062
|
geometry.barRadius
|
|
@@ -1087,7 +1072,7 @@ var drawEvents = (ctx, view, scene, font, animator) => {
|
|
|
1087
1072
|
let width = timeToWidth(event.startTime, event.endTime, tick);
|
|
1088
1073
|
const y = rowY + animator.eventTop(
|
|
1089
1074
|
event.id,
|
|
1090
|
-
laneTop(lanes.laneOf.get(event.id), geometry)
|
|
1075
|
+
inset + laneTop(lanes.laneOf.get(event.id), geometry)
|
|
1091
1076
|
);
|
|
1092
1077
|
const resize = view.resizePreview;
|
|
1093
1078
|
const resizing = resize !== null && resize.eventId === event.id;
|
|
@@ -1247,7 +1232,7 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1247
1232
|
}
|
|
1248
1233
|
if (rowId === null) return null;
|
|
1249
1234
|
const lanes = scene.getLanes(rowId, windowStart, windowEnd);
|
|
1250
|
-
const
|
|
1235
|
+
const lanesY = rowTop - scrollTop + scene.getLaneInset(rowId, windowStart, windowEnd);
|
|
1251
1236
|
const events = cullToWindow(
|
|
1252
1237
|
scene.getRowEvents(rowId),
|
|
1253
1238
|
windowStart,
|
|
@@ -1257,7 +1242,7 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1257
1242
|
const event = events[i];
|
|
1258
1243
|
const rect = {
|
|
1259
1244
|
x: timeToX(event.startTime, windowStart, tick),
|
|
1260
|
-
y:
|
|
1245
|
+
y: lanesY + laneTop(lanes.laneOf.get(event.id), geometry),
|
|
1261
1246
|
width: timeToWidth(event.startTime, event.endTime, tick),
|
|
1262
1247
|
height: geometry.barHeight
|
|
1263
1248
|
};
|
|
@@ -1274,7 +1259,7 @@ var hitTest = (scene, view, x, y) => {
|
|
|
1274
1259
|
const event = statics[i];
|
|
1275
1260
|
const rect = {
|
|
1276
1261
|
x: timeToX(event.startTime, windowStart, tick),
|
|
1277
|
-
y:
|
|
1262
|
+
y: lanesY + geometry.laneTopOffset,
|
|
1278
1263
|
width: timeToWidth(event.startTime, event.endTime, tick),
|
|
1279
1264
|
height: staticEventHeight(lanes.highestLane, geometry)
|
|
1280
1265
|
};
|
|
@@ -2661,6 +2646,17 @@ var SceneStore = class {
|
|
|
2661
2646
|
const labelHeight = (_a = this.labelMinHeights.get(rowId)) != null ? _a : 0;
|
|
2662
2647
|
return Math.max(laneHeight, labelHeight);
|
|
2663
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
|
+
}
|
|
2664
2660
|
/**
|
|
2665
2661
|
* y offset of each row's top edge (content coordinates, before scroll) plus
|
|
2666
2662
|
* the total content height — drives both drawing and the scroll spacer.
|
|
@@ -2830,6 +2826,7 @@ var Timeline = (0, import_react7.forwardRef)(
|
|
|
2830
2826
|
selectable = false,
|
|
2831
2827
|
defaultSelectedEventIds,
|
|
2832
2828
|
onSelectionChange,
|
|
2829
|
+
onWindowChange,
|
|
2833
2830
|
defaultCollapsedRowIds,
|
|
2834
2831
|
startDate,
|
|
2835
2832
|
endDate,
|
|
@@ -2934,6 +2931,12 @@ var Timeline = (0, import_react7.forwardRef)(
|
|
|
2934
2931
|
}, [scene, defaultCollapsedRowIds]);
|
|
2935
2932
|
const windowTimeRef = (0, import_react7.useRef)(windowTime);
|
|
2936
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]]);
|
|
2937
2940
|
(0, import_react7.useImperativeHandle)(
|
|
2938
2941
|
handleRef,
|
|
2939
2942
|
() => ({
|