如何调整bpmnR生成的BPMN图为从左到右线性布局?
用bpmnR实现BPMN图从左到右线性展示
要让你的BPMN图呈现从左到右的线性布局,最直接的方法是手动指定每个元素的坐标,bpmnR支持在创建节点和事件时添加x、y坐标参数来精准控制位置。
修改你的代码如下:
library(dplyr) library(bpmnR) # 创建BPMN元素数据(添加x、y坐标指定横向排列位置) nodes <- tibble(id = "task", name = "Task name", objectType = "task", gatewayDirection = NA, x = 200, y = 100) # 任务节点居中放置 events <- tibble(id = c("start", "end"), name = c("Start event", "End event"), objectType = c("startEvent", "endEvent"), x = c(50, 350), y = c(100, 100)) # 起始事件左置、结束事件右置,保持同一水平线 flows <- tibble(id = c("flow1", "flow2"), name = c("flow1", "flow2"), sourceRef = c("start", "task"), targetRef = c("task", "end"), objectType = c("sequenceFlow", "sequenceFlow")) # 创建BPMN模型 model <- create_bpmn(nodes, flows, events) # 渲染BPMN图 render_bpmn( model, # 使用创建好的model viewer.suppress = FALSE, width = NULL, height = NULL, elementId = NULL, xml_version_number = "1.0", xml_encoding_declaration = "UTF-8" )
说明
- 将所有元素的
y值设为相同(示例中为100),保证它们处于同一水平线上;按起始事件→任务→结束事件的顺序递增x值,就能实现严格的左到右线性排列。 - 若后续扩展复杂线性流程,只需按规律递增每个新增元素的
x坐标,即可维持横向布局。
内容的提问来源于stack exchange,提问作者Irfan Malick
相关产品推荐
相关产品推荐

