Skip to content

Commit 7063d3d

Browse files
authored
Vertical scale and test mocks updates (#1577)
# Pull Request ## 🤨 Rationale The HTML canvas has its origin in the [top-left corner](https://www.w3schools.com/graphics/canvas_coordinates.asp). When rendering the dies, we need to take this into consideration and flip the vertical scale so that the origin location will be respected. Another improvement is the wafer mock utilities for each module. ## 👩‍💻 Implementation switched the ends of the scale range and updated tests. replaced individual mocks with a utility method ## 🧪 Testing tests are passing locally ## ✅ Checklist <!--- Review the list and put an x in the boxes that apply or ~~strike through~~ around items that don't (along with an explanation). --> - [x] I have updated the project documentation to reflect my changes or determined no changes are needed.
1 parent bd52805 commit 7063d3d

9 files changed

+252
-476
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Flipped the vertical scale and created wafer map mocks for tests",
4+
"packageName": "@ni/nimble-components",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/nimble-components/src/wafer-map/modules/computations.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,15 @@ export class Computations {
249249
.paddingOuter(0)
250250
.align(0)
251251
.round(false);
252+
// html canvas has top-left origin https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Drawing_shapes#the_grid
253+
// we need to flip the vertical scale
252254
if (
253255
originLocation === WaferMapOriginLocation.bottomLeft
254256
|| originLocation === WaferMapOriginLocation.bottomRight
255257
) {
256-
return scale.range([0, containerHeight]);
258+
return scale.range([containerHeight, 0]);
257259
}
258-
return scale.range([containerHeight, 0]);
260+
return scale.range([0, containerHeight]);
259261
}
260262

261263
private createInvertedVerticalScale(
@@ -264,15 +266,17 @@ export class Computations {
264266
containerHeight: number
265267
): ScaleQuantile<number, number> {
266268
const scale = scaleQuantile().domain([0, containerHeight]);
269+
// html canvas has top-left origin https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Drawing_shapes#the_grid
270+
// we need to flip the inverted vertical scale
267271
if (
268272
originLocation === WaferMapOriginLocation.bottomLeft
269273
|| originLocation === WaferMapOriginLocation.bottomRight
270274
) {
271-
return scale.range(range(grid.origin.y, grid.origin.y + grid.rows));
275+
return scale.range(
276+
range(grid.origin.y, grid.origin.y + grid.rows).reverse()
277+
);
272278
}
273-
return scale.range(
274-
range(grid.origin.y, grid.origin.y + grid.rows).reverse()
275-
);
279+
return scale.range(range(grid.origin.y, grid.origin.y + grid.rows));
276280
}
277281

278282
private calculateMarginAddition(
Lines changed: 49 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { WaferMap } from '..';
22
import { Computations } from '../modules/computations';
33
import { Margin, WaferMapOriginLocation } from '../types';
4-
import { getWaferMapDies } from './utilities';
4+
import { getWaferMapMockComputations, getWaferMapDies } from './utilities';
55

66
describe('Wafermap Computations module', () => {
77
let computationsModule: Computations;
@@ -14,20 +14,12 @@ describe('Wafermap Computations module', () => {
1414
left: 4
1515
};
1616
beforeEach(() => {
17-
const waferMock: Pick<
18-
WaferMap,
19-
| 'dies'
20-
| 'originLocation'
21-
| 'canvasWidth'
22-
| 'canvasHeight'
23-
| 'validity'
24-
> = {
25-
dies: getWaferMapDies(),
26-
originLocation: WaferMapOriginLocation.topLeft,
27-
canvasWidth: 100,
28-
canvasHeight: 100,
29-
validity: { invalidGridDimensions: false }
30-
};
17+
const waferMock = getWaferMapMockComputations(
18+
getWaferMapDies(),
19+
WaferMapOriginLocation.topLeft,
20+
100,
21+
100
22+
);
3123
computationsModule = new Computations(waferMock as WaferMap);
3224
computationsModule.updateContainerDimensions();
3325
});
@@ -72,20 +64,12 @@ describe('Wafermap Computations module', () => {
7264

7365
describe('with rectangular canvas', () => {
7466
beforeEach(() => {
75-
const waferMock: Pick<
76-
WaferMap,
77-
| 'dies'
78-
| 'originLocation'
79-
| 'canvasWidth'
80-
| 'canvasHeight'
81-
| 'validity'
82-
> = {
83-
dies: getWaferMapDies(),
84-
originLocation: WaferMapOriginLocation.topLeft,
85-
canvasWidth: 200,
86-
canvasHeight: 100,
87-
validity: { invalidGridDimensions: false }
88-
};
67+
const waferMock = getWaferMapMockComputations(
68+
getWaferMapDies(),
69+
WaferMapOriginLocation.topLeft,
70+
200,
71+
100
72+
);
8973
computationsModule = new Computations(waferMock as WaferMap);
9074
computationsModule.updateContainerDimensions();
9175
});
@@ -124,20 +108,12 @@ describe('Wafermap Computations module', () => {
124108

125109
describe('with top left originLocation', () => {
126110
beforeEach(() => {
127-
const waferMock: Pick<
128-
WaferMap,
129-
| 'dies'
130-
| 'originLocation'
131-
| 'canvasWidth'
132-
| 'canvasHeight'
133-
| 'validity'
134-
> = {
135-
dies: getWaferMapDies(),
136-
originLocation: WaferMapOriginLocation.topLeft,
137-
canvasWidth: 100,
138-
canvasHeight: 100,
139-
validity: { invalidGridDimensions: false }
140-
};
111+
const waferMock = getWaferMapMockComputations(
112+
getWaferMapDies(),
113+
WaferMapOriginLocation.topLeft,
114+
100,
115+
100
116+
);
141117
computationsModule = new Computations(waferMock as WaferMap);
142118
computationsModule.updateContainerDimensions();
143119
});
@@ -146,27 +122,20 @@ describe('Wafermap Computations module', () => {
146122
expect(computationsModule.horizontalScale.range()).toEqual([0, 92]);
147123
});
148124

149-
it('should have decreasing vertical range', () => {
150-
expect(computationsModule.verticalScale.range()).toEqual([92, 0]);
125+
it('should have increasing vertical range', () => {
126+
// because the canvas has top-left origin location we need to flip the vertical scale
127+
expect(computationsModule.verticalScale.range()).toEqual([0, 92]);
151128
});
152129
});
153130

154131
describe('with top right originLocation', () => {
155132
beforeEach(() => {
156-
const waferMock: Pick<
157-
WaferMap,
158-
| 'dies'
159-
| 'originLocation'
160-
| 'canvasWidth'
161-
| 'canvasHeight'
162-
| 'validity'
163-
> = {
164-
dies: getWaferMapDies(),
165-
originLocation: WaferMapOriginLocation.topRight,
166-
canvasWidth: 100,
167-
canvasHeight: 100,
168-
validity: { invalidGridDimensions: false }
169-
};
133+
const waferMock = getWaferMapMockComputations(
134+
getWaferMapDies(),
135+
WaferMapOriginLocation.topRight,
136+
100,
137+
100
138+
);
170139
computationsModule = new Computations(waferMock as WaferMap);
171140
computationsModule.updateContainerDimensions();
172141
});
@@ -175,27 +144,20 @@ describe('Wafermap Computations module', () => {
175144
expect(computationsModule.horizontalScale.range()).toEqual([92, 0]);
176145
});
177146

178-
it('should have decreasing vertical range', () => {
179-
expect(computationsModule.verticalScale.range()).toEqual([92, 0]);
147+
it('should have increasing vertical range', () => {
148+
// because the canvas has top-left origin location we need to flip the vertical scale
149+
expect(computationsModule.verticalScale.range()).toEqual([0, 92]);
180150
});
181151
});
182152

183153
describe('with bottom left originLocation', () => {
184154
beforeEach(() => {
185-
const waferMock: Pick<
186-
WaferMap,
187-
| 'dies'
188-
| 'originLocation'
189-
| 'canvasWidth'
190-
| 'canvasHeight'
191-
| 'validity'
192-
> = {
193-
dies: getWaferMapDies(),
194-
originLocation: WaferMapOriginLocation.bottomLeft,
195-
canvasWidth: 100,
196-
canvasHeight: 100,
197-
validity: { invalidGridDimensions: false }
198-
};
155+
const waferMock = getWaferMapMockComputations(
156+
getWaferMapDies(),
157+
WaferMapOriginLocation.bottomLeft,
158+
100,
159+
100
160+
);
199161
computationsModule = new Computations(waferMock as WaferMap);
200162
computationsModule.updateContainerDimensions();
201163
});
@@ -204,27 +166,20 @@ describe('Wafermap Computations module', () => {
204166
expect(computationsModule.horizontalScale.range()).toEqual([0, 92]);
205167
});
206168

207-
it('should have increasing vertical range', () => {
208-
expect(computationsModule.verticalScale.range()).toEqual([0, 92]);
169+
it('should have decreasing vertical range', () => {
170+
// because the canvas has top-left origin location we need to flip the vertical scale
171+
expect(computationsModule.verticalScale.range()).toEqual([92, 0]);
209172
});
210173
});
211174

212175
describe('with bottom right originLocation', () => {
213176
beforeEach(() => {
214-
const waferMock: Pick<
215-
WaferMap,
216-
| 'dies'
217-
| 'originLocation'
218-
| 'canvasWidth'
219-
| 'canvasHeight'
220-
| 'validity'
221-
> = {
222-
dies: getWaferMapDies(),
223-
originLocation: WaferMapOriginLocation.bottomRight,
224-
canvasWidth: 100,
225-
canvasHeight: 100,
226-
validity: { invalidGridDimensions: false }
227-
};
177+
const waferMock = getWaferMapMockComputations(
178+
getWaferMapDies(),
179+
WaferMapOriginLocation.bottomRight,
180+
100,
181+
100
182+
);
228183
computationsModule = new Computations(waferMock as WaferMap);
229184
computationsModule.updateContainerDimensions();
230185
});
@@ -233,8 +188,9 @@ describe('Wafermap Computations module', () => {
233188
expect(computationsModule.horizontalScale.range()).toEqual([92, 0]);
234189
});
235190

236-
it('should have increasing vertical range', () => {
237-
expect(computationsModule.verticalScale.range()).toEqual([0, 92]);
191+
it('should have decreasing vertical range', () => {
192+
// because the canvas has top-left origin location we need to flip the vertical scale
193+
expect(computationsModule.verticalScale.range()).toEqual([92, 0]);
238194
});
239195
});
240196
});

packages/nimble-components/src/wafer-map/tests/data-manager.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ describe('Wafermap Data Manager', () => {
9393
expect(dataManagerModule.horizontalScale.range()).toEqual([0, 92]);
9494
});
9595

96-
it('should have increasing vertical range', () => {
97-
expect(dataManagerModule.verticalScale.range()).toEqual([0, 92]);
96+
it('should have decreasing vertical range', () => {
97+
// because the canvas has top-left origin location we need to flip the vertical scale
98+
expect(dataManagerModule.verticalScale.range()).toEqual([92, 0]);
9899
});
99100

100101
it('should not have labelsFontSize larger than the die height', () => {

0 commit comments

Comments
 (0)