@spider-analyzer/timeline 4.0.2 → 5.0.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +70 -1
  2. package/README.md +275 -637
  3. package/dist/index.d.mts +132 -0
  4. package/dist/index.d.ts +132 -0
  5. package/dist/index.js +2913 -22
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +2906 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/dist/timeline-EX2XZ6IP.css +139 -0
  10. package/package.json +48 -15
  11. package/src/Cursor.jsx +5 -13
  12. package/src/TimeLine.tsx +994 -0
  13. package/src/TimeLineResizer.jsx +2 -8
  14. package/src/ToolTip.jsx +7 -7
  15. package/src/cursorElements/CursorIcon.jsx +6 -29
  16. package/src/cursorElements/CursorSelection.jsx +4 -19
  17. package/src/cursorElements/DragOverlay.jsx +2 -12
  18. package/src/cursorElements/LeftHandle.jsx +3 -19
  19. package/src/cursorElements/LeftToolTip.jsx +2 -7
  20. package/src/cursorElements/RightHandle.jsx +3 -19
  21. package/src/cursorElements/RightToolTip.jsx +4 -13
  22. package/src/cursorElements/ZoomIn.jsx +5 -25
  23. package/src/cursorElements/ZoomOut.jsx +4 -21
  24. package/src/cursorElements/utils.js +1 -1
  25. package/src/index.js +6 -0
  26. package/src/index.ts +158 -0
  27. package/src/moment-shim.ts +169 -0
  28. package/src/styles.ts +15 -0
  29. package/src/time.ts +52 -0
  30. package/src/timeLineElements/Button.jsx +5 -30
  31. package/src/timeLineElements/HistoToolTip.jsx +3 -17
  32. package/src/timeLineElements/Histogram.jsx +4 -16
  33. package/src/timeLineElements/Legend.jsx +2 -16
  34. package/src/timeLineElements/QualityLine.jsx +4 -11
  35. package/src/timeLineElements/Tools.jsx +1 -1
  36. package/src/timeLineElements/XAxis.jsx +5 -8
  37. package/src/timeLineElements/XGrid.jsx +3 -7
  38. package/src/timeLineElements/YAxis.jsx +4 -7
  39. package/src/timeLineElements/YGrid.jsx +2 -6
  40. package/src/timeLineElements/axesStyles.jsx +0 -49
  41. package/src/timeline.css +139 -0
  42. package/src/utils.ts +60 -0
  43. package/.babelrc +0 -8
  44. package/.gitlab-ci.yml +0 -27
  45. package/Makefile +0 -20
  46. package/dist/Cursor.js +0 -290
  47. package/dist/TimeLine.js +0 -1173
  48. package/dist/TimeLineResizer.js +0 -70
  49. package/dist/ToolTip.js +0 -43
  50. package/dist/cursorElements/CursorIcon.js +0 -98
  51. package/dist/cursorElements/CursorSelection.js +0 -179
  52. package/dist/cursorElements/DragOverlay.js +0 -168
  53. package/dist/cursorElements/LeftHandle.js +0 -95
  54. package/dist/cursorElements/LeftToolTip.js +0 -70
  55. package/dist/cursorElements/RightHandle.js +0 -95
  56. package/dist/cursorElements/RightToolTip.js +0 -75
  57. package/dist/cursorElements/ZoomIn.js +0 -93
  58. package/dist/cursorElements/ZoomOut.js +0 -67
  59. package/dist/cursorElements/commonStyles.js +0 -28
  60. package/dist/cursorElements/handleHistoHovering.js +0 -79
  61. package/dist/cursorElements/utils.js +0 -30
  62. package/dist/theme.js +0 -59
  63. package/dist/timeLineElements/Button.js +0 -101
  64. package/dist/timeLineElements/HistoToolTip.js +0 -78
  65. package/dist/timeLineElements/Histogram.js +0 -110
  66. package/dist/timeLineElements/Legend.js +0 -70
  67. package/dist/timeLineElements/QualityLine.js +0 -81
  68. package/dist/timeLineElements/Tools.js +0 -115
  69. package/dist/timeLineElements/XAxis.js +0 -76
  70. package/dist/timeLineElements/XGrid.js +0 -47
  71. package/dist/timeLineElements/YAxis.js +0 -60
  72. package/dist/timeLineElements/YGrid.js +0 -46
  73. package/dist/timeLineElements/axesStyles.js +0 -57
  74. package/src/TimeLine.jsx +0 -1158
  75. package/src/cursorElements/commonStyles.js +0 -21
  76. /package/dist/{tipDark.css → tipDark-BQEJ43KY.css} +0 -0
package/dist/index.js CHANGED
@@ -1,27 +1,2918 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "default", {
7
- enumerable: true,
8
- get: function get() {
9
- return _TimeLineResizer["default"];
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+ var luxon = require('luxon');
7
+ var d3Scale = require('d3-scale');
8
+ var PropTypes11 = require('prop-types');
9
+ var d3Selection = require('d3-selection');
10
+ var d3Drag = require('d3-drag');
11
+ var jsxRuntime = require('react/jsx-runtime');
12
+ var clsx3 = require('clsx');
13
+ require('./timeline-EX2XZ6IP.css');
14
+ var ToolTipBase = require('rc-tooltip');
15
+ require('./tipDark-BQEJ43KY.css');
16
+ var d3Time = require('d3-time');
17
+
18
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
19
+
20
+ var PropTypes11__default = /*#__PURE__*/_interopDefault(PropTypes11);
21
+ var clsx3__default = /*#__PURE__*/_interopDefault(clsx3);
22
+ var ToolTipBase__default = /*#__PURE__*/_interopDefault(ToolTipBase);
23
+
24
+ var __defProp = Object.defineProperty;
25
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
26
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
27
+ var unitMap = {
28
+ ms: "milliseconds",
29
+ milliseconds: "milliseconds",
30
+ millisecond: "milliseconds",
31
+ second: "seconds",
32
+ seconds: "seconds",
33
+ minute: "minutes",
34
+ minutes: "minutes",
35
+ hour: "hours",
36
+ hours: "hours",
37
+ day: "days",
38
+ days: "days",
39
+ month: "months",
40
+ months: "months",
41
+ year: "years",
42
+ years: "years"
43
+ };
44
+ function normalizeUnit(unit) {
45
+ if (!unit) return "milliseconds";
46
+ const norm = unit.toLowerCase();
47
+ return unitMap[norm] ?? norm;
48
+ }
49
+ var DurationLike = class {
50
+ constructor(d) {
51
+ __publicField(this, "d");
52
+ this.d = d;
10
53
  }
11
- });
12
- Object.defineProperty(exports, "Cursor", {
13
- enumerable: true,
14
- get: function get() {
15
- return _Cursor2["default"];
54
+ asMilliseconds() {
55
+ return this.d.as("milliseconds");
16
56
  }
17
- });
18
- Object.defineProperty(exports, "TimeLine", {
19
- enumerable: true,
20
- get: function get() {
21
- return _TimeLine2["default"];
57
+ valueOf() {
58
+ return this.d.as("milliseconds");
59
+ }
60
+ };
61
+ function toDurationLike(x) {
62
+ if (x instanceof DurationLike) return x;
63
+ if (typeof x === "number") return new DurationLike(luxon.Duration.fromMillis(x));
64
+ if (typeof x === "string") return new DurationLike(luxon.Duration.fromISO(x));
65
+ if (x && typeof x.asMilliseconds === "function") {
66
+ return new DurationLike(luxon.Duration.fromMillis(x.asMilliseconds()));
67
+ }
68
+ return new DurationLike(luxon.Duration.fromMillis(0));
69
+ }
70
+ var MomentLike = class _MomentLike {
71
+ constructor(dt) {
72
+ __publicField(this, "_dt");
73
+ this._dt = dt;
74
+ }
75
+ _toDT(other) {
76
+ if (other instanceof _MomentLike) return other._dt;
77
+ if (other instanceof Date) return luxon.DateTime.fromJSDate(other);
78
+ if (typeof other === "number") return luxon.DateTime.fromMillis(other);
79
+ if (other instanceof luxon.DateTime) return other;
80
+ return luxon.DateTime.fromJSDate(new Date(other));
81
+ }
82
+ _addMillis(ms) {
83
+ return this._dt.toMillis() + ms;
84
+ }
85
+ isBefore(other) {
86
+ return this._dt.toMillis() < this._toDT(other).toMillis();
87
+ }
88
+ isAfter(other) {
89
+ return this._dt.toMillis() > this._toDT(other).toMillis();
90
+ }
91
+ isSame(other) {
92
+ return this._dt.toMillis() === this._toDT(other).toMillis();
93
+ }
94
+ isSameOrBefore(other) {
95
+ return this._dt.toMillis() <= this._toDT(other).toMillis();
96
+ }
97
+ isSameOrAfter(other) {
98
+ return this._dt.toMillis() >= this._toDT(other).toMillis();
99
+ }
100
+ // moment returns duration by default; library internals always use the
101
+ // no-arg form and treat the result as a number via arithmetic. Return ms.
102
+ diff(other) {
103
+ return this._dt.toMillis() - this._toDT(other).toMillis();
104
+ }
105
+ add(n, unit) {
106
+ const ms = normalizeToMillis(n, unit);
107
+ return new _MomentLike(luxon.DateTime.fromMillis(this._addMillis(ms), { zone: this._dt.zone }));
108
+ }
109
+ subtract(n, unit) {
110
+ const ms = normalizeToMillis(n, unit);
111
+ return new _MomentLike(luxon.DateTime.fromMillis(this._addMillis(-ms), { zone: this._dt.zone }));
112
+ }
113
+ toDate() {
114
+ return this._dt.toJSDate();
115
+ }
116
+ toISOString() {
117
+ return this._dt.toUTC().toISO() ?? "";
118
+ }
119
+ valueOf() {
120
+ return this._dt.toMillis();
121
+ }
122
+ format(fmt) {
123
+ if (!fmt) return this._dt.toISO() ?? "";
124
+ return this._dt.toFormat(momentFmtToLuxon(fmt));
22
125
  }
126
+ // setter chain used in demo: .second(0).millisecond(0)
127
+ second(v) {
128
+ return new _MomentLike(this._dt.set({ second: v }));
129
+ }
130
+ millisecond(v) {
131
+ return new _MomentLike(this._dt.set({ millisecond: v }));
132
+ }
133
+ // Internal (escape hatch — prefer the wrapper API above).
134
+ toLuxon() {
135
+ return this._dt;
136
+ }
137
+ };
138
+ function normalizeToMillis(n, unit) {
139
+ if (n instanceof DurationLike) return n.asMilliseconds();
140
+ if (n && typeof n.asMilliseconds === "function") return n.asMilliseconds();
141
+ if (typeof n === "number") {
142
+ if (!unit) return n;
143
+ const u = normalizeUnit(unit);
144
+ return luxon.Duration.fromObject({ [u]: n }).as("milliseconds");
145
+ }
146
+ return 0;
147
+ }
148
+ function momentFmtToLuxon(fmt) {
149
+ return fmt.replace(/YYYY/g, "yyyy").replace(/YY/g, "yy").replace(/DD/g, "dd").replace(/A/g, "a");
150
+ }
151
+ function toDT(x) {
152
+ if (x === void 0 || x === null) return luxon.DateTime.now();
153
+ if (x instanceof MomentLike) return x.toLuxon();
154
+ if (x instanceof Date) return luxon.DateTime.fromJSDate(x);
155
+ if (typeof x === "number") return luxon.DateTime.fromMillis(x);
156
+ if (typeof x === "string") return luxon.DateTime.fromISO(x);
157
+ return luxon.DateTime.fromJSDate(new Date(x));
158
+ }
159
+ var moment = function moment2(x) {
160
+ return new MomentLike(toDT(x));
161
+ };
162
+ moment.isMoment = (x) => x instanceof MomentLike;
163
+ moment.isDuration = (x) => x instanceof DurationLike;
164
+ moment.duration = (x, unit) => {
165
+ if (typeof x === "number" && unit) {
166
+ const u = normalizeUnit(unit);
167
+ return new DurationLike(luxon.Duration.fromObject({ [u]: x }));
168
+ }
169
+ return toDurationLike(x);
170
+ };
171
+ moment.tz = (x, zone) => {
172
+ const base = toDT(x);
173
+ return new MomentLike(base.setZone(zone));
174
+ };
175
+ var moment_shim_default = moment;
176
+
177
+ // src/utils.ts
178
+ var max = (arr) => arr && arr.length ? Math.max(...arr) : void 0;
179
+ var sum = (arr) => arr ? arr.reduce((acc, v) => acc + v, 0) : 0;
180
+ var floor = (n, precision = 0) => {
181
+ const p = Math.pow(10, precision);
182
+ return Math.floor(n * p) / p;
183
+ };
184
+ var round = (n, precision = 0) => {
185
+ const p = Math.pow(10, precision);
186
+ return Math.round(n * p) / p;
187
+ };
188
+ var clamp = (n, lower, upper) => Math.max(lower, Math.min(upper, n));
189
+ var isFunction = (v) => typeof v === "function";
190
+ function isEqual(a, b) {
191
+ if (a === b) return true;
192
+ if (a == null || b == null) return false;
193
+ if (typeof a !== "object" || typeof b !== "object") return false;
194
+ const ka = Object.keys(a);
195
+ const kb = Object.keys(b);
196
+ if (ka.length !== kb.length) return false;
197
+ for (const k of ka) {
198
+ if (!isEqual(a[k], b[k])) return false;
199
+ }
200
+ return true;
201
+ }
202
+ function merge(target, ...sources) {
203
+ for (const src of sources) {
204
+ if (!src || typeof src !== "object") continue;
205
+ for (const k of Object.keys(src)) {
206
+ const v = src[k];
207
+ if (v && typeof v === "object" && !Array.isArray(v) && target[k] && typeof target[k] === "object" && !Array.isArray(target[k])) {
208
+ target[k] = merge({ ...target[k] }, v);
209
+ } else {
210
+ target[k] = v;
211
+ }
212
+ }
213
+ }
214
+ return target;
215
+ }
216
+
217
+ // src/cursorElements/utils.js
218
+ function hide(element) {
219
+ element.style.opacity = 0;
220
+ element.style.visibility = "hidden";
221
+ }
222
+ function show(element) {
223
+ element.style.opacity = 1;
224
+ element.style.visibility = "visible";
225
+ }
226
+ var resizeToolTip = (height) => clamp(2 * height / 30, 1.9, 4);
227
+ var resizeToolTipText = (height) => clamp(7 * height / 29, 7, 14);
228
+ var resizeToolTipRightDelta = (height) => clamp(4 * height / 30, 4, 9);
229
+ function handleHistoOver({
230
+ showHistoToolTip,
231
+ dragging,
232
+ event,
233
+ dragOverlay,
234
+ marginBottom,
235
+ items,
236
+ height,
237
+ tooltipVisible,
238
+ timer,
239
+ barHovered,
240
+ setTimer,
241
+ setToolTipVisible,
242
+ setBarHovered
243
+ }) {
244
+ if (showHistoToolTip && !dragging && dragOverlay) {
245
+ const [x, y] = d3Selection.pointer(event, dragOverlay.current);
246
+ const margin = marginBottom || 0;
247
+ const index = items.findIndex(
248
+ (element) => element.x1 <= x && element.x2 > x && y >= height - element.height - margin && y < height - margin
249
+ );
250
+ if (!tooltipVisible && !timer) {
251
+ setTimer(setTimeout(() => {
252
+ setToolTipVisible(true);
253
+ setTimer(null);
254
+ }, 1e3));
255
+ } else if (timer && barHovered !== index) {
256
+ clearTimeout(timer);
257
+ setTimer(setTimeout(() => {
258
+ setToolTipVisible(true);
259
+ setTimer(null);
260
+ }, 1e3));
261
+ } else if (index < 0 && tooltipVisible) {
262
+ setToolTipVisible(false);
263
+ }
264
+ if (barHovered !== index) {
265
+ setBarHovered(index);
266
+ }
267
+ }
268
+ }
269
+ function handleHistoOut({ setToolTipVisible, setBarHovered, timer, friendTarget }) {
270
+ return (event) => {
271
+ if (event.relatedTarget !== (friendTarget && friendTarget.current)) {
272
+ setToolTipVisible(false);
273
+ setBarHovered(-1);
274
+ }
275
+ if (timer) {
276
+ clearTimeout(timer);
277
+ }
278
+ };
279
+ }
280
+ function DragOverlay({
281
+ width,
282
+ height,
283
+ marginBottom,
284
+ showToolTipLeft,
285
+ showToolTipRight,
286
+ onDrawCursor,
287
+ onStartDrawCursor,
288
+ onMovedDomain,
289
+ onMoveDomain,
290
+ onEndCursor,
291
+ dragOverlayRef,
292
+ tooltipVisible,
293
+ items,
294
+ showHistoToolTip,
295
+ dragging,
296
+ barHovered,
297
+ cursorSelection,
298
+ setDragging,
299
+ setToolTipVisible,
300
+ setBarHovered
301
+ }) {
302
+ const dragOverlayContainer = react.useRef();
303
+ const [timer, setTimer] = react.useState(null);
304
+ const setOverlayCursor = (event) => {
305
+ if (event.ctrlKey) {
306
+ dragOverlayRef.current.style.cursor = "move";
307
+ } else {
308
+ dragOverlayRef.current.style.cursor = "crosshair";
309
+ }
310
+ handleHistoOver({
311
+ showHistoToolTip,
312
+ dragging,
313
+ event,
314
+ dragOverlay: dragOverlayRef,
315
+ marginBottom,
316
+ items,
317
+ height,
318
+ tooltipVisible,
319
+ timer,
320
+ setTimer,
321
+ setToolTipVisible,
322
+ barHovered,
323
+ setBarHovered
324
+ });
325
+ };
326
+ react.useEffect(() => {
327
+ let mode = null;
328
+ d3Selection.select(dragOverlayRef.current).call(
329
+ d3Drag.drag().filter((event) => !event.button).container(dragOverlayContainer.current).on("start", (event) => {
330
+ if (event.sourceEvent.ctrlKey) {
331
+ mode = "DOMAIN";
332
+ } else {
333
+ mode = "CURSOR";
334
+ showToolTipLeft(true);
335
+ onStartDrawCursor(event.x);
336
+ }
337
+ }).on("drag", (event) => {
338
+ if (mode === "DOMAIN") {
339
+ onMoveDomain(event.dx);
340
+ } else if (mode === "CURSOR") {
341
+ showToolTipRight(true);
342
+ onDrawCursor(event.dx, d3Selection.pointer(event, dragOverlayRef.current));
343
+ }
344
+ setDragging(true);
345
+ }).on("end", () => {
346
+ if (mode === "DOMAIN") {
347
+ onMovedDomain();
348
+ } else if (mode === "CURSOR") {
349
+ showToolTipLeft(false);
350
+ showToolTipRight(false);
351
+ onEndCursor();
352
+ }
353
+ mode = null;
354
+ setDragging(false);
355
+ })
356
+ );
357
+ }, []);
358
+ return /* @__PURE__ */ jsxRuntime.jsx("g", { ref: dragOverlayContainer, children: /* @__PURE__ */ jsxRuntime.jsx(
359
+ "rect",
360
+ {
361
+ ref: dragOverlayRef,
362
+ className: "tl-dragOverlay",
363
+ x: 0,
364
+ y: 0,
365
+ width,
366
+ height,
367
+ onMouseMove: setOverlayCursor,
368
+ onMouseOver: setOverlayCursor,
369
+ onMouseOut: handleHistoOut({ setToolTipVisible, setBarHovered, timer, friendTarget: cursorSelection })
370
+ }
371
+ ) });
372
+ }
373
+ DragOverlay.propTypes = {
374
+ height: PropTypes11__default.default.number.isRequired,
375
+ width: PropTypes11__default.default.number.isRequired,
376
+ marginBottom: PropTypes11__default.default.number,
377
+ items: PropTypes11__default.default.arrayOf(PropTypes11__default.default.shape({
378
+ start: PropTypes11__default.default.instanceOf(moment_shim_default).isRequired,
379
+ end: PropTypes11__default.default.instanceOf(moment_shim_default).isRequired,
380
+ x1: PropTypes11__default.default.number,
381
+ x2: PropTypes11__default.default.number,
382
+ metrics: PropTypes11__default.default.arrayOf(PropTypes11__default.default.number).isRequired,
383
+ total: PropTypes11__default.default.number.isRequired
384
+ })),
385
+ tooltipVisible: PropTypes11__default.default.bool,
386
+ barHovered: PropTypes11__default.default.number,
387
+ setBarHovered: PropTypes11__default.default.func,
388
+ setTooltipVisible: PropTypes11__default.default.func,
389
+ showToolTipLeft: PropTypes11__default.default.func.isRequired,
390
+ showToolTipRight: PropTypes11__default.default.func.isRequired,
391
+ showHistoToolTip: PropTypes11__default.default.bool,
392
+ onStartDrawCursor: PropTypes11__default.default.func.isRequired,
393
+ onDrawCursor: PropTypes11__default.default.func.isRequired,
394
+ onEndCursor: PropTypes11__default.default.func.isRequired,
395
+ onMoveDomain: PropTypes11__default.default.func,
396
+ onMovedDomain: PropTypes11__default.default.func
397
+ };
398
+ function dragOverlayFwd(props, ref) {
399
+ return /* @__PURE__ */ jsxRuntime.jsx(DragOverlay, { ...props, dragOverlayRef: ref });
400
+ }
401
+ var DragOverlay_default = react.forwardRef(dragOverlayFwd);
402
+ function cn(name, classes) {
403
+ return clsx3__default.default(`tl-${name}`, classes?.[name]);
404
+ }
405
+ var theme = {
406
+ rcToolTipPrefixCls: "rc-tooltip-dark"
407
+ };
408
+ var theme_default = theme;
409
+ var defaultLabels = {
410
+ forwardButtonTip: "Slide forward",
411
+ backwardButtonTip: "Slide backward",
412
+ resetButtonTip: "Reset time span",
413
+ gotoNowButtonTip: "Goto Now",
414
+ doubleClickMaxZoomMsg: "Cannot zoom anymore!",
415
+ scrollMaxZoomMsg: "Cannot zoom anymore!",
416
+ zoomInWithoutChangingSelectionMsg: "Please change time selection before clicking on zoom ;)",
417
+ zoomSelectionResolutionExtended: "You reached maximum zoom level",
418
+ minZoomMsg: "You reached minimum zoom level",
419
+ maxSelectionMsg: "You reached maximum selection",
420
+ maxDomainMsg: "You reached maximum visible time",
421
+ minDomainMsg: "You reached minimum visible time",
422
+ gotoCursor: "Goto Cursor",
423
+ zoomInLabel: "Zoom in",
424
+ zoomOutLabel: "Zoom out"
425
+ };
426
+ var defaultQualityScale = d3Scale.scaleLinear().domain([0, 0.9, 1]).range(["#ff3724", "rgba(255,0,0,0.09)", "rgba(155,249,135,0.94)"]).clamp(true);
427
+ function ToolTip({ overlay, placement = "top", mouseEnterDelay = 0.5, prefixCls, align, visible, hidden, children }) {
428
+ const extraProps = {};
429
+ if (visible) extraProps.open = true;
430
+ if (hidden) extraProps.open = false;
431
+ return /* @__PURE__ */ jsxRuntime.jsx(
432
+ ToolTipBase__default.default,
433
+ {
434
+ placement,
435
+ prefixCls: prefixCls || theme_default.rcToolTipPrefixCls,
436
+ overlay,
437
+ mouseEnterDelay,
438
+ destroyTooltipOnHide: true,
439
+ align,
440
+ ...extraProps,
441
+ children
442
+ }
443
+ );
444
+ }
445
+ ToolTip.propTypes = {
446
+ overlay: PropTypes11__default.default.any.isRequired,
447
+ placement: PropTypes11__default.default.string,
448
+ mouseEnterDelay: PropTypes11__default.default.number
449
+ };
450
+ var zoomOutIcon = "M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14zM7 9h5v1H7z";
451
+ function ZoomOut({ classes, origin, zoomOutLabel, onZoomOut, rcToolTipPrefixCls }) {
452
+ const className = (n) => cn(n, classes);
453
+ return /* @__PURE__ */ jsxRuntime.jsx(
454
+ ToolTip,
455
+ {
456
+ placement: "left",
457
+ overlay: zoomOutLabel,
458
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
459
+ "g",
460
+ {
461
+ className: "tl-zoomOutContainer",
462
+ transform: `translate(${origin.x}, ${origin.y})`,
463
+ onClick: onZoomOut,
464
+ children: [
465
+ /* @__PURE__ */ jsxRuntime.jsx(
466
+ "rect",
467
+ {
468
+ className: "tl-zoomArea",
469
+ x: 0,
470
+ y: 0,
471
+ width: 23,
472
+ height: 23
473
+ }
474
+ ),
475
+ /* @__PURE__ */ jsxRuntime.jsx(
476
+ "path",
477
+ {
478
+ className: className("zoomOut"),
479
+ d: zoomOutIcon
480
+ }
481
+ )
482
+ ]
483
+ }
484
+ )
485
+ }
486
+ );
487
+ }
488
+ ZoomOut.propTypes = {
489
+ classes: PropTypes11__default.default.object.isRequired,
490
+ rcToolTipPrefixCls: PropTypes11__default.default.string.isRequired,
491
+ origin: PropTypes11__default.default.shape({
492
+ x: PropTypes11__default.default.number.isRequired,
493
+ y: PropTypes11__default.default.number.isRequired
494
+ }).isRequired,
495
+ zoomOutLabel: PropTypes11__default.default.string,
496
+ onZoomOut: PropTypes11__default.default.func
497
+ };
498
+ function CursorIcon({
499
+ classes,
500
+ rcToolTipPrefixCls,
501
+ origin,
502
+ position,
503
+ gotoCursorLabel,
504
+ onGotoCursor
505
+ }) {
506
+ const [isOver, setIsOver] = react.useState(false);
507
+ return /* @__PURE__ */ jsxRuntime.jsx(
508
+ ToolTip,
509
+ {
510
+ placement: position === "right" ? "left" : "right",
511
+ overlay: gotoCursorLabel,
512
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
513
+ "g",
514
+ {
515
+ transform: `translate(${origin.x},${origin.y}) scale(2)`,
516
+ style: { cursor: "pointer" },
517
+ onClick: onGotoCursor,
518
+ onMouseOver: () => setIsOver(true),
519
+ onMouseOut: () => setIsOver(false),
520
+ children: [
521
+ /* @__PURE__ */ jsxRuntime.jsx(
522
+ "rect",
523
+ {
524
+ className: clsx3__default.default(
525
+ "tl-cursorIconRect",
526
+ classes.cursorIconRect,
527
+ isOver && "tl-cursorIconRectOver",
528
+ isOver && classes.cursorIconRectOver
529
+ ),
530
+ width: "5.5",
531
+ height: "13.72",
532
+ x: "9.56",
533
+ y: "4.76"
534
+ }
535
+ ),
536
+ /* @__PURE__ */ jsxRuntime.jsx(
537
+ "circle",
538
+ {
539
+ className: clsx3__default.default(
540
+ "tl-cursorIconCircle",
541
+ classes.cursorIconCircle,
542
+ isOver && "tl-cursorIconCircleOver",
543
+ isOver && classes.cursorIconCircleOver
544
+ ),
545
+ cx: "9.63",
546
+ cy: "11.62",
547
+ r: "1.4"
548
+ }
549
+ ),
550
+ /* @__PURE__ */ jsxRuntime.jsx(
551
+ "circle",
552
+ {
553
+ className: clsx3__default.default(
554
+ "tl-cursorIconCircle",
555
+ classes.cursorIconCircle,
556
+ isOver && "tl-cursorIconCircleOver",
557
+ isOver && classes.cursorIconCircleOver
558
+ ),
559
+ cx: "15",
560
+ cy: "11.70",
561
+ r: "1.4"
562
+ }
563
+ )
564
+ ]
565
+ }
566
+ )
567
+ }
568
+ );
569
+ }
570
+ CursorIcon.propTypes = {
571
+ classes: PropTypes11__default.default.object.isRequired,
572
+ rcToolTipPrefixCls: PropTypes11__default.default.string.isRequired,
573
+ origin: PropTypes11__default.default.shape({
574
+ x: PropTypes11__default.default.number.isRequired,
575
+ y: PropTypes11__default.default.number.isRequired
576
+ }).isRequired,
577
+ onGotoCursor: PropTypes11__default.default.func,
578
+ gotoCursorLabel: PropTypes11__default.default.string.isRequired,
579
+ position: PropTypes11__default.default.string.isRequired
580
+ };
581
+ function CursorSelection({
582
+ classes,
583
+ cursor,
584
+ height,
585
+ maxSize,
586
+ zoomIn,
587
+ canZoom,
588
+ dragOverlay,
589
+ onMoveDomain,
590
+ onDragCursor,
591
+ onMovedDomain,
592
+ onEndDragCursor,
593
+ showToolTipLeft,
594
+ showToolTipRight,
595
+ width,
596
+ tooltipVisible,
597
+ items,
598
+ showHistoToolTip,
599
+ dragging,
600
+ barHovered,
601
+ marginBottom,
602
+ setDragging,
603
+ setBarHovered,
604
+ setToolTipVisible
605
+ }) {
606
+ const className = (n) => cn(n, classes);
607
+ const [timer, setTimer] = react.useState(null);
608
+ const setOverlayCursor = (event) => handleHistoOver({
609
+ showHistoToolTip,
610
+ dragging,
611
+ event,
612
+ dragOverlay,
613
+ marginBottom,
614
+ items,
615
+ height,
616
+ tooltipVisible,
617
+ timer,
618
+ setTimer,
619
+ setToolTipVisible,
620
+ barHovered,
621
+ setBarHovered
622
+ });
623
+ react.useEffect(
624
+ () => {
625
+ let mode = null;
626
+ d3Selection.select(cursor.current).call(
627
+ d3Drag.drag().filter((event) => !event.button).container(dragOverlay.current).on("start", (event) => {
628
+ if (event.sourceEvent.ctrlKey) {
629
+ mode = "DOMAIN";
630
+ } else {
631
+ mode = "CURSOR";
632
+ showToolTipRight(true);
633
+ showToolTipLeft(true);
634
+ }
635
+ }).on("drag", (event) => {
636
+ if (mode === "DOMAIN" && event.sourceEvent.ctrlKey) {
637
+ onMoveDomain(event.dx);
638
+ } else if (mode === "CURSOR") {
639
+ onDragCursor(event.dx, d3Selection.pointer(event, dragOverlay.current));
640
+ }
641
+ setDragging(true);
642
+ }).on("end", () => {
643
+ if (mode === "DOMAIN") {
644
+ onMovedDomain();
645
+ } else if (mode === "CURSOR") {
646
+ showToolTipRight(false);
647
+ showToolTipLeft(false);
648
+ onEndDragCursor();
649
+ }
650
+ mode = null;
651
+ mode = null;
652
+ setDragging(false);
653
+ })
654
+ );
655
+ },
656
+ [cursor.current]
657
+ );
658
+ return /* @__PURE__ */ jsxRuntime.jsx(
659
+ "rect",
660
+ {
661
+ ref: cursor,
662
+ className: clsx3__default.default(className("cursorArea"), maxSize && "tl--maxSize"),
663
+ x: 0,
664
+ y: -3,
665
+ width,
666
+ height: height + 10,
667
+ onDoubleClick: canZoom ? zoomIn : void 0,
668
+ onMouseMove: setOverlayCursor,
669
+ onMouseOver: setOverlayCursor,
670
+ onMouseOut: handleHistoOut({ setToolTipVisible, setBarHovered, timer, friendTarget: dragOverlay })
671
+ }
672
+ );
673
+ }
674
+ CursorSelection.propTypes = {
675
+ classes: PropTypes11__default.default.object.isRequired,
676
+ width: PropTypes11__default.default.number.isRequired,
677
+ height: PropTypes11__default.default.number.isRequired,
678
+ maxSize: PropTypes11__default.default.bool.isRequired,
679
+ zoomIn: PropTypes11__default.default.func.isRequired,
680
+ canZoom: PropTypes11__default.default.bool.isRequired,
681
+ dragOverlay: PropTypes11__default.default.object.isRequired,
682
+ onMoveDomain: PropTypes11__default.default.func.isRequired,
683
+ onMovedDomain: PropTypes11__default.default.func.isRequired,
684
+ onDragCursor: PropTypes11__default.default.func.isRequired,
685
+ onEndDragCursor: PropTypes11__default.default.func.isRequired,
686
+ showToolTipLeft: PropTypes11__default.default.func.isRequired,
687
+ showToolTipRight: PropTypes11__default.default.func.isRequired,
688
+ items: PropTypes11__default.default.arrayOf(PropTypes11__default.default.shape({
689
+ start: PropTypes11__default.default.instanceOf(moment_shim_default).isRequired,
690
+ end: PropTypes11__default.default.instanceOf(moment_shim_default).isRequired,
691
+ x1: PropTypes11__default.default.number,
692
+ x2: PropTypes11__default.default.number,
693
+ metrics: PropTypes11__default.default.arrayOf(PropTypes11__default.default.number).isRequired,
694
+ total: PropTypes11__default.default.number.isRequired
695
+ })),
696
+ tooltipVisible: PropTypes11__default.default.bool,
697
+ barHovered: PropTypes11__default.default.number,
698
+ setBarHovered: PropTypes11__default.default.func,
699
+ setTooltipVisible: PropTypes11__default.default.func
700
+ };
701
+ function CursorSelectionFwd(props, ref) {
702
+ return /* @__PURE__ */ jsxRuntime.jsx(CursorSelection, { ...props, cursor: ref });
703
+ }
704
+ var CursorSelection_default = react.forwardRef(CursorSelectionFwd);
705
+ function LeftHandle({
706
+ classes,
707
+ maxSize,
708
+ onResizeLeftCursor,
709
+ onEndResizeCursor,
710
+ dragOverlay,
711
+ showToolTipLeft,
712
+ origin,
713
+ startIsOutOfView,
714
+ setDragging
715
+ }) {
716
+ const className = (n) => cn(n, classes);
717
+ const cursorLeftHandle = react.useRef();
718
+ react.useEffect(() => {
719
+ cursorLeftHandle.current && d3Selection.select(cursorLeftHandle.current).call(
720
+ d3Drag.drag().filter((event) => !event.button).container(dragOverlay.current).on("start", () => {
721
+ setDragging(true);
722
+ showToolTipLeft(true);
723
+ }).on("drag", (event) => onResizeLeftCursor(event.dx, d3Selection.pointer(event, dragOverlay.current))).on("end", () => {
724
+ setDragging(false);
725
+ showToolTipLeft(false);
726
+ onEndResizeCursor();
727
+ })
728
+ );
729
+ }, [cursorLeftHandle.current]);
730
+ return /* @__PURE__ */ jsxRuntime.jsx(
731
+ "circle",
732
+ {
733
+ ref: cursorLeftHandle,
734
+ className: clsx3__default.default(className("cursorLeftHandle"), maxSize && "tl--maxSize", startIsOutOfView && "tl--outOfView"),
735
+ r: "4",
736
+ cx: origin.x,
737
+ cy: origin.y
738
+ }
739
+ );
740
+ }
741
+ LeftHandle.propTypes = {
742
+ classes: PropTypes11__default.default.object.isRequired,
743
+ origin: PropTypes11__default.default.shape({
744
+ x: PropTypes11__default.default.number.isRequired,
745
+ y: PropTypes11__default.default.number.isRequired
746
+ }).isRequired,
747
+ maxSize: PropTypes11__default.default.bool.isRequired,
748
+ dragOverlay: PropTypes11__default.default.object.isRequired,
749
+ startIsOutOfView: PropTypes11__default.default.bool.isRequired,
750
+ showToolTipLeft: PropTypes11__default.default.func.isRequired,
751
+ onResizeLeftCursor: PropTypes11__default.default.func.isRequired,
752
+ onEndResizeCursor: PropTypes11__default.default.func.isRequired,
753
+ setDragging: PropTypes11__default.default.func.isRequired
754
+ };
755
+ function RightHandle({
756
+ classes,
757
+ maxSize,
758
+ origin,
759
+ onResizeRightCursor,
760
+ onEndResizeCursor,
761
+ dragOverlay,
762
+ showToolTipRight,
763
+ endIsOutOfView,
764
+ setDragging
765
+ }) {
766
+ const className = (n) => cn(n, classes);
767
+ const cursorRightHandle = react.useRef();
768
+ react.useEffect(() => {
769
+ cursorRightHandle.current && d3Selection.select(cursorRightHandle.current).call(
770
+ d3Drag.drag().filter((event) => !event.button).container(dragOverlay.current).on("start", () => {
771
+ setDragging(true);
772
+ showToolTipRight(true);
773
+ }).on("drag", (event) => onResizeRightCursor(event.dx, d3Selection.pointer(event, dragOverlay.current))).on("end", () => {
774
+ setDragging(false);
775
+ showToolTipRight(false);
776
+ onEndResizeCursor();
777
+ })
778
+ );
779
+ }, [cursorRightHandle.current]);
780
+ return /* @__PURE__ */ jsxRuntime.jsx(
781
+ "circle",
782
+ {
783
+ ref: cursorRightHandle,
784
+ className: clsx3__default.default(className("cursorRightHandle"), maxSize && "tl--maxSize", endIsOutOfView && "tl--outOfView"),
785
+ r: "4",
786
+ cx: origin.x,
787
+ cy: origin.y
788
+ }
789
+ );
790
+ }
791
+ RightHandle.propTypes = {
792
+ classes: PropTypes11__default.default.object.isRequired,
793
+ origin: PropTypes11__default.default.shape({
794
+ x: PropTypes11__default.default.number.isRequired,
795
+ y: PropTypes11__default.default.number.isRequired
796
+ }).isRequired,
797
+ maxSize: PropTypes11__default.default.bool.isRequired,
798
+ dragOverlay: PropTypes11__default.default.object.isRequired,
799
+ endIsOutOfView: PropTypes11__default.default.bool.isRequired,
800
+ showToolTipRight: PropTypes11__default.default.func.isRequired,
801
+ onResizeRightCursor: PropTypes11__default.default.func.isRequired,
802
+ onEndResizeCursor: PropTypes11__default.default.func.isRequired,
803
+ setDragging: PropTypes11__default.default.func.isRequired
804
+ };
805
+ var zoomIcon = "M 15.5 14 h -0.79 l -0.28 -0.27 C 15.41 12.59 16 11.11 16 9.5 C 16 5.91 13.09 3 9.5 3 S 3 5.91 3 9.5 S 5.91 16 9.5 16 c 1.61 0 3.09 -0.59 4.23 -1.57 l 0.27 0.28 v 0.79 l 5 4.99 L 20.49 19 l -4.99 -5 Z m -6 0 C 7.01 14 5 11.99 5 9.5 S 7.01 5 9.5 5 S 14 7.01 14 9.5 S 11.99 14 9.5 14 Z";
806
+ var plusSign = "M12 10h-2v2H9v-2H7V9h2V7h1v2h2v1z";
807
+ function ZoomIn({
808
+ classes,
809
+ origin,
810
+ zoomInLabel,
811
+ onZoomIn,
812
+ rcToolTipPrefixCls,
813
+ forwardedRef
814
+ }) {
815
+ const className = (n) => cn(n, classes);
816
+ return /* @__PURE__ */ jsxRuntime.jsx(
817
+ ToolTip,
818
+ {
819
+ placement: "left",
820
+ overlay: zoomInLabel,
821
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
822
+ "g",
823
+ {
824
+ className: "tl-zoomInContainer",
825
+ ref: forwardedRef,
826
+ transform: `translate(${origin.x}, ${origin.y})`,
827
+ onClick: onZoomIn,
828
+ children: [
829
+ /* @__PURE__ */ jsxRuntime.jsx(
830
+ "rect",
831
+ {
832
+ className: "tl-zoomArea",
833
+ x: 0,
834
+ y: 0,
835
+ width: 23,
836
+ height: 23
837
+ }
838
+ ),
839
+ /* @__PURE__ */ jsxRuntime.jsx(
840
+ "path",
841
+ {
842
+ className: className("zoomIn"),
843
+ d: zoomIcon
844
+ }
845
+ ),
846
+ /* @__PURE__ */ jsxRuntime.jsx(
847
+ "path",
848
+ {
849
+ className: className("zoomIn"),
850
+ d: plusSign
851
+ }
852
+ ),
853
+ /* @__PURE__ */ jsxRuntime.jsx(
854
+ "rect",
855
+ {
856
+ className: "tl-zoomArea",
857
+ x: 0,
858
+ y: 0,
859
+ width: 23,
860
+ height: 23
861
+ }
862
+ )
863
+ ]
864
+ }
865
+ )
866
+ }
867
+ );
868
+ }
869
+ ZoomIn.propTypes = {
870
+ classes: PropTypes11__default.default.object.isRequired,
871
+ rcToolTipPrefixCls: PropTypes11__default.default.string.isRequired,
872
+ origin: PropTypes11__default.default.shape({
873
+ x: PropTypes11__default.default.number.isRequired,
874
+ y: PropTypes11__default.default.number.isRequired
875
+ }).isRequired,
876
+ zoomInLabel: PropTypes11__default.default.string,
877
+ onZoomIn: PropTypes11__default.default.func
878
+ };
879
+ function zoomInFwd(props, ref) {
880
+ return /* @__PURE__ */ jsxRuntime.jsx(ZoomIn, { ...props, forwardedRef: ref });
881
+ }
882
+ var ZoomIn_default = react.forwardRef(zoomInFwd);
883
+ function LeftToolTip({
884
+ classes,
885
+ height,
886
+ origin,
887
+ isVisibleTooltipLeft,
888
+ startText
889
+ }) {
890
+ const className = (n) => cn(n, classes);
891
+ const toolTipLeft = react.useRef();
892
+ react.useEffect(() => {
893
+ if (isVisibleTooltipLeft)
894
+ show(toolTipLeft.current);
895
+ else hide(toolTipLeft.current);
896
+ }, [isVisibleTooltipLeft]);
897
+ return /* @__PURE__ */ jsxRuntime.jsxs(
898
+ "g",
899
+ {
900
+ transform: `translate(${origin.x}, ${origin.y})`,
901
+ className: className("toolTipArea"),
902
+ ref: toolTipLeft,
903
+ children: [
904
+ /* @__PURE__ */ jsxRuntime.jsxs(
905
+ "g",
906
+ {
907
+ transform: `scale(${resizeToolTip(height)})`,
908
+ children: [
909
+ /* @__PURE__ */ jsxRuntime.jsx(
910
+ "rect",
911
+ {
912
+ className: className("toolTip"),
913
+ x: -2.5,
914
+ y: -8,
915
+ width: startText.length * 2,
916
+ height: 6.5,
917
+ rx: 1
918
+ }
919
+ ),
920
+ /* @__PURE__ */ jsxRuntime.jsx(
921
+ "path",
922
+ {
923
+ className: className("toolTip"),
924
+ d: "M -1,-1.7 0,-0.5 1,-1.7"
925
+ }
926
+ )
927
+ ]
928
+ }
929
+ ),
930
+ /* @__PURE__ */ jsxRuntime.jsx(
931
+ "text",
932
+ {
933
+ className: className("toolTipText"),
934
+ style: {
935
+ fontSize: resizeToolTipText(height) + "px"
936
+ },
937
+ x: "-2",
938
+ y: -resizeToolTipText(height),
939
+ children: startText
940
+ }
941
+ )
942
+ ]
943
+ }
944
+ );
945
+ }
946
+ LeftToolTip.propTypes = {
947
+ classes: PropTypes11__default.default.object.isRequired,
948
+ origin: PropTypes11__default.default.shape({
949
+ x: PropTypes11__default.default.number.isRequired,
950
+ y: PropTypes11__default.default.number.isRequired
951
+ }).isRequired,
952
+ height: PropTypes11__default.default.number.isRequired,
953
+ isVisibleTooltipLeft: PropTypes11__default.default.bool.isRequired,
954
+ startText: PropTypes11__default.default.string.isRequired
955
+ };
956
+ function RightToolTip({
957
+ classes,
958
+ origin,
959
+ isVisibleTooltipRight,
960
+ stopText,
961
+ height
962
+ }) {
963
+ const className = (n) => cn(n, classes);
964
+ const toolTipRight = react.useRef();
965
+ react.useEffect(() => {
966
+ if (isVisibleTooltipRight)
967
+ show(toolTipRight.current);
968
+ else hide(toolTipRight.current);
969
+ }, [isVisibleTooltipRight]);
970
+ return /* @__PURE__ */ jsxRuntime.jsxs(
971
+ "g",
972
+ {
973
+ transform: `translate(${origin.x}, ${origin.y})`,
974
+ className: className("toolTipArea"),
975
+ ref: toolTipRight,
976
+ children: [
977
+ /* @__PURE__ */ jsxRuntime.jsxs(
978
+ "g",
979
+ {
980
+ transform: `scale(-${resizeToolTip(height)},-${resizeToolTip(height)})`,
981
+ children: [
982
+ /* @__PURE__ */ jsxRuntime.jsx(
983
+ "rect",
984
+ {
985
+ className: className("toolTip"),
986
+ x: -2.5,
987
+ y: -8,
988
+ width: stopText.length * 2,
989
+ height: 6.5,
990
+ rx: 1
991
+ }
992
+ ),
993
+ /* @__PURE__ */ jsxRuntime.jsx(
994
+ "path",
995
+ {
996
+ className: className("toolTip"),
997
+ d: "M -1,-1.7 0,-0.5 1,-1.7"
998
+ }
999
+ )
1000
+ ]
1001
+ }
1002
+ ),
1003
+ /* @__PURE__ */ jsxRuntime.jsx(
1004
+ "text",
1005
+ {
1006
+ className: clsx3__default.default(
1007
+ "tl-toolTipText",
1008
+ classes.toolTipText,
1009
+ "tl-toolTipTextRight",
1010
+ classes.toolTipTextRight
1011
+ ),
1012
+ style: {
1013
+ fontSize: resizeToolTipText(height) + "px"
1014
+ },
1015
+ x: "2",
1016
+ y: resizeToolTipText(height) + resizeToolTipRightDelta(height),
1017
+ children: stopText
1018
+ }
1019
+ )
1020
+ ]
1021
+ }
1022
+ );
1023
+ }
1024
+ RightToolTip.propTypes = {
1025
+ classes: PropTypes11__default.default.object.isRequired,
1026
+ origin: PropTypes11__default.default.shape({
1027
+ x: PropTypes11__default.default.number.isRequired,
1028
+ y: PropTypes11__default.default.number.isRequired
1029
+ }).isRequired,
1030
+ height: PropTypes11__default.default.number.isRequired,
1031
+ isVisibleTooltipRight: PropTypes11__default.default.bool.isRequired,
1032
+ stopText: PropTypes11__default.default.string.isRequired
1033
+ };
1034
+ function Cursor({
1035
+ overlayWidth,
1036
+ overlayHeight,
1037
+ items,
1038
+ setBarHovered = identity,
1039
+ setToolTipVisible = identity,
1040
+ showHistoToolTip,
1041
+ tooltipVisible,
1042
+ barHovered,
1043
+ dragging,
1044
+ setDragging = identity,
1045
+ origin,
1046
+ height,
1047
+ startPos,
1048
+ endPos,
1049
+ canZoom,
1050
+ minZoom,
1051
+ maxZoom,
1052
+ maxSize,
1053
+ zoomOutLabel,
1054
+ zoomOut,
1055
+ cursorIsAfterView,
1056
+ cursorIsBeforeView,
1057
+ gotoCursorLabel,
1058
+ onGotoCursor,
1059
+ rcToolTipPrefixCls,
1060
+ classes = {},
1061
+ onStartDrawCursor,
1062
+ onDrawCursor,
1063
+ onEndCursor,
1064
+ onMoveDomain = identity,
1065
+ onMovedDomain = identity,
1066
+ onDragCursor,
1067
+ onEndDragCursor,
1068
+ startText,
1069
+ stopText,
1070
+ zoomInLabel,
1071
+ zoomIn,
1072
+ startIsOutOfView,
1073
+ endIsOutOfView,
1074
+ tools,
1075
+ onResizeLeftCursor,
1076
+ onResizeRightCursor,
1077
+ onEndResizeCursor
1078
+ }) {
1079
+ const dragOverlay = react.useRef();
1080
+ const zoomInButton = react.useRef();
1081
+ const cursorSelection = react.useRef();
1082
+ const renderIcon = cursorIsAfterView || cursorIsBeforeView;
1083
+ const cursorWidth = endPos - startPos < 1 ? 1 : endPos - startPos;
1084
+ const [isVisibleTTR, setVisibleTTR] = react.useState(false);
1085
+ const [isVisibleTTL, setVisibleTTL] = react.useState(false);
1086
+ const originSelection = {
1087
+ x: startPos,
1088
+ y: 0
1089
+ };
1090
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { transform: `translate(${origin.x},${origin.y})`, children: [
1091
+ /* @__PURE__ */ jsxRuntime.jsx(
1092
+ DragOverlay_default,
1093
+ {
1094
+ ref: dragOverlay,
1095
+ width: overlayWidth,
1096
+ height: overlayHeight,
1097
+ showToolTipLeft: setVisibleTTL,
1098
+ showToolTipRight: setVisibleTTR,
1099
+ onDrawCursor,
1100
+ onEndCursor,
1101
+ onMovedDomain,
1102
+ onMoveDomain,
1103
+ onStartDrawCursor,
1104
+ setToolTipVisible,
1105
+ setBarHovered,
1106
+ items,
1107
+ tooltipVisible,
1108
+ barHovered,
1109
+ showHistoToolTip,
1110
+ marginBottom: overlayHeight - height - 4,
1111
+ dragging,
1112
+ setDragging,
1113
+ cursorSelection
1114
+ }
1115
+ ),
1116
+ renderIcon && /* @__PURE__ */ jsxRuntime.jsx(
1117
+ CursorIcon,
1118
+ {
1119
+ classes,
1120
+ rcToolTipPrefixCls,
1121
+ origin: {
1122
+ x: cursorIsAfterView ? startPos - 17 : startPos - 23,
1123
+ y: height / 2 - 24
1124
+ },
1125
+ position: startPos === 1 ? "left" : "right",
1126
+ gotoCursorLabel,
1127
+ onGotoCursor
1128
+ }
1129
+ ),
1130
+ /* @__PURE__ */ jsxRuntime.jsxs(
1131
+ "g",
1132
+ {
1133
+ style: { display: renderIcon ? "none" : void 0 },
1134
+ transform: `translate(${originSelection.x},${originSelection.y})`,
1135
+ onMouseOver: () => {
1136
+ canZoom && tools.zoomIn !== false && !maxZoom && show(zoomInButton.current);
1137
+ },
1138
+ onMouseOut: () => {
1139
+ canZoom && tools.zoomIn !== false && hide(zoomInButton.current);
1140
+ },
1141
+ children: [
1142
+ /* @__PURE__ */ jsxRuntime.jsx(
1143
+ CursorSelection_default,
1144
+ {
1145
+ ref: cursorSelection,
1146
+ classes,
1147
+ dragOverlay,
1148
+ maxSize,
1149
+ canZoom,
1150
+ startPos,
1151
+ endPos,
1152
+ height,
1153
+ showToolTipLeft: setVisibleTTL,
1154
+ showToolTipRight: setVisibleTTR,
1155
+ onDragCursor,
1156
+ onEndDragCursor,
1157
+ onMovedDomain,
1158
+ onMoveDomain,
1159
+ zoomIn,
1160
+ width: cursorWidth,
1161
+ setToolTipVisible,
1162
+ setBarHovered,
1163
+ items,
1164
+ tooltipVisible,
1165
+ barHovered,
1166
+ showHistoToolTip,
1167
+ dragging,
1168
+ setDragging
1169
+ }
1170
+ ),
1171
+ /* @__PURE__ */ jsxRuntime.jsx(
1172
+ LeftHandle,
1173
+ {
1174
+ classes,
1175
+ origin: {
1176
+ x: 0,
1177
+ y: height / 2 + 2
1178
+ },
1179
+ maxSize,
1180
+ dragOverlay,
1181
+ startIsOutOfView,
1182
+ showToolTipLeft: setVisibleTTL,
1183
+ onResizeLeftCursor,
1184
+ onEndResizeCursor,
1185
+ setDragging
1186
+ }
1187
+ ),
1188
+ /* @__PURE__ */ jsxRuntime.jsx(
1189
+ RightHandle,
1190
+ {
1191
+ classes,
1192
+ origin: {
1193
+ x: cursorWidth,
1194
+ y: height / 2 + 2
1195
+ },
1196
+ maxSize,
1197
+ dragOverlay,
1198
+ endIsOutOfView,
1199
+ showToolTipRight: setVisibleTTR,
1200
+ onResizeRightCursor,
1201
+ onEndResizeCursor,
1202
+ setDragging
1203
+ }
1204
+ ),
1205
+ canZoom && tools.zoomIn !== false && /* @__PURE__ */ jsxRuntime.jsx(
1206
+ ZoomIn_default,
1207
+ {
1208
+ ref: zoomInButton,
1209
+ classes,
1210
+ rcToolTipPrefixCls,
1211
+ origin: {
1212
+ x: cursorWidth - 25,
1213
+ y: 0
1214
+ },
1215
+ zoomInLabel,
1216
+ onZoomIn: zoomIn
1217
+ }
1218
+ ),
1219
+ /* @__PURE__ */ jsxRuntime.jsx(
1220
+ LeftToolTip,
1221
+ {
1222
+ classes,
1223
+ origin: {
1224
+ x: 0,
1225
+ y: height / 2
1226
+ },
1227
+ height,
1228
+ startText,
1229
+ isVisibleTooltipLeft: isVisibleTTL
1230
+ }
1231
+ ),
1232
+ /* @__PURE__ */ jsxRuntime.jsx(
1233
+ RightToolTip,
1234
+ {
1235
+ classes,
1236
+ origin: {
1237
+ x: cursorWidth,
1238
+ y: height / 2 + 4
1239
+ },
1240
+ height,
1241
+ stopText,
1242
+ isVisibleTooltipRight: isVisibleTTR
1243
+ }
1244
+ )
1245
+ ]
1246
+ }
1247
+ ),
1248
+ canZoom && !minZoom && tools.zoomOut !== false && /* @__PURE__ */ jsxRuntime.jsx(
1249
+ ZoomOut,
1250
+ {
1251
+ classes,
1252
+ rcToolTipPrefixCls,
1253
+ origin: {
1254
+ x: overlayWidth - 10,
1255
+ y: height - 20
1256
+ },
1257
+ zoomOutLabel,
1258
+ onZoomOut: zoomOut
1259
+ }
1260
+ )
1261
+ ] });
1262
+ }
1263
+ Cursor.propTypes = {
1264
+ origin: PropTypes11__default.default.shape({
1265
+ x: PropTypes11__default.default.number.isRequired,
1266
+ y: PropTypes11__default.default.number.isRequired
1267
+ }).isRequired,
1268
+ startPos: PropTypes11__default.default.number.isRequired,
1269
+ startIsOutOfView: PropTypes11__default.default.bool,
1270
+ endPos: PropTypes11__default.default.number.isRequired,
1271
+ endIsOutOfView: PropTypes11__default.default.bool,
1272
+ height: PropTypes11__default.default.number.isRequired,
1273
+ overlayHeight: PropTypes11__default.default.number.isRequired,
1274
+ overlayWidth: PropTypes11__default.default.number.isRequired,
1275
+ items: PropTypes11__default.default.arrayOf(PropTypes11__default.default.shape({
1276
+ start: PropTypes11__default.default.instanceOf(moment_shim_default).isRequired,
1277
+ end: PropTypes11__default.default.instanceOf(moment_shim_default).isRequired,
1278
+ x1: PropTypes11__default.default.number,
1279
+ x2: PropTypes11__default.default.number,
1280
+ metrics: PropTypes11__default.default.arrayOf(PropTypes11__default.default.number).isRequired,
1281
+ total: PropTypes11__default.default.number.isRequired
1282
+ })),
1283
+ tooltipVisible: PropTypes11__default.default.bool,
1284
+ barHovered: PropTypes11__default.default.number,
1285
+ dragging: PropTypes11__default.default.bool,
1286
+ setBarHovered: PropTypes11__default.default.func,
1287
+ setToolTipVisible: PropTypes11__default.default.func,
1288
+ setDragging: PropTypes11__default.default.func,
1289
+ cursorIsBeforeView: PropTypes11__default.default.bool,
1290
+ cursorIsAfterView: PropTypes11__default.default.bool,
1291
+ maxSize: PropTypes11__default.default.bool,
1292
+ startText: PropTypes11__default.default.string.isRequired,
1293
+ stopText: PropTypes11__default.default.string.isRequired,
1294
+ canZoom: PropTypes11__default.default.bool.isRequired,
1295
+ maxZoom: PropTypes11__default.default.bool,
1296
+ minZoom: PropTypes11__default.default.bool,
1297
+ zoomIn: PropTypes11__default.default.func,
1298
+ zoomOut: PropTypes11__default.default.func,
1299
+ onResizeLeftCursor: PropTypes11__default.default.func.isRequired,
1300
+ onResizeRightCursor: PropTypes11__default.default.func.isRequired,
1301
+ onEndResizeCursor: PropTypes11__default.default.func.isRequired,
1302
+ onDragCursor: PropTypes11__default.default.func.isRequired,
1303
+ onEndDragCursor: PropTypes11__default.default.func.isRequired,
1304
+ onStartDrawCursor: PropTypes11__default.default.func.isRequired,
1305
+ onDrawCursor: PropTypes11__default.default.func.isRequired,
1306
+ onEndCursor: PropTypes11__default.default.func.isRequired,
1307
+ onMoveDomain: PropTypes11__default.default.func,
1308
+ onMovedDomain: PropTypes11__default.default.func,
1309
+ onGotoCursor: PropTypes11__default.default.func,
1310
+ gotoCursorLabel: PropTypes11__default.default.string,
1311
+ zoomInLabel: PropTypes11__default.default.string,
1312
+ zoomOutLabel: PropTypes11__default.default.string,
1313
+ classes: PropTypes11__default.default.object,
1314
+ rcToolTipPrefixCls: PropTypes11__default.default.string.isRequired,
1315
+ tools: PropTypes11__default.default.shape({
1316
+ zoomIn: PropTypes11__default.default.bool,
1317
+ zoomOut: PropTypes11__default.default.bool
1318
+ })
1319
+ };
1320
+ var identity = () => {
1321
+ };
1322
+ function Histogram({
1323
+ classes,
1324
+ items,
1325
+ metricsDefinition,
1326
+ origin,
1327
+ barHovered,
1328
+ tooltipVisible,
1329
+ verticalScale,
1330
+ dragging,
1331
+ HistoToolTip,
1332
+ onFormatMetricLegend,
1333
+ onFormatTimeToolTips
1334
+ }) {
1335
+ if (!items) {
1336
+ return null;
1337
+ }
1338
+ const className = (n) => cn(n, classes);
1339
+ return /* @__PURE__ */ jsxRuntime.jsx("g", { transform: `translate(${origin.x}, ${origin.y})`, children: items.map((item, i) => /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
1340
+ metricsDefinition.colors.map((color, m) => item.metrics[m] > 0 && /* @__PURE__ */ jsxRuntime.jsx(
1341
+ "rect",
1342
+ {
1343
+ className: className("histoItem"),
1344
+ style: {
1345
+ fill: color.fill,
1346
+ stroke: color.stroke
1347
+ },
1348
+ x: item.x1,
1349
+ y: -verticalScale(sum(item.metrics.slice(0, m + 1))),
1350
+ width: item.x2 - item.x1,
1351
+ height: verticalScale(item.metrics[m])
1352
+ },
1353
+ m
1354
+ )),
1355
+ barHovered === i && !dragging && /* @__PURE__ */ jsxRuntime.jsx(
1356
+ ToolTip,
1357
+ {
1358
+ overlay: /* @__PURE__ */ jsxRuntime.jsx(
1359
+ HistoToolTip,
1360
+ {
1361
+ item,
1362
+ metricsDefinition,
1363
+ onFormatTimeToolTips,
1364
+ onFormatMetricLegend,
1365
+ classes
1366
+ }
1367
+ ),
1368
+ visible: tooltipVisible,
1369
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1370
+ "rect",
1371
+ {
1372
+ className: className("histoHovered"),
1373
+ x: item.x1,
1374
+ y: -item.height,
1375
+ width: item.x2 - item.x1,
1376
+ height: item.height
1377
+ }
1378
+ )
1379
+ }
1380
+ )
1381
+ ] }, i)) });
1382
+ }
1383
+ Histogram.propTypes = {
1384
+ classes: PropTypes11__default.default.object,
1385
+ items: PropTypes11__default.default.arrayOf(PropTypes11__default.default.shape({
1386
+ start: PropTypes11__default.default.instanceOf(moment_shim_default).isRequired,
1387
+ end: PropTypes11__default.default.instanceOf(moment_shim_default).isRequired,
1388
+ x1: PropTypes11__default.default.number,
1389
+ x2: PropTypes11__default.default.number,
1390
+ metrics: PropTypes11__default.default.arrayOf(PropTypes11__default.default.number).isRequired,
1391
+ total: PropTypes11__default.default.number.isRequired
1392
+ })),
1393
+ metricsDefinition: PropTypes11__default.default.shape({
1394
+ count: PropTypes11__default.default.number.isRequired,
1395
+ legends: PropTypes11__default.default.arrayOf(PropTypes11__default.default.string).isRequired,
1396
+ colors: PropTypes11__default.default.arrayOf(PropTypes11__default.default.shape({
1397
+ fill: PropTypes11__default.default.string.isRequired,
1398
+ stroke: PropTypes11__default.default.string.isRequired,
1399
+ text: PropTypes11__default.default.string.isRequired
1400
+ })).isRequired
1401
+ }).isRequired,
1402
+ origin: PropTypes11__default.default.shape({
1403
+ x: PropTypes11__default.default.number.isRequired,
1404
+ y: PropTypes11__default.default.number.isRequired
1405
+ }).isRequired,
1406
+ verticalScale: PropTypes11__default.default.func.isRequired,
1407
+ onFormatTimeToolTips: PropTypes11__default.default.func.isRequired,
1408
+ onFormatMetricLegend: PropTypes11__default.default.func.isRequired,
1409
+ HistoToolTip: PropTypes11__default.default.elementType,
1410
+ barHovered: PropTypes11__default.default.number,
1411
+ tooltipVisible: PropTypes11__default.default.bool
1412
+ };
1413
+
1414
+ // src/timeLineElements/axesStyles.jsx
1415
+ var arrow = `m 0,-5 5,5 -5,5`;
1416
+ function XAxis({ min, max: max2, origin, axisWidth, marks, xAxis, classes, arrowPath = arrow, onFormatTimeLegend }) {
1417
+ const now = moment_shim_default();
1418
+ const className = (n) => cn(n, classes);
1419
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1420
+ "g",
1421
+ {
1422
+ transform: `translate(${origin.x}, ${origin.y})`,
1423
+ children: [
1424
+ /* @__PURE__ */ jsxRuntime.jsx(
1425
+ "path",
1426
+ {
1427
+ className: className("axis"),
1428
+ d: `M 0,-6 0,6`
1429
+ }
1430
+ ),
1431
+ /* @__PURE__ */ jsxRuntime.jsx(
1432
+ "path",
1433
+ {
1434
+ className: className("axis"),
1435
+ d: `M 0,0 ${axisWidth + 5},0`
1436
+ }
1437
+ ),
1438
+ /* @__PURE__ */ jsxRuntime.jsx("g", { transform: `translate(${axisWidth},0)`, children: /* @__PURE__ */ jsxRuntime.jsx(
1439
+ "path",
1440
+ {
1441
+ className: className("arrow"),
1442
+ d: arrowPath
1443
+ }
1444
+ ) }),
1445
+ marks && marks.map(
1446
+ (m, index) => /* @__PURE__ */ jsxRuntime.jsxs(
1447
+ "g",
1448
+ {
1449
+ transform: `translate(${xAxis(m)},0)`,
1450
+ children: [
1451
+ /* @__PURE__ */ jsxRuntime.jsx(
1452
+ "path",
1453
+ {
1454
+ className: className("limitMarker"),
1455
+ d: "M 0,0 0,6"
1456
+ }
1457
+ ),
1458
+ /* @__PURE__ */ jsxRuntime.jsx(
1459
+ "text",
1460
+ {
1461
+ x: 0,
1462
+ y: 15,
1463
+ className: clsx3__default.default(className("timeAxisText"), d3Time.timeDay(m) >= m && className("timeAxisDaysText")),
1464
+ children: onFormatTimeLegend(m)
1465
+ }
1466
+ )
1467
+ ]
1468
+ },
1469
+ m.toISOString()
1470
+ )
1471
+ ),
1472
+ xAxis && now.isSameOrBefore(max2) && now.isSameOrAfter(min) && /* @__PURE__ */ jsxRuntime.jsx(
1473
+ "path",
1474
+ {
1475
+ transform: `translate(${xAxis(now)},0)`,
1476
+ className: className("now"),
1477
+ d: `m -3,6 6,0 -3,-6 Z`
1478
+ }
1479
+ )
1480
+ ]
1481
+ }
1482
+ );
1483
+ }
1484
+ XAxis.propTypes = {
1485
+ axisWidth: PropTypes11__default.default.number.isRequired,
1486
+ classes: PropTypes11__default.default.object,
1487
+ min: PropTypes11__default.default.instanceOf(moment_shim_default),
1488
+ max: PropTypes11__default.default.instanceOf(moment_shim_default),
1489
+ origin: PropTypes11__default.default.shape({
1490
+ x: PropTypes11__default.default.number.isRequired,
1491
+ y: PropTypes11__default.default.number.isRequired
1492
+ }).isRequired,
1493
+ marks: PropTypes11__default.default.array,
1494
+ xAxis: PropTypes11__default.default.func,
1495
+ arrowPath: PropTypes11__default.default.string,
1496
+ onFormatTimeLegend: PropTypes11__default.default.func.isRequired
1497
+ };
1498
+ function YAxis({ classes, marks, yAxis, onFormatMetricLegend, maxHeight, origin, arrowPath = arrow }) {
1499
+ const className = (n) => cn(n, classes);
1500
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1501
+ "g",
1502
+ {
1503
+ transform: `translate(${origin.x}, ${origin.y})`,
1504
+ children: [
1505
+ /* @__PURE__ */ jsxRuntime.jsx(
1506
+ "path",
1507
+ {
1508
+ className: className("axis"),
1509
+ d: `M 0,0 0, ${-maxHeight - 5}`
1510
+ }
1511
+ ),
1512
+ /* @__PURE__ */ jsxRuntime.jsx("g", { transform: `translate(0, ${-maxHeight}) rotate(270)`, children: /* @__PURE__ */ jsxRuntime.jsx(
1513
+ "path",
1514
+ {
1515
+ className: className("arrow"),
1516
+ d: arrowPath
1517
+ }
1518
+ ) }),
1519
+ marks.map((m, index) => /* @__PURE__ */ jsxRuntime.jsx(
1520
+ "g",
1521
+ {
1522
+ transform: `translate(0,${-yAxis(m)})`,
1523
+ children: m > 0 && /* @__PURE__ */ jsxRuntime.jsx(
1524
+ "text",
1525
+ {
1526
+ transform: `translate(0,5)`,
1527
+ className: className("verticalAxisText"),
1528
+ x: -7,
1529
+ y: -3,
1530
+ children: onFormatMetricLegend(m)
1531
+ }
1532
+ )
1533
+ },
1534
+ index
1535
+ ))
1536
+ ]
1537
+ }
1538
+ );
1539
+ }
1540
+ YAxis.propTypes = {
1541
+ classes: PropTypes11__default.default.object,
1542
+ maxHeight: PropTypes11__default.default.number.isRequired,
1543
+ origin: PropTypes11__default.default.shape({
1544
+ x: PropTypes11__default.default.number.isRequired,
1545
+ y: PropTypes11__default.default.number.isRequired
1546
+ }).isRequired,
1547
+ marks: PropTypes11__default.default.array,
1548
+ yAxis: PropTypes11__default.default.func,
1549
+ arrowPath: PropTypes11__default.default.string,
1550
+ onFormatMetricLegend: PropTypes11__default.default.func.isRequired
1551
+ };
1552
+ function Legend({ classes, metricsDefinition, origin }) {
1553
+ const fill = [...metricsDefinition.colors].reverse();
1554
+ const legends = [...metricsDefinition.legends].reverse();
1555
+ const className = (n) => cn(n, classes);
1556
+ return /* @__PURE__ */ jsxRuntime.jsx(
1557
+ "g",
1558
+ {
1559
+ transform: `translate(${origin.x},${origin.y})`,
1560
+ children: legends.map((leg, i) => /* @__PURE__ */ jsxRuntime.jsx(
1561
+ "text",
1562
+ {
1563
+ className: className("legend"),
1564
+ style: {
1565
+ fill: fill[i].text
1566
+ },
1567
+ x: 0,
1568
+ y: 14 * (i + 1),
1569
+ children: /* @__PURE__ */ jsxRuntime.jsx("tspan", { children: leg })
1570
+ },
1571
+ i
1572
+ ))
1573
+ }
1574
+ );
1575
+ }
1576
+ Legend.propTypes = {
1577
+ classes: PropTypes11__default.default.object.isRequired,
1578
+ origin: PropTypes11__default.default.shape({
1579
+ x: PropTypes11__default.default.number.isRequired,
1580
+ y: PropTypes11__default.default.number.isRequired
1581
+ }).isRequired,
1582
+ metricsDefinition: PropTypes11__default.default.shape({
1583
+ count: PropTypes11__default.default.number.isRequired,
1584
+ legends: PropTypes11__default.default.arrayOf(PropTypes11__default.default.string).isRequired,
1585
+ colors: PropTypes11__default.default.arrayOf(PropTypes11__default.default.shape({
1586
+ fill: PropTypes11__default.default.string.isRequired,
1587
+ stroke: PropTypes11__default.default.string.isRequired,
1588
+ text: PropTypes11__default.default.string.isRequired
1589
+ })).isRequired
1590
+ }).isRequired
1591
+ };
1592
+ function Button({ tipPlacement, tipOverlay, path, origin, scale, iconSize, onClick, classes, rcToolTipPrefixCls, isActive }) {
1593
+ const [isOver, setOver] = react.useState(false);
1594
+ return /* @__PURE__ */ jsxRuntime.jsx(
1595
+ ToolTip,
1596
+ {
1597
+ placement: tipPlacement,
1598
+ overlay: tipOverlay,
1599
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
1600
+ "g",
1601
+ {
1602
+ className: clsx3__default.default(
1603
+ "tl-buttonGroup",
1604
+ classes.buttonGroup,
1605
+ !isActive && "tl-buttonGroupInactive",
1606
+ !isActive && classes.buttonGroupInactive
1607
+ ),
1608
+ transform: `translate(${origin.x},${origin.y}) scale(${scale})`,
1609
+ onMouseOver: (event) => {
1610
+ isActive && setOver(true);
1611
+ },
1612
+ onMouseOut: (event) => {
1613
+ isActive && setOver(false);
1614
+ },
1615
+ onClick: () => {
1616
+ isActive && onClick();
1617
+ },
1618
+ children: [
1619
+ /* @__PURE__ */ jsxRuntime.jsx(
1620
+ "rect",
1621
+ {
1622
+ className: clsx3__default.default(
1623
+ "tl-buttonOverShape",
1624
+ classes.buttonOverShape
1625
+ ),
1626
+ x: "0",
1627
+ y: "0",
1628
+ height: iconSize,
1629
+ width: iconSize
1630
+ }
1631
+ ),
1632
+ /* @__PURE__ */ jsxRuntime.jsx(
1633
+ "path",
1634
+ {
1635
+ className: clsx3__default.default(
1636
+ "tl-buttonIcon",
1637
+ classes.buttonIcon,
1638
+ isOver && "tl-buttonIconOver",
1639
+ isOver && classes.buttonIconOver
1640
+ ),
1641
+ d: path
1642
+ }
1643
+ )
1644
+ ]
1645
+ }
1646
+ )
1647
+ }
1648
+ );
1649
+ }
1650
+ Button.propTypes = {
1651
+ tipPlacement: PropTypes11__default.default.string.isRequired,
1652
+ tipOverlay: PropTypes11__default.default.string.isRequired,
1653
+ path: PropTypes11__default.default.string.isRequired,
1654
+ origin: PropTypes11__default.default.shape({
1655
+ x: PropTypes11__default.default.number.isRequired,
1656
+ y: PropTypes11__default.default.number.isRequired
1657
+ }).isRequired,
1658
+ scale: PropTypes11__default.default.number.isRequired,
1659
+ iconSize: PropTypes11__default.default.number.isRequired,
1660
+ onClick: PropTypes11__default.default.func.isRequired,
1661
+ classes: PropTypes11__default.default.object.isRequired,
1662
+ rcToolTipPrefixCls: PropTypes11__default.default.string.isRequired,
1663
+ isActive: PropTypes11__default.default.bool.isRequired
1664
+ };
1665
+ var doubleArrowIcon = "m 0,0 5,5 0,-5 5,5 -5,5 0,-5 -5,5 Z";
1666
+ var resetIcon = "M5 15H3v4c0 1.1.9 2 2 2h4v-2H5v-4zM5 5h4V3H5c-1.1 0-2 .9-2 2v4h2V5zm14-2h-4v2h4v4h2V5c0-1.1-.9-2-2-2zm0 16h-4v2h4c1.1 0 2-.9 2-2v-4h-2v4zM12 9c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z";
1667
+ var gotoNowIcon = "M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm.5-13H11v6l5.25 3.15.75-1.23-4.5-2.67z";
1668
+ function Tools({
1669
+ tools,
1670
+ classes,
1671
+ rcToolTipPrefixCls,
1672
+ labels,
1673
+ histoWidth,
1674
+ isActive,
1675
+ origin,
1676
+ onResetTime,
1677
+ shiftTimeLine,
1678
+ onGoto
1679
+ }) {
1680
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1681
+ "g",
1682
+ {
1683
+ transform: `translate(${origin.x}, ${origin.y})`,
1684
+ children: [
1685
+ tools.slideForward !== false && /* @__PURE__ */ jsxRuntime.jsx(
1686
+ Button,
1687
+ {
1688
+ classes,
1689
+ rcToolTipPrefixCls,
1690
+ tipPlacement: "left",
1691
+ tipOverlay: labels.forwardButtonTip,
1692
+ origin: { x: histoWidth + 22, y: -5 },
1693
+ scale: 1,
1694
+ path: doubleArrowIcon,
1695
+ iconSize: 10,
1696
+ isActive,
1697
+ onClick: () => {
1698
+ shiftTimeLine(-120);
1699
+ }
1700
+ }
1701
+ ),
1702
+ tools.slideBackward !== false && /* @__PURE__ */ jsxRuntime.jsx(
1703
+ Button,
1704
+ {
1705
+ classes,
1706
+ rcToolTipPrefixCls,
1707
+ tipPlacement: "right",
1708
+ tipOverlay: labels.backwardButtonTip,
1709
+ origin: { x: -7, y: 5 },
1710
+ scale: -1,
1711
+ path: doubleArrowIcon,
1712
+ iconSize: 10,
1713
+ isActive,
1714
+ onClick: () => {
1715
+ shiftTimeLine(120);
1716
+ }
1717
+ }
1718
+ ),
1719
+ tools.resetTimeline !== false && /* @__PURE__ */ jsxRuntime.jsx(
1720
+ Button,
1721
+ {
1722
+ classes,
1723
+ rcToolTipPrefixCls,
1724
+ tipPlacement: "left",
1725
+ tipOverlay: labels.resetButtonTip,
1726
+ origin: { x: histoWidth + 17, y: -30 },
1727
+ scale: 0.75,
1728
+ path: resetIcon,
1729
+ iconSize: 24,
1730
+ isActive,
1731
+ onClick: onResetTime
1732
+ }
1733
+ ),
1734
+ tools.gotoNow !== false && /* @__PURE__ */ jsxRuntime.jsx(
1735
+ Button,
1736
+ {
1737
+ classes,
1738
+ rcToolTipPrefixCls,
1739
+ tipPlacement: "left",
1740
+ tipOverlay: labels.gotoNowButtonTip,
1741
+ origin: { x: histoWidth + 17, y: tools.resetTimeline !== false ? -53 : -30 },
1742
+ scale: 0.75,
1743
+ path: gotoNowIcon,
1744
+ iconSize: 24,
1745
+ isActive,
1746
+ onClick: onGoto
1747
+ }
1748
+ )
1749
+ ]
1750
+ }
1751
+ );
1752
+ }
1753
+ Tools.propTypes = {
1754
+ tools: PropTypes11__default.default.shape({
1755
+ slideForward: PropTypes11__default.default.bool,
1756
+ slideBackward: PropTypes11__default.default.bool,
1757
+ resetTimeline: PropTypes11__default.default.bool,
1758
+ gotoNow: PropTypes11__default.default.bool,
1759
+ cursor: PropTypes11__default.default.bool
1760
+ }).isRequired,
1761
+ classes: PropTypes11__default.default.object.isRequired,
1762
+ rcToolTipPrefixCls: PropTypes11__default.default.string.isRequired,
1763
+ labels: PropTypes11__default.default.shape({
1764
+ forwardButtonTip: PropTypes11__default.default.string.isRequired,
1765
+ backwardButtonTip: PropTypes11__default.default.string.isRequired,
1766
+ resetButtonTip: PropTypes11__default.default.string.isRequired,
1767
+ gotoNowButtonTip: PropTypes11__default.default.string.isRequired
1768
+ }).isRequired,
1769
+ histoWidth: PropTypes11__default.default.number.isRequired,
1770
+ isActive: PropTypes11__default.default.bool.isRequired,
1771
+ origin: PropTypes11__default.default.shape({
1772
+ x: PropTypes11__default.default.number.isRequired,
1773
+ y: PropTypes11__default.default.number.isRequired
1774
+ }).isRequired,
1775
+ onResetTime: PropTypes11__default.default.func.isRequired,
1776
+ shiftTimeLine: PropTypes11__default.default.func.isRequired,
1777
+ onGoto: PropTypes11__default.default.func.isRequired
1778
+ };
1779
+ function HistoTooltip({ metricsDefinition, item, onFormatTimeToolTips, onFormatMetricLegend, classes }) {
1780
+ const className = (n) => cn(n, classes);
1781
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1782
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1783
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: className("innerTipLeft"), children: [
1784
+ /* @__PURE__ */ jsxRuntime.jsx("br", {}),
1785
+ "\u2192"
1786
+ ] }),
1787
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: className("innerTipRight"), children: [
1788
+ onFormatTimeToolTips(item.start),
1789
+ /* @__PURE__ */ jsxRuntime.jsx("br", {}),
1790
+ onFormatTimeToolTips(item.end)
1791
+ ] })
1792
+ ] }),
1793
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: className("innerTipMetrics"), children: [
1794
+ metricsDefinition.colors.map((color, m) => {
1795
+ const reversed = metricsDefinition.colors.length - m - 1;
1796
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1797
+ "- ",
1798
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: metricsDefinition.colors[reversed].stroke }, children: metricsDefinition.legends[reversed] }),
1799
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: className("innerTipRight"), children: onFormatMetricLegend(item.metrics[reversed]) })
1800
+ ] }, reversed);
1801
+ }),
1802
+ /* @__PURE__ */ jsxRuntime.jsx("hr", {}),
1803
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1804
+ "Total",
1805
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: className("innerTipRight"), children: onFormatMetricLegend(item.total) })
1806
+ ] })
1807
+ ] })
1808
+ ] });
1809
+ }
1810
+ HistoTooltip.propTypes = {
1811
+ classes: PropTypes11__default.default.object,
1812
+ item: PropTypes11__default.default.shape({
1813
+ start: PropTypes11__default.default.instanceOf(moment_shim_default).isRequired,
1814
+ end: PropTypes11__default.default.instanceOf(moment_shim_default).isRequired,
1815
+ x1: PropTypes11__default.default.number,
1816
+ x2: PropTypes11__default.default.number,
1817
+ metrics: PropTypes11__default.default.arrayOf(PropTypes11__default.default.number).isRequired,
1818
+ total: PropTypes11__default.default.number.isRequired
1819
+ }),
1820
+ metricsDefinition: PropTypes11__default.default.shape({
1821
+ count: PropTypes11__default.default.number.isRequired,
1822
+ legends: PropTypes11__default.default.arrayOf(PropTypes11__default.default.string).isRequired,
1823
+ colors: PropTypes11__default.default.arrayOf(PropTypes11__default.default.shape({
1824
+ fill: PropTypes11__default.default.string.isRequired,
1825
+ stroke: PropTypes11__default.default.string.isRequired,
1826
+ text: PropTypes11__default.default.string.isRequired
1827
+ })).isRequired
1828
+ }).isRequired,
1829
+ onFormatTimeToolTips: PropTypes11__default.default.func.isRequired,
1830
+ onFormatMetricLegend: PropTypes11__default.default.func.isRequired
1831
+ };
1832
+ var qualityHeight = 3;
1833
+ function QualityLine({ classes, rcToolTipPrefixCls, origin, quality, xAxis, qualityScale }) {
1834
+ const className = (n) => cn(n, classes);
1835
+ return /* @__PURE__ */ jsxRuntime.jsx("g", { transform: `translate(${origin.x}, ${origin.y})`, children: quality.items.map((item, i) => {
1836
+ const x1 = xAxis(item.time);
1837
+ const x2 = xAxis(moment_shim_default(item.time).add(quality.intervalMin, "minutes"));
1838
+ const rect = /* @__PURE__ */ jsxRuntime.jsx(
1839
+ "rect",
1840
+ {
1841
+ className: className("qualityCell"),
1842
+ style: {
1843
+ fill: qualityScale(item.quality)
1844
+ },
1845
+ onMouseOver: (event) => {
1846
+ event.target.style.fill = "#00ebeb";
1847
+ },
1848
+ onMouseOut: (event) => {
1849
+ event.target.style.fill = qualityScale(item.quality);
1850
+ },
1851
+ x: x1,
1852
+ y: 1,
1853
+ width: x2 - x1,
1854
+ height: qualityHeight
1855
+ },
1856
+ i
1857
+ );
1858
+ if (item.tip) {
1859
+ return /* @__PURE__ */ jsxRuntime.jsx(
1860
+ ToolTip,
1861
+ {
1862
+ placement: "bottom",
1863
+ overlay: item.tip,
1864
+ mouseEnterDelay: 0.1,
1865
+ children: rect
1866
+ },
1867
+ i
1868
+ );
1869
+ } else return rect;
1870
+ }) });
1871
+ }
1872
+ QualityLine.propTypes = {
1873
+ classes: PropTypes11__default.default.object.isRequired,
1874
+ rcToolTipPrefixCls: PropTypes11__default.default.string.isRequired,
1875
+ origin: PropTypes11__default.default.shape({
1876
+ x: PropTypes11__default.default.number.isRequired,
1877
+ y: PropTypes11__default.default.number.isRequired
1878
+ }).isRequired,
1879
+ xAxis: PropTypes11__default.default.func.isRequired,
1880
+ quality: PropTypes11__default.default.shape({
1881
+ items: PropTypes11__default.default.arrayOf(PropTypes11__default.default.shape({
1882
+ time: PropTypes11__default.default.instanceOf(moment_shim_default).isRequired,
1883
+ quality: PropTypes11__default.default.number.isRequired,
1884
+ tip: PropTypes11__default.default.node
1885
+ })),
1886
+ intervalMin: PropTypes11__default.default.number
1887
+ }).isRequired,
1888
+ qualityScale: PropTypes11__default.default.func.isRequired
1889
+ };
1890
+ function YAxis2({ classes, marks, yAxis, origin, xAxisWidth }) {
1891
+ const className = (n) => cn(n, classes);
1892
+ return /* @__PURE__ */ jsxRuntime.jsx(
1893
+ "g",
1894
+ {
1895
+ transform: `translate(${origin.x}, ${origin.y})`,
1896
+ children: marks.map((m, index) => /* @__PURE__ */ jsxRuntime.jsx(
1897
+ "g",
1898
+ {
1899
+ transform: `translate(0,${-yAxis(m)})`,
1900
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1901
+ "path",
1902
+ {
1903
+ className: className("grid"),
1904
+ d: `M -5,0 ${xAxisWidth},0`
1905
+ }
1906
+ )
1907
+ },
1908
+ index
1909
+ ))
1910
+ }
1911
+ );
1912
+ }
1913
+ YAxis2.propTypes = {
1914
+ classes: PropTypes11__default.default.object,
1915
+ origin: PropTypes11__default.default.shape({
1916
+ x: PropTypes11__default.default.number.isRequired,
1917
+ y: PropTypes11__default.default.number.isRequired
1918
+ }).isRequired,
1919
+ marks: PropTypes11__default.default.array,
1920
+ yAxis: PropTypes11__default.default.func,
1921
+ xAxisWidth: PropTypes11__default.default.number
1922
+ };
1923
+ function XAxis2({ origin, marks, xAxis, classes, yAxisHeight }) {
1924
+ const className = (n) => cn(n, classes);
1925
+ return /* @__PURE__ */ jsxRuntime.jsx("g", { transform: `translate(${origin.x}, ${origin.y})`, children: marks && marks.map(
1926
+ (m, index) => /* @__PURE__ */ jsxRuntime.jsx(
1927
+ "g",
1928
+ {
1929
+ transform: `translate(${xAxis(m)},0)`,
1930
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1931
+ "path",
1932
+ {
1933
+ className: className("grid"),
1934
+ d: `M 0,0 0,${-yAxisHeight}`
1935
+ }
1936
+ )
1937
+ },
1938
+ m.toISOString()
1939
+ )
1940
+ ) });
1941
+ }
1942
+ XAxis2.propTypes = {
1943
+ classes: PropTypes11__default.default.object,
1944
+ origin: PropTypes11__default.default.shape({
1945
+ x: PropTypes11__default.default.number.isRequired,
1946
+ y: PropTypes11__default.default.number.isRequired
1947
+ }).isRequired,
1948
+ marks: PropTypes11__default.default.array,
1949
+ xAxis: PropTypes11__default.default.func,
1950
+ yAxisHeight: PropTypes11__default.default.number
1951
+ };
1952
+
1953
+ // src/time.ts
1954
+ function toMoment(x, zone) {
1955
+ if (moment_shim_default.isMoment(x)) return x;
1956
+ const m = zone ? moment_shim_default.tz(x, zone) : moment_shim_default(x);
1957
+ return m;
1958
+ }
1959
+ function toDuration(x) {
1960
+ if (moment_shim_default.isDuration(x)) return x;
1961
+ return moment_shim_default.duration(x);
1962
+ }
1963
+ function domainToMoments(d, zone) {
1964
+ return { min: toMoment(d.min, zone), max: toMoment(d.max, zone) };
1965
+ }
1966
+ function timeSpanToMoments(t, zone) {
1967
+ return { start: toMoment(t.start, zone), stop: toMoment(t.stop, zone) };
1968
+ }
1969
+ var Cursor2 = Cursor;
1970
+ var Histogram2 = Histogram;
1971
+ var XAxis3 = XAxis;
1972
+ var YAxis3 = YAxis;
1973
+ var Legend2 = Legend;
1974
+ var Tools2 = Tools;
1975
+ var HistoToolTipDefault = HistoTooltip;
1976
+ var marginDefault = { left: 50, right: 45, top: 5, bottom: 5 };
1977
+ var xAxisDefault = { height: 20, spaceBetweenTicks: 70, barsBetweenTicks: 8 };
1978
+ var defaultZoomOutFactor = 1.25;
1979
+ var defaultTools = {
1980
+ slideForward: true,
1981
+ slideBackward: true,
1982
+ resetTimeline: true,
1983
+ gotoNow: true,
1984
+ cursor: true,
1985
+ zoomIn: true,
1986
+ zoomOut: true
1987
+ };
1988
+ function computeMarginAndWidth(props) {
1989
+ const { margin, showLegend, metricsDefinition, width } = props;
1990
+ const localMargin = { ...marginDefault, ...margin };
1991
+ if (showLegend) {
1992
+ const maxLength = max(metricsDefinition.legends.map((s) => s.length));
1993
+ localMargin.left = max([5 + maxLength * 9, localMargin.left]);
1994
+ }
1995
+ return {
1996
+ margin: localMargin,
1997
+ histoWidth: width - localMargin.left - localMargin.right
1998
+ };
1999
+ }
2000
+ var momentToDate = (m) => m && m.toDate ? m.toDate() : m ?? null;
2001
+ var TimeLineInner = react.forwardRef(function TimeLine(props, ref) {
2002
+ const {
2003
+ width,
2004
+ height,
2005
+ histo,
2006
+ quality,
2007
+ qualityScale = defaultQualityScale,
2008
+ metricsDefinition,
2009
+ classes = {},
2010
+ rcToolTipPrefixCls = theme_default.rcToolTipPrefixCls,
2011
+ showLegend = true,
2012
+ tools = defaultTools,
2013
+ onFormatTimeLegend,
2014
+ onFormatMetricLegend,
2015
+ onResetTime,
2016
+ onFormatTimeToolTips,
2017
+ xAxis: xAxisProp = xAxisDefault,
2018
+ yAxis: yAxisProp = {},
2019
+ showHistoToolTip,
2020
+ HistoToolTip = HistoToolTipDefault
2021
+ } = props;
2022
+ const xAxisRef = react.useRef(null);
2023
+ const timelineElementRef = react.useRef(null);
2024
+ const autoMoveRef = react.useRef(null);
2025
+ const isAutoMovingRef = react.useRef(false);
2026
+ const lastAutoMovingDeltaRef = react.useRef(0);
2027
+ const movedSinceLastFetchedRef = react.useRef(0);
2028
+ const widthOfLastUpdateRef = react.useRef(null);
2029
+ const itemsRef = react.useRef([]);
2030
+ const labelsRef = react.useRef(merge({ ...defaultLabels }, props.labels));
2031
+ react.useEffect(() => {
2032
+ labelsRef.current = merge({ ...defaultLabels }, props.labels);
2033
+ }, [props.labels]);
2034
+ const [state, setStateRaw] = react.useState(() => {
2035
+ const initial = {
2036
+ isActive: false,
2037
+ start: props.timeSpan.start,
2038
+ stop: props.timeSpan.stop,
2039
+ maxTimespan: false,
2040
+ waitForLoad: false,
2041
+ tooltipVisible: false,
2042
+ barHovered: null,
2043
+ dragging: false,
2044
+ ticks: [],
2045
+ verticalMarks: [],
2046
+ ...computeMarginAndWidth(props)
2047
+ };
2048
+ return {
2049
+ ...initial,
2050
+ ...checkAndCorrectDomainPure({
2051
+ domain: props.domains[0],
2052
+ biggestVisibleDomain: props.biggestVisibleDomain,
2053
+ maxDomain: props.maxDomain,
2054
+ smallestResolution: props.smallestResolution,
2055
+ histoWidth: initial.histoWidth
2056
+ })
2057
+ };
2058
+ });
2059
+ const stateRef = react.useRef(state);
2060
+ stateRef.current = state;
2061
+ const propsRef = react.useRef(props);
2062
+ propsRef.current = props;
2063
+ const patchState = react.useCallback((patch) => {
2064
+ setStateRaw((s) => ({ ...s, ...typeof patch === "function" ? patch(s) : patch }));
2065
+ }, []);
2066
+ const checkAndCorrectDomain = react.useCallback(({ domain: domain2 }) => {
2067
+ return checkAndCorrectDomainPure({
2068
+ domain: domain2,
2069
+ biggestVisibleDomain: propsRef.current.biggestVisibleDomain,
2070
+ maxDomain: propsRef.current.maxDomain,
2071
+ smallestResolution: propsRef.current.smallestResolution,
2072
+ histoWidth: stateRef.current.histoWidth
2073
+ });
2074
+ }, []);
2075
+ const getItems = react.useCallback((p, domain2, shouldReload = true) => {
2076
+ const histoWidth2 = computeMarginAndWidth(propsRef.current).histoWidth;
2077
+ const xAxis = d3Scale.scaleTime().domain([domain2.min, domain2.max]).range([0, histoWidth2]);
2078
+ xAxis.clamp(true);
2079
+ xAxisRef.current = xAxis;
2080
+ const ticks2 = xAxis.ticks(floor(histoWidth2 / p.xAxis.spaceBetweenTicks));
2081
+ const intervalMs = max([
2082
+ round(moment_shim_default(ticks2[1]).diff(moment_shim_default(ticks2[0])) / p.xAxis.barsBetweenTicks),
2083
+ propsRef.current.smallestResolution.asMilliseconds()
2084
+ ]);
2085
+ patchState({ histoWidth: histoWidth2, isActive: true, ticks: ticks2 });
2086
+ if (shouldReload && intervalMs) {
2087
+ widthOfLastUpdateRef.current = p.width;
2088
+ patchState({ waitForLoad: true });
2089
+ p.onLoadHisto(intervalMs, domain2.min, domain2.max);
2090
+ }
2091
+ }, [patchState]);
2092
+ react.useEffect(() => {
2093
+ if (stateRef.current.domain) {
2094
+ getItems(propsRef.current, stateRef.current.domain);
2095
+ } else {
2096
+ propsRef.current.onLoadDefaultDomain();
2097
+ }
2098
+ patchState(computeMarginAndWidth(propsRef.current));
2099
+ }, []);
2100
+ const prevMaxTimespanRef = react.useRef(state.maxTimespan);
2101
+ react.useEffect(() => {
2102
+ if (!prevMaxTimespanRef.current && state.maxTimespan) {
2103
+ propsRef.current.onShowMessage(labelsRef.current.maxSelectionMsg);
2104
+ }
2105
+ prevMaxTimespanRef.current = state.maxTimespan;
2106
+ }, [state.maxTimespan]);
2107
+ const prevWidthRef = react.useRef(props.width);
2108
+ const prevMarginRef = react.useRef(props.margin);
2109
+ react.useEffect(() => {
2110
+ if (prevWidthRef.current === props.width && isEqual(prevMarginRef.current, props.margin)) {
2111
+ prevWidthRef.current = props.width;
2112
+ prevMarginRef.current = props.margin;
2113
+ return;
2114
+ }
2115
+ const s = stateRef.current;
2116
+ if (s.isActive) {
2117
+ const big = widthOfLastUpdateRef.current !== null && Math.abs((props.width ?? 0) - (widthOfLastUpdateRef.current ?? 0)) > 30;
2118
+ getItems(props, s.domain, big);
2119
+ patchState(computeMarginAndWidth(props));
2120
+ } else {
2121
+ patchState(computeMarginAndWidth(props));
2122
+ }
2123
+ if (stateRef.current.domain) {
2124
+ const res = checkAndCorrectDomain({ domain: stateRef.current.domain });
2125
+ const { maxZoom: maxZoom2, minZoom: minZoom2, domain: domain2, domainHasChanged, minTime, maxTime } = res;
2126
+ if (maxZoom2 !== stateRef.current.maxZoom || minZoom2 !== stateRef.current.minZoom) {
2127
+ patchState({
2128
+ maxZoom: maxZoom2,
2129
+ minZoom: minZoom2,
2130
+ minTime,
2131
+ maxTime,
2132
+ domain: domainHasChanged ? domain2 : stateRef.current.domain
2133
+ });
2134
+ if (domainHasChanged) {
2135
+ const newDomains = [domain2, ...propsRef.current.domains.slice(1)];
2136
+ propsRef.current.onUpdateDomains(newDomains);
2137
+ }
2138
+ }
2139
+ }
2140
+ prevWidthRef.current = props.width;
2141
+ prevMarginRef.current = props.margin;
2142
+ }, [props.width, props.margin, getItems, patchState, checkAndCorrectDomain]);
2143
+ const prevTimeSpanRef = react.useRef(props.timeSpan);
2144
+ react.useEffect(() => {
2145
+ const prev = prevTimeSpanRef.current;
2146
+ if (prev.start.isSame(props.timeSpan.start) && prev.stop.isSame(props.timeSpan.stop)) {
2147
+ return;
2148
+ }
2149
+ const newDomains = shiftDomainsPure(props.domains, {
2150
+ min: props.timeSpan.start,
2151
+ max: props.timeSpan.stop
2152
+ }, props.biggestVisibleDomain);
2153
+ if (newDomains !== props.domains) {
2154
+ props.onUpdateDomains(newDomains);
2155
+ }
2156
+ patchState({ start: props.timeSpan.start, stop: props.timeSpan.stop });
2157
+ prevTimeSpanRef.current = props.timeSpan;
2158
+ }, [props.timeSpan, props.domains, props.biggestVisibleDomain, props, patchState]);
2159
+ const prevDomain0Ref = react.useRef(props.domains[0]);
2160
+ react.useEffect(() => {
2161
+ const prev = prevDomain0Ref.current;
2162
+ const curr = props.domains[0];
2163
+ const changed = !prev && curr || prev && curr && (!prev.min.isSame(curr.min) || !prev.max.isSame(curr.max));
2164
+ if (!changed) {
2165
+ prevDomain0Ref.current = curr;
2166
+ return;
2167
+ }
2168
+ const res = checkAndCorrectDomain({ domain: curr });
2169
+ const { maxZoom: maxZoom2, minZoom: minZoom2, domain: domain2, domainHasChanged, minTime, maxTime } = res;
2170
+ patchState({ maxZoom: maxZoom2, minZoom: minZoom2, minTime, maxTime, domain: domain2 });
2171
+ if (domainHasChanged) {
2172
+ const newDomains = [domain2, ...propsRef.current.domains.slice(1)];
2173
+ propsRef.current.onUpdateDomains(newDomains);
2174
+ } else {
2175
+ getItems(propsRef.current, domain2);
2176
+ }
2177
+ prevDomain0Ref.current = curr;
2178
+ }, [props.domains, checkAndCorrectDomain, getItems, patchState]);
2179
+ const prevHistoRef = react.useRef(props.histo);
2180
+ react.useEffect(() => {
2181
+ if (prevHistoRef.current !== props.histo) {
2182
+ patchState({ waitForLoad: false });
2183
+ prevHistoRef.current = props.histo;
2184
+ }
2185
+ }, [props.histo, patchState]);
2186
+ const prevLegendsRef = react.useRef(props.metricsDefinition.legends);
2187
+ react.useEffect(() => {
2188
+ if (prevLegendsRef.current !== props.metricsDefinition.legends) {
2189
+ patchState(computeMarginAndWidth(propsRef.current));
2190
+ prevLegendsRef.current = props.metricsDefinition.legends;
2191
+ }
2192
+ }, [props.metricsDefinition.legends, patchState]);
2193
+ const prepareVerticalScale = react.useCallback(() => {
2194
+ const items2 = histo && histo.items;
2195
+ const s = stateRef.current;
2196
+ const maxHeight2 = height - s.margin.bottom - s.margin.top - (xAxisProp.height || xAxisDefault.height);
2197
+ const maxScale = items2 ? max(items2.map((i) => i.total)) || 0 : 0;
2198
+ const verticalScale2 = d3Scale.scaleLinear().domain([0, maxScale]).range([0, maxHeight2]);
2199
+ const verticalMarks2 = yAxisProp.spaceBetweenTicks && maxHeight2 > yAxisProp.spaceBetweenTicks * 2 ? verticalScale2.ticks(floor(maxHeight2 / yAxisProp.spaceBetweenTicks)) : [maxScale];
2200
+ return { verticalScale: verticalScale2, verticalMarks: verticalMarks2, maxHeight: maxHeight2 };
2201
+ }, [histo, height, xAxisProp, yAxisProp]);
2202
+ const prepareHistogram = react.useCallback((args) => {
2203
+ const { domain: domain2, verticalScale: verticalScale2 } = args;
2204
+ const xAxis = xAxisRef.current;
2205
+ if (histo && histo.items && domain2 && xAxis) {
2206
+ const { min, max: max2 } = domain2;
2207
+ return histo.items.filter(
2208
+ (item) => item.total > 0 && item.time.isSameOrAfter(min) && item.time.isBefore(max2)
2209
+ ).map((item) => {
2210
+ const start2 = moment_shim_default(item.time);
2211
+ const end = moment_shim_default(item.time).add(histo.intervalMs);
2212
+ return {
2213
+ x1: xAxis(start2),
2214
+ x2: xAxis(end),
2215
+ start: start2,
2216
+ end,
2217
+ metrics: item.metrics,
2218
+ total: item.total,
2219
+ height: verticalScale2(item.total)
2220
+ };
2221
+ });
2222
+ }
2223
+ return [];
2224
+ }, [histo]);
2225
+ const setAutoMove = react.useCallback((active, action, delta) => {
2226
+ if (active) {
2227
+ if (!autoMoveRef.current || autoMoveRef.current && Math.abs(lastAutoMovingDeltaRef.current - (delta ?? 0)) > 5) {
2228
+ if (autoMoveRef.current) clearInterval(autoMoveRef.current);
2229
+ autoMoveRef.current = setInterval(() => {
2230
+ action(delta);
2231
+ moveTimeLine(-(delta ?? 0));
2232
+ isAutoMovingRef.current = true;
2233
+ lastAutoMovingDeltaRef.current = delta ?? 0;
2234
+ }, 30);
2235
+ }
2236
+ } else {
2237
+ if (autoMoveRef.current) clearInterval(autoMoveRef.current);
2238
+ autoMoveRef.current = null;
2239
+ }
2240
+ }, []);
2241
+ const handleAutoSliding = react.useCallback((mouse, action) => {
2242
+ if (!mouse) return;
2243
+ const posX = mouse[0];
2244
+ const s = stateRef.current;
2245
+ if (posX < 0) setAutoMove(true, action, posX);
2246
+ else if (posX >= 0 && posX <= s.histoWidth) setAutoMove(false);
2247
+ else if (posX > s.histoWidth) setAutoMove(true, action, posX - s.histoWidth);
2248
+ }, [setAutoMove]);
2249
+ const movedTimeLine = react.useCallback(() => {
2250
+ movedSinceLastFetchedRef.current = 0;
2251
+ const domain2 = stateRef.current.domain;
2252
+ const p = propsRef.current;
2253
+ const domains = [domain2, ...p.domains.slice(1)];
2254
+ const newDomains = shiftDomainsPure(domains, domain2, p.biggestVisibleDomain);
2255
+ p.onUpdateDomains(newDomains);
2256
+ }, []);
2257
+ const stopAutoMove = react.useCallback(() => {
2258
+ if (autoMoveRef.current) setAutoMove(false);
2259
+ if (isAutoMovingRef.current) {
2260
+ isAutoMovingRef.current = false;
2261
+ movedTimeLine();
2262
+ }
2263
+ }, [setAutoMove, movedTimeLine]);
2264
+ const moveTimeLineCore = react.useCallback((delta) => {
2265
+ const p = propsRef.current;
2266
+ const s = stateRef.current;
2267
+ const { maxDomain, onShowMessage } = p;
2268
+ let { domain: currentDomain, minTime = false, maxTime = false } = s;
2269
+ const currentSpan = currentDomain.max.diff(currentDomain.min);
2270
+ if (minTime && delta > 0 || maxTime && delta < 0) {
2271
+ return { ...currentDomain, moved: 0, minTime, maxTime };
2272
+ }
2273
+ const xAxis = xAxisRef.current;
2274
+ let min = moment_shim_default(xAxis.invert(-delta));
2275
+ let max2 = moment_shim_default(xAxis.invert(s.histoWidth - delta));
2276
+ let moved = delta;
2277
+ if (maxDomain.min && min.isBefore(maxDomain.min)) {
2278
+ moved = xAxis(maxDomain.min);
2279
+ min = moment_shim_default(maxDomain.min);
2280
+ max2 = moment_shim_default(min).add(currentSpan);
2281
+ minTime = true;
2282
+ onShowMessage(labelsRef.current.minDomainMsg);
2283
+ }
2284
+ if (maxDomain.max && max2.isAfter(maxDomain.max)) {
2285
+ moved = xAxis(maxDomain.max);
2286
+ max2 = moment_shim_default(maxDomain.max);
2287
+ min = moment_shim_default(max2).subtract(currentSpan);
2288
+ maxTime = true;
2289
+ onShowMessage(labelsRef.current.maxDomainMsg);
2290
+ }
2291
+ return { min, max: max2, moved, minTime, maxTime };
2292
+ }, []);
2293
+ const moveTimeLine = react.useCallback((delta) => {
2294
+ const xAxis = xAxisRef.current;
2295
+ xAxis.clamp(false);
2296
+ const { min, max: max2, moved, minTime, maxTime } = moveTimeLineCore(delta);
2297
+ if (moved !== 0) {
2298
+ xAxis.domain([min, max2]);
2299
+ xAxis.clamp(true);
2300
+ const p = propsRef.current;
2301
+ const s = stateRef.current;
2302
+ const ticks2 = xAxis.ticks(floor(s.histoWidth / p.xAxis.spaceBetweenTicks));
2303
+ movedSinceLastFetchedRef.current += moved;
2304
+ if (Math.abs(movedSinceLastFetchedRef.current) > 75 && p.fetchWhileSliding) {
2305
+ movedSinceLastFetchedRef.current = 0;
2306
+ getItems(p, { min, max: max2 });
2307
+ }
2308
+ patchState({ domain: { min, max: max2 }, minTime, maxTime, ticks: ticks2 });
2309
+ }
2310
+ }, [moveTimeLineCore, getItems, patchState]);
2311
+ const onResizeLeftCursor = react.useCallback((delta, mouse) => {
2312
+ const xAxis = xAxisRef.current;
2313
+ const s = stateRef.current;
2314
+ const p = propsRef.current;
2315
+ let newStart = moment_shim_default(xAxis.invert(xAxis(s.start) + delta));
2316
+ let newStop = s.stop;
2317
+ let maxTimespan2 = false;
2318
+ if (newStart.isSameOrAfter(newStop)) {
2319
+ newStop = moment_shim_default(xAxis.invert(xAxis(newStop) + delta));
2320
+ }
2321
+ if (p.biggestTimeSpan) {
2322
+ const min = moment_shim_default(newStop).subtract(p.biggestTimeSpan);
2323
+ if (min.isSameOrAfter(newStart)) {
2324
+ newStart = min;
2325
+ maxTimespan2 = true;
2326
+ }
2327
+ }
2328
+ handleAutoSliding(mouse, onResizeLeftCursor);
2329
+ if (newStop !== s.stop && newStop.isSameOrBefore(s.domain.max) || newStart.isSameOrAfter(s.domain.min)) {
2330
+ patchState({ start: newStart, stop: newStop, maxTimespan: maxTimespan2 });
2331
+ }
2332
+ }, [handleAutoSliding, patchState]);
2333
+ const onResizeRightCursor = react.useCallback((delta, mouse) => {
2334
+ const xAxis = xAxisRef.current;
2335
+ const s = stateRef.current;
2336
+ const p = propsRef.current;
2337
+ let newStop = moment_shim_default(xAxis.invert(xAxis(s.stop) + delta));
2338
+ let newStart = s.start;
2339
+ let maxTimespan2 = false;
2340
+ if (newStop.isSameOrBefore(newStart)) {
2341
+ newStart = moment_shim_default(xAxis.invert(xAxis(newStart) + delta));
2342
+ }
2343
+ if (p.biggestTimeSpan) {
2344
+ const max2 = moment_shim_default(newStart).add(p.biggestTimeSpan);
2345
+ if (max2.isSameOrBefore(newStop)) {
2346
+ newStop = max2;
2347
+ maxTimespan2 = true;
2348
+ }
2349
+ }
2350
+ handleAutoSliding(mouse, onResizeRightCursor);
2351
+ if (newStop.isSameOrBefore(s.domain.max) && newStart.isSameOrAfter(s.domain.min)) {
2352
+ patchState({ start: newStart, stop: newStop, maxTimespan: maxTimespan2 });
2353
+ }
2354
+ }, [handleAutoSliding, patchState]);
2355
+ const onDragCursor = react.useCallback((delta, mouse) => {
2356
+ const xAxis = xAxisRef.current;
2357
+ const s = stateRef.current;
2358
+ const p = propsRef.current;
2359
+ xAxis.clamp(false);
2360
+ const duration = s.stop.diff(s.start);
2361
+ let newStart = moment_shim_default(xAxis.invert(xAxis(s.start) + delta));
2362
+ let newStop = moment_shim_default(newStart).add(duration, "milliseconds");
2363
+ xAxis.clamp(true);
2364
+ const { maxDomain } = p;
2365
+ if (maxDomain.min && newStart.isBefore(maxDomain.min)) newStart = moment_shim_default(maxDomain.min);
2366
+ if (maxDomain.max && newStop.isAfter(maxDomain.max)) newStop = moment_shim_default(maxDomain.max);
2367
+ handleAutoSliding(mouse, onDragCursor);
2368
+ patchState({ start: newStart, stop: newStop });
2369
+ }, [handleAutoSliding, patchState]);
2370
+ const onStartDrawCursor = react.useCallback((pos) => {
2371
+ const xAxis = xAxisRef.current;
2372
+ patchState({
2373
+ start: moment_shim_default(xAxis.invert(pos)),
2374
+ stop: moment_shim_default(xAxis.invert(pos + 1)),
2375
+ maxTimespan: false
2376
+ });
2377
+ }, [patchState]);
2378
+ const onDrawCursor = react.useCallback((delta, mouse) => {
2379
+ const xAxis = xAxisRef.current;
2380
+ const s = stateRef.current;
2381
+ const p = propsRef.current;
2382
+ let newStop = moment_shim_default(xAxis.invert(xAxis(s.stop) + delta));
2383
+ let newStart = s.start;
2384
+ let maxTimespan2 = false;
2385
+ if (newStop.isSameOrBefore(newStart)) {
2386
+ newStart = moment_shim_default(xAxis.invert(xAxis(newStart) + delta));
2387
+ }
2388
+ if (p.biggestTimeSpan) {
2389
+ const max2 = moment_shim_default(newStart).add(p.biggestTimeSpan);
2390
+ if (max2.isSameOrBefore(newStop)) {
2391
+ newStop = max2;
2392
+ maxTimespan2 = true;
2393
+ }
2394
+ }
2395
+ handleAutoSliding(mouse, onDrawCursor);
2396
+ if (newStop.isSameOrBefore(s.domain.max) && newStart.isSameOrAfter(s.domain.min)) {
2397
+ patchState({ start: newStart, stop: newStop, maxTimespan: maxTimespan2 });
2398
+ }
2399
+ }, [handleAutoSliding, patchState]);
2400
+ const onEndDrawCursor = react.useCallback(() => {
2401
+ stopAutoMove();
2402
+ const { onCustomRange, selectBarOnClick } = propsRef.current;
2403
+ const s = stateRef.current;
2404
+ let { start: start2, stop: stop2, barHovered: barHovered2 } = s;
2405
+ if (selectBarOnClick && itemsRef.current && barHovered2 > -1) {
2406
+ const item = itemsRef.current[barHovered2];
2407
+ if (start2.isSameOrAfter(item.start) && stop2.isSameOrBefore(item.end)) {
2408
+ start2 = moment_shim_default(item.start);
2409
+ stop2 = moment_shim_default(item.end);
2410
+ patchState({ start: start2, stop: stop2 });
2411
+ }
2412
+ }
2413
+ onCustomRange(start2, stop2);
2414
+ }, [stopAutoMove, patchState]);
2415
+ const onEndChangeCursor = react.useCallback(() => {
2416
+ stopAutoMove();
2417
+ const { onCustomRange } = propsRef.current;
2418
+ const { start: start2, stop: stop2 } = stateRef.current;
2419
+ onCustomRange(start2, stop2);
2420
+ }, [stopAutoMove]);
2421
+ const zoomOnDomain = react.useCallback((targetDomain) => {
2422
+ const p = propsRef.current;
2423
+ const s = stateRef.current;
2424
+ if (s.waitForLoad) return;
2425
+ if (targetDomain.min.isSame(s.domain.min) && targetDomain.max.isSame(s.domain.max)) {
2426
+ p.onShowMessage(labelsRef.current.zoomInWithoutChangingSelectionMsg);
2427
+ return;
2428
+ }
2429
+ const { maxZoom: maxZoom2, domain: domain2 } = checkAndCorrectDomain({ domain: targetDomain });
2430
+ const { maxZoom: currentMaxZoom } = s;
2431
+ if (maxZoom2 && maxZoom2 !== currentMaxZoom) {
2432
+ p.onShowMessage(labelsRef.current.zoomSelectionResolutionExtended);
2433
+ }
2434
+ const domains = [domain2, ...p.domains];
2435
+ patchState({ maxZoom: maxZoom2, minZoom: false, domain: domain2 });
2436
+ p.onUpdateDomains(domains);
2437
+ }, [checkAndCorrectDomain, patchState]);
2438
+ const zoomOutTo = react.useCallback((domains) => {
2439
+ const res = checkAndCorrectDomain({ domain: domains[0] });
2440
+ const { minZoom: minZoom2, domain: domain2, domainHasChanged, maxTime, minTime } = res;
2441
+ const p = propsRef.current;
2442
+ if (minZoom2) p.onShowMessage(labelsRef.current.minZoomMsg);
2443
+ if (minTime) p.onShowMessage(labelsRef.current.minDomainMsg);
2444
+ if (maxTime) p.onShowMessage(labelsRef.current.maxDomainMsg);
2445
+ const newDomains = domainHasChanged ? [domain2, ...p.domains.slice(1)] : domains;
2446
+ patchState({ maxZoom: false, minZoom: minZoom2, domain: domain2 });
2447
+ p.onUpdateDomains(newDomains);
2448
+ }, [checkAndCorrectDomain, patchState]);
2449
+ const zoomOnTarget = react.useCallback((x) => {
2450
+ const xAxis = xAxisRef.current;
2451
+ const [minOrigin, maxOrigin] = xAxis.domain();
2452
+ const target = moment_shim_default(xAxis.invert(x));
2453
+ const min = moment_shim_default(target).subtract(0.25 * target.diff(moment_shim_default(minOrigin)));
2454
+ const max2 = moment_shim_default(target).add(0.25 * moment_shim_default(maxOrigin).diff(target));
2455
+ zoomOnDomain({ min, max: max2 });
2456
+ }, [zoomOnDomain]);
2457
+ const zoomOutOfTarget = react.useCallback((x) => {
2458
+ const xAxis = xAxisRef.current;
2459
+ const [minOrigin, maxOrigin] = xAxis.domain();
2460
+ const target = moment_shim_default(xAxis.invert(x));
2461
+ const min = moment_shim_default(target).subtract(1.25 * target.diff(moment_shim_default(minOrigin)));
2462
+ const max2 = moment_shim_default(target).add(1.25 * moment_shim_default(maxOrigin).diff(target));
2463
+ zoomOutTo([{ min, max: max2 }]);
2464
+ }, [zoomOutTo]);
2465
+ const zoomIn = react.useCallback(() => {
2466
+ const s = stateRef.current;
2467
+ if (!s.maxZoom) {
2468
+ zoomOnDomain({ min: s.start, max: s.stop });
2469
+ } else {
2470
+ propsRef.current.onShowMessage(labelsRef.current.doubleClickMaxZoomMsg);
2471
+ }
2472
+ }, [zoomOnDomain]);
2473
+ const zoomOut = react.useCallback(() => {
2474
+ const s = stateRef.current;
2475
+ if (s.waitForLoad || s.minZoom) return;
2476
+ const p = propsRef.current;
2477
+ const domains = [...p.domains];
2478
+ if (domains.length > 1) {
2479
+ domains.shift();
2480
+ } else {
2481
+ const xAxis = xAxisRef.current;
2482
+ const [minOrigin, maxOrigin] = xAxis.domain();
2483
+ const halfDuration = moment_shim_default(maxOrigin).diff(moment_shim_default(minOrigin)) / 2;
2484
+ const target = moment_shim_default(minOrigin).add(halfDuration);
2485
+ const zoomOutFactor = p.zoomOutFactor ?? defaultZoomOutFactor;
2486
+ const min = moment_shim_default(target).subtract(zoomOutFactor * halfDuration);
2487
+ const max2 = moment_shim_default(target).add(zoomOutFactor * halfDuration);
2488
+ domains[0] = { min, max: max2 };
2489
+ }
2490
+ zoomOutTo(domains);
2491
+ }, [zoomOutTo]);
2492
+ const onWheel = react.useCallback((event) => {
2493
+ const s = stateRef.current;
2494
+ const p = propsRef.current;
2495
+ event.stopPropagation();
2496
+ const baseX = timelineElementRef.current?.getBoundingClientRect().left ?? 0;
2497
+ const x = event.clientX - baseX - s.margin.left;
2498
+ if (s.waitForLoad) return;
2499
+ if (event.deltaY < -50) {
2500
+ if (s.maxZoom) p.onShowMessage(labelsRef.current.scrollMaxZoomMsg);
2501
+ else zoomOnTarget(x);
2502
+ } else if (event.deltaY > 50) {
2503
+ if (s.minZoom) p.onShowMessage(labelsRef.current.minZoomMsg);
2504
+ else if (p.domains.length > 1) zoomOut();
2505
+ else zoomOutOfTarget(x);
2506
+ }
2507
+ }, [zoomOnTarget, zoomOut, zoomOutOfTarget]);
2508
+ const onGotoCursor = react.useCallback(() => {
2509
+ const s = stateRef.current;
2510
+ const p = propsRef.current;
2511
+ const middle = moment_shim_default(s.start).add(s.stop.diff(s.start) / 2);
2512
+ const xAxis = xAxisRef.current;
2513
+ xAxis.clamp(false);
2514
+ const currentX = s.histoWidth / 2;
2515
+ const newX = xAxis(middle);
2516
+ const newDomain = moveTimeLineCore(currentX - newX);
2517
+ const domains = [...p.domains];
2518
+ domains.splice(0, 1, newDomain);
2519
+ const newDomains = shiftDomainsPure(domains, newDomain, p.biggestVisibleDomain);
2520
+ p.onUpdateDomains(newDomains);
2521
+ xAxis.clamp(true);
2522
+ }, [moveTimeLineCore]);
2523
+ const onGoto = react.useCallback((d) => {
2524
+ const s = stateRef.current;
2525
+ const p = propsRef.current;
2526
+ const halfTimeAgg = s.stop.diff(s.start) / 2;
2527
+ const when = d || moment_shim_default();
2528
+ const newStop = moment_shim_default(when).add(halfTimeAgg);
2529
+ const newStart = moment_shim_default(when).subtract(halfTimeAgg);
2530
+ p.onCustomRange(newStart, newStop);
2531
+ }, []);
2532
+ const shiftTimeLine = react.useCallback((delta) => {
2533
+ const incr = delta / Math.abs(delta) * 8;
2534
+ let i = 0;
2535
+ function step() {
2536
+ moveTimeLine(incr);
2537
+ i += 8;
2538
+ if (i < Math.abs(delta)) setTimeout(step, 10);
2539
+ else movedTimeLine();
2540
+ }
2541
+ step();
2542
+ }, [moveTimeLine, movedTimeLine]);
2543
+ react.useEffect(() => () => {
2544
+ if (autoMoveRef.current) clearInterval(autoMoveRef.current);
2545
+ }, []);
2546
+ react.useImperativeHandle(ref, () => ({ zoomIn, zoomOut, shiftTimeLine }), [zoomIn, zoomOut, shiftTimeLine]);
2547
+ const {
2548
+ isActive,
2549
+ domain,
2550
+ histoWidth,
2551
+ margin,
2552
+ start,
2553
+ stop,
2554
+ maxZoom,
2555
+ minZoom,
2556
+ maxTimespan,
2557
+ barHovered,
2558
+ tooltipVisible,
2559
+ ticks,
2560
+ dragging
2561
+ } = state;
2562
+ const xAxisHeight = xAxisProp.height || xAxisDefault.height;
2563
+ const pointZero = { x: 0, y: height - margin.bottom - xAxisHeight };
2564
+ const originCursor = { x: 0, y: margin.top - 5 };
2565
+ if (!isFunction(xAxisRef.current)) return null;
2566
+ const { verticalScale, verticalMarks, maxHeight } = prepareVerticalScale();
2567
+ const items = prepareHistogram({ domain, verticalScale });
2568
+ itemsRef.current = items;
2569
+ return /* @__PURE__ */ jsxRuntime.jsx(
2570
+ "svg",
2571
+ {
2572
+ ref: timelineElementRef,
2573
+ width,
2574
+ height,
2575
+ onWheel: isActive ? onWheel : void 0,
2576
+ children: /* @__PURE__ */ jsxRuntime.jsxs("g", { transform: `translate(${margin.left},${margin.top})`, children: [
2577
+ yAxisProp.showGrid && /* @__PURE__ */ jsxRuntime.jsx(
2578
+ YAxis2,
2579
+ {
2580
+ classes,
2581
+ origin: pointZero,
2582
+ yAxis: verticalScale,
2583
+ marks: verticalMarks,
2584
+ xAxisWidth: histoWidth + 13
2585
+ }
2586
+ ),
2587
+ xAxisProp.showGrid && /* @__PURE__ */ jsxRuntime.jsx(
2588
+ XAxis2,
2589
+ {
2590
+ classes,
2591
+ origin: pointZero,
2592
+ xAxis: xAxisRef.current,
2593
+ marks: ticks,
2594
+ yAxisHeight: maxHeight
2595
+ }
2596
+ ),
2597
+ isActive && /* @__PURE__ */ jsxRuntime.jsx(
2598
+ Histogram2,
2599
+ {
2600
+ classes,
2601
+ origin: pointZero,
2602
+ items,
2603
+ histo,
2604
+ verticalScale,
2605
+ metricsDefinition,
2606
+ barHovered,
2607
+ dragging,
2608
+ tooltipVisible,
2609
+ onFormatTimeToolTips,
2610
+ onFormatMetricLegend,
2611
+ HistoToolTip
2612
+ }
2613
+ ),
2614
+ /* @__PURE__ */ jsxRuntime.jsx(
2615
+ XAxis3,
2616
+ {
2617
+ classes,
2618
+ origin: pointZero,
2619
+ axisWidth: histoWidth + 13,
2620
+ min: domain && domain.min,
2621
+ max: domain && domain.max,
2622
+ xAxis: xAxisRef.current,
2623
+ marks: ticks,
2624
+ arrowPath: xAxisProp.arrowPath,
2625
+ yAxisHeight: maxHeight,
2626
+ showGrid: xAxisProp.showGrid,
2627
+ onFormatTimeLegend
2628
+ }
2629
+ ),
2630
+ /* @__PURE__ */ jsxRuntime.jsx(
2631
+ Tools2,
2632
+ {
2633
+ classes,
2634
+ rcToolTipPrefixCls,
2635
+ origin: pointZero,
2636
+ histoWidth,
2637
+ isActive,
2638
+ tools,
2639
+ labels: labelsRef.current,
2640
+ onGoto,
2641
+ onResetTime,
2642
+ shiftTimeLine
2643
+ }
2644
+ ),
2645
+ /* @__PURE__ */ jsxRuntime.jsx(
2646
+ YAxis3,
2647
+ {
2648
+ classes,
2649
+ origin: pointZero,
2650
+ maxHeight,
2651
+ yAxis: verticalScale,
2652
+ marks: verticalMarks,
2653
+ arrowPath: yAxisProp.arrowPath,
2654
+ showGrid: yAxisProp.showGrid,
2655
+ xAxisWidth: histoWidth + 13,
2656
+ onFormatMetricLegend
2657
+ }
2658
+ ),
2659
+ showLegend && /* @__PURE__ */ jsxRuntime.jsx(
2660
+ Legend2,
2661
+ {
2662
+ classes,
2663
+ origin: { x: -5, y: margin.top + 2 },
2664
+ metricsDefinition
2665
+ }
2666
+ ),
2667
+ isActive && tools.cursor !== false && /* @__PURE__ */ jsxRuntime.jsx(
2668
+ Cursor2,
2669
+ {
2670
+ origin: originCursor,
2671
+ rcToolTipPrefixCls,
2672
+ classes,
2673
+ startPos: xAxisRef.current(start),
2674
+ startIsOutOfView: start.isBefore(domain.min) || start.isAfter(domain.max),
2675
+ endPos: xAxisRef.current(stop),
2676
+ endIsOutOfView: stop.isBefore(domain.min) || stop.isAfter(domain.max),
2677
+ cursorIsBeforeView: start.isBefore(domain.min) && stop.isBefore(domain.min),
2678
+ cursorIsAfterView: start.isAfter(domain.max) && stop.isAfter(domain.max),
2679
+ height: maxHeight,
2680
+ overlayHeight: height - margin.top,
2681
+ overlayWidth: histoWidth,
2682
+ tooltipVisible,
2683
+ barHovered,
2684
+ setToolTipVisible: (v) => patchState({ tooltipVisible: v }),
2685
+ setBarHovered: (b) => patchState({ barHovered: b }),
2686
+ items,
2687
+ showHistoToolTip,
2688
+ dragging,
2689
+ setDragging: (d) => patchState({ dragging: d }),
2690
+ canZoom: true,
2691
+ minZoom,
2692
+ maxZoom,
2693
+ startText: onFormatTimeToolTips(start),
2694
+ stopText: onFormatTimeToolTips(stop),
2695
+ maxSize: maxTimespan,
2696
+ tools,
2697
+ gotoCursorLabel: labelsRef.current.gotoCursor,
2698
+ zoomInLabel: labelsRef.current.zoomInLabel,
2699
+ zoomOutLabel: labelsRef.current.zoomOutLabel,
2700
+ zoomIn,
2701
+ zoomOut,
2702
+ onResizeLeftCursor,
2703
+ onResizeRightCursor,
2704
+ onEndResizeCursor: onEndChangeCursor,
2705
+ onDragCursor,
2706
+ onEndDragCursor: onEndChangeCursor,
2707
+ onStartDrawCursor,
2708
+ onDrawCursor,
2709
+ onEndCursor: onEndDrawCursor,
2710
+ onMoveDomain: moveTimeLine,
2711
+ onMovedDomain: movedTimeLine,
2712
+ onGotoCursor
2713
+ }
2714
+ ),
2715
+ isActive && quality && quality.items && /* @__PURE__ */ jsxRuntime.jsx(
2716
+ QualityLine,
2717
+ {
2718
+ classes,
2719
+ rcToolTipPrefixCls,
2720
+ origin: pointZero,
2721
+ quality,
2722
+ qualityScale,
2723
+ xAxis: xAxisRef.current
2724
+ }
2725
+ )
2726
+ ] })
2727
+ }
2728
+ );
2729
+ });
2730
+ var TimeLine2 = react.forwardRef(function TimeLineWrapper(props, ref) {
2731
+ const zone = props.timeZone;
2732
+ const [stack, setStack] = react.useState(
2733
+ () => props.domain ? [domainToMoments(props.domain, zone)] : []
2734
+ );
2735
+ const prevDomainRef = react.useRef(props.domain);
2736
+ react.useEffect(() => {
2737
+ if (prevDomainRef.current === props.domain) return;
2738
+ prevDomainRef.current = props.domain;
2739
+ if (!props.domain) {
2740
+ setStack([]);
2741
+ return;
2742
+ }
2743
+ const m = domainToMoments(props.domain, zone);
2744
+ setStack((prev) => {
2745
+ if (prev.length === 0) return [m];
2746
+ const top = prev[0];
2747
+ if (top.min.isSame(m.min) && top.max.isSame(m.max)) return prev;
2748
+ return [m, ...prev.slice(1)];
2749
+ });
2750
+ }, [props.domain, zone]);
2751
+ const handleUpdateDomains = react.useCallback((newDomains) => {
2752
+ setStack(newDomains);
2753
+ const top = newDomains[0];
2754
+ if (top && props.onDomainChange) {
2755
+ props.onDomainChange({ min: top.min.toDate(), max: top.max.toDate() });
2756
+ }
2757
+ }, [props.onDomainChange]);
2758
+ const handleLoadDefault = react.useCallback(() => {
2759
+ const ret = props.onLoadDefaultDomain?.();
2760
+ const apply = (d) => {
2761
+ if (!d) return;
2762
+ const m = domainToMoments(d, zone);
2763
+ setStack([m]);
2764
+ if (props.onDomainChange) {
2765
+ props.onDomainChange({ min: m.min.toDate(), max: m.max.toDate() });
2766
+ }
2767
+ };
2768
+ if (ret && typeof ret.then === "function") ret.then(apply);
2769
+ else if (ret) apply(ret);
2770
+ }, [props.onLoadDefaultDomain, props.onDomainChange, zone]);
2771
+ const innerProps = {
2772
+ ...props,
2773
+ domains: stack,
2774
+ timeSpan: props.timeSpan ? timeSpanToMoments(props.timeSpan, zone) : void 0,
2775
+ maxDomain: props.maxDomain ? domainToMoments(props.maxDomain, zone) : void 0,
2776
+ histo: props.histo?.items ? { ...props.histo, items: props.histo.items.map((it) => ({ ...it, time: toMoment(it.time, zone) })) } : props.histo,
2777
+ quality: props.quality?.items ? { ...props.quality, items: props.quality.items.map((it) => ({ ...it, time: toMoment(it.time, zone) })) } : props.quality,
2778
+ biggestVisibleDomain: props.biggestVisibleDomain != null ? toDuration(props.biggestVisibleDomain) : void 0,
2779
+ biggestTimeSpan: props.biggestTimeSpan != null ? toDuration(props.biggestTimeSpan) : void 0,
2780
+ smallestResolution: props.smallestResolution != null ? toDuration(props.smallestResolution) : void 0,
2781
+ onUpdateDomains: handleUpdateDomains,
2782
+ onLoadDefaultDomain: handleLoadDefault,
2783
+ // onLoadHisto: object shape + Date instants
2784
+ onLoadHisto: props.onLoadHisto ? (ms, start, end) => props.onLoadHisto({ intervalMs: ms, start: momentToDate(start), end: momentToDate(end) }) : void 0,
2785
+ // onCustomRange → onTimeSpanChange, object shape
2786
+ onCustomRange: props.onTimeSpanChange ? (start, stop) => props.onTimeSpanChange({ start: momentToDate(start), stop: momentToDate(stop) }) : props.onCustomRange,
2787
+ onFormatTimeToolTips: props.onFormatTimeToolTips ? (t) => props.onFormatTimeToolTips(momentToDate(t)) : void 0,
2788
+ onFormatTimeLegend: props.onFormatTimeLegend ? (t) => props.onFormatTimeLegend(momentToDate(t)) : void 0
2789
+ };
2790
+ return /* @__PURE__ */ jsxRuntime.jsx(TimeLineInner, { ...innerProps, ref });
23
2791
  });
24
- var _TimeLineResizer = _interopRequireDefault(require("./TimeLineResizer"));
25
- var _Cursor2 = _interopRequireDefault(require("./Cursor"));
26
- var _TimeLine2 = _interopRequireDefault(require("./TimeLine"));
27
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
2792
+ var TimeLine_default = TimeLine2;
2793
+ function checkAndCorrectDomainPure({
2794
+ domain,
2795
+ biggestVisibleDomain,
2796
+ maxDomain,
2797
+ smallestResolution,
2798
+ histoWidth
2799
+ }) {
2800
+ if (!domain) {
2801
+ return { domain, maxZoom: false, minZoom: false, domainHasChanged: false };
2802
+ }
2803
+ const newDomain = { ...domain };
2804
+ let domainHasChanged = false;
2805
+ const duration = newDomain.max.diff(newDomain.min);
2806
+ let maxZoom = false;
2807
+ const minRes = smallestResolution.asMilliseconds();
2808
+ if (duration <= histoWidth * minRes / 15) {
2809
+ maxZoom = true;
2810
+ newDomain.max = moment_shim_default(newDomain.min).add(histoWidth * minRes / 15, "ms");
2811
+ }
2812
+ let minTime;
2813
+ let maxTime;
2814
+ if (maxDomain?.min && newDomain.min.isBefore(maxDomain.min)) {
2815
+ newDomain.min = moment_shim_default(maxDomain.min);
2816
+ minTime = true;
2817
+ }
2818
+ if (maxDomain?.max && newDomain.max.isAfter(maxDomain.max)) {
2819
+ newDomain.max = moment_shim_default(maxDomain.max);
2820
+ maxTime = true;
2821
+ }
2822
+ let minZoom = false;
2823
+ if (biggestVisibleDomain && newDomain.max.isSameOrAfter(moment_shim_default(newDomain.min).add(biggestVisibleDomain))) {
2824
+ minZoom = true;
2825
+ newDomain.min = moment_shim_default(newDomain.max).subtract(biggestVisibleDomain);
2826
+ }
2827
+ if (!(newDomain.min.isSame(domain.min) && newDomain.max.isSame(domain.max))) {
2828
+ domainHasChanged = true;
2829
+ }
2830
+ return {
2831
+ domain: domainHasChanged ? newDomain : domain,
2832
+ maxZoom,
2833
+ minZoom,
2834
+ maxTime,
2835
+ minTime,
2836
+ domainHasChanged
2837
+ };
2838
+ }
2839
+ function shiftDomainsPure(domains, { min, max: max2 }, biggestVisibleDomain) {
2840
+ let toUpdate = false;
2841
+ const newDomains = domains.map((domain, index) => {
2842
+ if (min && min.isBefore(domain.min) || max2 && max2.isAfter(domain.max)) {
2843
+ toUpdate = true;
2844
+ if (index === domains.length - 1) {
2845
+ const newDomain = {
2846
+ min: min && min.isBefore(domain.min) ? min : domain.min,
2847
+ max: max2 && max2.isAfter(domain.max) ? max2 : domain.max
2848
+ };
2849
+ if (biggestVisibleDomain && moment_shim_default(newDomain.min).add(biggestVisibleDomain).isSameOrBefore(newDomain.max)) {
2850
+ if (min.isBefore(domain.min)) newDomain.max = moment_shim_default(min).add(biggestVisibleDomain);
2851
+ else newDomain.min = moment_shim_default(max2).subtract(biggestVisibleDomain);
2852
+ }
2853
+ return newDomain;
2854
+ }
2855
+ if (min && min.isBefore(domain.min)) {
2856
+ return { min, max: moment_shim_default(domain.max).subtract(domain.min.diff(min)) };
2857
+ }
2858
+ return { min: moment_shim_default(domain.min).add(max2.diff(domain.max)), max: max2 };
2859
+ }
2860
+ return domain;
2861
+ });
2862
+ return toUpdate ? newDomains : domains;
2863
+ }
2864
+ var defaultWidth = 900;
2865
+ var defaultHeight = 100;
2866
+ function TimeLineResizer(props) {
2867
+ const [dimensions, setDimensions] = react.useState({
2868
+ width: defaultWidth,
2869
+ height: defaultHeight
2870
+ });
2871
+ const container = react.useRef(null);
2872
+ const onViewResize = () => {
2873
+ if (container.current) {
2874
+ setDimensions({
2875
+ width: container.current.clientWidth,
2876
+ height: container.current.clientHeight
2877
+ });
2878
+ }
2879
+ };
2880
+ react.useEffect(() => {
2881
+ if (container.current) {
2882
+ onViewResize();
2883
+ window.addEventListener("resize", onViewResize);
2884
+ }
2885
+ }, [container.current]);
2886
+ return /* @__PURE__ */ jsxRuntime.jsx(
2887
+ "div",
2888
+ {
2889
+ ref: container,
2890
+ className: "tl-root tl-timelineContainer",
2891
+ children: /* @__PURE__ */ jsxRuntime.jsx(
2892
+ TimeLine_default,
2893
+ {
2894
+ ref: props.forwardedRef,
2895
+ width: dimensions.width,
2896
+ height: dimensions.height,
2897
+ ...props
2898
+ }
2899
+ )
2900
+ }
2901
+ );
2902
+ }
2903
+ function timeLineFwd(props, ref) {
2904
+ return /* @__PURE__ */ jsxRuntime.jsx(TimeLineResizer, { ...props, forwardedRef: ref });
2905
+ }
2906
+ var TimeLineResizer_default = react.forwardRef(timeLineFwd);
2907
+
2908
+ // src/index.ts
2909
+ var _TimeLine = TimeLine_default;
2910
+ var _TimeLineResizer = TimeLineResizer_default;
2911
+ var _Cursor = Cursor;
2912
+ var index_default = _TimeLineResizer;
2913
+
2914
+ exports.Cursor = _Cursor;
2915
+ exports.TimeLine = _TimeLine;
2916
+ exports.default = index_default;
2917
+ //# sourceMappingURL=index.js.map
2918
+ //# sourceMappingURL=index.js.map