1. 安装

参考前面《安装

2. 导入画布类

  1. // 导入绘画引擎
  2. import { Topology } from 'topology-core';

3. 引用第三方图形库

  1. // 使用第三方图形库
  2. // 1. 先导入注册函数
  3. import { registerNode } from 'topology-core/middles';
  4. // 2. 导入图形库图形及其相关元素
  5. import {
  6. flowData,
  7. flowDataAnchors,
  8. flowDataIconRect,
  9. flowDataTextRect,
  10. flowSubprocess,
  11. flowSubprocessIconRect,
  12. flowSubprocessTextRect,
  13. flowDb,
  14. flowDbIconRect,
  15. flowDbTextRect,
  16. flowDocument,
  17. flowDocumentAnchors,
  18. flowDocumentIconRect,
  19. flowDocumentTextRect,
  20. flowInternalStorage,
  21. flowInternalStorageIconRect,
  22. flowInternalStorageTextRect,
  23. flowExternStorage,
  24. flowExternStorageAnchors,
  25. flowExternStorageIconRect,
  26. flowExternStorageTextRect,
  27. flowQueue,
  28. flowQueueIconRect,
  29. flowQueueTextRect,
  30. flowManually,
  31. flowManuallyAnchors,
  32. flowManuallyIconRect,
  33. flowManuallyTextRect,
  34. flowDisplay,
  35. flowDisplayAnchors,
  36. flowDisplayIconRect,
  37. flowDisplayTextRect,
  38. flowParallel,
  39. flowParallelAnchors,
  40. flowComment,
  41. flowCommentAnchors
  42. } from 'topology-flow-diagram';
  43. // 3. 向引擎注册图形库图形及其相关元素
  44. registerNode('flowData', flowData, flowDataAnchors, flowDataIconRect, flowDataTextRect);
  45. registerNode('flowSubprocess', flowSubprocess, null, flowSubprocessIconRect, flowSubprocessTextRect);
  46. registerNode('flowDb', flowDb, null, flowDbIconRect, flowDbTextRect);
  47. registerNode('flowDocument', flowDocument, flowDocumentAnchors, flowDocumentIconRect, flowDocumentTextRect);
  48. // ...
  49. // 下面是简单的注册函数介绍,详情请参考api文档
  50. // registerNode: 注册一个自定义图形节点node.
  51. // name - node名称.
  52. // drawFn - node渲染函数。传入canvas ctx和node数据,自己决定如何绘画node
  53. // anchorsFn - 计算node的锚点,如果为null,表示使用缺省计算锚点方法
  54. // iconRectFn - 计算node的图标区域,如果为null,表示使用缺省计算图标区域方法
  55. // textRectFn - 计算node的文字区域,如果为null,表示使用缺省计算文字区域方法
  56. // force - 如果已经存在同名node,是否覆盖.
  57. export function registerNode(
  58. name: string,
  59. drawFn: (ctx: CanvasRenderingContext2D, node: Node) => void,
  60. anchorsFn?: (node: Node) => void,
  61. iconRectFn?: (node: Node) => void,
  62. textRectFn?: (node: Node) => void,
  63. force?: boolean
  64. );
  65. 4. 初始化画布实例
  66. const canvas = new Topology('topology-canvas', canvasOptions)
  67. 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