UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

64 lines (63 loc) • 1.83 kB
/** * DevExtreme (esm/__internal/viz/core/layout_element.js) * Version: 26.1.6 * Build date: Fri Oct 16 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import { noop } from "../../core/utils/m_common"; const _round = Math.round; const defaultOffset = { horizontal: 0, vertical: 0 }; const alignFactors = { center: .5, right: 1, bottom: 1, left: 0, top: 0 }; class LayoutElement { constructor(options) { this._options = options } position(options) { const ofBBox = options.of.getLayoutOptions(); const myBBox = this.getLayoutOptions(); const { at: at } = options; const { my: my } = options; const offset = options.offset || defaultOffset; const shiftX = -alignFactors[my.horizontal] * myBBox.width + ofBBox.x + alignFactors[at.horizontal] * ofBBox.width + parseInt(offset.horizontal); const shiftY = -alignFactors[my.vertical] * myBBox.height + ofBBox.y + alignFactors[at.vertical] * ofBBox.height + parseInt(offset.vertical); this.shift(_round(shiftX), _round(shiftY)) } } Object.assign(LayoutElement.prototype, { getLayoutOptions: noop }); class WrapperLayoutElement extends LayoutElement { constructor(renderElement, bBox) { super(); this._renderElement = renderElement; this._cacheBBox = bBox } getLayoutOptions() { return this._cacheBBox || this._renderElement.getBBox() } shift(shiftX, shiftY) { const bBox = this.getLayoutOptions(); this._renderElement.move(_round(shiftX - bBox.x), _round(shiftY - bBox.y)) } } export { LayoutElement, WrapperLayoutElement };