-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'select-placeholder' of https://github.com/ni/nimble int…
…o select-placeholder
- Loading branch information
Showing
20 changed files
with
270 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
"^@tanstack/", | ||
"^@tiptap/", | ||
"@types/markdown-it", | ||
"comlink", | ||
"d3-", | ||
"prosemirror-" | ||
], | ||
|
15 changes: 15 additions & 0 deletions
15
angular-workspace/projects/ni/nimble-angular/CHANGELOG.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
src/icons | ||
src/wafer-map/workers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
{ | ||
"name": "@ni/nimble-components", | ||
"entries": [ | ||
{ | ||
"date": "Wed, 28 Feb 2024 21:22:49 GMT", | ||
"version": "21.7.1", | ||
"tag": "@ni/nimble-components_v21.7.1", | ||
"comments": { | ||
"patch": [ | ||
{ | ||
"author": "[email protected]", | ||
"package": "@ni/nimble-components", | ||
"commit": "52693524c553f3b115e6c1004c902d10e7dd4050", | ||
"comment": "Create web worker class for future faster rendering wafer map" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"date": "Wed, 28 Feb 2024 19:35:04 GMT", | ||
"version": "21.7.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/nimble-components/build/generate-workers/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generate Workers | ||
|
||
This directory contains wafer map rendering code and build scripts which compile it to run in a web worker. | ||
|
||
## Behavior | ||
|
||
- the `source` directory and `index.ts` are built using `tsc` | ||
- `source/matrix-renderer.ts` is bundled with rollup | ||
- `index.ts` has the purpose to prepare and move `dist/bundle/matrix-renderer` to `src/wafer-map/worker` | ||
- `src/wafer-map/worker/matrix-renderer` will be used to create a `Blob` object which is then used to create a `URL` for a web worker. | ||
|
||
## How to run | ||
|
||
This script runs as part of `npm run build` but before `npm run build-components`. | ||
|
||
To run manually: | ||
|
||
1. Run `npm run generate-workers` inside nimble-components directory. |
39 changes: 39 additions & 0 deletions
39
packages/nimble-components/build/generate-workers/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
function resolveModulePath(moduleName: string): string { | ||
return path.resolve(require.resolve(moduleName)); | ||
} | ||
|
||
function prepareDirectory(dirPath: string): void { | ||
if (fs.existsSync(dirPath)) { | ||
console.log(`Deleting existing directory "${dirPath}"`); | ||
fs.rmSync(dirPath, { recursive: true }); | ||
console.log('Finished deleting existing directory'); | ||
} | ||
console.log(`Creating directory "${dirPath}"`); | ||
fs.mkdirSync(dirPath); | ||
console.log('Finished creating directory'); | ||
} | ||
|
||
function writeFile(filePath: string, content: string): void { | ||
console.log(`Writing file "${filePath}"`); | ||
fs.writeFileSync(filePath, content, { encoding: 'utf-8' }); | ||
console.log('Finished writing file'); | ||
} | ||
|
||
const renderModuleName: string = '../bundle/matrix-renderer.js'; | ||
const workersDirectory: string = path.resolve('./src/wafer-map/workers'); | ||
|
||
prepareDirectory(workersDirectory); | ||
|
||
const modulePath: string = resolveModulePath(renderModuleName); | ||
const sourceCode: string = fs.readFileSync(modulePath, 'utf-8'); | ||
|
||
const fileContent: string = `// eslint-disable-next-line no-template-curly-in-string | ||
export const workerCode = ${JSON.stringify(sourceCode)}; | ||
`; | ||
|
||
const renderFilePath: string = path.resolve(workersDirectory, 'matrix-renderer.ts'); | ||
|
||
writeFile(renderFilePath, fileContent); |
13 changes: 13 additions & 0 deletions
13
packages/nimble-components/build/generate-workers/rollup.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import nodeResolve from '@rollup/plugin-node-resolve'; | ||
import path from 'path'; | ||
|
||
export default { | ||
input: path.resolve(__dirname, 'dist/esm/source/matrix-renderer.js'), | ||
output: { | ||
file: path.resolve(__dirname, 'dist/bundle/matrix-renderer.js'), | ||
format: 'iife', | ||
name: 'MatrixRenderer', | ||
sourcemap: false | ||
}, | ||
plugins: [nodeResolve()] | ||
}; |
23 changes: 23 additions & 0 deletions
23
packages/nimble-components/build/generate-workers/source/matrix-renderer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { expose } from 'comlink'; | ||
|
||
/** | ||
* 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 emptyMatrix(): void { | ||
this.dieMatrix = Uint8Array.from([]);; | ||
} | ||
|
||
public updateMatrix( | ||
data: Iterable<number> | ||
): void { | ||
this.dieMatrix = Uint8Array.from(data); | ||
} | ||
} | ||
expose(MatrixRenderer); |
28 changes: 28 additions & 0 deletions
28
packages/nimble-components/build/generate-workers/source/tests/matrix-renderer.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Remote, expose, wrap } from 'comlink'; | ||
import { MatrixRenderer } from '../matrix-renderer'; | ||
|
||
describe('MatrixRenderer with MessageChannel', () => { | ||
let matrixRenderer: Remote<MatrixRenderer>; | ||
|
||
beforeEach(async () => { | ||
const { port1, port2 } = new MessageChannel(); | ||
const worker = new MatrixRenderer(); | ||
expose(worker, port1); | ||
matrixRenderer = await wrap<MatrixRenderer>(port2); | ||
}); | ||
|
||
it('updateMatrix should update the dieMatrix', async () => { | ||
const testData = [4, 5, 6]; | ||
await matrixRenderer.updateMatrix(testData); | ||
|
||
const updatedMatrix = await matrixRenderer.dieMatrix; | ||
expect(updatedMatrix).toEqual(Uint8Array.from(testData)); | ||
}); | ||
|
||
it('emptyMatrix should empty the dieMatrix', async () => { | ||
await matrixRenderer.emptyMatrix(); | ||
|
||
const updatedMatrix = await matrixRenderer.dieMatrix; | ||
expect(updatedMatrix.length).toEqual(0); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/nimble-components/build/generate-workers/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["source", "index.ts"], | ||
"compilerOptions": { | ||
"outDir": "./dist/esm" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/nimble-components/src/wafer-map/modules/create-matrix-renderer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { wrap, Remote } from 'comlink'; | ||
import { workerCode } from '../workers/matrix-renderer'; | ||
import type { MatrixRenderer } from '../../../build/generate-workers/dist/esm/source/matrix-renderer'; | ||
|
||
let url: string; | ||
|
||
/** | ||
* Asynchronously creates and returns a Remote<MatrixRenderer> instance. | ||
* This function simplifies the process of creating and accessing MatrixRenderer instances. | ||
*/ | ||
export const createMatrixRenderer = async (): Promise<{ | ||
matrixRenderer: Remote<MatrixRenderer>, | ||
terminate: () => void | ||
}> => { | ||
if (url === undefined) { | ||
const blob = new Blob([workerCode], { type: 'text/javascript' }); | ||
url = URL.createObjectURL(blob); | ||
} | ||
const worker = new Worker(url); | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const RemoteMatrixRenderer = wrap<new() => MatrixRenderer>(worker); | ||
const matrixRenderer = await new RemoteMatrixRenderer(); | ||
const terminate = (): void => worker.terminate(); | ||
return { | ||
matrixRenderer, | ||
terminate | ||
}; | ||
}; |
Oops, something went wrong.