From aef2fffd55c0315fd2dc92aaf4573417c89402fb Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Mon, 20 Dec 2021 11:41:19 +0545 Subject: [PATCH] allow to set scaleFactor in opts --- src/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index c2d8a8d..c22eddc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,6 +35,7 @@ interface GraphEntry { } interface Options { + scaleFactor?: number; themeName?: keyof typeof themes; customTheme?: Theme; skipHeader?: boolean; @@ -82,7 +83,6 @@ const defaultFontFace = "IBM Plex Mono"; const headerHeight = 60; const canvasMargin = 20; const yearHeight = textHeight + (boxWidth + boxMargin) * 8 + canvasMargin; -const scaleFactor = getPixelRatio(); function getTheme(opts: Options): Theme { const { themeName, customTheme } = opts; @@ -279,6 +279,12 @@ export function drawContributions(canvas: HTMLCanvasElement, opts: Options) { data.years.length * yearHeight + canvasMargin + headerOffset + 10; const width = 53 * (boxWidth + boxMargin) + canvasMargin * 2; + let scaleFactor; + if (!opts.scaleFactor) { + scaleFactor = getPixelRatio(); + } else { + scaleFactor = opts.scaleFactor; + } canvas.width = width * scaleFactor; canvas.height = height * scaleFactor;