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

Improve the Wafer Map web worker class to support offscreen rendering #1929

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
229 commits
Select commit Hold shift + click to select a range
f9a18d3
changes
Razvan1928 Mar 7, 2024
ce89ae5
offscreencanvas working
Razvan1928 Mar 7, 2024
56f5458
changes
Razvan1928 Mar 8, 2024
8924f49
Merge branch 'main' of https://github.com/ni/nimble into users/rnazar…
Razvan1928 Mar 8, 2024
99c63a4
Update package-lock.json
Razvan1928 Mar 8, 2024
b2bb758
changes
Razvan1928 Mar 8, 2024
afb642d
installed arquero
munteannatan Mar 11, 2024
2f50975
new zoom handler, touch enabled
munteannatan Mar 11, 2024
b3e807d
float64 expected
munteannatan Mar 11, 2024
a45a726
new hover handler uses arquero for parsing
munteannatan Mar 11, 2024
c615836
experimental swapping strategy
munteannatan Mar 11, 2024
4f5467d
some test changes
munteannatan Mar 11, 2024
72a55a3
lint
munteannatan Mar 11, 2024
0e91f3a
changed zoom altogether and updated tests
munteannatan Mar 12, 2024
9a90542
kinda working
Razvan1928 Mar 12, 2024
bf233ac
kinda working
Razvan1928 Mar 12, 2024
492d05e
data
Razvan1928 Mar 13, 2024
43f5810
Update index.ts
Razvan1928 Mar 13, 2024
35f2649
Merge branch 'main' of https://github.com/ni/nimble into users/rnazar…
Razvan1928 Mar 13, 2024
a6c0d34
Change files
Razvan1928 Mar 13, 2024
ac418f3
Update @ni-nimble-components-f866e449-14a0-410d-be26-c5570bf1006d.json
Razvan1928 Mar 13, 2024
e08e849
added tests, removed setters, made everything public
Razvan1928 Mar 13, 2024
e085d2f
Update matrix-renderer.ts
Razvan1928 Mar 13, 2024
a6340e1
repaired tests
Razvan1928 Mar 13, 2024
90e0444
Update index.ts
Razvan1928 Mar 13, 2024
926c724
repaired lint
Razvan1928 Mar 13, 2024
7cdfe56
changed data types
Razvan1928 Mar 14, 2024
c1b0adb
changed computations
munteannatan Mar 14, 2024
913c269
deleted text on dies
Razvan1928 Mar 14, 2024
a26740d
changed Float32 to Float64
Razvan1928 Mar 14, 2024
724afb9
added some experimental data in storybook
Razvan1928 Mar 14, 2024
b6bfba6
deleted experimental data
Razvan1928 Mar 14, 2024
6f5b3f3
put back not needed to be deleted line
Razvan1928 Mar 14, 2024
9428735
deleted obsolete addTextOnDies assertion
Razvan1928 Mar 14, 2024
208a66e
removed arquero and added unit test
munteannatan Mar 15, 2024
07e0bbc
Change files
munteannatan Mar 15, 2024
cba3d20
fixed firefox tests
munteannatan Mar 18, 2024
85d961a
Merge branch 'main' into users/munteannatan/experimental-events
munteannatan Mar 18, 2024
3d7324b
typos
munteannatan Mar 18, 2024
805f105
replaced with experimental
munteannatan Mar 18, 2024
fa6993a
created test parameters and added arquero mention
munteannatan Mar 18, 2024
43b944e
Merge branch 'users/munteannatan/experimental-events' into users/munt…
munteannatan Mar 19, 2024
1fc0fdc
removed arquero and used alternative
munteannatan Mar 19, 2024
39b82b5
added tests
munteannatan Mar 19, 2024
c8a6397
lint
munteannatan Mar 19, 2024
294e1e0
Change files
munteannatan Mar 19, 2024
ecfd8b3
test skip and fixes
munteannatan Mar 19, 2024
c5ca71e
removed event coordinator and made connect and disconnect internal api
munteannatan Mar 19, 2024
a8401b5
Merge branch 'main' into users/munteannatan/experimental-events
munteannatan Mar 19, 2024
5f7c4d8
Merge branch 'users/munteannatan/experimental-events' into users/munt…
munteannatan Mar 19, 2024
e72f613
Merge branch 'main' into users/munteannatan/experimental-computations
munteannatan Mar 19, 2024
715ce26
internal public method
munteannatan Mar 19, 2024
16a5c7d
internal mark
munteannatan Mar 19, 2024
cd80eff
Merge branch 'users/munteannatan/experimental-events' into users/munt…
munteannatan Mar 19, 2024
51e2e7a
created new prerendering
munteannatan Mar 20, 2024
f3e4d27
public color scale
munteannatan Mar 20, 2024
099e087
Update worker-renderer.ts
Razvan1928 Mar 20, 2024
b246bc9
Merge branch 'users/munteannatan/experimental-prerendering' of https:…
Razvan1928 Mar 20, 2024
2a6ce73
package lock update
munteannatan Mar 20, 2024
5421f53
changed tests
munteannatan Mar 20, 2024
0483b04
created experimental check
munteannatan Mar 20, 2024
2c83beb
lint
munteannatan Mar 20, 2024
9d81c1f
test fixes
munteannatan Mar 20, 2024
a63188f
update package lock
munteannatan Mar 20, 2024
a76a981
Merge branch 'users/munteannatan/experimental-events' into users/munt…
munteannatan Mar 20, 2024
bafba2d
arquero PR link
munteannatan Mar 20, 2024
c8d3a5a
test fixes and lint
munteannatan Mar 20, 2024
dc4ac9c
lint
munteannatan Mar 20, 2024
3a3edcb
changes
Razvan1928 Mar 20, 2024
7c6542f
changes
Razvan1928 Mar 20, 2024
54eb557
eslint
Razvan1928 Mar 20, 2024
88fceef
deleted console log
Razvan1928 Mar 20, 2024
dac1089
switched renderers
munteannatan Mar 20, 2024
942ffe2
used generic types
munteannatan Mar 20, 2024
1f5ed84
forgot cast
munteannatan Mar 20, 2024
b70dfce
more type fixes
munteannatan Mar 20, 2024
f39337d
Merge branch 'main' into users/munteannatan/experimental-events
munteannatan Mar 20, 2024
ea1b5c4
working version
Razvan1928 Mar 21, 2024
5655594
Merge branch 'users/munteannatan/experimental-events' into users/munt…
munteannatan Mar 21, 2024
6361929
type changes
munteannatan Mar 21, 2024
4a136d3
lint
munteannatan Mar 21, 2024
c7eb2bb
deleted unnecessary castings
Razvan1928 Mar 21, 2024
c403590
linted index.ts
Razvan1928 Mar 21, 2024
9340ac7
Merge branch 'users/munteannatan/experimental-computations' into user…
munteannatan Mar 21, 2024
5ebf8bd
lint
munteannatan Mar 21, 2024
1e525e4
handled this.wafermap.update() promise, made margin property private
Razvan1928 Mar 21, 2024
a951b22
Merge branch 'users/munteannatan/experimental-events' into users/munt…
munteannatan Mar 21, 2024
ccec7aa
removed .then nesting
Razvan1928 Mar 21, 2024
bac2166
renamed drawWorkerRender into drawWafer, added await to this.render.d…
Razvan1928 Mar 21, 2024
864bbe0
lint
munteannatan Mar 21, 2024
c59a1ce
renamed workerOne to worker
Razvan1928 Mar 21, 2024
0be4387
Merge branch 'users/munteannatan/experimental-computations' into user…
munteannatan Mar 21, 2024
0e25e4a
renamed canvasOne to workerCanvas, moved drawWafer inside a better if
Razvan1928 Mar 21, 2024
2c071fd
dragged testData ouside tests and reused it
Razvan1928 Mar 21, 2024
305a87a
made most of the methods inside matrix-renderer async
Razvan1928 Mar 21, 2024
35e67b2
Update matrix-renderer.ts
Razvan1928 Mar 22, 2024
fa2cf92
made one canvas from two
Razvan1928 Mar 22, 2024
fdf8f8f
Update index.ts
Razvan1928 Mar 22, 2024
3164de5
Update matrix-renderer.ts
Razvan1928 Mar 22, 2024
bd8b87f
Merge branch 'users/munteannatan/experimental-prerendering' of https:…
Razvan1928 Mar 22, 2024
2af5b77
Update index.ts
Razvan1928 Mar 22, 2024
49f1308
repaired lint
Razvan1928 Mar 22, 2024
a8974b2
removed generics from modules
munteannatan Mar 25, 2024
0dd1349
some type casts
munteannatan Mar 25, 2024
70ad078
lint
munteannatan Mar 25, 2024
66888e2
Merge branch 'main' into users/munteannatan/experimental-events
munteannatan Mar 25, 2024
42cb95f
Merge branch 'users/munteannatan/experimental-events' into users/munt…
munteannatan Mar 25, 2024
123fc1e
Merge branch 'users/munteannatan/experimental-computations' into user…
munteannatan Mar 25, 2024
32d2475
Update matrix-renderer.spec.ts
Razvan1928 Mar 25, 2024
754b836
Merge branch 'users/munteannatan/experimental-prerendering' of https:…
Razvan1928 Mar 25, 2024
00971c2
Update worker-renderer.ts
Razvan1928 Mar 25, 2024
1e907e8
Update matrix-renderer.spec.ts
Razvan1928 Mar 25, 2024
dbbe3b0
Update index.ts
Razvan1928 Mar 25, 2024
c46b8b7
moved testData variable outside the tests
Razvan1928 Mar 26, 2024
4ab7063
changed Uint32Arrays into Int32Array
Razvan1928 Mar 26, 2024
54476c8
added default values for matrix-renderer properties
Razvan1928 Mar 26, 2024
e664460
working version, big changes in the hood
Razvan1928 Mar 26, 2024
0676555
fixed 2 tests
Razvan1928 Mar 26, 2024
7e4665a
renamed offscreenone to offscreenCanvas
Razvan1928 Mar 26, 2024
22301f8
fixed zoom test
Razvan1928 Mar 26, 2024
b776920
Update index.ts
Razvan1928 Mar 27, 2024
454d287
put default values for _containerDimensions and _margin
Razvan1928 Mar 27, 2024
ff36c75
Update index.ts
Razvan1928 Mar 28, 2024
4feecf0
moved creation of worker and canvas worker into separate functions
Razvan1928 Mar 28, 2024
7cab37a
Update index.ts
Razvan1928 Mar 28, 2024
56491cd
Update index.ts
Razvan1928 Mar 28, 2024
30db374
tests are passing but the worker rendered wafer is not displayed in t…
Razvan1928 Mar 28, 2024
93fa3fe
changed 'offscreenCanvas as unknown as Transferable' into 'offscreenC…
Razvan1928 Mar 29, 2024
c53160f
Update index.ts
Razvan1928 Apr 1, 2024
e187cf1
moved worker initialization inside update
Razvan1928 Apr 1, 2024
e09b8bd
Update index.ts
Razvan1928 Apr 1, 2024
64d3db8
Update index.ts
Razvan1928 Apr 1, 2024
4f9b85f
Update index.ts
Razvan1928 Apr 1, 2024
9a40f70
Update index.ts
Razvan1928 Apr 1, 2024
786ef8c
moved worker setup logic to happen inside worker-renderer
Razvan1928 Apr 2, 2024
7e2a559
repaired tests
Razvan1928 Apr 3, 2024
eff19fe
solved the missing die issue
Razvan1928 Apr 3, 2024
6e1b17a
repaired lint
Razvan1928 Apr 3, 2024
42ebcea
deleted not needed isDieVisible
Razvan1928 Apr 3, 2024
c3bbebc
added explanatory comment
Razvan1928 Apr 3, 2024
2a05d1f
Update template.ts
Razvan1928 Apr 3, 2024
4221433
many changes
Razvan1928 Apr 3, 2024
64e07fb
repaired tests
Razvan1928 Apr 3, 2024
d93ed1c
changed new Float64Array([]) to Float64Array.from([]), deleted unnece…
Razvan1928 Apr 4, 2024
a8b9148
Change files
Razvan1928 Apr 4, 2024
054c784
Update @ni-nimble-blazor-1cbfc49b-865a-4368-ab38-15ee937d0420.json
Razvan1928 Apr 4, 2024
c550573
changed email at npm change
Razvan1928 Apr 4, 2024
a68bbb0
renamed col to column
Razvan1928 Apr 4, 2024
3dcd115
renamings columnIndexes
Razvan1928 Apr 4, 2024
2ac8aab
removed ! operator and added null check
Razvan1928 Apr 4, 2024
bd78e6f
Update matrix-renderer.ts
Razvan1928 Apr 4, 2024
76952ef
Merge branch 'main' of https://github.com/ni/nimble into users/rnazar…
Razvan1928 Apr 5, 2024
af1be35
merge
Razvan1928 Apr 5, 2024
d35ff50
Update wafer-map.spec.ts
Razvan1928 Apr 5, 2024
ac8a40f
many changes
Razvan1928 Apr 5, 2024
f932165
Delete @ni-nimble-components-a395f7f8-e46b-414d-ac9c-800e43462953.json
Razvan1928 Apr 5, 2024
0fb28ec
many changes
Razvan1928 Apr 8, 2024
36f0ba6
many changes, still working
Razvan1928 Apr 8, 2024
eddd8f7
Update index.ts
Razvan1928 Apr 8, 2024
b763913
working version
Razvan1928 Apr 8, 2024
54113a8
changes
Razvan1928 Apr 8, 2024
ee5d33a
Merge branch 'users/rnazare/worker-canvas' of https://github.com/ni/n…
Razvan1928 Apr 8, 2024
f3a16d6
changes
Razvan1928 Apr 8, 2024
6b4ea94
changes
Razvan1928 Apr 8, 2024
5030e9e
Update index.ts
Razvan1928 Apr 8, 2024
4142d49
columnPositions
Razvan1928 Apr 8, 2024
ee5c054
pulled length variable out of for
Razvan1928 Apr 8, 2024
d12f8e0
moved isWorkerAlive variable inside worker-renderer file
Razvan1928 Apr 8, 2024
d22b613
Update index.ts
Razvan1928 Apr 8, 2024
abb6031
reduced zoom scope
Razvan1928 Apr 8, 2024
5255baa
introduced smallestMarginPossible
Razvan1928 Apr 8, 2024
403b6e7
Update index.ts
Razvan1928 Apr 8, 2024
0f872ea
Update matrix-renderer.ts
Razvan1928 Apr 8, 2024
bb7f66b
Update wafer-map.spec.ts
Razvan1928 Apr 8, 2024
4e82ab3
Update create-matrix-renderer.spec.ts
Razvan1928 Apr 8, 2024
0120290
added null checking for canvas width and height
Razvan1928 Apr 9, 2024
213644b
moved connect & disconnect
Razvan1928 Apr 9, 2024
6262937
replaced updateSortedDies and draw wafer with setupAndDrawWafer
Razvan1928 Apr 9, 2024
a26ccf9
Update index.ts
Razvan1928 Apr 9, 2024
47f9626
calculated scaled indexes correctly
Razvan1928 Apr 9, 2024
e3fda38
make worker to not be created at every update
Razvan1928 Apr 9, 2024
d4a5775
added explanation comment
Razvan1928 Apr 9, 2024
a29b2f8
Update wafer-map.spec.ts
Razvan1928 Apr 9, 2024
42e1f73
deleted not needed test
Razvan1928 Apr 9, 2024
5d1b1fb
Merge branch 'main' of https://github.com/ni/nimble into users/rnazar…
Razvan1928 Apr 9, 2024
ea55fa9
Update packages.lock.json
Razvan1928 Apr 9, 2024
67f4941
Update utilities.ts
Razvan1928 Apr 9, 2024
1640500
implemented observable pattern for zoom behavior inside zoom-handler …
Razvan1928 Apr 10, 2024
d6f174b
added worker null check
Razvan1928 Apr 10, 2024
dcb88cb
added a better unsubscribe
Razvan1928 Apr 10, 2024
7395ec5
added a few tests
Razvan1928 Apr 11, 2024
e6e9f1c
added plenty of tests
Razvan1928 Apr 11, 2024
be62587
added chromatic test
Razvan1928 Apr 11, 2024
e277cd4
added zoom tests when canvas width and height is changed
Razvan1928 Apr 11, 2024
3cec825
Update prerendering.ts
Razvan1928 Apr 12, 2024
0596bc4
Merge branch 'main' of https://github.com/ni/nimble into users/rnazar…
Razvan1928 Apr 12, 2024
6afe9a0
Update prerendering.ts
Razvan1928 Apr 12, 2024
0cf182c
added build directory paths to gitignore
Razvan1928 Apr 16, 2024
524f78c
formatted tsconfig
Razvan1928 Apr 16, 2024
512f238
changed change type from patch to none
Razvan1928 Apr 16, 2024
2c85816
deleted ids for wafers and located them via classes
Razvan1928 Apr 16, 2024
65bab90
made createWorker() and createWorkerCanvas() internal
Razvan1928 Apr 16, 2024
3bb03dd
removed null check for worker
Razvan1928 Apr 16, 2024
794aa9c
deleted undefined assertion for wafermap.worker
Razvan1928 Apr 16, 2024
e9d99ae
moving worker related logic from index to worker-renderer
Razvan1928 Apr 16, 2024
1067162
Merge branch 'main' into users/rnazare/Improve-the-web-worker-class-t…
rajsite Apr 17, 2024
0486013
modifier prettier to run only on build/generate-workers
Razvan1928 Apr 19, 2024
d1dd606
made update synchronouse
Razvan1928 Apr 23, 2024
5c74f69
reorganized copy & transfer arrays
Razvan1928 Apr 23, 2024
53e8fba
Merge branch 'main' of https://github.com/ni/nimble into users/rnazar…
Razvan1928 Apr 23, 2024
609aa68
Merge branch 'main' of https://github.com/ni/nimble into users/rnazar…
Razvan1928 Apr 23, 2024
2acda5d
replaced .then with void async
Razvan1928 Apr 24, 2024
b1e08c9
replaced .then with void and moved currentTask undefined assignment i…
Razvan1928 Apr 24, 2024
8b64240
deleted isWorkerAlive, replaced with worker undefined check
Razvan1928 Apr 24, 2024
3c777a2
deleted unnecessary void expression
Razvan1928 Apr 25, 2024
a8abae2
improved subscribe/unsubscribe mechanism
Razvan1928 Apr 25, 2024
aba64d2
solved prettier error
Razvan1928 Apr 25, 2024
28e0169
Merge branch 'main' of https://github.com/ni/nimble into users/rnazar…
Razvan1928 Apr 25, 2024
5250426
Don't continuously subscribe and unsubscribe to canvas size changes
rajsite Apr 25, 2024
1312191
split setup and draw work
rajsite Apr 25, 2024
4c54fbd
Test updates for split draw and setup fns
rajsite Apr 25, 2024
b1983c2
lint
rajsite Apr 26, 2024
a97c5b2
Fix tests
rajsite Apr 26, 2024
6c037d8
Passthrough so test runs
rajsite Apr 26, 2024
1b6bfe2
Async timing for test
rajsite Apr 26, 2024
025a997
Merge branch 'main' into users/rnazare/Improve-the-web-worker-class-t…
rajsite Apr 26, 2024
66756db
replaced diesTable undefined check with isExperimentalUpdate() check
Razvan1928 Apr 26, 2024
73ef93f
deleted not needed apiVersion parameter
Razvan1928 Apr 26, 2024
bb0e11b
deleted not needed check, added better diesTable undefined check
Razvan1928 Apr 26, 2024
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 @@
{
"type": "none",
"comment": "Added an additional canvas in wafer map template caused the blazor tests to fail due to missing unique identifiers for canvases, adding different ids for the canvases and explicitly telling the tests to look for one canvas id solved the issue",
Razvan1928 marked this conversation as resolved.
Show resolved Hide resolved
"packageName": "@ni/nimble-blazor",
"email": "110180309+Razvan1928@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
Razvan1928 marked this conversation as resolved.
Show resolved Hide resolved
"type": "patch",
"comment": "Updated wafer map web worker class to support offscreen rendering",
"packageName": "@ni/nimble-components",
"email": "110180309+Razvan1928@users.noreply.github.com",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public async Task WaferMap_WithDiesAndColorScale_RendersColorsAsync()
{
await using var pageWrapper = await NewPageForRouteAsync("WaferMapRenderTest");
var page = pageWrapper.Page;
var canvas = page.Locator("canvas");
var canvas = page.Locator(".main-wafer");

await Assertions.Expect(canvas).ToBeVisibleAsync();
await Task.Delay(RenderingTimeout);
Expand All @@ -30,7 +30,7 @@ public async Task WaferMap_WithGridDimensions_IsValidAsync()
{
await using var pageWrapper = await NewPageForRouteAsync("WaferMapRenderTest");
var page = pageWrapper.Page;
var canvas = page.Locator("canvas");
var canvas = page.Locator(".main-wafer");
var validButton = page.Locator("nimble-button");
var textField = page.Locator("nimble-text-field");

Expand All @@ -46,7 +46,7 @@ public async Task WaferMap_WithHoverEvent_TriggersDieChangeEventAsync()
{
await using var pageWrapper = await NewPageForRouteAsync("WaferMapRenderTest");
var page = pageWrapper.Page;
var canvas = page.Locator("canvas");
var canvas = page.Locator(".main-wafer");
var textField = page.Locator("nimble-text-field");

await Assertions.Expect(canvas).ToBeVisibleAsync();
Expand Down
5 changes: 5 additions & 0 deletions packages/nimble-components/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
!*.mdx
!*.json
!src/
!build/
!/.storybook/

/src/**/*.*
Expand All @@ -19,6 +20,10 @@
/.storybook/*.*
!/.storybook/*.js

/build/**/*.*
!build/generate-workers/**/*.ts
!build/generate-workers/**/*.json

# Explicitly exclude the below files and folders
dist
node_modules
Expand Down
7 changes: 5 additions & 2 deletions packages/nimble-components/build/generate-workers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const fileContent: string = `// eslint-disable-next-line no-template-curly-in-st
export const workerCode = ${JSON.stringify(sourceCode)};
`;

const renderFilePath: string = path.resolve(workersDirectory, 'matrix-renderer.ts');
const renderFilePath: string = path.resolve(
workersDirectory,
'matrix-renderer.ts'
);

writeFile(renderFilePath, fileContent);
writeFile(renderFilePath, fileContent);
Original file line number Diff line number Diff line change
@@ -1,23 +1,224 @@
import { expose } from 'comlink';
Razvan1928 marked this conversation as resolved.
Show resolved Hide resolved
import type {
Dimensions,
Transform,
WaferMapMatrix,
WaferMapTypedMatrix
} from './types';

/**
* MatrixRenderer class is meant to be used within a Web Worker context,
* using Comlink to facilitate communication between the main thread and the worker.
* The MatrixRenderer class manages a matrix of dies, once an instance of MatrixRenderer is created,
* MatrixRenderer class is meant to be used within a Web Worker context,
* using Comlink to facilitate communication between the main thread and the worker.
* The MatrixRenderer class manages a matrix of dies, once an instance of MatrixRenderer is created,
* it is exposed to the main thread using Comlink's `expose` method.
* This setup is used in the wafer-map component to perform heavy computational duties
*/
export class MatrixRenderer {
public dieMatrix: Uint8Array = Uint8Array.from([]);
public columnIndexes = Int32Array.from([]);
Razvan1928 marked this conversation as resolved.
Show resolved Hide resolved
public rowIndexes = Int32Array.from([]);
public values = Float64Array.from([]);
public scaledColumnIndex = Float64Array.from([]);
public scaledRowIndex = Float64Array.from([]);
public columnIndexPositions = Int32Array.from([]);
public canvas!: OffscreenCanvas;
public context!: OffscreenCanvasRenderingContext2D;
private scaleX: number = 1;
private scaleY: number = 1;
private baseX: number = 1;
private baseY: number = 1;
private dieDimensions: Dimensions = { width: 1, height: 1 };
private transform: Transform = { k: 1, x: 0, y: 0 };
private topLeftCanvasCorner!: { x: number; y: number };
private bottomRightCanvasCorner!: { x: number; y: number };
private readonly smallestMarginPossible: number = 20;
private margin: {
top: number;
right: number;
bottom: number;
left: number;
} = {
top: this.smallestMarginPossible,
right: this.smallestMarginPossible,
bottom: this.smallestMarginPossible,
left: this.smallestMarginPossible
};

public emptyMatrix(): void {
this.dieMatrix = Uint8Array.from([]);;
public calculateXScaledIndex(columnIndex: number): number {
return this.scaleX * columnIndex + this.baseX + this.margin.left;
}

public calculateYScaledIndex(rowIndex: number): number {
return this.scaleY * rowIndex + this.baseY + this.margin.top;
}

public setColumnIndexes(columnIndexes: Int32Array): void {
this.columnIndexes = columnIndexes;
if (columnIndexes.length === 0 || this.columnIndexes[0] === undefined) {
return;
}
const scaledColumnIndex = [
this.calculateXScaledIndex(this.columnIndexes[0])
];
const columnPositions = [0];
let prev = this.columnIndexes[0];
for (let i = 1; i < this.columnIndexes.length; i++) {
const xIndex = this.columnIndexes[i];
if (xIndex && xIndex !== prev) {
const scaledX = this.calculateXScaledIndex(
this.columnIndexes[i]!
);
scaledColumnIndex.push(scaledX);
columnPositions.push(i);
prev = xIndex;
}
}
this.scaledColumnIndex = Float64Array.from(scaledColumnIndex);
this.columnIndexPositions = Int32Array.from(columnPositions);
}

public updateMatrix(
data: Iterable<number>
public setRowIndexes(rowIndexesBuffer: Int32Array): void {
this.rowIndexes = rowIndexesBuffer;
this.scaledRowIndex = new Float64Array(this.rowIndexes.length);
for (let i = 0; i < this.rowIndexes.length; i++) {
this.scaledRowIndex[i] = this.calculateYScaledIndex(
this.rowIndexes[i]!
);
}
}

public setMargin(margin: {
top: number;
right: number;
bottom: number;
left: number;
}): void {
this.margin = margin;
}

public setCanvasCorners(
topLeft: { x: number; y: number },
bottomRight: { x: number; y: number }
): void {
this.dieMatrix = Uint8Array.from(data);
this.topLeftCanvasCorner = topLeft;
this.bottomRightCanvasCorner = bottomRight;
}

public setDiesDimensions(data: Dimensions): void {
this.dieDimensions = { width: data.width, height: data.height };
}

public setScaling(scaleX: number, scaleY: number): void {
this.scaleX = scaleX;
this.scaleY = scaleY;
}

public setBases(baseX: number, baseY: number): void {
this.baseX = baseX;
this.baseY = baseY;
}

public setTransform(transform: Transform): void {
this.transform = transform;
}

public setCanvas(canvas: OffscreenCanvas): void {
this.canvas = canvas;
this.context = canvas.getContext('2d')!;
}

public getMatrix(): WaferMapTypedMatrix {
return {
columnIndexes: this.columnIndexes,
rowIndexes: this.rowIndexes,
values: this.values
};
}

public emptyMatrix(): void {
this.columnIndexes = Int32Array.from([]);
this.rowIndexes = Int32Array.from([]);
this.values = Float64Array.from([]);
}

public scaleCanvas(): void {
this.context.translate(this.transform.x, this.transform.y);
this.context.scale(this.transform.k, this.transform.k);
}

public updateMatrix(data: WaferMapMatrix): void {
this.columnIndexes = Int32Array.from(data.columnIndexes);
this.rowIndexes = Int32Array.from(data.rowIndexes);
this.values = Float64Array.from(data.values);
}

public setCanvasDimensions(data: Dimensions): void {
this.canvas.width = data.width;
this.canvas.height = data.height;
}

public getCanvasDimensions(): Dimensions {
return {
width: this.canvas.width,
height: this.canvas.height
};
}

public clearCanvas(): void {
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
}

public drawWafer(): void {
atmgrifter00 marked this conversation as resolved.
Show resolved Hide resolved
this.context.restore();
this.context.save();
this.clearCanvas();
this.scaleCanvas();
if (
this.topLeftCanvasCorner === undefined
|| this.bottomRightCanvasCorner === undefined
) {
throw new Error('Canvas corners are not set');
}
for (let i = 0; i < this.scaledColumnIndex.length; i++) {
const scaledX = this.scaledColumnIndex[i]!;
if (
!(
scaledX >= this.topLeftCanvasCorner.x
&& scaledX < this.bottomRightCanvasCorner.x
)
) {
continue;
}

// columnIndexPositions is used to get chunks to determine the start and end index of the column, it looks something like [0, 1, 4, 9, 12]
// This means that the first column has a start index of 0 and an end index of 1, the second column has a start index of 1 and an end index of 4, and so on
// scaledRowIndex is used when we reach the end of the columnIndexPositions, when columnIndexPositions is [0, 1, 4, 9, 12], scaledRowIndex is 13
const columnEndIndex = this.columnIndexPositions[i + 1] !== undefined
? this.columnIndexPositions[i + 1]!
: this.scaledRowIndex.length;
for (
let columnStartIndex = this.columnIndexPositions[i]!;
columnStartIndex < columnEndIndex;
columnStartIndex++
) {
const scaledY = this.scaledRowIndex[columnStartIndex]!;
if (
!(
scaledY >= this.topLeftCanvasCorner.y
&& scaledY < this.bottomRightCanvasCorner.y
)
) {
continue;
}
// Fill style is temporary green for all dies, will be replaced with a color based on the value of the die in a future implementation
this.context.fillStyle = 'Green';
this.context.fillRect(
scaledX,
scaledY,
this.dieDimensions.width,
this.dieDimensions.height
);
}
}
}
}
expose(MatrixRenderer);
expose(MatrixRenderer);
Loading
Loading