highcharts
Version:
JavaScript charting framework
69 lines (68 loc) • 1.57 kB
JavaScript
/* *
*
* (c) 2009-2026 Highsoft AS
* Author: Torstein Hønsi
*
* A commercial license may be required depending on use.
* See www.highcharts.com/license
*
*
* */
;
/* *
*
* Functions
*
* */
/**
* Counter-clockwise, part of the fast line intersection logic.
*
* @internal
* @function ccw
*/
function ccw(x1, y1, x2, y2, x3, y3) {
const cw = ((y3 - y1) * (x2 - x1)) - ((y2 - y1) * (x3 - x1));
return cw > 0 ? true : !(cw < 0);
}
/**
* Detect if two lines intersect.
*
* @internal
* @function intersectLine
*/
function intersectLine(x1, y1, x2, y2, x3, y3, x4, y4) {
return ccw(x1, y1, x3, y3, x4, y4) !== ccw(x2, y2, x3, y3, x4, y4) &&
ccw(x1, y1, x2, y2, x3, y3) !== ccw(x1, y1, x2, y2, x4, y4);
}
/**
* Detect if a box intersects with a line.
*
* @internal
* @function boxIntersectLine
*/
function boxIntersectLine(x, y, w, h, x1, y1, x2, y2) {
return (intersectLine(x, y, x + w, y, x1, y1, x2, y2) || // Top of label
intersectLine(x + w, y, x + w, y + h, x1, y1, x2, y2) || // Right
intersectLine(x, y + h, x + w, y + h, x1, y1, x2, y2) || // Bottom
intersectLine(x, y, x, y + h, x1, y1, x2, y2) // Left of label
);
}
/** @internal */
function intersectRect(r1, r2) {
return !(r2.left > r1.right ||
r2.right < r1.left ||
r2.top > r1.bottom ||
r2.bottom < r1.top);
}
/* *
*
* Default Export
*
* */
/** @internal */
const SeriesLabelUtilities = {
boxIntersectLine,
intersectRect
};
/** @internal */
export default SeriesLabelUtilities;