shape.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. import { Graph, Dom, Node } from '@antv/x6'
  2. import { basicPorts, customPorts } from './ports'
  3. // 基础节点
  4. export const FlowChartRect = Graph.registerNode('flow-chart-rect', {
  5. inherit: 'rect',
  6. width: 80,
  7. height: 42,
  8. attrs: {
  9. body: {
  10. stroke: '#5F95FF',
  11. strokeWidth: 1,
  12. fill: '#ffffff'
  13. },
  14. text: {
  15. fontSize: 12,
  16. fill: '#080808'
  17. }
  18. },
  19. markup: [
  20. {
  21. tagName: 'rect',
  22. selector: 'body'
  23. },
  24. {
  25. tagName: 'text',
  26. selector: 'text'
  27. },
  28. {
  29. tagName: 'foreignObject',
  30. selector: 'fo',
  31. children: [
  32. {
  33. ns: Dom.ns.xhtml,
  34. tagName: 'body',
  35. selector: 'foBody',
  36. children: [
  37. {
  38. tagName: 'div',
  39. selector: 'edit-text'
  40. }
  41. ]
  42. }
  43. ]
  44. }
  45. ],
  46. ports: { ...basicPorts }
  47. })
  48. // 子流程节点
  49. export const SubRect = Graph.registerNode('sub-flow-rect', {
  50. inherit: 'rect',
  51. width: 200,
  52. height: 60,
  53. attrs: {
  54. body: {
  55. stroke: '#5F95FF',
  56. strokeWidth: 1,
  57. fill: 'rgba(95,149,255,0.05)'
  58. },
  59. title: {
  60. text: 'Node',
  61. refX: 40,
  62. refY: 14,
  63. fill: 'rgba(0,0,0,0.85)',
  64. fontSize: 12,
  65. 'text-anchor': 'start'
  66. },
  67. text: {
  68. text: 'this is content text',
  69. refX: 40,
  70. refY: 38,
  71. fontSize: 12,
  72. fill: 'rgba(0,0,0,0.6)',
  73. 'text-anchor': 'start'
  74. }
  75. },
  76. markup: [
  77. {
  78. tagName: 'rect',
  79. selector: 'body'
  80. },
  81. {
  82. tagName: 'text',
  83. selector: 'title'
  84. },
  85. {
  86. tagName: 'text',
  87. selector: 'text'
  88. }
  89. ],
  90. ports: { ...basicPorts }
  91. })
  92. // 逻辑节点
  93. export const logicPath = Graph.registerNode('logic-flow-path', {
  94. inherit: 'circle',
  95. width: 20,
  96. height: 20,
  97. attrs: {
  98. body: {
  99. stroke: '#5F95FF',
  100. strokeWidth: 1,
  101. fill: '#ffffff'
  102. },
  103. lip: {
  104. refX: 4,
  105. refY: 4,
  106. fill: '#d4237a',
  107. transform: 'scale(0.01)'
  108. }
  109. },
  110. markup: [
  111. {
  112. tagName: 'circle',
  113. selector: 'body'
  114. },
  115. {
  116. tagName: 'path',
  117. selector: 'lip',
  118. attrs: {
  119. d: 'M366.336 270.506667c20.736 19.029333 21.333333 49.493333 1.536 68.949333l-1.536 1.536L131.84 554.666667l234.496 213.674666c20.736 18.944 21.333333 49.322667 1.536 68.864l-1.536 1.536a58.538667 58.538667 0 0 1-75.605333 1.450667l-1.706667-1.450667-273.066667-248.917333a46.677333 46.677333 0 0 1-1.536-68.864l1.536-1.450667 273.066667-248.917333a58.453333 58.453333 0 0 1 77.312 0z m593.92 425.216c35.242667 0 63.744 26.709333 63.744 59.733333 0 32.256-27.306667 58.624-61.525333 59.733333H509.696c-35.157333 0-63.658667-26.794667-63.658667-59.733333 0-32.341333 27.306667-58.624 61.44-59.733333h452.778667z m0-398.250667c35.242667 0 63.744 26.794667 63.744 59.733333 0 32.341333-27.306667 58.624-61.525333 59.733334H509.696c-35.157333 0-63.658667-26.709333-63.658667-59.733334 0-32.256 27.306667-58.624 61.44-59.733333h452.778667z'
  120. }
  121. }
  122. ],
  123. ports: { ...basicPorts }
  124. })
  125. // 组合节点
  126. export const FlowChartImageRect = Graph.registerNode('flow-chart-image-rect', {
  127. inherit: 'rect',
  128. width: 200,
  129. height: 60,
  130. attrs: {
  131. body: {
  132. stroke: '#5F95FF',
  133. strokeWidth: 1,
  134. fill: 'rgba(95,149,255,0.05)'
  135. },
  136. title: {
  137. text: 'Node',
  138. refX: 40,
  139. refY: 14,
  140. fill: 'rgba(0,0,0,0.85)',
  141. fontSize: 12,
  142. 'text-anchor': 'start'
  143. },
  144. text: {
  145. text: 'this is content text',
  146. refX: 40,
  147. refY: 38,
  148. fontSize: 12,
  149. fill: 'rgba(0,0,0,0.6)',
  150. 'text-anchor': 'start'
  151. }
  152. },
  153. markup: [
  154. {
  155. tagName: 'rect',
  156. selector: 'body'
  157. },
  158. {
  159. tagName: 'text',
  160. selector: 'title'
  161. },
  162. {
  163. tagName: 'text',
  164. selector: 'text'
  165. }
  166. ],
  167. ports: { ...basicPorts }
  168. })
  169. export const FlowChartTitleRect = Graph.registerNode('flow-chart-title-rect', {
  170. inherit: 'rect',
  171. width: 200,
  172. height: 68,
  173. attrs: {
  174. body: {
  175. stroke: '#5F95FF',
  176. strokeWidth: 1,
  177. fill: 'rgba(95,149,255,0.05)'
  178. },
  179. head: {
  180. refWidth: '100%',
  181. stroke: 'transparent',
  182. height: 28,
  183. fill: 'rgb(95,149,255)'
  184. },
  185. image: {
  186. 'xlink:href': 'https://gw.alipayobjects.com/zos/antfincdn/FLrTNDvlna/antv.png',
  187. height: 16,
  188. x: 6,
  189. y: 6
  190. },
  191. title: {
  192. text: 'Node',
  193. refX: 30,
  194. refY: 9,
  195. fill: '#ffffff',
  196. fontSize: 12,
  197. 'text-anchor': 'start'
  198. },
  199. text: {
  200. text: 'this is content text',
  201. refX: 8,
  202. refY: 45,
  203. fontSize: 12,
  204. fill: 'rgba(0,0,0,0.6)',
  205. 'text-anchor': 'start'
  206. }
  207. },
  208. markup: [
  209. {
  210. tagName: 'rect',
  211. selector: 'body'
  212. },
  213. {
  214. tagName: 'rect',
  215. selector: 'head'
  216. },
  217. {
  218. tagName: 'image',
  219. selector: 'image'
  220. },
  221. {
  222. tagName: 'text',
  223. selector: 'title'
  224. },
  225. {
  226. tagName: 'text',
  227. selector: 'text'
  228. }
  229. ],
  230. ports: { ...basicPorts }
  231. })
  232. export const FlowChartAnimateText = Graph.registerNode('flow-chart-animate-text', {
  233. inherit: 'rect',
  234. width: 200,
  235. height: 60,
  236. attrs: {
  237. body: {
  238. stroke: '#5F95FF',
  239. strokeWidth: 1,
  240. fill: 'rgba(95,149,255,0.05)'
  241. },
  242. text1: {
  243. class: 'animate-text1',
  244. text: 'AntV X6',
  245. fontSize: 32
  246. },
  247. text2: {
  248. class: 'animate-text2',
  249. text: 'AntV X6',
  250. fontSize: 32
  251. }
  252. },
  253. markup: [
  254. {
  255. tagName: 'rect',
  256. selector: 'body'
  257. },
  258. {
  259. tagName: 'text',
  260. selector: 'text1'
  261. },
  262. {
  263. tagName: 'text',
  264. selector: 'text2'
  265. }
  266. ]
  267. })
  268. // 自定义 系统设计图
  269. export const FlowChartImageRectCustom = Graph.registerNode('flow-chart-image-rect-custom', {
  270. inherit: 'rect',
  271. width: 80,
  272. height: 80,
  273. markup: [
  274. {
  275. tagName: 'rect',
  276. selector: 'body'
  277. },
  278. {
  279. tagName: 'image'
  280. },
  281. {
  282. tagName: 'text',
  283. selector: 'label'
  284. }
  285. ],
  286. attrs: {
  287. body: {
  288. // 节点线的颜色
  289. stroke: 'transparent',
  290. // 背景填充色
  291. fill: 'transparent'
  292. },
  293. // 自定义图片
  294. image: {
  295. width: 60,
  296. height: 60,
  297. refX: 0,
  298. refY: 0
  299. },
  300. label: {
  301. refX: 3,
  302. refY: 2,
  303. textAnchor: 'left',
  304. textVerticalAnchor: 'top',
  305. fontSize: 12,
  306. fill: 'black'
  307. },
  308. text: {
  309. fontSize: 12,
  310. fill: '#080808'
  311. }
  312. },
  313. ports: { ...customPorts }
  314. })
  315. // 节点组
  316. export class NodeGroup extends Node {
  317. collapsed = true
  318. postprocess() {
  319. this.toggleCollapse(true)
  320. }
  321. isCollapsed() {
  322. return this.collapsed
  323. }
  324. toggleCollapse(collapsed?: boolean) {
  325. const target = collapsed == null ? !this.collapsed : collapsed
  326. if (target) {
  327. this.attr('buttonSign', { d: 'M 1 5 9 5 M 5 1 5 9' })
  328. this.resize(200, 40)
  329. } else {
  330. this.attr('buttonSign', { d: 'M 2 5 8 5' })
  331. this.resize(240, 240)
  332. }
  333. this.collapsed = target
  334. }
  335. }
  336. NodeGroup.config({
  337. shape: 'rect',
  338. markup: [
  339. {
  340. tagName: 'rect',
  341. selector: 'body'
  342. },
  343. {
  344. tagName: 'image',
  345. selector: 'image'
  346. },
  347. {
  348. tagName: 'text',
  349. selector: 'text'
  350. },
  351. {
  352. tagName: 'g',
  353. selector: 'buttonGroup',
  354. children: [
  355. {
  356. tagName: 'rect',
  357. selector: 'button',
  358. attrs: {
  359. 'pointer-events': 'visiblePainted'
  360. }
  361. },
  362. {
  363. tagName: 'path',
  364. selector: 'buttonSign',
  365. attrs: {
  366. fill: 'none',
  367. 'pointer-events': 'none'
  368. }
  369. }
  370. ]
  371. }
  372. ],
  373. attrs: {
  374. body: {
  375. refWidth: '100%',
  376. refHeight: '100%',
  377. strokeWidth: 1,
  378. fill: 'rgba(95,149,255,0.05)',
  379. stroke: '#5F95FF'
  380. },
  381. image: {
  382. 'xlink:href':
  383. 'https://gw.alipayobjects.com/mdn/rms_0b51a4/afts/img/A*X4e0TrDsEiIAAAAAAAAAAAAAARQnAQ',
  384. width: 16,
  385. height: 16,
  386. x: 8,
  387. y: 12
  388. },
  389. text: {
  390. fontSize: 12,
  391. fill: 'rgba(0,0,0,0.85)',
  392. refX: 30,
  393. refY: 15
  394. },
  395. buttonGroup: {
  396. refX: '100%',
  397. refX2: -25,
  398. refY: 13
  399. },
  400. button: {
  401. height: 14,
  402. width: 16,
  403. rx: 2,
  404. ry: 2,
  405. fill: '#f5f5f5',
  406. stroke: '#ccc',
  407. cursor: 'pointer',
  408. event: 'node:collapse'
  409. },
  410. buttonSign: {
  411. refX: 3,
  412. refY: 2,
  413. stroke: '#808080'
  414. }
  415. }
  416. })
  417. Graph.registerNode('groupNode', NodeGroup)