/** * Collision-aware label placement. Callers register obstacles (node boxes, * connector polylines, arrowhead zones, already placed labels) and pick the * cheapest of several candidate positions for each label. Costs grow with the * area of overlapping boxes and the length of line segments running through * the label, so labels avoid covering lines, heads and other labels. * @module layout/labels */ export type Box = { x: number; y: number; w: number; h: number; }; export type Point = [number, number]; /** @typedef {{ x: number, y: number, w: number, h: number }} Box */ /** @typedef {[number, number]} Point */ /** * Length of the part of segment a→b inside a box (Liang–Barsky clipping). * @param {Point} a * @param {Point} b * @param {Box} r */ export declare function segmentInBox(a: Point, b: Point, r: Box): number; /** * @param {Box} a * @param {Box} b */ export declare function overlapArea(a: Box, b: Box): number; /** @public */ export declare class Obstacles { /** @type {{ box: Box, weight: number, owner: string | null }[]} */ boxes: { box: Box; weight: number; owner: string | null; }[]; /** @type {{ a: Point, b: Point, weight: number, owner: string | null }[]} */ segments: { a: Point; b: Point; weight: number; owner: string | null; }[]; constructor(); /** * @param {Box} box * @param {{ weight?: number, owner?: string | null }} [o] */ addBox(box: Box, o?: { weight?: number; owner?: string | null; }): void; /** * @param {Point[]} points * @param {{ weight?: number, owner?: string | null }} [o] */ addPolyline(points: Point[], o?: { weight?: number; owner?: string | null; }): void; /** * Protect the area around a line end (arrowheads, crow's feet, diamonds). * @param {Point} tip * @param {Point} from Neighbouring point on the line. * @param {number} [size] */ addHead(tip: Point, from: Point, size?: number): void; /** * Cost of putting a label at `box`. Obstacles owned by `ignore` (the * label's own edge, for example) only count where they cross the label. * @param {Box} box * @param {string | null} [ignore] */ cost(box: Box, ignore?: string | null): number; /** * Choose the cheapest candidate (ties keep the earlier candidate) and * register it as an obstacle. * @param {(Box & { penalty?: number })[]} candidates * @param {{ owner?: string | null, register?: boolean }} [o] * @returns {Box} */ place(candidates: (Box & { penalty?: number; })[], o?: { owner?: string | null; register?: boolean; }): Box; } /** * Candidate boxes for a label of size `w × h` along a polyline: at several * points of every segment, on both sides, plus centred on the line. * @param {Point[]} points * @param {number} w * @param {number} h * @param {{ margin?: number, keepFromEnds?: number, preferred?: Box | null }} [o] * @returns {(Box & { penalty: number })[]} */ export declare function alongPolyline(points: Point[], w: number, h: number, o?: { margin?: number; keepFromEnds?: number; preferred?: Box | null; }): (Box & { penalty: number; })[]; /** * Candidate boxes for an end label (multiplicity, role) near `tip`, beyond * the arrowhead zone and on either side of the line. * @param {Point} tip * @param {Point} from * @param {number} w * @param {number} h * @param {boolean} [headed] The end carries an arrowhead / diamond; labels keep clear of it. * @returns {(Box & { penalty: number })[]} */ export declare function nearEnd(tip: Point, from: Point, w: number, h: number, headed?: boolean): (Box & { penalty: number; })[];