|
function generateRandomColor(){ |
|
let maxVal = 0xFFFFFF; |
|
let randomNumber = Math.random() * maxVal; |
|
randomNumber = Math.floor(randomNumber); |
|
randomNumber = randomNumber.toString(16); |
|
let randColor = randomNumber.padStart(6, 0); |
|
return `#${randColor.toUpperCase()}` |
|
} |
|
|
|
|
|
function getScaledCoordinates(box, img) { |
|
|
|
const originalWidth = img.naturalWidth; |
|
const originalHeight = img.naturalHeight; |
|
|
|
|
|
const scaledWidth = img.offsetWidth; |
|
const scaledHeight = img.offsetHeight; |
|
|
|
|
|
const scale = scaledWidth / originalWidth; |
|
|
|
|
|
let ymax = box.ymax * scale; |
|
let xmax = box.xmax * scale; |
|
let ymin = box.ymin * scale; |
|
let xmin = box.xmin * scale; |
|
|
|
|
|
|
|
ymin = Math.max(0, box.ymin * scale) |
|
xmin = Math.max(0, box.xmin * scale) |
|
ymax = Math.min(scaledHeight, ymax) |
|
xmax = Math.min(scaledWidth, xmax) |
|
|
|
return { |
|
ymin, |
|
xmin, |
|
ymax, |
|
xmax |
|
} |
|
} |
|
|
|
|
|
function removeElements(className) { |
|
const HTMLcollection = document.getElementsByClassName(className) |
|
Array.from(HTMLcollection).forEach(element => element.remove()) |
|
} |
|
|
|
export { generateRandomColor, removeElements, getScaledCoordinates } |