MCPcopy Index your code
hub / github.com/leeoniya/uPlot / updateCursor

Function updateCursor

src/uPlot.js:2686–3070  ·  view source on GitHub ↗
(src, _fire, _pub)

Source from the content-addressed store, hash-verified

2684 }
2685
2686 function updateCursor(src, _fire, _pub) {
2687 // ts == null && log("updateCursor()", arguments);
2688
2689 rawMouseLeft1 = mouseLeft1;
2690 rawMouseTop1 = mouseTop1;
2691
2692 [mouseLeft1, mouseTop1] = cursor.move(self, mouseLeft1, mouseTop1);
2693
2694 cursor.left = mouseLeft1;
2695 cursor.top = mouseTop1;
2696
2697 if (showCursor) {
2698 vCursor && elTrans(vCursor, round(mouseLeft1), 0, plotWidCss, plotHgtCss);
2699 hCursor && elTrans(hCursor, 0, round(mouseTop1), plotWidCss, plotHgtCss);
2700 }
2701
2702 let idx;
2703
2704 // when zooming to an x scale range between datapoints the binary search
2705 // for nearest min/max indices results in this condition. cheap hack :D
2706 let noDataInRange = i0 > i1; // works for mode 1 only
2707
2708 closestDist = inf;
2709 closestSeries = null;
2710
2711 // TODO: extract
2712 let xDim = scaleX.ori == 0 ? plotWidCss : plotHgtCss;
2713 let yDim = scaleX.ori == 1 ? plotWidCss : plotHgtCss;
2714
2715 // if cursor hidden, hide points & clear legend vals
2716 if (mouseLeft1 < 0 || dataLen == 0 || noDataInRange) {
2717 idx = cursor.idx = null;
2718
2719 for (let i = 0; i < series.length; i++) {
2720 let pt = cursorPts[i];
2721 pt != null && elTrans(pt, -10, -10, plotWidCss, plotHgtCss);
2722 }
2723
2724 if (cursorFocus)
2725 setSeries(null, FOCUS_TRUE, true, src == null && syncOpts.setSeries);
2726
2727 if (FEAT_LEGEND && legend.live) {
2728 activeIdxs.fill(idx);
2729 shouldSetLegend = true;
2730 }
2731 }
2732 else {
2733 // let pctY = 1 - (y / rect.height);
2734
2735 let mouseXPos, valAtPosX, xPos;
2736
2737 if (mode == 1) {
2738 mouseXPos = scaleX.ori == 0 ? mouseLeft1 : mouseTop1;
2739 valAtPosX = posToVal(mouseXPos, xScaleKey);
2740 idx = cursor.idx = closestIdx(valAtPosX, data[0], i0, i1);
2741 xPos = valToPosX(data[0][idx], scaleX, xDim, 0);
2742 }
2743

Callers 5

_commitFunction · 0.85
uPlotFunction · 0.85
mouseMoveFunction · 0.85
mouseUpFunction · 0.85
mouseLeaveFunction · 0.85

Calls 10

elTransFunction · 0.90
closestIdxFunction · 0.90
elSizeFunction · 0.90
elColorFunction · 0.90
setSeriesFunction · 0.85
posToValFunction · 0.85
hideSelectFunction · 0.85
pubSyncFunction · 0.85
setLegendFunction · 0.85
fireFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…