@rfkit/charts 1.3.3 → 1.3.4
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/index.js +37 -13
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -14432,25 +14432,49 @@ const useMarkers = (props)=>{
|
|
|
14432
14432
|
const totalPoints = segments.totalPoints || dataLength;
|
|
14433
14433
|
const intervalWidth = zoom.interval.end - zoom.interval.start + 1;
|
|
14434
14434
|
const insideLeft = (target.left * totalPoints / 100 - zoom.interval.start) * 100 / intervalWidth;
|
|
14435
|
-
let currentIndex = Math.
|
|
14436
|
-
currentIndex =
|
|
14437
|
-
const isPeakAt = (index)=>{
|
|
14438
|
-
if (index <= 0 || index >= dataLength - 1) return false;
|
|
14439
|
-
const value1 = data[index];
|
|
14440
|
-
return value1 > data[index - 1] && value1 > data[index + 1];
|
|
14441
|
-
};
|
|
14435
|
+
let currentIndex = Math.floor(dataLength * insideLeft / 100);
|
|
14436
|
+
if (100 === insideLeft) currentIndex = dataLength - 1;
|
|
14442
14437
|
let nextIndex = -1;
|
|
14443
|
-
if (
|
|
14444
|
-
|
|
14438
|
+
if (data.peaks?.peaks && Array.isArray(data.peaks.peaks)) {
|
|
14439
|
+
const peaks = data.peaks.peaks;
|
|
14440
|
+
if ('left' === direction) {
|
|
14441
|
+
let closestDist = 1 / 0;
|
|
14442
|
+
for (const peak of peaks)if (peak.index < currentIndex) {
|
|
14443
|
+
const dist = currentIndex - peak.index;
|
|
14444
|
+
if (dist < closestDist) {
|
|
14445
|
+
closestDist = dist;
|
|
14446
|
+
nextIndex = peak.index;
|
|
14447
|
+
}
|
|
14448
|
+
}
|
|
14449
|
+
} else {
|
|
14450
|
+
let closestDist = 1 / 0;
|
|
14451
|
+
for (const peak of peaks)if (peak.index > currentIndex) {
|
|
14452
|
+
const dist = peak.index - currentIndex;
|
|
14453
|
+
if (dist < closestDist) {
|
|
14454
|
+
closestDist = dist;
|
|
14455
|
+
nextIndex = peak.index;
|
|
14456
|
+
}
|
|
14457
|
+
}
|
|
14458
|
+
}
|
|
14459
|
+
}
|
|
14460
|
+
if (-1 === nextIndex) {
|
|
14461
|
+
const isPeakAt = (index)=>{
|
|
14462
|
+
if (index <= 0 || index >= dataLength - 1) return false;
|
|
14463
|
+
const value1 = data[index];
|
|
14464
|
+
return value1 > data[index - 1] && value1 > data[index + 1];
|
|
14465
|
+
};
|
|
14466
|
+
if ('left' === direction) {
|
|
14467
|
+
for(let i = currentIndex - 1; i > 0; i -= 1)if (isPeakAt(i)) {
|
|
14468
|
+
nextIndex = i;
|
|
14469
|
+
break;
|
|
14470
|
+
}
|
|
14471
|
+
} else for(let i = currentIndex + 1; i < dataLength - 1; i += 1)if (isPeakAt(i)) {
|
|
14445
14472
|
nextIndex = i;
|
|
14446
14473
|
break;
|
|
14447
14474
|
}
|
|
14448
|
-
} else for(let i = currentIndex + 1; i < dataLength - 1; i += 1)if (isPeakAt(i)) {
|
|
14449
|
-
nextIndex = i;
|
|
14450
|
-
break;
|
|
14451
14475
|
}
|
|
14452
14476
|
if (-1 === nextIndex) return prevState;
|
|
14453
|
-
const nextInsideLeft =
|
|
14477
|
+
const nextInsideLeft = (nextIndex + 0.5) * 100 / dataLength;
|
|
14454
14478
|
const nextLeft = (nextInsideLeft * intervalWidth / 100 + zoom.interval.start) * (100 / totalPoints);
|
|
14455
14479
|
const nextMarkers = prevState.markers.map((m)=>{
|
|
14456
14480
|
if (m.id !== markerId) return {
|