### Local Development Setup for LogicFlow Source: https://github.com/didi/logicflow/blob/master/README.md Shell commands to install dependencies, build the core package, and start the example server for local development. ```shell # 安装项目依赖和初始化构建 $ pnpm install # 进入到指定项目开发和调试 cd packages/core pnpm run build:watch # 启动 example 查看效果 cd examples/feature-examples pnpm run start ``` -------------------------------- ### Development Setup for LogicFlow Source: https://github.com/didi/logicflow/blob/master/README.en-US.md Commands for setting up the development environment for LogicFlow. Includes installing dependencies, building the core package with watch mode, and starting an example for development. ```shell # install deps and build $ pnpm install # enter the specified project for development and debugging cd packages/core pnpm run build:watch # start example to develop cd examples/feature-examples pnpm run start ``` -------------------------------- ### Full Example with Pools, Lanes, and Nodes Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/extension/pool.en.md Provides a complete example demonstrating the data structure for a pool containing multiple lanes and nodes. ```APIDOC ## Full Example This example shows a pool with two lanes, each containing a node. ```typescript lf.render({ nodes: [ { id: 'pool_1', type: 'pool', x: 500, y: 260, text: 'Pool (H)', properties: { direction: 'horizontal', width: 520, height: 360, children: ['lane_1', 'lane_2'], }, children: ['lane_1', 'lane_2'], }, { id: 'lane_1', type: 'lane', x: 540, y: 340, text: 'Lane 1', properties: { parent: 'pool_1', width: 440, height: 180, isRestrict: true, autoResize: false, children: ['rect_1'], }, children: ['rect_1'], }, { id: 'lane_2', type: 'lane', x: 540, y: 160, text: 'Lane 2', properties: { parent: 'pool_1', width: 440, height: 180, children: ['circle_1'], }, children: ['circle_1'], }, { id: 'rect_1', type: 'rect', x: 470, y: 350, text: 'Node A', properties: { parent: 'lane_1', }, }, { id: 'circle_1', type: 'circle', x: 620, y: 150, text: 'Node B', properties: { parent: 'lane_2', }, }, ], edges: [], }) ``` ``` -------------------------------- ### Install LogicFlow Core and Extensions Source: https://github.com/didi/logicflow/blob/master/README.md Install the LogicFlow core editor and its extension packages using npm, yarn, or pnpm. ```shell # npm $ npm install @logicflow/core @logicflow/extension --save ``` ```shell # yarn $ yarn add @logicflow/core @logicflow/extension ``` ```shell # pnpm $ pnpm add @logicflow/core @logicflow/extension ``` -------------------------------- ### Core Verification Workflow Source: https://github.com/didi/logicflow/blob/master/packages/core/ARCHITECTURE.md Steps to verify core changes by building the package and running examples. This includes watching for build changes and starting a local development server. ```sh cd packages/core pnpm run build:watch cd examples/feature-examples pnpm start ``` -------------------------------- ### Example Graph Data Definition and Rendering Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/basic/class.en.md A complete example demonstrating how to define graph data, including nodes and edges, and then render it using the LogicFlow instance. ```javascript const graphData = { nodes: [ { id: 'node-1', type: 'rect', x: 100, y: 100, text: 'Node 1' }, { id: 'node-2', type: 'circle', x: 300, y: 100, text: 'Node 2' } ], edges: [ { id: 'edge-1', type: 'line', sourceNodeId: 'node-1', targetNodeId: 'node-2' } ] }; lf.render(graphData); ``` -------------------------------- ### Global Plugin Installation via CDN Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/extension/intro.en.md Install LogicFlow core and extension plugins, including the Menu plugin, using CDN links. The Menu plugin is then registered globally. ```html ``` -------------------------------- ### Install LogicFlow Extension with pnpm Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/get-started.en.md Install the LogicFlow extension package using pnpm. This is required if you plan to use additional plugins. ```bash pnpm add @logicflow/extension ``` -------------------------------- ### Render BPMN Start Event with Timer Definition Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/extension/bpmn-element.en.md Renders a BPMN start event node with a timer event definition. This example shows how to set the `definitionType` in the node's properties to apply the configured timer definition. ```typescript lf.render({ nodes: [ { id: 1, type: 'bpmn:startEvent', text: '5 min timed start', properties: { definitionType: 'bpmn:timerEventDefinition', }, } ] }) ``` -------------------------------- ### Install Control Panel Plugin via CDN Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/get-started.en.md Use this snippet to install the control panel plugin when using LogicFlow via CDN. It includes importing the extension script and CSS, and then initializing LogicFlow with the Control plugin. ```html
``` -------------------------------- ### Example Extension Implementation Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/api/type/MainTypes.zh.md Demonstrates how to implement the ExtensionRenderFunc for a custom LogicFlow extension. This example creates a simple div element and appends it to the provided container. ```typescript const myExtension: ExtensionDefinition = { pluginName: 'MyCustomExtension', render: (lf, container) => { const element = document.createElement('div'); element.innerHTML = 'Hello from MyCustomExtension!'; container.appendChild(element); }, }; ``` -------------------------------- ### Install LogicFlow Core with pnpm Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/get-started.en.md Install the core LogicFlow package using pnpm. This is the primary dependency for creating flowcharts. ```bash pnpm add @logicflow/core ``` -------------------------------- ### Install LogicFlow Core with npm Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/get-started.en.md Install the core LogicFlow package using npm. This is the primary dependency for creating flowcharts. ```bash npm install @logicflow/core --save ``` -------------------------------- ### Install BpmnElement Extension (CDN) Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/extension/bpmn-element.zh.md Include the extension script and CSS via CDN, then use BpmnElement globally or for a single LogicFlow instance. ```html ``` -------------------------------- ### Install LogicFlow Extension with npm Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/get-started.en.md Install the LogicFlow extension package using npm. This is required if you plan to use additional plugins. ```bash npm install @logicflow/extension --save ``` -------------------------------- ### Instance-Level Plugin Installation Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/extension/intro.en.md Install plugins like DndPanel and SelectionSelect directly on a LogicFlow instance by passing them in the `plugins` array during initialization. This allows for different plugins on different pages within a single-page application. ```tsx import LogicFlow from "@logicflow/core"; import { DndPanel, SelectionSelect } from "@logicflow/extension"; import "@logicflow/core/lib/style/index.css"; // import "@logicflow/core/dist/style/index.css"; // Introduced before version 2.0 import "@logicflow/extension/lib/style/index.css"; const lf = new LogicFlow({ container: document.querySelector("#app"), grid: true, plugins: [DndPanel, SelectionSelect] }); ``` -------------------------------- ### Install LogicFlow Core with yarn Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/get-started.en.md Install the core LogicFlow package using yarn. This is the primary dependency for creating flowcharts. ```bash yarn add @logicflow/core ``` -------------------------------- ### Install LogicFlow Extension with yarn Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/get-started.en.md Install the LogicFlow extension package using yarn. This is required if you plan to use additional plugins. ```bash yarn add @logicflow/extension ``` -------------------------------- ### Full Example with Pools, Lanes, and Nodes Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/extension/pool.en.md Demonstrates the data structure for rendering a pool with multiple lanes and nodes, including hierarchy and properties. ```ts lf.render({ nodes: [ { id: 'pool_1', type: 'pool', x: 500, y: 260, text: 'Pool (H)', properties: { direction: 'horizontal', width: 520, height: 360, children: ['lane_1', 'lane_2'], }, children: ['lane_1', 'lane_2'], }, { id: 'lane_1', type: 'lane', x: 540, y: 340, text: 'Lane 1', properties: { parent: 'pool_1', width: 440, height: 180, isRestrict: true, autoResize: false, children: ['rect_1'], }, children: ['rect_1'], }, { id: 'lane_2', type: 'lane', x: 540, y: 160, text: 'Lane 2', properties: { parent: 'pool_1', width: 440, height: 180, children: ['circle_1'], }, children: ['circle_1'], }, { id: 'rect_1', type: 'rect', x: 470, y: 350, text: 'Node A', properties: { parent: 'lane_1', }, }, { id: 'circle_1', type: 'circle', x: 620, y: 150, text: 'Node B', properties: { parent: 'lane_2', }, }, ], edges: [], }) ``` -------------------------------- ### Full Example with Pools and Lanes Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/extension/pool.zh.md Demonstrates a complete data structure for a pool containing multiple lanes and nodes. ```APIDOC ## Full Example with Pools and Lanes ### Description Demonstrates a complete data structure for a pool containing multiple lanes and nodes. ### Method ```ts lf.render({ nodes: [ { id: 'pool_1', type: 'pool', x: 500, y: 260, text: '横向泳池', properties: { direction: 'horizontal', width: 520, height: 360, children: ['lane_1', 'lane_2'], }, children: ['lane_1', 'lane_2'], }, { id: 'lane_1', type: 'lane', x: 540, y: 340, text: '泳道1', properties: { parent: 'pool_1', width: 440, height: 180, isRestrict: true, autoResize: false, children: ['rect_1'], }, children: ['rect_1'], }, { id: 'lane_2', type: 'lane', x: 540, y: 160, text: '泳道2', properties: { parent: 'pool_1', width: 440, height: 180, children: ['circle_1'], }, children: ['circle_1'], }, { id: 'rect_1', type: 'rect', x: 470, y: 350, text: '节点A', properties: { parent: 'lane_1', }, }, { id: 'circle_1', type: 'circle', x: 620, y: 150, text: '节点B', properties: { parent: 'lane_2', }, }, ], edges: [], }) ``` ``` -------------------------------- ### ExtensionConfig Example Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/api/type/MainTypes.zh.md An example of how to configure a LogicFlow extension using the ExtensionConfig type. This includes a unique plugin flag, the extension definition, and optional properties. ```typescript const myExtensionConfig: LogicFlow.ExtensionConfig = { pluginFlag: Symbol('myExtension'), extension: myExtension, // 这可以是 ExtensionConstructor 或 ExtensionDefinition 的实例 props: { // 传递给扩展的额外属性 } }; ``` -------------------------------- ### Install BpmnElement Plugin Globally Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/extension/intro.en.md Use the BpmnElement plugin by importing it from `@logicflow/extension` and applying it globally with `LogicFlow.use()`. ```tsx import { BpmnElement } from '@logicflow/extension' LogicFlow.use(BpmnElement) ``` -------------------------------- ### Install BpmnElement Extension (npm) Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/extension/bpmn-element.zh.md Import and use the BpmnElement extension globally or for a single LogicFlow instance when using npm. ```tsx import { BpmnElement } from '@logicflow/extension' // 全局使用 LogicFlow.use(BpmnElement) // 单实例使用 const lf = new LogicFlow({ // ..., // 其他配置项 plugins: [BpmnElement], }) ``` -------------------------------- ### Dynamic Group Node Configuration Example Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/extension/dynamic-group.en.md An example configuration object for a dynamic group node, specifying its ID, type, position, text, and various properties like collapsible, size, and child restrictions. ```typescript const dynamicGroupNodeConfig = { id: 'dynamic-group_1', type: 'dynamic-group', x: 500, y: 140, text: 'dynamic-group_1', resizable: true, rotatable: false, properties: { children: ["rect_3"], collapsible: true, // Enable collapsing isCollapsed: false, // Initial state is expanded width: 420, // Width when expanded height: 250, // Height when expanded collapsedWidth: 80, // Width when collapsed collapsedHeight: 60, // Height when collapsed radius: 5, // Border radius isRestrict: false, // Don't restrict child node movement autoResize: false, // Don't auto-resize transformWithContainer: true, // Transform children with group zIndex: -1000, // Layer index autoToFront: true, // Auto bring to front when selected }, } ``` -------------------------------- ### Global Plugin Installation Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/extension/intro.en.md Install common extension plugins like Control, Menu, and DndPanel globally for use across your LogicFlow editor. Ensure the extension CSS is also imported. ```tsx import LogicFlow from '@logicflow/core' import { Control, Menu, DndPanel } from '@logicflow/extension' import '@logicflow/extension/lib/style/index.css' ``` ```tsx LogicFlow.use(Control) LogicFlow.use(Menu) LogicFlow.use(DndPanel) ``` -------------------------------- ### ExtensionConstructor Implementation Example Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/api/type/MainTypes.zh.md Shows how to implement the ExtensionConstructor for a LogicFlow plugin. This class defines the pluginName and initializes the extension using provided properties. ```typescript class MyCustomExtension implements ExtensionConstructor { pluginName = 'MyCustomExtension'; constructor(props: IExtensionProps) { // 使用提供的 props 初始化扩展 } } ``` -------------------------------- ### Install BPMN Adapter (CDN) Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/extension/bpmn-element.zh.md Include the extension script and CSS via CDN. Initialize LogicFlow globally or as a single instance, selecting the appropriate BPMN adapter. ```html ``` -------------------------------- ### getBeginAnchor Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/api/runtime-model/edgeModel.zh.md Gets the starting anchor point for the edge. ```APIDOC ## getBeginAnchor Gets the starting anchor point. ### Description Retrieves the starting anchor point coordinates for the edge. ### Method `getBeginAnchor(sourceNode: BaseNodeModel, targetNode: BaseNodeModel)` ### Parameters - `sourceNode` (BaseNodeModel) - The source node model. - `targetNode` (BaseNodeModel) - The target node model. ### Returns - `LogicFlow.Point` - The coordinates of the starting anchor point. ``` -------------------------------- ### Install BPMN Adapter (npm) Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/extension/bpmn-element.zh.md Import and use BPMNElements, BPMNAdapter, or BPMNBaseAdapter for global or single-instance LogicFlow initialization. Choose the adapter based on your needs. ```tsx import { BPMNElements, BPMNBaseAdapter, BPMNAdapter } from '@logicflow/extension' LogicFlow.use(BPMNElements) // 根据实际需求,选择引入 BPMNAdapter 或 BPMNBaseAdapter // 全局使用 LogicFlow.use(BPMNAdapter) // LogicFlow.use(BPMNBaseAdapter) // 单实例使用 const lf = new LogicFlow({ // ..., // 其他配置项 plugins: [ BPMNElements, // 根据实际需求,选择引入 BpmnAdapter 或 BpmnXmlAdapter BPMNAdapter, // BPMNBaseAdapter ], }) ``` -------------------------------- ### Define Connection Rules for Start Node (Target) Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/api/runtime-model/nodeModel.zh.md Overrides getConnectedTargetRules to add custom rules for when a node can be a connection target. This example prevents the start node from being a target. ```typescript class StartEventModel extends CircleNodeModel { getConnectedTargetRules() { const rules = super.getConnectedTargetRules(); const notAsTarget = { message: "起始节点不能作为边的终点", validate: () => false, }; rules.push(notAsTarget); return rules; } } ``` -------------------------------- ### Initialization with PoolElements Plugin Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/extension/pool.en.md Demonstrates how to initialize LogicFlow with the PoolElements plugin enabled. ```APIDOC ## Initialization ### Description Initialize LogicFlow with the `PoolElements` plugin to enable swimlane functionality. ### Code ```typescript import LogicFlow from '@logicflow/core' import { PoolElements } from '@logicflow/extension' import '@logicflow/core/es/index.css' import '@logicflow/extension/es/index.css' const lf = new LogicFlow({ container: document.querySelector('#container') as HTMLElement, plugins: [PoolElements], allowResize: true, }) ``` ``` -------------------------------- ### Initialize LogicFlow Instance Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/article/architecture-of-logicflow.zh.md Demonstrates the basic instantiation of LogicFlow with container, dimensions, background, and grid configurations. Use this to set up a new LogicFlow instance for rendering a flowchart. ```javascript const lf = new LogicFlow({ container: document.querySelector('#graph'), width: 700, height: 600, background: { color: '#F0F0F0' }, grid: { type: 'dot', size: 20, }, }); lf.render({ nodes: [], edges: []}); ``` -------------------------------- ### Get Node Rotate Control Style Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/api/runtime-model/nodeModel.zh.md Retrieves the style for the current node's rotation control point. No specific setup is required beyond having a node instance. ```typescript getRotateControlStyle() ``` -------------------------------- ### Get Graph Data Example Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/api/type/MainTypes.zh.md Demonstrates how to retrieve the current graph data using the getGraphData method. The output is a GraphData object representing the diagram's nodes and edges. ```javascript const graphData = lf.getGraphData() console.log(graphData) // { // nodes: [ // { // id: 'node_1', // type: 'rect', // x: 100, // y: 100, // text: { // value: 'Start', // x: 100, // y: 100, // }, // }, // { // id: 'node_2', // type: 'circle', // x: 300, // y: 200, // text: { // value: 'End', // x: 300, // y: 200, // }, // }, // ], // edges: [ // { // id: 'edge_1', // type: 'polyline', // sourceNodeId: 'node_1', // targetNodeId: 'node_2', // }, // ], // } ``` -------------------------------- ### Initialize LogicFlow with DndPanel and SelectionSelect Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/tutorial/extension/dnd-panel.en.md This snippet shows the basic setup for LogicFlow, enabling the DndPanel and SelectionSelect extensions. Ensure the necessary CSS is imported for proper styling. ```tsx import LogicFlow from '@logicflow/core'; import "@logicflow/core/lib/style/index.css"; // import "@logicflow/core/dist/style/index.css"; // Introduced before version 2.0 import { DndPanel, SelectionSelect } from '@logicflow/extension'; import '@logicflow/extension/lib/style/index.css' LogicFlow.use(DndPanel); LogicFlow.use(SelectionSelect); const lf = new LogicFlow({ container: document.querySelector('#graph') as HTMLElement }); ``` -------------------------------- ### Registering Custom Event Definitions Source: https://github.com/didi/logicflow/blob/master/sites/docs/docs/api/type/MainTypes.zh.md Use DefinitionConfigType to register custom event definitions for multiple node types. This example shows how to configure timer events for start, intermediate catch, and boundary events. ```typescript const customDefinition: DefinitionConfigType[] = [ { // 为startEvent、intermediateCatchEvent、boundaryEvent添加definition nodes: ['startEvent', 'intermediateCatchEvent', 'boundaryEvent'], definition: { // EventDefinitionType类型 /** * definition的type属性,对应XML数据中的节点名 * 例如一个时间非中断边界事件的XML数据如下: *