Skip to content

Commit 7cffa4d

Browse files
author
Oskar Widmark
committed
fix: end draw when out of bounds
1 parent 6c61474 commit 7cffa4d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/canvas-controller.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,14 @@ export class CanvasController {
226226
return i >= 0 && i < this.context.columnNbr;
227227
};
228228

229-
boundDrawHeight = (y: number) => {
229+
boundColHeight = (y: number) => {
230230
return Math.min(Math.max(y, 0), this.context.columnNbr - 1);
231231
};
232232

233+
colHeightInBounds = (y: number) => {
234+
return y === this.boundColHeight(y);
235+
};
236+
233237
getDrawData = (mouseX: number, mouseY: number): DrawData[] => {
234238
if (!this.isDrawing) return [];
235239

@@ -268,7 +272,7 @@ export class CanvasController {
268272
curHeight +=
269273
(colHeight - this.prevDrawHeight) /
270274
Math.abs(colIndex - this.prevDrawIndex);
271-
curHeight = this.boundDrawHeight(curHeight);
275+
curHeight = this.boundColHeight(curHeight);
272276
drawData.push({
273277
index: i,
274278
value: Math.floor(curHeight),
@@ -279,12 +283,16 @@ export class CanvasController {
279283
if (this.indexInBounds(colIndex)) {
280284
drawData.push({
281285
index: colIndex,
282-
value: this.boundDrawHeight(colHeight),
286+
value: this.boundColHeight(colHeight),
283287
});
284288
this.prevDrawIndex = colIndex;
285289
this.prevDrawHeight = colHeight;
286290
}
287291

292+
if (!this.indexInBounds(colIndex) || !this.colHeightInBounds(colHeight)) {
293+
this.endDraw();
294+
}
295+
288296
return drawData;
289297
};
290298

0 commit comments

Comments
 (0)