Skip to content

Commit ab1175b

Browse files
authored
perf(word-cloud): add willReadFrequently option when canvas getContext (#3438)
1 parent 18c95e1 commit ab1175b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/utils/transform/word-cloud.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,14 @@ function tagCloud() {
403403

404404
function getContext(canvas: HTMLCanvasElement) {
405405
canvas.width = canvas.height = 1;
406-
const ratio = Math.sqrt(canvas.getContext('2d')!.getImageData(0, 0, 1, 1).data.length >> 2);
406+
const ratio = Math.sqrt(
407+
(canvas.getContext('2d', { willReadFrequently: true }) as CanvasRenderingContext2D)!.getImageData(0, 0, 1, 1).data
408+
.length >> 2
409+
);
407410
canvas.width = (cw << 5) / ratio;
408411
canvas.height = ch / ratio;
409412

410-
const context = canvas.getContext('2d') as CanvasRenderingContext2D;
413+
const context = canvas.getContext('2d', { willReadFrequently: true }) as CanvasRenderingContext2D;
411414
context.fillStyle = context.strokeStyle = 'red';
412415
context.textAlign = 'center';
413416
return { context, ratio };

0 commit comments

Comments
 (0)