@spider-analyzer/timeline 5.0.6 → 5.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/dist/index.js +61 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Cursor.jsx +3 -3
- package/src/TimeLine.tsx +36 -13
- package/src/cursorElements/CursorSelection.jsx +3 -3
- package/src/cursorElements/DragOverlay.jsx +3 -3
- package/src/moment-shim.ts +25 -0
- package/src/timeLineElements/HistoToolTip.jsx +3 -3
- package/src/timeLineElements/Histogram.jsx +7 -5
- package/src/timeLineElements/QualityLine.jsx +2 -2
- package/src/timeLineElements/XAxis.jsx +7 -5
- package/src/timeLineElements/XGrid.jsx +4 -2
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { forwardRef, useRef, useEffect, useState, useCallback, useImperativeHandle, useMemo } from 'react';
|
|
1
|
+
import { forwardRef, memo, useRef, useEffect, useState, useCallback, useImperativeHandle, useMemo } from 'react';
|
|
2
|
+
import { flushSync } from 'react-dom';
|
|
2
3
|
import { DateTime, Duration } from 'luxon';
|
|
3
4
|
import { scaleLinear, scaleTime } from 'd3-scale';
|
|
4
5
|
import PropTypes11 from 'prop-types';
|
|
@@ -162,6 +163,25 @@ moment.tz = (x, zone) => {
|
|
|
162
163
|
const base = toDT(x);
|
|
163
164
|
return new MomentLike(base.setZone(zone));
|
|
164
165
|
};
|
|
166
|
+
function validate(props, propName, componentName) {
|
|
167
|
+
const v = props[propName];
|
|
168
|
+
if (v == null) return null;
|
|
169
|
+
if (moment.isMoment(v)) return null;
|
|
170
|
+
return new Error(
|
|
171
|
+
`Invalid prop \`${propName}\` supplied to \`${componentName}\`, expected a moment-like object.`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
var required = (props, propName, componentName) => {
|
|
175
|
+
const v = props[propName];
|
|
176
|
+
if (v == null) {
|
|
177
|
+
return new Error(
|
|
178
|
+
`The prop \`${propName}\` is marked as required in \`${componentName}\`, but its value is \`${v}\`.`
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
return validate(props, propName, componentName);
|
|
182
|
+
};
|
|
183
|
+
var momentType = validate;
|
|
184
|
+
momentType.isRequired = required;
|
|
165
185
|
var moment_shim_default = moment;
|
|
166
186
|
|
|
167
187
|
// src/utils.ts
|
|
@@ -365,8 +385,8 @@ DragOverlay.propTypes = {
|
|
|
365
385
|
width: PropTypes11.number.isRequired,
|
|
366
386
|
marginBottom: PropTypes11.number,
|
|
367
387
|
items: PropTypes11.arrayOf(PropTypes11.shape({
|
|
368
|
-
start:
|
|
369
|
-
end:
|
|
388
|
+
start: momentType.isRequired,
|
|
389
|
+
end: momentType.isRequired,
|
|
370
390
|
x1: PropTypes11.number,
|
|
371
391
|
x2: PropTypes11.number,
|
|
372
392
|
metrics: PropTypes11.arrayOf(PropTypes11.number).isRequired,
|
|
@@ -676,8 +696,8 @@ CursorSelection.propTypes = {
|
|
|
676
696
|
showToolTipLeft: PropTypes11.func.isRequired,
|
|
677
697
|
showToolTipRight: PropTypes11.func.isRequired,
|
|
678
698
|
items: PropTypes11.arrayOf(PropTypes11.shape({
|
|
679
|
-
start:
|
|
680
|
-
end:
|
|
699
|
+
start: momentType.isRequired,
|
|
700
|
+
end: momentType.isRequired,
|
|
681
701
|
x1: PropTypes11.number,
|
|
682
702
|
x2: PropTypes11.number,
|
|
683
703
|
metrics: PropTypes11.arrayOf(PropTypes11.number).isRequired,
|
|
@@ -1263,8 +1283,8 @@ Cursor.propTypes = {
|
|
|
1263
1283
|
overlayHeight: PropTypes11.number.isRequired,
|
|
1264
1284
|
overlayWidth: PropTypes11.number.isRequired,
|
|
1265
1285
|
items: PropTypes11.arrayOf(PropTypes11.shape({
|
|
1266
|
-
start:
|
|
1267
|
-
end:
|
|
1286
|
+
start: momentType.isRequired,
|
|
1287
|
+
end: momentType.isRequired,
|
|
1268
1288
|
x1: PropTypes11.number,
|
|
1269
1289
|
x2: PropTypes11.number,
|
|
1270
1290
|
metrics: PropTypes11.arrayOf(PropTypes11.number).isRequired,
|
|
@@ -1373,8 +1393,8 @@ function Histogram({
|
|
|
1373
1393
|
Histogram.propTypes = {
|
|
1374
1394
|
classes: PropTypes11.object,
|
|
1375
1395
|
items: PropTypes11.arrayOf(PropTypes11.shape({
|
|
1376
|
-
start:
|
|
1377
|
-
end:
|
|
1396
|
+
start: momentType.isRequired,
|
|
1397
|
+
end: momentType.isRequired,
|
|
1378
1398
|
x1: PropTypes11.number,
|
|
1379
1399
|
x2: PropTypes11.number,
|
|
1380
1400
|
metrics: PropTypes11.arrayOf(PropTypes11.number).isRequired,
|
|
@@ -1400,6 +1420,7 @@ Histogram.propTypes = {
|
|
|
1400
1420
|
barHovered: PropTypes11.number,
|
|
1401
1421
|
tooltipVisible: PropTypes11.bool
|
|
1402
1422
|
};
|
|
1423
|
+
var Histogram_default = memo(Histogram);
|
|
1403
1424
|
|
|
1404
1425
|
// src/timeLineElements/axesStyles.jsx
|
|
1405
1426
|
var arrow = `m 0,-5 5,5 -5,5`;
|
|
@@ -1474,8 +1495,8 @@ function XAxis({ min, max: max2, origin, axisWidth, marks, xAxis, classes, arrow
|
|
|
1474
1495
|
XAxis.propTypes = {
|
|
1475
1496
|
axisWidth: PropTypes11.number.isRequired,
|
|
1476
1497
|
classes: PropTypes11.object,
|
|
1477
|
-
min:
|
|
1478
|
-
max:
|
|
1498
|
+
min: momentType,
|
|
1499
|
+
max: momentType,
|
|
1479
1500
|
origin: PropTypes11.shape({
|
|
1480
1501
|
x: PropTypes11.number.isRequired,
|
|
1481
1502
|
y: PropTypes11.number.isRequired
|
|
@@ -1485,6 +1506,7 @@ XAxis.propTypes = {
|
|
|
1485
1506
|
arrowPath: PropTypes11.string,
|
|
1486
1507
|
onFormatTimeLegend: PropTypes11.func.isRequired
|
|
1487
1508
|
};
|
|
1509
|
+
var XAxis_default = memo(XAxis);
|
|
1488
1510
|
function YAxis({ classes, marks, yAxis, onFormatMetricLegend, maxHeight, origin, arrowPath = arrow }) {
|
|
1489
1511
|
const className = (n) => cn(n, classes);
|
|
1490
1512
|
return /* @__PURE__ */ jsxs(
|
|
@@ -1800,8 +1822,8 @@ function HistoTooltip({ metricsDefinition, item, onFormatTimeToolTips, onFormatM
|
|
|
1800
1822
|
HistoTooltip.propTypes = {
|
|
1801
1823
|
classes: PropTypes11.object,
|
|
1802
1824
|
item: PropTypes11.shape({
|
|
1803
|
-
start:
|
|
1804
|
-
end:
|
|
1825
|
+
start: momentType.isRequired,
|
|
1826
|
+
end: momentType.isRequired,
|
|
1805
1827
|
x1: PropTypes11.number,
|
|
1806
1828
|
x2: PropTypes11.number,
|
|
1807
1829
|
metrics: PropTypes11.arrayOf(PropTypes11.number).isRequired,
|
|
@@ -1869,7 +1891,7 @@ QualityLine.propTypes = {
|
|
|
1869
1891
|
xAxis: PropTypes11.func.isRequired,
|
|
1870
1892
|
quality: PropTypes11.shape({
|
|
1871
1893
|
items: PropTypes11.arrayOf(PropTypes11.shape({
|
|
1872
|
-
time:
|
|
1894
|
+
time: momentType.isRequired,
|
|
1873
1895
|
quality: PropTypes11.number.isRequired,
|
|
1874
1896
|
tip: PropTypes11.node
|
|
1875
1897
|
})),
|
|
@@ -1939,6 +1961,7 @@ XAxis2.propTypes = {
|
|
|
1939
1961
|
xAxis: PropTypes11.func,
|
|
1940
1962
|
yAxisHeight: PropTypes11.number
|
|
1941
1963
|
};
|
|
1964
|
+
var XGrid_default = memo(XAxis2);
|
|
1942
1965
|
|
|
1943
1966
|
// src/time.ts
|
|
1944
1967
|
function toMoment(x, zone) {
|
|
@@ -1961,8 +1984,8 @@ function timeSpanToMoments(t, zone) {
|
|
|
1961
1984
|
return { start: toMomentOpt(t.start, zone), stop: toMomentOpt(t.stop, zone) };
|
|
1962
1985
|
}
|
|
1963
1986
|
var Cursor2 = Cursor;
|
|
1964
|
-
var Histogram2 =
|
|
1965
|
-
var XAxis3 =
|
|
1987
|
+
var Histogram2 = Histogram_default;
|
|
1988
|
+
var XAxis3 = XAxis_default;
|
|
1966
1989
|
var YAxis3 = YAxis;
|
|
1967
1990
|
var Legend2 = Legend;
|
|
1968
1991
|
var Tools2 = Tools;
|
|
@@ -2057,6 +2080,11 @@ var TimeLineInner = forwardRef(function TimeLine(props, ref) {
|
|
|
2057
2080
|
const patchState = useCallback((patch) => {
|
|
2058
2081
|
setStateRaw((s) => ({ ...s, ...typeof patch === "function" ? patch(s) : patch }));
|
|
2059
2082
|
}, []);
|
|
2083
|
+
const patchStateSync = useCallback((patch) => {
|
|
2084
|
+
flushSync(() => {
|
|
2085
|
+
setStateRaw((s) => ({ ...s, ...typeof patch === "function" ? patch(s) : patch }));
|
|
2086
|
+
});
|
|
2087
|
+
}, []);
|
|
2060
2088
|
const checkAndCorrectDomain = useCallback(({ domain: domain2 }) => {
|
|
2061
2089
|
return checkAndCorrectDomainPure({
|
|
2062
2090
|
domain: domain2,
|
|
@@ -2300,9 +2328,9 @@ var TimeLineInner = forwardRef(function TimeLine(props, ref) {
|
|
|
2300
2328
|
movedSinceLastFetchedRef.current = 0;
|
|
2301
2329
|
getItems(p, { min, max: max2 });
|
|
2302
2330
|
}
|
|
2303
|
-
|
|
2331
|
+
patchStateSync({ domain: { min, max: max2 }, minTime, maxTime, ticks: ticks2 });
|
|
2304
2332
|
}
|
|
2305
|
-
}, [moveTimeLineCore, getItems,
|
|
2333
|
+
}, [moveTimeLineCore, getItems, patchStateSync]);
|
|
2306
2334
|
const onResizeLeftCursor = useCallback((delta, mouse) => {
|
|
2307
2335
|
const xAxis = xAxisRef.current;
|
|
2308
2336
|
const s = stateRef.current;
|
|
@@ -2322,9 +2350,9 @@ var TimeLineInner = forwardRef(function TimeLine(props, ref) {
|
|
|
2322
2350
|
}
|
|
2323
2351
|
handleAutoSliding(mouse, onResizeLeftCursor);
|
|
2324
2352
|
if (newStop !== s.stop && newStop.isSameOrBefore(s.domain.max) || newStart.isSameOrAfter(s.domain.min)) {
|
|
2325
|
-
|
|
2353
|
+
patchStateSync({ start: newStart, stop: newStop, maxTimespan: maxTimespan2 });
|
|
2326
2354
|
}
|
|
2327
|
-
}, [handleAutoSliding,
|
|
2355
|
+
}, [handleAutoSliding, patchStateSync]);
|
|
2328
2356
|
const onResizeRightCursor = useCallback((delta, mouse) => {
|
|
2329
2357
|
const xAxis = xAxisRef.current;
|
|
2330
2358
|
const s = stateRef.current;
|
|
@@ -2344,9 +2372,9 @@ var TimeLineInner = forwardRef(function TimeLine(props, ref) {
|
|
|
2344
2372
|
}
|
|
2345
2373
|
handleAutoSliding(mouse, onResizeRightCursor);
|
|
2346
2374
|
if (newStop.isSameOrBefore(s.domain.max) && newStart.isSameOrAfter(s.domain.min)) {
|
|
2347
|
-
|
|
2375
|
+
patchStateSync({ start: newStart, stop: newStop, maxTimespan: maxTimespan2 });
|
|
2348
2376
|
}
|
|
2349
|
-
}, [handleAutoSliding,
|
|
2377
|
+
}, [handleAutoSliding, patchStateSync]);
|
|
2350
2378
|
const onDragCursor = useCallback((delta, mouse) => {
|
|
2351
2379
|
const xAxis = xAxisRef.current;
|
|
2352
2380
|
const s = stateRef.current;
|
|
@@ -2360,8 +2388,8 @@ var TimeLineInner = forwardRef(function TimeLine(props, ref) {
|
|
|
2360
2388
|
if (maxDomain.min && newStart.isBefore(maxDomain.min)) newStart = moment_shim_default(maxDomain.min);
|
|
2361
2389
|
if (maxDomain.max && newStop.isAfter(maxDomain.max)) newStop = moment_shim_default(maxDomain.max);
|
|
2362
2390
|
handleAutoSliding(mouse, onDragCursor);
|
|
2363
|
-
|
|
2364
|
-
}, [handleAutoSliding,
|
|
2391
|
+
patchStateSync({ start: newStart, stop: newStop });
|
|
2392
|
+
}, [handleAutoSliding, patchStateSync]);
|
|
2365
2393
|
const onStartDrawCursor = useCallback((pos) => {
|
|
2366
2394
|
const xAxis = xAxisRef.current;
|
|
2367
2395
|
patchState({
|
|
@@ -2389,9 +2417,9 @@ var TimeLineInner = forwardRef(function TimeLine(props, ref) {
|
|
|
2389
2417
|
}
|
|
2390
2418
|
handleAutoSliding(mouse, onDrawCursor);
|
|
2391
2419
|
if (newStop.isSameOrBefore(s.domain.max) && newStart.isSameOrAfter(s.domain.min)) {
|
|
2392
|
-
|
|
2420
|
+
patchStateSync({ start: newStart, stop: newStop, maxTimespan: maxTimespan2 });
|
|
2393
2421
|
}
|
|
2394
|
-
}, [handleAutoSliding,
|
|
2422
|
+
}, [handleAutoSliding, patchStateSync]);
|
|
2395
2423
|
const onEndDrawCursor = useCallback(() => {
|
|
2396
2424
|
stopAutoMove();
|
|
2397
2425
|
const { onCustomRange, selectBarOnClick } = propsRef.current;
|
|
@@ -2554,13 +2582,17 @@ var TimeLineInner = forwardRef(function TimeLine(props, ref) {
|
|
|
2554
2582
|
ticks,
|
|
2555
2583
|
dragging
|
|
2556
2584
|
} = state;
|
|
2585
|
+
const verticalScaleData = useMemo(() => prepareVerticalScale(), [prepareVerticalScale]);
|
|
2586
|
+
const items = useMemo(
|
|
2587
|
+
() => prepareHistogram({ domain, verticalScale: verticalScaleData.verticalScale }),
|
|
2588
|
+
[prepareHistogram, domain, verticalScaleData, histoWidth]
|
|
2589
|
+
);
|
|
2590
|
+
itemsRef.current = items;
|
|
2557
2591
|
const xAxisHeight = xAxisProp.height || xAxisDefault.height;
|
|
2558
2592
|
const pointZero = { x: 0, y: height - margin.bottom - xAxisHeight };
|
|
2559
2593
|
const originCursor = { x: 0, y: margin.top - 5 };
|
|
2560
2594
|
if (!isFunction(xAxisRef.current)) return null;
|
|
2561
|
-
const { verticalScale, verticalMarks, maxHeight } =
|
|
2562
|
-
const items = prepareHistogram({ domain, verticalScale });
|
|
2563
|
-
itemsRef.current = items;
|
|
2595
|
+
const { verticalScale, verticalMarks, maxHeight } = verticalScaleData;
|
|
2564
2596
|
return /* @__PURE__ */ jsx(
|
|
2565
2597
|
"svg",
|
|
2566
2598
|
{
|
|
@@ -2580,7 +2612,7 @@ var TimeLineInner = forwardRef(function TimeLine(props, ref) {
|
|
|
2580
2612
|
}
|
|
2581
2613
|
),
|
|
2582
2614
|
xAxisProp.showGrid && /* @__PURE__ */ jsx(
|
|
2583
|
-
|
|
2615
|
+
XGrid_default,
|
|
2584
2616
|
{
|
|
2585
2617
|
classes,
|
|
2586
2618
|
origin: pointZero,
|