Skip to content

Commit 7ad0111

Browse files
committed
revert, use different approach
1 parent 7df6851 commit 7ad0111

File tree

6 files changed

+16
-41
lines changed

6 files changed

+16
-41
lines changed

demos/nearest-non-null.html

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -335,25 +335,21 @@
335335

336336
let data = [
337337
[0,1,2,3,4,5,6,7,8,9],
338-
[5,5,5,5,_,_,5,5,5,5],
338+
[5,5,5,5,5,_,5,5,5,5],
339339
];
340340

341341
let opts = {
342-
title: 'Snap hover points (and/or cusror) to previous non-null',
342+
title: 'Snap hover points and cursor to previous non-null',
343343
width: 1000,
344344
height: 500,
345345
cursor: {
346-
// can use this if only snapping hover points, but keeping cursor at mouse coords
347-
hover: {
348-
bias: -1,
349-
skip: [null],
350-
},
351-
/*
352-
// OR...
346+
y: false,
353347

354-
// this manually implements bias instead of relying on dataIdx/hover opts since they
355-
// are invoked later (and currently depend on the output coords of cursor.move)
348+
// this manually implements custom skipping and bias behavior
356349
move: (u, mouseLeft, mouseTop) => {
350+
if (mouseLeft < 0)
351+
return [mouseLeft, mouseTop];
352+
357353
let curXVal = u.posToVal(mouseLeft, 'x');
358354
let curIdx = u.valToIdx(curXVal);
359355
let dataX = u.data[0];
@@ -376,7 +372,6 @@
376372
mouseTop,
377373
];
378374
},
379-
*/
380375
},
381376
scales: {
382377
x: {

dist/uPlot.cjs.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3508,6 +3508,8 @@ function uPlot(opts, data, then) {
35083508
if (seriesIdx == 0)
35093509
return cursorIdx;
35103510

3511+
let idx2 = cursorIdx;
3512+
35113513
let _prox = prox(self, seriesIdx, cursorIdx, valAtPosX) ?? inf;
35123514
let withProx = _prox >= 0 && _prox < inf;
35133515
let xDim = scaleX.ori == 0 ? plotWidCss : plotHgtCss;
@@ -3516,13 +3518,6 @@ function uPlot(opts, data, then) {
35163518
let xValues = data[0];
35173519
let yValues = data[seriesIdx];
35183520

3519-
if (bias == 1 && cursorIdx < dataLen - 1 && valAtPosX > xValues[cursorIdx])
3520-
cursorIdx++;
3521-
else if (bias == -1 && cursorIdx > 0 && valAtPosX < xValues[cursorIdx])
3522-
cursorIdx--;
3523-
3524-
let idx2 = cursorIdx;
3525-
35263521
if (skip.has(yValues[cursorIdx])) {
35273522
idx2 = null;
35283523

dist/uPlot.esm.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,6 +3506,8 @@ function uPlot(opts, data, then) {
35063506
if (seriesIdx == 0)
35073507
return cursorIdx;
35083508

3509+
let idx2 = cursorIdx;
3510+
35093511
let _prox = prox(self, seriesIdx, cursorIdx, valAtPosX) ?? inf;
35103512
let withProx = _prox >= 0 && _prox < inf;
35113513
let xDim = scaleX.ori == 0 ? plotWidCss : plotHgtCss;
@@ -3514,13 +3516,6 @@ function uPlot(opts, data, then) {
35143516
let xValues = data[0];
35153517
let yValues = data[seriesIdx];
35163518

3517-
if (bias == 1 && cursorIdx < dataLen - 1 && valAtPosX > xValues[cursorIdx])
3518-
cursorIdx++;
3519-
else if (bias == -1 && cursorIdx > 0 && valAtPosX < xValues[cursorIdx])
3520-
cursorIdx--;
3521-
3522-
let idx2 = cursorIdx;
3523-
35243519
if (skip.has(yValues[cursorIdx])) {
35253520
idx2 = null;
35263521

dist/uPlot.iife.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,6 +3509,8 @@ var uPlot = (function () {
35093509
if (seriesIdx == 0)
35103510
return cursorIdx;
35113511

3512+
let idx2 = cursorIdx;
3513+
35123514
let _prox = prox(self, seriesIdx, cursorIdx, valAtPosX) ?? inf;
35133515
let withProx = _prox >= 0 && _prox < inf;
35143516
let xDim = scaleX.ori == 0 ? plotWidCss : plotHgtCss;
@@ -3517,13 +3519,6 @@ var uPlot = (function () {
35173519
let xValues = data[0];
35183520
let yValues = data[seriesIdx];
35193521

3520-
if (bias == 1 && cursorIdx < dataLen - 1 && valAtPosX > xValues[cursorIdx])
3521-
cursorIdx++;
3522-
else if (bias == -1 && cursorIdx > 0 && valAtPosX < xValues[cursorIdx])
3523-
cursorIdx--;
3524-
3525-
let idx2 = cursorIdx;
3526-
35273522
if (skip.has(yValues[cursorIdx])) {
35283523
idx2 = null;
35293524

dist/uPlot.iife.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uPlot.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,8 @@ export default function uPlot(opts, data, then) {
893893
if (seriesIdx == 0)
894894
return cursorIdx;
895895

896+
let idx2 = cursorIdx;
897+
896898
let _prox = prox(self, seriesIdx, cursorIdx, valAtPosX) ?? inf;
897899
let withProx = _prox >= 0 && _prox < inf;
898900
let xDim = scaleX.ori == 0 ? plotWidCss : plotHgtCss;
@@ -901,13 +903,6 @@ export default function uPlot(opts, data, then) {
901903
let xValues = data[0];
902904
let yValues = data[seriesIdx];
903905

904-
if (bias == 1 && cursorIdx < dataLen - 1 && valAtPosX > xValues[cursorIdx])
905-
cursorIdx++;
906-
else if (bias == -1 && cursorIdx > 0 && valAtPosX < xValues[cursorIdx])
907-
cursorIdx--;
908-
909-
let idx2 = cursorIdx;
910-
911906
if (skip.has(yValues[cursorIdx])) {
912907
idx2 = null;
913908

0 commit comments

Comments
 (0)