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

Add zoom functionality to wafermap #923

Merged
merged 20 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 18 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
arinluca333 marked this conversation as resolved.
Show resolved Hide resolved
arinluca333 marked this conversation as resolved.
Show resolved Hide resolved
"type": "minor",
arinluca333 marked this conversation as resolved.
Show resolved Hide resolved
"comment": "Add zoom functionality to wafer map",
"packageName": "@ni/nimble-components",
"email": "49208904+arinluca333@users.noreply.github.com",
"dependentChangeType": "patch"
}
138 changes: 138 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/nimble-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
"@tanstack/table-core": "^8.7.0",
"@types/d3": "^7.4.0",
"@types/d3-scale": "^4.0.2",
"@types/d3-zoom": "^3.0.0",
"@types/d3-selection": "^3.0.0",
"d3-selection": "^3.0.0",
"d3-zoom": "^3.0.0",
"d3-random": "^3.0.1",
"d3-scale": "^4.0.2",
"hex-rgb": "^5.0.0",
Expand Down
27 changes: 23 additions & 4 deletions packages/nimble-components/src/wafer-map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from './types';
import { DataManager } from './modules/data-manager';
import { RenderingModule } from './modules/rendering';
import { ZoomHandler } from './modules/zoom-handler';

declare global {
interface HTMLElementTagNameMap {
Expand Down Expand Up @@ -62,7 +63,12 @@ export class WaferMap extends FoundationElement {
/**
* @internal
*/
@observable public canvasSideLength: number | undefined;
public readonly zoomContainer!: HTMLElement;

/**
* @internal
*/
arinluca333 marked this conversation as resolved.
Show resolved Hide resolved
@observable public canvasSideLength?: number;

@observable public colorScaleMode: WaferMapColorScaleMode = WaferMapColorScaleMode.linear;

Expand All @@ -74,9 +80,10 @@ export class WaferMap extends FoundationElement {
};

private renderQueued = false;
private dataManager: DataManager | undefined;
private renderer: RenderingModule | undefined;
private resizeObserver: ResizeObserver | undefined;
private dataManager?: DataManager;
private renderer?: RenderingModule;
private resizeObserver?: ResizeObserver;
private zoomHandler?: ZoomHandler;
public override connectedCallback(): void {
super.connectedCallback();
this.resizeObserver = new ResizeObserver(entries => {
Expand All @@ -86,6 +93,9 @@ export class WaferMap extends FoundationElement {
this.canvasSideLength = Math.min(height, width);
});
this.resizeObserver.observe(this);
this.canvas.addEventListener('wheel', event => event.preventDefault(), {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove this event listener in the disconnectedCallback, otherwise we'll end up with duplicate listeners if the same element is added, removed, and re-added to the page.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arinluca333 I don't think the approach you used in removeEventListener() will work. I believe the add/remove functions track the listener function by reference. You're attempting to remove a new listener function which is a copy of the original one. So removeEventListener won't find any listener that matches it and will silently fail.

From the MDN docs:

Calling removeEventListener() with arguments that do not identify any currently registered event listener on the EventTarget has no effect.

Instead you need to save the event listener to a class member variable and pass that variable to both addEventListener and removeEventListener.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I filed #964 to you to track fixing this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the exact same function reference must be used, concretely (pseudocode):

class {
    private wheelHandler = () => {};

    connectedCallback() { this.canvas.addEventListener('wheel', wheelHandler);}
    disconnectedCallback() { this.canvas.removeEventListener('wheel', wheelHandler); }
}

passive: false
});
this.queueRender();
}

Expand Down Expand Up @@ -116,6 +126,14 @@ export class WaferMap extends FoundationElement {
this.maxCharacters
);
this.renderer = new RenderingModule(this.dataManager, this.canvas);
this.zoomHandler = new ZoomHandler(
this.canvas,
this.zoomContainer,
this.dataManager,
this.renderer,
this.canvasSideLength
);
this.zoomHandler.attachZoomBehavior();
this.renderer.drawWafer();
}

Expand Down Expand Up @@ -163,6 +181,7 @@ export class WaferMap extends FoundationElement {
this.canvas.width = this.canvasSideLength;
this.canvas.height = this.canvasSideLength;
}
this.zoomHandler?.resetTransform();
this.queueRender();
}

Expand Down
Loading