1. 安装
参考前面《安装》
2. 导入画布类
// 导入绘画引擎import { Topology } from 'topology-core';
3. 引用第三方图形库
// 使用第三方图形库// 1. 先导入注册函数import { registerNode } from 'topology-core/middles';// 2. 导入图形库图形及其相关元素import {flowData,flowDataAnchors,flowDataIconRect,flowDataTextRect,flowSubprocess,flowSubprocessIconRect,flowSubprocessTextRect,flowDb,flowDbIconRect,flowDbTextRect,flowDocument,flowDocumentAnchors,flowDocumentIconRect,flowDocumentTextRect,flowInternalStorage,flowInternalStorageIconRect,flowInternalStorageTextRect,flowExternStorage,flowExternStorageAnchors,flowExternStorageIconRect,flowExternStorageTextRect,flowQueue,flowQueueIconRect,flowQueueTextRect,flowManually,flowManuallyAnchors,flowManuallyIconRect,flowManuallyTextRect,flowDisplay,flowDisplayAnchors,flowDisplayIconRect,flowDisplayTextRect,flowParallel,flowParallelAnchors,flowComment,flowCommentAnchors} from 'topology-flow-diagram';// 3. 向引擎注册图形库图形及其相关元素registerNode('flowData', flowData, flowDataAnchors, flowDataIconRect, flowDataTextRect);registerNode('flowSubprocess', flowSubprocess, null, flowSubprocessIconRect, flowSubprocessTextRect);registerNode('flowDb', flowDb, null, flowDbIconRect, flowDbTextRect);registerNode('flowDocument', flowDocument, flowDocumentAnchors, flowDocumentIconRect, flowDocumentTextRect);// ...// 下面是简单的注册函数介绍,详情请参考api文档// registerNode: 注册一个自定义图形节点node.// name - node名称.// drawFn - node渲染函数。传入canvas ctx和node数据,自己决定如何绘画node// anchorsFn - 计算node的锚点,如果为null,表示使用缺省计算锚点方法// iconRectFn - 计算node的图标区域,如果为null,表示使用缺省计算图标区域方法// textRectFn - 计算node的文字区域,如果为null,表示使用缺省计算文字区域方法// force - 如果已经存在同名node,是否覆盖.export function registerNode(name: string,drawFn: (ctx: CanvasRenderingContext2D, node: Node) => void,anchorsFn?: (node: Node) => void,iconRectFn?: (node: Node) => void,textRectFn?: (node: Node) => void,force?: boolean);4. 初始化画布实例const canvas = new Topology('topology-canvas', canvasOptions)canvas.open({nodes:[], lines:[]})
4. webpack编译
参考 https://github.com/le5le-com/topology-demo-es6
4.1 安装依赖库
参考 https://github.com/le5le-com/topology-demo-es6/blob/master/package.json
4.2 配置wepback
参考 https://github.com/le5le-com/topology-demo-es6/blob/master/webpack.config.js
其中:output.filename: ‘topology.js’ 为编译后生成的文件
4.3 index.html中引入
参考 https://github.com/le5le-com/topology-demo-es6/blob/master/index.html
