Skip to content

Commit

Permalink
fix: tooltip pinnig (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
zefirka authored Jul 13, 2023
1 parent 4021753 commit 2d2b4a4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/YagrCore/plugins/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ class YagrTooltip {
};

private onMouseDown = () => {
this.state.range = [this.evtToRange(), null];
this.state.range = [this.getCursorPosition(), null];
};

private detectClickOutside = (event: MouseEvent) => {
Expand All @@ -534,14 +534,18 @@ class YagrTooltip {

private onMouseMove = () => {
if (this.state.range?.length) {
this.state.range[1] = this.evtToRange();
this.state.range[1] = this.getCursorPosition();
}
};

private onMouseUp = (event: MouseEvent) => {
private onMouseUp = () => {
const [from] = this.state.range || [];
const cursor = this.getCursorPosition();

if (this.opts.strategy === 'all' || (this.opts.strategy === 'pin' && from && from.clientX === event.clientX)) {
if (
this.opts.strategy === 'all' ||
(this.opts.strategy === 'pin' && from && from.clientX === cursor?.clientX)
) {
this.pin(!this.state.pinned);
this.show();
this.renderTooltipCloses();
Expand Down Expand Up @@ -585,7 +589,7 @@ class YagrTooltip {
return '-';
};

private evtToRange = (): SelectionRange[number] => {
private getCursorPosition = (): SelectionRange[number] => {
const x = this.yagr.uplot.cursor.left;

if (x === undefined) {
Expand Down

0 comments on commit 2d2b4a4

Please sign in to comment.