detectOverlap = (labelArray, svgBox, spacer = 0) => {
const newArray = labelArray.reduce((acc, currentLabel) => {
const svg = {
boundingBox: svgBox,
position: { x: 0, y: 0 }
};
const isInside = hasCanvasBoxOverlap(svg, currentLabel, spacer);
if (!isInside) {
currentLabel.overlap = {
hide: true,
conflict: "outside",
conflictIds: -1
};
return acc;
}
const overlappingObjects = acc.filter((existingLabel) =>
hasBoundingBoxOverlap(existingLabel, currentLabel, spacer)
);
const overlapFound = overlappingObjects.length > 0;
currentLabel.overlap = {
hide: overlapFound,
conflict: overlapFound ? "overlap" : "none",
conflictIds: overlappingObjects.map((d) => d.text)
};
if (!overlapFound) acc.push(currentLabel);
return acc;
}, []);
}