Accept both absolute and relative values for config padding (#308)
This commit is contained in:
@@ -283,13 +283,20 @@ export const svg = {
|
|||||||
console.debug(`metrics/svg/resize > started ${await svg.resize.browser.version()}`)
|
console.debug(`metrics/svg/resize > started ${await svg.resize.browser.version()}`)
|
||||||
}
|
}
|
||||||
//Format padding
|
//Format padding
|
||||||
const [pw = 1, ph] = (Array.isArray(paddings) ? paddings : `${paddings}`.split(",").map(x => x.trim())).map(padding => `${padding}`.substring(0, padding.length - 1)).map(value => 1 + Number(value) / 100)
|
const padding = {width:1, height:1, absolute:{width:0, height:0}}
|
||||||
const padding = {width:pw, height:(ph ?? pw)}
|
paddings = Array.isArray(paddings) ? paddings : `${paddings}`.split(",").map(x => x.trim())
|
||||||
if (!Number.isFinite(padding.width))
|
for (const [i, dimension] of [[0, "width"], [1, "height"]]) {
|
||||||
padding.width = 1
|
let operands = (paddings?.[i] ?? paddings[0])
|
||||||
if (!Number.isFinite(padding.height))
|
let {relative} = operands.match(/(?<relative>[+-]?[\d.]+)%$/)?.groups ?? {}
|
||||||
padding.height = 1
|
operands = operands.replace(relative, "").trim()
|
||||||
console.debug(`metrics/svg/resize > padding width*${padding.width}, height*${padding.height}`)
|
let {absolute} = operands.match(/^(?<absolute>[+-]?[\d.]+)/)?.groups ?? {}
|
||||||
|
operands = operands.replace(absolute, "").trim()
|
||||||
|
if (Number.isFinite(Number(absolute)))
|
||||||
|
padding.absolute[dimension] = Number(absolute)
|
||||||
|
if (Number.isFinite(Number(relative)))
|
||||||
|
padding[dimension] = 1 + Number(relative/100)
|
||||||
|
}
|
||||||
|
console.debug(`metrics/svg/resize > padding width*${padding.width}+${padding.absolute.width}, height*${padding.height}+${padding.absolute.height}`)
|
||||||
//Render through browser and resize height
|
//Render through browser and resize height
|
||||||
console.debug("metrics/svg/resize > loading svg")
|
console.debug("metrics/svg/resize > loading svg")
|
||||||
const page = await svg.resize.browser.newPage()
|
const page = await svg.resize.browser.newPage()
|
||||||
@@ -311,9 +318,9 @@ export const svg = {
|
|||||||
//Get bounds and resize
|
//Get bounds and resize
|
||||||
let {y:height, width} = document.querySelector("svg #metrics-end").getBoundingClientRect()
|
let {y:height, width} = document.querySelector("svg #metrics-end").getBoundingClientRect()
|
||||||
console.debug(`bounds width=${width}, height=${height}`)
|
console.debug(`bounds width=${width}, height=${height}`)
|
||||||
height = Math.ceil(height * padding.height)
|
height = Math.ceil(height * padding.height + padding.absolute.height)
|
||||||
width = Math.ceil(width * padding.width)
|
width = Math.ceil(width * padding.width + padding.absolute.width)
|
||||||
console.debug(`bounds after applying padding width=${width} (*${padding.width}), height=${height} (*${padding.height})`)
|
console.debug(`bounds after applying padding width=${width} (*${padding.width}+${padding.absolute.width}), height=${height} (*${padding.height}+${padding.absolute.height})`)
|
||||||
//Resize svg
|
//Resize svg
|
||||||
document.querySelector("svg").setAttribute("height", height)
|
document.querySelector("svg").setAttribute("height", height)
|
||||||
//Enable animations
|
//Enable animations
|
||||||
|
|||||||
@@ -161,7 +161,9 @@ As it can depend on fonts and operating system, it is possible that final result
|
|||||||
|
|
||||||
You can adjust padding by using `config_padding` option.
|
You can adjust padding by using `config_padding` option.
|
||||||
|
|
||||||
Specify a single value to apply it to both height and with, and two values to use the first one for width and the second for height. Both positive and negative values are accepted, but you must specify a percentage.
|
Specify a single value to apply it to both height and with, and two values to use the first one for width and the second for height. Both positive and negative values are accepted.
|
||||||
|
|
||||||
|
The allowed format is `(absolute padding) + (relative padding)%` (each operand is optional).
|
||||||
|
|
||||||
#### ℹ️ Examples workflows
|
#### ℹ️ Examples workflows
|
||||||
|
|
||||||
@@ -169,7 +171,7 @@ Specify a single value to apply it to both height and with, and two values to us
|
|||||||
- uses: lowlighter/metrics@latest
|
- uses: lowlighter/metrics@latest
|
||||||
with:
|
with:
|
||||||
# ... other options
|
# ... other options
|
||||||
config_padding: 6%, 15% # 6% width padding, 15% height padding
|
config_padding: 16, 32 + 8% # 16px width padding, 32px + 8% height padding
|
||||||
```
|
```
|
||||||
|
|
||||||
### 🧶 Using commits, pull requests, manual reviews or gists to handle metrics output
|
### 🧶 Using commits, pull requests, manual reviews or gists to handle metrics output
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ inputs:
|
|||||||
description: Image padding
|
description: Image padding
|
||||||
type: array
|
type: array
|
||||||
format: comma-separated
|
format: comma-separated
|
||||||
default: 6%, 15%
|
default: 16, 32 + 8%
|
||||||
|
|
||||||
# Metrics output format
|
# Metrics output format
|
||||||
config_output:
|
config_output:
|
||||||
|
|||||||
Reference in New Issue
Block a user