From 0334af1f9344a8605efd856d8e4e175649447a51 Mon Sep 17 00:00:00 2001 From: Anastasiia Beriia Date: Wed, 2 Sep 2026 13:11:46 +0400 Subject: [PATCH] fix: tooltip orientation horizontal tracking --- src/YagrCore/plugins/tooltip/tooltip.ts | 3 +- tests/plugins/tooltip.test.ts | 37 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/YagrCore/plugins/tooltip/tooltip.ts b/src/YagrCore/plugins/tooltip/tooltip.ts index c22cc70..9069fde 100644 --- a/src/YagrCore/plugins/tooltip/tooltip.ts +++ b/src/YagrCore/plugins/tooltip/tooltip.ts @@ -348,7 +348,8 @@ class YagrTooltip { rows: [], }; const section = sections[scale]; - const cursorValue = Number(u.posToVal(top, scale).toFixed(2)); + const cursorPosition = u.scales[scale].ori === 0 ? left : top; + const cursorValue = Number(u.posToVal(cursorPosition, scale).toFixed(2)); const valueRender = getOptionValue(opts.value, scale); diff --git a/tests/plugins/tooltip.test.ts b/tests/plugins/tooltip.test.ts index 3915e2d..aad2122 100644 --- a/tests/plugins/tooltip.test.ts +++ b/tests/plugins/tooltip.test.ts @@ -47,6 +47,43 @@ describe('tooltip', () => { yagr.dispose(); }); + + it.each([ + {ori: 0 as const}, + {ori: 1 as const}, + ])( + 'should track cursor along the value scale with orientation $ori', + ({ori}) => { + const tracking = jest.fn(() => 0); + const yagr = gen({ + timeline: [1], + series: [{data: [1]}], + scales: { + y: {ori}, + }, + tooltip: { + tracking, + }, + }); + + const left = (yagr.uplot.bbox.left + yagr.uplot.bbox.width) / devicePixelRatio; + const top = (yagr.uplot.bbox.top + yagr.uplot.bbox.height) / devicePixelRatio; + const cursorPosition = ori === 0 ? left : top; + const expectedCursorValue = Number( + yagr.uplot.posToVal(cursorPosition, 'y').toFixed(2), + ); + + yagr.plugins.tooltip?.display({left: 10, top: 20, idx: 0}); + + expect(tracking).toHaveBeenCalledWith( + expect.anything(), + expectedCursorValue, + expect.anything(), + ); + + yagr.dispose(); + }, + ); }); describe('color', () => {