UNPKG

@visactor/vgrammar-core

Version:

VGrammar is a visual grammar library

40 lines (34 loc) 2.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.registerDefaultLayout = exports.defaultDoLayout = void 0; const vutils_1 = require("@visactor/vutils"), constants_1 = require("./../../view/constants"), enums_1 = require("../enums"), grid_1 = require("./grid"), relative_1 = require("./relative"), factory_1 = require("../../core/factory"), defaultDoLayout = (layoutMarks, options, view) => { null == layoutMarks || layoutMarks.forEach((mark => { var _a; if (mark.markType !== enums_1.GrammarMarkType.group) return; const layoutChildren = mark.layoutChildren, layoutSpec = mark.getSpec().layout, bounds = null !== (_a = mark.layoutBounds) && void 0 !== _a ? _a : mark.getBounds(); if (bounds) { if ((0, vutils_1.isFunction)(layoutSpec)) layoutSpec.call(null, mark, layoutChildren, bounds, options); else if ((0, vutils_1.isFunction)(layoutSpec.callback)) layoutSpec.callback.call(null, mark, layoutChildren, bounds, options); else if ("relative" === layoutSpec.display) if (layoutSpec.updateViewSignals) { const oldViewBox = view.getViewBox(); oldViewBox && bounds.intersect(oldViewBox); const viewBounds = (0, relative_1.doRelativeLayout)(mark, layoutChildren, bounds, options), viewWidth = viewBounds.width(), viewHeight = viewBounds.height(), padding = { top: viewBounds.y1, right: view.width() - viewBounds.x2, left: viewBounds.x1, bottom: view.height() - viewBounds.y2 }; view.updateSignal(constants_1.SIGNAL_VIEW_WIDTH, viewWidth), view.updateSignal(constants_1.SIGNAL_VIEW_HEIGHT, viewHeight), view.updateSignal(constants_1.SIGNAL_PADDING, padding); } else (0, relative_1.doRelativeLayout)(mark, layoutChildren, bounds, options); else "grid" === layoutSpec.display && (0, grid_1.doGridLayout)(mark, layoutChildren, bounds, options); (0, exports.defaultDoLayout)(layoutChildren, options, view); } })); }; exports.defaultDoLayout = defaultDoLayout; const registerDefaultLayout = () => { factory_1.Factory.registerDefaultLayout(exports.defaultDoLayout); }; exports.registerDefaultLayout = registerDefaultLayout; //# sourceMappingURL=layout.js.map