awesome-timeline-react 0.4.2 → 0.5.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.
@@ -52,6 +52,7 @@ declare type CanvasBoardProps = {
52
52
  onEventClick?: (props: OnEventClickProps) => void;
53
53
  onEventHover?: (props: OnEventHoverProps) => void;
54
54
  eventsResize: boolean;
55
+ stripeOverlap: boolean;
55
56
  panZoom?: PanZoomConfig;
56
57
  animations: {
57
58
  layoutMs: number;
@@ -629,6 +630,7 @@ export declare type RendererView = {
629
630
  theme: ResolvedTheme;
630
631
  drawEvent?: DrawEventFn;
631
632
  eventsResize: boolean;
633
+ stripeOverlap: boolean;
632
634
  hoveredEventId: string | null;
633
635
  draggedEventId: string | null;
634
636
  resizePreview: ResizePreview | null;
@@ -788,6 +790,10 @@ declare type Theme = {
788
790
  eventStroke?: string;
789
791
  eventTextColor?: string;
790
792
  staticEventFill?: string;
793
+ /** color of the 45° stripes drawn over the slice of an event bar that overlaps
794
+ * a static event, when the `stripeOverlap` prop is on (default a translucent
795
+ * slate so it reads over any bar fill). */
796
+ overlapStripeColor?: string;
791
797
  gridColor?: string;
792
798
  timeBarBorder?: string;
793
799
  timeBarTextColor?: string;
@@ -972,6 +978,12 @@ declare type TimelineProps = {
972
978
  additionalClassNames?: PartialRecord<keyof ModifableElements, string>;
973
979
  showRTIndicator?: boolean;
974
980
  eventsResize?: boolean;
981
+ /** draw 45° diagonal stripes on the slice of an event bar that overlaps a
982
+ * static event (e.g. an off-shift/downtime band) on the same row. This gives
983
+ * a visible cause for a bar that looks "too wide" because it spans
984
+ * non-working time. Stripe color is `theme.overlapStripeColor`. Default
985
+ * false (no striping). */
986
+ stripeOverlap?: boolean;
975
987
  showEventPrompt?: boolean;
976
988
  eventPromptTemplate?: (event: EventType) => JSX.Element;
977
989
  panZoom?: PanZoomConfig;
@@ -1040,6 +1052,17 @@ export declare const TimelineShiftBar: () => React_2.JSX.Element;
1040
1052
  */
1041
1053
  export declare const TimelineStreaming10k: () => React_2.JSX.Element;
1042
1054
 
1055
+ /**
1056
+ * `stripeOverlap`: where an event bar overlaps a static event (an off-shift /
1057
+ * downtime band) on the same row, its overlapping slice is hatched with 45°
1058
+ * stripes so an over-wide bar has a visible cause (spec §6.4 — "why is my 2h op
1059
+ * 14h wide?"). Toggle it to compare. Row 1's op straddles the band (striped over
1060
+ * the gap only); row 2's op starts at the band's end (no overlap → no stripes),
1061
+ * modelling a "continuous / no-straddle" op that shifted whole. Stripe color is
1062
+ * `theme.overlapStripeColor`.
1063
+ */
1064
+ export declare const TimelineStripedOverlap: () => React_2.JSX.Element;
1065
+
1043
1066
  /**
1044
1067
  * Themeable bar geometry: chunky 32px bars with a 6px lane gap, wide row
1045
1068
  * padding, and a larger corner radius. Verifies stacking, hit-testing
@@ -52,6 +52,7 @@ declare type CanvasBoardProps = {
52
52
  onEventClick?: (props: OnEventClickProps) => void;
53
53
  onEventHover?: (props: OnEventHoverProps) => void;
54
54
  eventsResize: boolean;
55
+ stripeOverlap: boolean;
55
56
  panZoom?: PanZoomConfig;
56
57
  animations: {
57
58
  layoutMs: number;
@@ -629,6 +630,7 @@ export declare type RendererView = {
629
630
  theme: ResolvedTheme;
630
631
  drawEvent?: DrawEventFn;
631
632
  eventsResize: boolean;
633
+ stripeOverlap: boolean;
632
634
  hoveredEventId: string | null;
633
635
  draggedEventId: string | null;
634
636
  resizePreview: ResizePreview | null;
@@ -788,6 +790,10 @@ declare type Theme = {
788
790
  eventStroke?: string;
789
791
  eventTextColor?: string;
790
792
  staticEventFill?: string;
793
+ /** color of the 45° stripes drawn over the slice of an event bar that overlaps
794
+ * a static event, when the `stripeOverlap` prop is on (default a translucent
795
+ * slate so it reads over any bar fill). */
796
+ overlapStripeColor?: string;
791
797
  gridColor?: string;
792
798
  timeBarBorder?: string;
793
799
  timeBarTextColor?: string;
@@ -972,6 +978,12 @@ declare type TimelineProps = {
972
978
  additionalClassNames?: PartialRecord<keyof ModifableElements, string>;
973
979
  showRTIndicator?: boolean;
974
980
  eventsResize?: boolean;
981
+ /** draw 45° diagonal stripes on the slice of an event bar that overlaps a
982
+ * static event (e.g. an off-shift/downtime band) on the same row. This gives
983
+ * a visible cause for a bar that looks "too wide" because it spans
984
+ * non-working time. Stripe color is `theme.overlapStripeColor`. Default
985
+ * false (no striping). */
986
+ stripeOverlap?: boolean;
975
987
  showEventPrompt?: boolean;
976
988
  eventPromptTemplate?: (event: EventType) => JSX.Element;
977
989
  panZoom?: PanZoomConfig;
@@ -1040,6 +1052,17 @@ export declare const TimelineShiftBar: () => React_2.JSX.Element;
1040
1052
  */
1041
1053
  export declare const TimelineStreaming10k: () => React_2.JSX.Element;
1042
1054
 
1055
+ /**
1056
+ * `stripeOverlap`: where an event bar overlaps a static event (an off-shift /
1057
+ * downtime band) on the same row, its overlapping slice is hatched with 45°
1058
+ * stripes so an over-wide bar has a visible cause (spec §6.4 — "why is my 2h op
1059
+ * 14h wide?"). Toggle it to compare. Row 1's op straddles the band (striped over
1060
+ * the gap only); row 2's op starts at the band's end (no overlap → no stripes),
1061
+ * modelling a "continuous / no-straddle" op that shifted whole. Stripe color is
1062
+ * `theme.overlapStripeColor`.
1063
+ */
1064
+ export declare const TimelineStripedOverlap: () => React_2.JSX.Element;
1065
+
1043
1066
  /**
1044
1067
  * Themeable bar geometry: chunky 32px bars with a 6px lane gap, wide row
1045
1068
  * padding, and a larger corner radius. Verifies stacking, hit-testing
package/dist/index.js CHANGED
@@ -454,6 +454,7 @@ var DEFAULT_THEME = {
454
454
  eventStroke: "#000000",
455
455
  eventTextColor: "#000000",
456
456
  staticEventFill: "#e0e0e0",
457
+ overlapStripeColor: "rgba(15,23,42,0.6)",
457
458
  gridColor: "#e4dcdc",
458
459
  timeBarBorder: "yellow",
459
460
  timeBarTextColor: "white",
@@ -800,7 +801,7 @@ var HANDLE_BAR_WIDTH = 3;
800
801
  var HANDLE_BAR_GAP = 1;
801
802
  var HANDLE_BAR_HEIGHT = 10;
802
803
  var roundedRect = (ctx, x, y, width, height, radius) => {
803
- const r = Math.min(radius, width / 2, height / 2);
804
+ const r = Math.max(0, Math.min(radius, width / 2, height / 2));
804
805
  ctx.beginPath();
805
806
  if (typeof ctx.roundRect === "function") {
806
807
  ctx.roundRect(x, y, width, height, r);
@@ -956,6 +957,43 @@ var defaultDrawEvent = (ctx, event, rect, view, font, barRadius) => {
956
957
  ctx.restore();
957
958
  }
958
959
  };
960
+ var STRIPE_STEP = 6;
961
+ var STRIPE_WIDTH = 2;
962
+ var STRIPE_WASH_ALPHA = 0.18;
963
+ var paintOverlapStripes = (ctx, event, rect, rowStatics, windowStart, tick, color) => {
964
+ const barRight = rect.x + rect.width;
965
+ for (const band of rowStatics) {
966
+ const overlapStart = Math.max(event.startTime, band.startTime);
967
+ const overlapEnd = Math.min(event.endTime, band.endTime);
968
+ if (overlapEnd <= overlapStart) continue;
969
+ const x0 = Math.max(timeToX(overlapStart, windowStart, tick), rect.x);
970
+ const x1 = Math.min(
971
+ timeToX(overlapStart, windowStart, tick) + timeToWidth(overlapStart, overlapEnd, tick),
972
+ barRight
973
+ );
974
+ const width = x1 - x0;
975
+ if (width <= 0) continue;
976
+ const { y, height } = rect;
977
+ ctx.save();
978
+ ctx.beginPath();
979
+ ctx.rect(x0, y, width, height);
980
+ ctx.clip();
981
+ const baseAlpha = ctx.globalAlpha;
982
+ ctx.globalAlpha = baseAlpha * STRIPE_WASH_ALPHA;
983
+ ctx.fillStyle = color;
984
+ ctx.fillRect(x0, y, width, height);
985
+ ctx.globalAlpha = baseAlpha;
986
+ ctx.strokeStyle = color;
987
+ ctx.lineWidth = STRIPE_WIDTH;
988
+ for (let sx = x0 - height; sx < x1; sx += STRIPE_STEP) {
989
+ ctx.beginPath();
990
+ ctx.moveTo(sx, y + height);
991
+ ctx.lineTo(sx + height, y);
992
+ ctx.stroke();
993
+ }
994
+ ctx.restore();
995
+ }
996
+ };
959
997
  var drawEvents = (ctx, view, scene, font, animator) => {
960
998
  var _a;
961
999
  if (view.tick === null) return;
@@ -968,9 +1006,10 @@ var drawEvents = (ctx, view, scene, font, animator) => {
968
1006
  const selectedIds = view.selectedEventIds;
969
1007
  const hasSelection = selectedIds.size > 0;
970
1008
  const deferred = [];
971
- const paintEvent = (event, rect, state, opts) => {
1009
+ const paintEvent = (event, rect, state, opts, rowStatics) => {
972
1010
  var _a2, _b, _c, _d, _e;
973
1011
  ctx.save();
1012
+ ctx.globalAlpha = 1;
974
1013
  if (opts.elevate) {
975
1014
  ctx.translate(0, -view.theme.selectionElevation);
976
1015
  ctx.shadowColor = view.theme.selectionShadowColor;
@@ -984,6 +1023,17 @@ var drawEvents = (ctx, view, scene, font, animator) => {
984
1023
  if (!drawn) {
985
1024
  defaultDrawEvent(ctx, event, rect, view, font, geometry.barRadius);
986
1025
  }
1026
+ if (view.stripeOverlap && rowStatics.length > 0) {
1027
+ paintOverlapStripes(
1028
+ ctx,
1029
+ event,
1030
+ rect,
1031
+ rowStatics,
1032
+ windowStart,
1033
+ tick,
1034
+ view.theme.overlapStripeColor
1035
+ );
1036
+ }
987
1037
  if (canResizeEvent(event, view.eventsResize)) {
988
1038
  const alpha = animator.handleAlpha(
989
1039
  event.id,
@@ -1009,11 +1059,12 @@ var drawEvents = (ctx, view, scene, font, animator) => {
1009
1059
  if (rowY + rowHeight < 0) continue;
1010
1060
  if (rowY > view.height) break;
1011
1061
  const lanes = scene.getLanes(rowId, windowStart, windowEnd);
1012
- for (const event of cullToWindow(
1062
+ const rowStatics = cullToWindow(
1013
1063
  scene.getRowStaticEvents(rowId),
1014
1064
  windowStart,
1015
1065
  windowEnd
1016
- )) {
1066
+ );
1067
+ for (const event of rowStatics) {
1017
1068
  const x = timeToX(event.startTime, windowStart, tick);
1018
1069
  const width = timeToWidth(event.startTime, event.endTime, tick);
1019
1070
  ctx.fillStyle = view.theme.staticEventFill;
@@ -1058,10 +1109,16 @@ var drawEvents = (ctx, view, scene, font, animator) => {
1058
1109
  };
1059
1110
  if (selected) {
1060
1111
  deferred.push(
1061
- () => paintEvent(event, rect, state, { dim: false, elevate: true })
1112
+ () => paintEvent(event, rect, state, { dim: false, elevate: true }, rowStatics)
1062
1113
  );
1063
1114
  } else {
1064
- paintEvent(event, rect, state, { dim: hasSelection, elevate: false });
1115
+ paintEvent(
1116
+ event,
1117
+ rect,
1118
+ state,
1119
+ { dim: hasSelection, elevate: false },
1120
+ rowStatics
1121
+ );
1065
1122
  }
1066
1123
  }
1067
1124
  }
@@ -1084,6 +1141,7 @@ var TimelineRenderer = class {
1084
1141
  theme: DEFAULT_THEME,
1085
1142
  drawEvent: void 0,
1086
1143
  eventsResize: true,
1144
+ stripeOverlap: false,
1087
1145
  hoveredEventId: null,
1088
1146
  draggedEventId: null,
1089
1147
  resizePreview: null,
@@ -1959,6 +2017,7 @@ var CanvasBoard = (0, import_react6.forwardRef)(
1959
2017
  onEventClick,
1960
2018
  onEventHover,
1961
2019
  eventsResize,
2020
+ stripeOverlap,
1962
2021
  panZoom,
1963
2022
  animations,
1964
2023
  selectable,
@@ -1997,7 +2056,8 @@ var CanvasBoard = (0, import_react6.forwardRef)(
1997
2056
  cellWidth,
1998
2057
  theme,
1999
2058
  drawEvent,
2000
- eventsResize
2059
+ eventsResize,
2060
+ stripeOverlap
2001
2061
  });
2002
2062
  }, [
2003
2063
  windowTime,
@@ -2006,6 +2066,7 @@ var CanvasBoard = (0, import_react6.forwardRef)(
2006
2066
  theme,
2007
2067
  drawEvent,
2008
2068
  eventsResize,
2069
+ stripeOverlap,
2009
2070
  animations,
2010
2071
  rendererRef
2011
2072
  ]);
@@ -2732,6 +2793,7 @@ var Timeline = (0, import_react7.forwardRef)(
2732
2793
  additionalClassNames,
2733
2794
  showRTIndicator = true,
2734
2795
  eventsResize = true,
2796
+ stripeOverlap = false,
2735
2797
  eventPromptTemplate,
2736
2798
  showEventPrompt = true,
2737
2799
  panZoom,
@@ -2801,9 +2863,17 @@ var Timeline = (0, import_react7.forwardRef)(
2801
2863
  (_a = rendererRef.current) == null ? void 0 : _a.animator.reset();
2802
2864
  }, [scene, rows]);
2803
2865
  (0, import_react7.useEffect)(() => {
2804
- var _a;
2866
+ var _a, _b, _c;
2805
2867
  scene.setEvents([...events].sort(sort_events_default));
2806
2868
  (_a = rendererRef.current) == null ? void 0 : _a.animator.reset();
2869
+ const survivors = [...selectionRef.current].filter(
2870
+ (id) => scene.getEvent(id) !== void 0
2871
+ );
2872
+ if (survivors.length !== selectionRef.current.size) {
2873
+ selectionRef.current = new Set(survivors);
2874
+ (_b = rendererRef.current) == null ? void 0 : _b.setView({ selectedEventIds: selectionRef.current });
2875
+ (_c = onSelectionChangeRef.current) == null ? void 0 : _c.call(onSelectionChangeRef, survivors);
2876
+ }
2807
2877
  }, [scene, events]);
2808
2878
  (0, import_react7.useEffect)(() => {
2809
2879
  scene.setStaticEvents(staticEvents ? [...staticEvents] : []);
@@ -2965,6 +3035,7 @@ var Timeline = (0, import_react7.forwardRef)(
2965
3035
  onEventClick,
2966
3036
  onEventHover,
2967
3037
  eventsResize,
3038
+ stripeOverlap,
2968
3039
  panZoom,
2969
3040
  animations: resolvedAnimations,
2970
3041
  selectable,