Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(draw_update): fix bug of mouse leave while hovering a shape #366

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.22.4]
### Fix
- Fix bug on tooltip origin when mouse leaving while hovering a shape

## [0.22.2]
### Fix
- Local import
Expand Down
2 changes: 2 additions & 0 deletions src/baseShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,6 @@ export class Shape {
public mouseUp(keepState: boolean): void {
this.isClicked = this.isHovered ? !this.isClicked : (keepState ? this.isClicked : false);
}

public mouseLeave(): void { this.isHovered = false }
}
2 changes: 2 additions & 0 deletions src/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export class ShapeCollection {

public mouseUp(keepState: boolean): void { this.shapes.forEach(shape => shape.mouseUp(keepState)) }

public mouseLeave(): void { this.shapes.forEach(shape => shape.mouseLeave()) }

public draw(context: CanvasRenderingContext2D): void { this.shapes.forEach(shape => shape.draw(context)) }

public removeShape(index: number): void {
Expand Down
17 changes: 17 additions & 0 deletions src/figures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,11 @@ export class Scatter extends Frame {
this.previousCoords = [];
}

public mouseLeave(): void {
super.mouseLeave();
this.previousCoords = [];
}

protected updateWithScale(): void {
super.updateWithScale();
if (this.nSamples > 0) this.computePoints();
Expand Down Expand Up @@ -798,6 +803,12 @@ export class Graph2D extends Scatter {
super.mouseUp(ctrlKey);
this.curves.forEach(curve => { if (curve.mouseClick) curve.previousMouseClick = curve.mouseClick.copy() });
}

public mouseLeave(): void {
super.mouseLeave();
this.curves.forEach(curve => { if (curve.mouseClick) curve.previousMouseClick = curve.mouseClick.copy() });
}

//TODO: Code duplicate, there is a middle class here between Scatter, Frame, Draw and Graph2D. Not so obvious.
public sendHoveredIndicesMultiplot(): number[] { return [] }

Expand Down Expand Up @@ -1033,6 +1044,12 @@ export class ParallelPlot extends Figure {
if (this.changedAxes.length == 0) this.clickedIndices = this.absoluteObjects.updateShapeStates('isClicked');
}

public mouseLeave(): void {
if (this.changedAxes.length != 0) this.updateAxesLocation();
super.mouseLeave();
if (this.changedAxes.length == 0) this.clickedIndices = this.absoluteObjects.updateShapeStates('isClicked');
}

protected regulateScale(): void {
for (const axis of this.axes) {
if (axis.boundingBox.isHovered) {
Expand Down
23 changes: 20 additions & 3 deletions src/remoteFigure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,14 @@ export class RemoteFigure {
this.fixedObjects.mouseUp(ctrlKey);
}

public mouseLeave(): void {
if (!this.isSelecting && !this.is_drawing_rubber_band && this.translation.normL1 < 10) {
this.absoluteObjects.mouseLeave();
this.relativeObjects.mouseLeave();
}
this.fixedObjects.mouseLeave();
}

public mouseMoveDrawer(canvas: HTMLElement, e: MouseEvent, canvasDown: Vertex, frameDown: Vertex, clickedObject: Shape): [Vertex, Vertex, Vertex] {
const [canvasMouse, frameMouse, absoluteMouse] = this.projectMouse(e);
this.isHovered = this.isInCanvas(absoluteMouse);
Expand All @@ -544,24 +552,33 @@ export class RemoteFigure {
return [canvasDown, frameDown, clickedObject]
}

public mouseUpDrawer(ctrlKey: boolean): [Shape, Vertex] {
private updateWithZoomBox(): void {
if (this.isZooming) {
if (this.zoomBox.area != 0) this.zoomBoxUpdateAxes(this.zoomBox);
this.zoomBox.update(new Vertex(0, 0), new Vertex(0, 0));
}
this.mouseUp(ctrlKey);
}

private mouseDropRedraw(): [Shape, Vertex] {
this.updateWithZoomBox();
this.draw();
return this.resetMouseEvents()
}

public mouseUpDrawer(ctrlKey: boolean): [Shape, Vertex] {
this.mouseUp(ctrlKey);
return this.mouseDropRedraw();
}

public mouseWheelDrawer(e: WheelEvent): void {
this.wheelFromEvent(e);
this.updateWithScale();
}

public mouseLeaveDrawer(canvas: HTMLElement, shiftKey: boolean): [boolean, Vertex] {
const isZooming = this.isZooming; // TODO: get rid of this with a mousehandler refactor
this.mouseUpDrawer(true);
this.mouseLeave();
this.mouseDropRedraw();
this.isZooming = isZooming;
this.axes.forEach(axis => {
axis.saveLocation();
Expand Down