容器與泳道
容器用於在畫板上表示帶邊框的區域、泳道、UML 包塊以及其他父子結構。容器的歸屬關係記錄在子元素上:parentId 指向所屬容器,泳道成員還會使用 laneId。
建立容器
TypeScript
const board = univerAPI.getActiveBoard()if (!board) throw new Error('No active Board')const containerId = 'scope'const containerCreated = board.createContainer({ id: containerId, title: 'Scope', left: 80, top: 80, width: 640, height: 360,})if (!containerCreated) { throw new Error('Cannot create container')}從畫布插入容器
畫布工具列中的容器面板提供四個固定長寬比的預設圖磚:16:9、4:3、1:1 和 A4。區段標題旁另提供自訂容器操作,以及精簡的縱向和橫向泳道按鈕。若要以程式方式插入,請使用 createContainer() 或 createSwimlane()。
將元素移入容器
TypeScript
board.moveElementsToContainer(['card-1', 'card-2'], containerId)board.fitContainerToContent(containerId)設定隸屬行為
TypeScript
board.setContainerMembershipLocked(containerId, true)board.setContainerAutoResize(containerId, false)泳道
泳道是帶有分道配置的容器。專用的 facade API 可以新增、移除、調整分道大小、重排分道、摺疊和重新命名分道。
TypeScript
const swimlaneId = 'delivery'const swimlaneCreated = board.createSwimlane({ id: swimlaneId, left: 80, top: 80, width: 720, height: 360, orientation: 'horizontal', lanes: [ { id: 'todo', title: 'Todo', size: 240 }, { id: 'done', title: 'Done', size: 240 }, ],})if (!swimlaneCreated) { throw new Error('Cannot create swimlane')}board.renameSwimlaneLane(swimlaneId, 'todo', 'Backlog')你覺得這篇文檔如何?