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.
package/dist/index.mjs CHANGED
@@ -434,6 +434,7 @@ var DEFAULT_THEME = {
434
434
  eventStroke: "#000000",
435
435
  eventTextColor: "#000000",
436
436
  staticEventFill: "#e0e0e0",
437
+ overlapStripeColor: "rgba(15,23,42,0.6)",
437
438
  gridColor: "#e4dcdc",
438
439
  timeBarBorder: "yellow",
439
440
  timeBarTextColor: "white",
@@ -788,7 +789,7 @@ var HANDLE_BAR_WIDTH = 3;
788
789
  var HANDLE_BAR_GAP = 1;
789
790
  var HANDLE_BAR_HEIGHT = 10;
790
791
  var roundedRect = (ctx, x, y, width, height, radius) => {
791
- const r = Math.min(radius, width / 2, height / 2);
792
+ const r = Math.max(0, Math.min(radius, width / 2, height / 2));
792
793
  ctx.beginPath();
793
794
  if (typeof ctx.roundRect === "function") {
794
795
  ctx.roundRect(x, y, width, height, r);
@@ -944,6 +945,43 @@ var defaultDrawEvent = (ctx, event, rect, view, font, barRadius) => {
944
945
  ctx.restore();
945
946
  }
946
947
  };
948
+ var STRIPE_STEP = 6;
949
+ var STRIPE_WIDTH = 2;
950
+ var STRIPE_WASH_ALPHA = 0.18;
951
+ var paintOverlapStripes = (ctx, event, rect, rowStatics, windowStart, tick, color) => {
952
+ const barRight = rect.x + rect.width;
953
+ for (const band of rowStatics) {
954
+ const overlapStart = Math.max(event.startTime, band.startTime);
955
+ const overlapEnd = Math.min(event.endTime, band.endTime);
956
+ if (overlapEnd <= overlapStart) continue;
957
+ const x0 = Math.max(timeToX(overlapStart, windowStart, tick), rect.x);
958
+ const x1 = Math.min(
959
+ timeToX(overlapStart, windowStart, tick) + timeToWidth(overlapStart, overlapEnd, tick),
960
+ barRight
961
+ );
962
+ const width = x1 - x0;
963
+ if (width <= 0) continue;
964
+ const { y, height } = rect;
965
+ ctx.save();
966
+ ctx.beginPath();
967
+ ctx.rect(x0, y, width, height);
968
+ ctx.clip();
969
+ const baseAlpha = ctx.globalAlpha;
970
+ ctx.globalAlpha = baseAlpha * STRIPE_WASH_ALPHA;
971
+ ctx.fillStyle = color;
972
+ ctx.fillRect(x0, y, width, height);
973
+ ctx.globalAlpha = baseAlpha;
974
+ ctx.strokeStyle = color;
975
+ ctx.lineWidth = STRIPE_WIDTH;
976
+ for (let sx = x0 - height; sx < x1; sx += STRIPE_STEP) {
977
+ ctx.beginPath();
978
+ ctx.moveTo(sx, y + height);
979
+ ctx.lineTo(sx + height, y);
980
+ ctx.stroke();
981
+ }
982
+ ctx.restore();
983
+ }
984
+ };
947
985
  var drawEvents = (ctx, view, scene, font, animator) => {
948
986
  var _a;
949
987
  if (view.tick === null) return;
@@ -956,9 +994,10 @@ var drawEvents = (ctx, view, scene, font, animator) => {
956
994
  const selectedIds = view.selectedEventIds;
957
995
  const hasSelection = selectedIds.size > 0;
958
996
  const deferred = [];
959
- const paintEvent = (event, rect, state, opts) => {
997
+ const paintEvent = (event, rect, state, opts, rowStatics) => {
960
998
  var _a2, _b, _c, _d, _e;
961
999
  ctx.save();
1000
+ ctx.globalAlpha = 1;
962
1001
  if (opts.elevate) {
963
1002
  ctx.translate(0, -view.theme.selectionElevation);
964
1003
  ctx.shadowColor = view.theme.selectionShadowColor;
@@ -972,6 +1011,17 @@ var drawEvents = (ctx, view, scene, font, animator) => {
972
1011
  if (!drawn) {
973
1012
  defaultDrawEvent(ctx, event, rect, view, font, geometry.barRadius);
974
1013
  }
1014
+ if (view.stripeOverlap && rowStatics.length > 0) {
1015
+ paintOverlapStripes(
1016
+ ctx,
1017
+ event,
1018
+ rect,
1019
+ rowStatics,
1020
+ windowStart,
1021
+ tick,
1022
+ view.theme.overlapStripeColor
1023
+ );
1024
+ }
975
1025
  if (canResizeEvent(event, view.eventsResize)) {
976
1026
  const alpha = animator.handleAlpha(
977
1027
  event.id,
@@ -997,11 +1047,12 @@ var drawEvents = (ctx, view, scene, font, animator) => {
997
1047
  if (rowY + rowHeight < 0) continue;
998
1048
  if (rowY > view.height) break;
999
1049
  const lanes = scene.getLanes(rowId, windowStart, windowEnd);
1000
- for (const event of cullToWindow(
1050
+ const rowStatics = cullToWindow(
1001
1051
  scene.getRowStaticEvents(rowId),
1002
1052
  windowStart,
1003
1053
  windowEnd
1004
- )) {
1054
+ );
1055
+ for (const event of rowStatics) {
1005
1056
  const x = timeToX(event.startTime, windowStart, tick);
1006
1057
  const width = timeToWidth(event.startTime, event.endTime, tick);
1007
1058
  ctx.fillStyle = view.theme.staticEventFill;
@@ -1046,10 +1097,16 @@ var drawEvents = (ctx, view, scene, font, animator) => {
1046
1097
  };
1047
1098
  if (selected) {
1048
1099
  deferred.push(
1049
- () => paintEvent(event, rect, state, { dim: false, elevate: true })
1100
+ () => paintEvent(event, rect, state, { dim: false, elevate: true }, rowStatics)
1050
1101
  );
1051
1102
  } else {
1052
- paintEvent(event, rect, state, { dim: hasSelection, elevate: false });
1103
+ paintEvent(
1104
+ event,
1105
+ rect,
1106
+ state,
1107
+ { dim: hasSelection, elevate: false },
1108
+ rowStatics
1109
+ );
1053
1110
  }
1054
1111
  }
1055
1112
  }
@@ -1072,6 +1129,7 @@ var TimelineRenderer = class {
1072
1129
  theme: DEFAULT_THEME,
1073
1130
  drawEvent: void 0,
1074
1131
  eventsResize: true,
1132
+ stripeOverlap: false,
1075
1133
  hoveredEventId: null,
1076
1134
  draggedEventId: null,
1077
1135
  resizePreview: null,
@@ -1947,6 +2005,7 @@ var CanvasBoard = forwardRef2(
1947
2005
  onEventClick,
1948
2006
  onEventHover,
1949
2007
  eventsResize,
2008
+ stripeOverlap,
1950
2009
  panZoom,
1951
2010
  animations,
1952
2011
  selectable,
@@ -1985,7 +2044,8 @@ var CanvasBoard = forwardRef2(
1985
2044
  cellWidth,
1986
2045
  theme,
1987
2046
  drawEvent,
1988
- eventsResize
2047
+ eventsResize,
2048
+ stripeOverlap
1989
2049
  });
1990
2050
  }, [
1991
2051
  windowTime,
@@ -1994,6 +2054,7 @@ var CanvasBoard = forwardRef2(
1994
2054
  theme,
1995
2055
  drawEvent,
1996
2056
  eventsResize,
2057
+ stripeOverlap,
1997
2058
  animations,
1998
2059
  rendererRef
1999
2060
  ]);
@@ -2720,6 +2781,7 @@ var Timeline = forwardRef3(
2720
2781
  additionalClassNames,
2721
2782
  showRTIndicator = true,
2722
2783
  eventsResize = true,
2784
+ stripeOverlap = false,
2723
2785
  eventPromptTemplate,
2724
2786
  showEventPrompt = true,
2725
2787
  panZoom,
@@ -2789,9 +2851,17 @@ var Timeline = forwardRef3(
2789
2851
  (_a = rendererRef.current) == null ? void 0 : _a.animator.reset();
2790
2852
  }, [scene, rows]);
2791
2853
  useEffect6(() => {
2792
- var _a;
2854
+ var _a, _b, _c;
2793
2855
  scene.setEvents([...events].sort(sort_events_default));
2794
2856
  (_a = rendererRef.current) == null ? void 0 : _a.animator.reset();
2857
+ const survivors = [...selectionRef.current].filter(
2858
+ (id) => scene.getEvent(id) !== void 0
2859
+ );
2860
+ if (survivors.length !== selectionRef.current.size) {
2861
+ selectionRef.current = new Set(survivors);
2862
+ (_b = rendererRef.current) == null ? void 0 : _b.setView({ selectedEventIds: selectionRef.current });
2863
+ (_c = onSelectionChangeRef.current) == null ? void 0 : _c.call(onSelectionChangeRef, survivors);
2864
+ }
2795
2865
  }, [scene, events]);
2796
2866
  useEffect6(() => {
2797
2867
  scene.setStaticEvents(staticEvents ? [...staticEvents] : []);
@@ -2953,6 +3023,7 @@ var Timeline = forwardRef3(
2953
3023
  onEventClick,
2954
3024
  onEventHover,
2955
3025
  eventsResize,
3026
+ stripeOverlap,
2956
3027
  panZoom,
2957
3028
  animations: resolvedAnimations,
2958
3029
  selectable,