diff --git a/action.yml b/action.yml index 9f048254..29a0348d 100644 --- a/action.yml +++ b/action.yml @@ -52,11 +52,11 @@ inputs: description: Enable or disable SVG animations default: yes - # Add bottom padding + # Add bottom padding (percentage) # This can used to add padding if generated image is cropped or on the contrary, remove empty space config_padding: description: Configure bottom padding - default: 20 + default: 2% # Number of repositories to use for metrics # A high number increase metrics accuracy, but will consume additional API requests when using plugins diff --git a/source/app/action/index.mjs b/source/app/action/index.mjs index 4afb95b3..6258d77b 100644 --- a/source/app/action/index.mjs +++ b/source/app/action/index.mjs @@ -113,7 +113,7 @@ "config.timezone":input.string("config_timezone"), "config.output":input.string("config_output"), "config.animations":input.bool("config_animations"), - "config.padding":input.number("config_padding"), + "config.padding":input.string("config_padding"), } info("Timezone", config["config.timezone"] ?? "(system default)") info("Convert SVG", config["config.output"] ?? "(no)") diff --git a/source/app/metrics.mjs b/source/app/metrics.mjs index b9d15c85..501cdc0d 100644 --- a/source/app/metrics.mjs +++ b/source/app/metrics.mjs @@ -84,7 +84,7 @@ console.debug(`metrics/compute/${login} > render`) let rendered = await ejs.render(image, {...data, s, style, fonts}, {async:true}) //Apply resizing - const {resized, mime} = await svgresize(rendered, {padding:"config.padding" in q ? Number(q["config.padding"]) : undefined, convert}) + const {resized, mime} = await svgresize(rendered, {padding:q["config.padding"], convert}) rendered = resized //Additional SVG transformations @@ -180,12 +180,16 @@ } /** Render svg */ - async function svgresize(svg, {padding = 20, convert} = {}) { + async function svgresize(svg, {padding = "2%", convert} = {}) { //Instantiate browser if needed if (!svgresize.browser) { svgresize.browser = await puppeteer.launch({headless:true, executablePath:process.env.PUPPETEER_BROWSER_PATH, args:["--no-sandbox", "--disable-extensions", "--disable-setuid-sandbox", "--disable-dev-shm-usage"]}) console.debug(`metrics/svgresize > started ${await svgresize.browser.version()}`) } + //Format padding + padding = ((Number(`${padding}`.substring(0, padding.length-1))||0)/100) + console.debug(`metrics/svgresize > padding ${(100*padding).toFixed(2)}%`) + padding += 1 //Render through browser and resize height const page = await svgresize.browser.newPage() await page.setContent(svg, {waitUntil:"load"}) @@ -197,7 +201,7 @@ document.querySelector("svg").classList.add("no-animations") //Get bounds and resize let {y:height, width} = document.querySelector("svg #metrics-end").getBoundingClientRect() - height = Math.ceil(height + padding) + height = Math.ceil(height*padding) width = Math.ceil(width) //Resize svg document.querySelector("svg").setAttribute("height", height)