UNPKG

@antv/x6

Version:

JavaScript diagramming library that uses SVG and HTML for rendering

61 lines 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.anchor = void 0; const util_1 = require("./util"); function alignLine(line, type, offset = 0) { const { start, end } = line; let a; let b; let direction; let coordinate; switch (type) { case 'left': coordinate = 'x'; a = end; b = start; direction = -1; break; case 'right': coordinate = 'x'; a = start; b = end; direction = 1; break; case 'top': coordinate = 'y'; a = end; b = start; direction = -1; break; case 'bottom': coordinate = 'y'; a = start; b = end; direction = 1; break; default: return; } if (start[coordinate] < end[coordinate]) { a[coordinate] = b[coordinate]; } else { b[coordinate] = a[coordinate]; } if (Number.isFinite(offset)) { a[coordinate] += direction * offset; b[coordinate] += direction * offset; } } /** * Places the connection point at the edge's endpoint. */ const anchor = (line, view, magnet, options) => { const { alignOffset, align } = options; if (align) { alignLine(line, align, alignOffset); } return (0, util_1.offset)(line.end, line.start, options.offset); }; exports.anchor = anchor; //# sourceMappingURL=anchor.js.map