FlowChartUtility.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. using Microsoft.AspNetCore.Components;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Dynamic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace wispro.sp.share.Utility
  9. {
  10. public class shapeNode
  11. {
  12. public int InCount { get; set; }
  13. public int OutCount { get; set; }
  14. public double x { get; set; }
  15. public double y { get; set; }
  16. public double width { get; set; }
  17. public double height { get; set; }
  18. /// <summary>
  19. /// 形状类型
  20. /// 0:圆
  21. /// 1:矩形
  22. /// 3: 虚拟
  23. /// </summary>
  24. public int Type { get; set; }
  25. public int Level { get; set; } = 1;
  26. public dynamic NodeObject { get; set; }
  27. public List<shapeNode> Childrens { get; set; }
  28. public List<shapeNode> Parents { get; set; }
  29. public string FillColor { get; set; } = "white";
  30. }
  31. public class FlowChartUtility
  32. {
  33. public double TitleHeight { get; set; } = 100;
  34. public double ChartWidth { get; set; } = 1200;
  35. public double ChartHeight { get; set; } = 900;
  36. public double rectWidth { get; set; } = 150;
  37. public double rectHeight { get; set; } = 60;
  38. public double initRadius { get; set; } = 20;
  39. public double EndRadius { get; set; } = 20;
  40. public double hSeparation { get; set; } = 40;
  41. public string StepShapeColor { get; set; } = "green";
  42. public string EndShapColor { get; set; } = "gray";
  43. int rectFontSize { get; set; } = 18;
  44. public List<entity.workflowDefine.Step> Steps { get; set; }
  45. public List<entity.workflowDefine.TrasferCondition> Transfers { get; set; }
  46. public List<entity.workflowDefine.Action> Actions { get; set; }
  47. public entity.workflowDefine.Workflow workflow { get; set; }
  48. private List<shapeNode> shapeTrees = null;
  49. private shapeNode FindNode(int stepId, out int Level, List<shapeNode> lstNodes)
  50. {
  51. Level = 1;
  52. foreach (var sNode in lstNodes)
  53. {
  54. if (sNode.NodeObject is entity.workflowDefine.Step && sNode.NodeObject.Id == stepId)
  55. {
  56. return sNode;
  57. }
  58. else
  59. {
  60. if (sNode.Childrens != null)
  61. {
  62. Level += 1;
  63. var retObj = FindNode(stepId, out Level, sNode.Childrens);
  64. if (retObj != null)
  65. {
  66. return retObj;
  67. }
  68. }
  69. }
  70. }
  71. return null;
  72. }
  73. private void GetShapeLevelNodes(Dictionary<int, List<shapeNode>> levelNodes, List<shapeNode> TreeNodes)
  74. {
  75. if (TreeNodes != null)
  76. {
  77. foreach (var sNode in TreeNodes)
  78. {
  79. List<shapeNode> nodes = new List<shapeNode>();
  80. if (levelNodes.ContainsKey(sNode.Level))
  81. {
  82. nodes = levelNodes[sNode.Level];
  83. nodes.Add(sNode);
  84. }
  85. else
  86. {
  87. nodes.Add(sNode);
  88. levelNodes.Add(sNode.Level, nodes);
  89. }
  90. GetShapeLevelNodes(levelNodes, sNode.Childrens);
  91. }
  92. }
  93. }
  94. public shapeNode startNode;
  95. public shapeNode InitShape;
  96. public shapeNode endNode;
  97. public Dictionary<int, List<shapeNode>> LevelNodes = new Dictionary<int, List<shapeNode>>();
  98. private void initShapeTree()
  99. {
  100. shapeTrees = new List<shapeNode>();
  101. LevelNodes = new Dictionary<int, List<shapeNode>>();
  102. #region 添加开始节点
  103. startNode = new shapeNode()
  104. {
  105. //NodeObject = workflow.InitAction,
  106. InCount = 0,
  107. OutCount = 0,
  108. width = 2 * initRadius,
  109. height = 2 * initRadius,
  110. Level = 0
  111. };
  112. #endregion
  113. #region 添加初始化Action节点
  114. InitShape = new shapeNode()
  115. {
  116. NodeObject = workflow.InitAction,
  117. InCount = 0,
  118. OutCount = 0,
  119. Type = 1,
  120. Level = 1,
  121. FillColor = StepShapeColor
  122. };
  123. startNode.Childrens = new List<shapeNode>();
  124. startNode.Childrens.Add(InitShape);
  125. InitShape.Parents = new List<shapeNode>();
  126. InitShape.Parents.Add(startNode);
  127. shapeTrees.Add(startNode);
  128. #endregion
  129. #region 将步骤对象生成形状Node并添加到列表中
  130. if (Steps != null)
  131. {
  132. foreach (var step in Steps)
  133. {
  134. var temNode = new shapeNode() { NodeObject = step, InCount = 0, OutCount = 0, Type = 1, FillColor = StepShapeColor };
  135. if (workflow.EndStepId == step.Id)
  136. {
  137. endNode = new shapeNode()
  138. {
  139. NodeObject = step,
  140. InCount = 0,
  141. OutCount = 0,
  142. height = 2 * EndRadius,
  143. width = 2 * EndRadius,
  144. FillColor = EndShapColor
  145. };
  146. temNode = endNode;
  147. }
  148. shapeTrees.Add(temNode);
  149. }
  150. }
  151. #endregion
  152. #region 遍历转移条件,生成流程树
  153. if (Transfers != null && Transfers.Count > 0)
  154. {
  155. foreach (var transfer in Transfers)
  156. {
  157. var FromNode = InitShape;
  158. int FromLevel = 0;
  159. if (transfer.StepId != null)
  160. {
  161. FromNode = FindNode(transfer.StepId.Value, out FromLevel, shapeTrees);
  162. }
  163. int ToLevel = 0;
  164. var ToNode = FindNode(transfer.nextStepId, out ToLevel, shapeTrees);
  165. if (FromNode.Childrens == null)
  166. {
  167. FromNode.Childrens = new List<shapeNode>();
  168. }
  169. FromNode.Childrens.Add(ToNode);
  170. if (ToNode.Parents == null)
  171. {
  172. ToNode.Parents = new List<shapeNode>();
  173. }
  174. ToNode.Parents.Add(FromNode);
  175. FromNode.OutCount += 1;
  176. ToNode.InCount += 1;
  177. if (FromNode.Level >= ToLevel)
  178. {
  179. ToNode.Level = FromNode.Level + 1;
  180. }
  181. if (shapeTrees.Contains(ToNode))
  182. {
  183. shapeTrees.Remove(ToNode);
  184. }
  185. }
  186. if (endNode.Parents != null && endNode.Parents[0].NodeObject is entity.workflowDefine.Step)
  187. {
  188. endNode.Level = endNode.Parents[0].Level + 1;
  189. }
  190. }
  191. else
  192. {
  193. InitShape.Childrens = new List<shapeNode>();
  194. InitShape.Childrens.Add(endNode);
  195. InitShape.OutCount += 1;
  196. endNode.Parents = new List<shapeNode>();
  197. endNode.Parents.Add(InitShape);
  198. endNode.InCount += 1;
  199. endNode.Level = InitShape.Level + 1;
  200. shapeTrees.Remove(endNode);
  201. //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(endNode));
  202. }
  203. #endregion
  204. GetShapeLevelNodes(LevelNodes, shapeTrees);
  205. #region 添加跨层连接的中间层的虚拟节点
  206. List<dynamic> AddNodes = new List<dynamic>();
  207. foreach (int level in LevelNodes.Keys)
  208. {
  209. foreach (var temNode in LevelNodes[level])
  210. {
  211. if (temNode.Childrens != null)
  212. {
  213. foreach (var temChildrenNode in temNode.Childrens)
  214. {
  215. if ((temChildrenNode.Level - temNode.Level) > 1)
  216. {
  217. dynamic temAddInfo = new ExpandoObject();
  218. temAddInfo.Parent = temNode;
  219. temAddInfo.Children = temChildrenNode;
  220. temAddInfo.Start = temNode.Level;
  221. temAddInfo.End = temChildrenNode.Level;
  222. AddNodes.Add(temAddInfo);
  223. }
  224. }
  225. }
  226. }
  227. }
  228. foreach (dynamic dynObj in AddNodes)
  229. {
  230. shapeNode parentNode = dynObj.Parent;
  231. shapeNode endNode = dynObj.Children;
  232. for (int i = dynObj.Start + 1; i < dynObj.End; i++)
  233. {
  234. var xnNode = new shapeNode() { Type = 3, Parents = new List<shapeNode>(), Childrens = new List<shapeNode>(), Level = i };
  235. parentNode.Childrens.Add(xnNode);
  236. xnNode.Parents.Add(parentNode);
  237. parentNode.Childrens.Remove(endNode);
  238. parentNode.Childrens.Add(xnNode);
  239. endNode.Parents.Remove(parentNode);
  240. endNode.Parents.Add(xnNode);
  241. parentNode = xnNode;
  242. LevelNodes[xnNode.Level].Add(xnNode);
  243. }
  244. }
  245. #endregion
  246. int MaxNodeLevel = 0;
  247. int NodeCount = 0;
  248. foreach (int level in LevelNodes.Keys)
  249. {
  250. if (level > 1)
  251. {
  252. int temLevelCount = 0;
  253. foreach (var temNode in LevelNodes[level])
  254. {
  255. int graterInOrOut = (temNode.OutCount > temNode.InCount) ? temNode.OutCount : temNode.InCount;
  256. if (graterInOrOut <= 1)
  257. {
  258. temLevelCount += 1;
  259. }
  260. else
  261. {
  262. temLevelCount += graterInOrOut;
  263. }
  264. }
  265. if (temLevelCount > MaxNodeLevel)
  266. {
  267. MaxNodeLevel = level;
  268. NodeCount = temLevelCount;
  269. }
  270. }
  271. }
  272. #region 每层节点排序
  273. for (var i = 1; i < LevelNodes.Count; ++i)
  274. {
  275. var top_layer = LevelNodes[i - 1];
  276. LevelNodes[i] = LevelNodes[i].OrderBy(node =>
  277. {
  278. if (node.Parents == null)
  279. {
  280. return 0;
  281. }
  282. var connected_nodes = node.Parents
  283. .Where(l => l.Level == (i - 1)).ToList();
  284. if (!connected_nodes.Any())
  285. {
  286. return 0;
  287. }
  288. var average_index = connected_nodes.Select(cn => { var i = top_layer.IndexOf(cn); return i; }).Average();
  289. return average_index;
  290. }).ToList();
  291. }
  292. if (LevelNodes.Count > 1)
  293. {
  294. LevelNodes[0] = LevelNodes[0].OrderBy(node =>
  295. {
  296. var connected_nodes = node.Childrens
  297. .Where(l => l.Level == 1)
  298. .ToList();
  299. if (!connected_nodes.Any())
  300. {
  301. return 0;
  302. }
  303. var average_index = connected_nodes.Select(cn => { var i = LevelNodes[1].IndexOf(cn); return i; }).Average();
  304. return average_index;
  305. }).ToList();
  306. }
  307. #endregion
  308. ArrangeNodesInRows(LevelNodes);
  309. }
  310. private void ArrangeNodesInRows(Dictionary<int, List<shapeNode>> LevelNodes)
  311. {
  312. double preBotton = TitleHeight;
  313. for (int iLevel = 0; iLevel < LevelNodes.Count; iLevel++)
  314. {
  315. int iCount = 0;
  316. foreach (var node in LevelNodes[iLevel])
  317. {
  318. int max = (node.InCount > node.OutCount) ? node.InCount : node.OutCount;
  319. if (max == 0)
  320. {
  321. max = 1;
  322. }
  323. iCount += max;
  324. }
  325. double onNodeWidth = ChartWidth / (iCount + 1);
  326. iCount = 0;
  327. double maxHeight = 0;
  328. foreach (var node in LevelNodes[iLevel])
  329. {
  330. int max = (node.InCount > node.OutCount) ? node.InCount : node.OutCount;
  331. if (max == 0)
  332. {
  333. max = 1;
  334. }
  335. node.x = onNodeWidth * (iCount + 1) + (max - 1) * onNodeWidth / 2;
  336. if (node.Type == 0)
  337. {
  338. node.width = 2 * initRadius;
  339. node.height = 2 * initRadius;
  340. }
  341. else
  342. {
  343. node.width = rectWidth;
  344. node.height = rectHeight;
  345. }
  346. iCount += max;
  347. if (node.height > maxHeight)
  348. {
  349. maxHeight = node.height;
  350. }
  351. }
  352. foreach (var node in LevelNodes[iLevel])
  353. {
  354. node.y = preBotton + hSeparation + maxHeight / 2;
  355. }
  356. preBotton = preBotton + hSeparation + maxHeight;
  357. }
  358. }
  359. public dynamic GetLineParater(entity.workflowDefine.TrasferCondition trasferCondition)
  360. {
  361. int level = 0;
  362. var startNode = InitShape;
  363. if (trasferCondition.StepId != null)
  364. {
  365. startNode = FindNode(trasferCondition.StepId.Value, out level, shapeTrees);
  366. }
  367. var endNode = FindNode(trasferCondition.nextStepId, out level, shapeTrees);
  368. dynamic ret = new ExpandoObject();
  369. ret.x1 = startNode.x;
  370. ret.y1 = startNode.y + startNode.height / 2;
  371. ret.x2 = endNode.x;
  372. ret.y2 = endNode.y - endNode.height / 2;
  373. double x3 = 0.0;
  374. double y3 = 0.0;
  375. GetArrorEndPoint(ret, out x3, out y3);
  376. ret.x2 = x3;
  377. ret.y2 = y3;
  378. return ret;
  379. }
  380. public void GetArrorEndPoint(dynamic ret, out double x3, out double y3)
  381. {
  382. if (ret.x1 == ret.x2)
  383. {
  384. x3 = ret.x1;
  385. if (ret.y2 > ret.y1)
  386. {
  387. y3 = ret.y2 - 8;
  388. }
  389. else
  390. {
  391. y3 = ret.y2 + 8;
  392. }
  393. }
  394. else
  395. {
  396. if (ret.y1 == ret.y2)
  397. {
  398. y3 = ret.y1;
  399. if (ret.x1 < ret.x2)
  400. {
  401. x3 = ret.x2 - 8;
  402. }
  403. else
  404. {
  405. x3 = ret.x2 + 8;
  406. }
  407. }
  408. else
  409. {
  410. double k = (ret.y1 - ret.y2) / (ret.x1 - ret.x2);
  411. double b = ret.y2 - k * ret.x2;
  412. double a = k * k + 1;
  413. double B = 2 * k * (b - ret.y2) - 2 * ret.x2;
  414. double c = (b - ret.y2) * (b - ret.y2) + ret.x2 * ret.x2 - 100;
  415. double x3_1 = (Math.Sqrt(B * B - 4 * a * c) - B) / (2 * a);
  416. double x3_2 = ((Math.Sqrt(B * B - 4 * a * c) + B) / (2 * a)) * -1;
  417. if (ret.x1 < ret.x2)
  418. {
  419. x3 = (x3_1 < x3_2) ? x3_1 : x3_2;
  420. }
  421. else
  422. {
  423. x3 = (x3_1 < x3_2) ? x3_2 : x3_1;
  424. }
  425. y3 = k * x3 + b;
  426. }
  427. }
  428. }
  429. public dynamic GetEndStepLine()
  430. {
  431. var startNode = InitShape;
  432. if (endNode.Parents != null)
  433. {
  434. startNode = endNode.Parents[0];
  435. }
  436. dynamic ret = new ExpandoObject();
  437. ret.x1 = startNode.x;
  438. ret.y1 = startNode.y + startNode.height / 2;
  439. ret.x2 = endNode.x;
  440. ret.y2 = endNode.y - endNode.height / 2;
  441. double x3 = 0.0;
  442. double y3 = 0.0;
  443. GetArrorEndPoint(ret, out x3, out y3);
  444. ret.x2 = x3;
  445. ret.y2 = y3;
  446. return ret;
  447. }
  448. public dynamic GetStartInitLine()
  449. {
  450. dynamic ret = new ExpandoObject();
  451. ret.x1 = this.startNode.x;
  452. ret.y1 = this.startNode.y + startNode.height / 2;
  453. ret.x2 = InitShape.x;
  454. ret.y2 = InitShape.y - InitShape.height / 2;
  455. double x3 = 0.0;
  456. double y3 = 0.0;
  457. GetArrorEndPoint(ret, out x3, out y3);
  458. ret.x2 = x3;
  459. ret.y2 = y3;
  460. return ret;
  461. }
  462. public void Refresh()
  463. {
  464. //System.Text.Json.JsonSerializer.Serialize(Actions);
  465. initShapeTree();
  466. }
  467. void InitAction()
  468. {
  469. }
  470. #region 单击/双击事件
  471. public EventCallback<entity.workflowDefine.Step> OnClickStep { get; set; }
  472. public EventCallback<entity.workflowDefine.Action> OnClickAction { get; set; }
  473. public EventCallback<entity.workflowDefine.TrasferCondition> OnClickTransfer { get; set; }
  474. public EventCallback<entity.workflowDefine.Step> OnDoubleClickStep { get; set; }
  475. [Parameter]
  476. public EventCallback<entity.workflowDefine.Action> OnDoubleClickAction { get; set; }
  477. [Parameter]
  478. public EventCallback<entity.workflowDefine.TrasferCondition> OnDoubleClickTransfer { get; set; }
  479. public shapeNode SelectedShape { get; set; }
  480. void ClickNode(shapeNode node)
  481. {
  482. SelectedShape = node;
  483. if (node.NodeObject is entity.workflowDefine.Step)
  484. {
  485. if (OnClickStep.HasDelegate)
  486. {
  487. OnClickStep.InvokeAsync((entity.workflowDefine.Step)node.NodeObject);
  488. }
  489. }
  490. if (node.NodeObject is entity.workflowDefine.Action)
  491. {
  492. if (OnClickAction.HasDelegate)
  493. {
  494. OnClickAction.InvokeAsync((entity.workflowDefine.Action)node.NodeObject);
  495. }
  496. }
  497. }
  498. void DoubleClickNode(shapeNode node)
  499. {
  500. SelectedShape = node;
  501. if (node.NodeObject is entity.workflowDefine.Step)
  502. {
  503. if (OnDoubleClickStep.HasDelegate)
  504. {
  505. OnDoubleClickStep.InvokeAsync((entity.workflowDefine.Step)node.NodeObject);
  506. }
  507. }
  508. if (node.NodeObject is entity.workflowDefine.Action)
  509. {
  510. if (OnDoubleClickAction.HasDelegate)
  511. {
  512. OnDoubleClickAction.InvokeAsync((entity.workflowDefine.Action)node.NodeObject);
  513. }
  514. }
  515. }
  516. void ClickTrasfer(entity.workflowDefine.TrasferCondition trasferCondition)
  517. {
  518. SelectedShape = null;
  519. if (OnClickTransfer.HasDelegate)
  520. {
  521. OnClickTransfer.InvokeAsync(trasferCondition);
  522. }
  523. }
  524. void DoubleClickTrasfer(entity.workflowDefine.TrasferCondition trasferCondition)
  525. {
  526. SelectedShape = null;
  527. if (OnDoubleClickTransfer.HasDelegate)
  528. {
  529. OnDoubleClickTransfer.InvokeAsync(trasferCondition);
  530. }
  531. }
  532. #endregion
  533. public string GetSvgString()
  534. {
  535. initShapeTree();
  536. string strReturn = $"<svg width =\"{ChartWidth}\" height = \"{ChartHeight}\" id = \"FlowChartContainer\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.2\">";
  537. strReturn = strReturn +
  538. "<defs>\r\n" +
  539. "\t<marker id =\"idArrow\" viewBox=\"0 0 20 20\" refX = \"0\" refY = \"10\" markerUnits = \"strokeWidth\" markerWidth = \"5\" markerHeight = \"10\" orient=\"auto\">\r\n" +
  540. "\t\t<path d =\"M 0 0 L 20 10 L 0 20 z\" fill=\"black\" stroke = \"black\" />\r\n" +
  541. "</marker>\r\n" +
  542. "</defs>\r\n";
  543. if (shapeTrees != null)
  544. {
  545. strReturn += $"<text x=\"{ChartWidth / 2}\" y=\"{TitleHeight / 2}\" fill=\"black\" alignment-baseline=\"middle\" text-anchor=\"middle\" font-size=\"{30}\" font-weight=\"800\">{workflow.Name}</text>\r\n";
  546. dynamic startLine = GetStartInitLine();
  547. strReturn += $"<line x1=\"{startLine.x1}\" y1=\"{startLine.y1}\" x2 =\"{startLine.x2}\" y2=\"{startLine.y2}\" stroke=\"black\" stroke-width=\"2\" marker-end=\"url(#idArrow)\"/>\r\n";
  548. for (int iLevel = 0; iLevel < LevelNodes.Count; iLevel++)
  549. {
  550. foreach (var node in LevelNodes[iLevel])
  551. {
  552. if (node.Type == 0)
  553. {
  554. strReturn += $"<circle cx =\"{node.x}\" cy=\"{node.y}\" r=\"{node.width / 2}\" stroke=\"black\" stroke-width=\"2\" fill=\"{node.FillColor}\"/>\r\n";
  555. strReturn += "<a>" +
  556. $"<text x =\"{node.x}\" y=\"{node.y}\" fill=\"black\" alignment-baseline=\"middle\" text-anchor=\"middle\" font-size=\"14\">\r\n";
  557. if (node == startNode)
  558. {
  559. strReturn += "开始";
  560. }
  561. else
  562. {
  563. if (node == endNode)
  564. {
  565. strReturn += "结束";
  566. }
  567. else
  568. {
  569. if (node.NodeObject is entity.workflowDefine.Step)
  570. {
  571. strReturn += ((entity.workflowDefine.Step)node.NodeObject).Name;
  572. }
  573. }
  574. }
  575. strReturn += "</text>\r\n</a>\r\n";
  576. }
  577. if (node.Type == 1)
  578. {
  579. strReturn += $"<rect x =\"{(node.x-node.width/2)}\" y=\"{(node.y-node.height/2)}\" rx=\"10\" ry=\"10\" width=\"{node.width}\" height=\"{node.height}\" style=\"fill:{node.FillColor};stroke:black;stroke-width:3;opacity:0.5\"/>\r\n";
  580. strReturn += $"<a ondblclick =\"() => DoubleClickNode(node)\" onclick=\"()=>ClickNode(node)\">\r\n";
  581. strReturn += $"<text x =\"{node.x}\" y=\"{node.y}\" fill=\"black\" alignment-baseline=\"middle\" text-anchor=\"middle\" font-size=\"{rectFontSize}\" font-weight=\"700\">\r\n";
  582. if (node.NodeObject is entity.workflowDefine.Action)
  583. {
  584. strReturn += ((workflow.InitAction == null || string.IsNullOrEmpty(workflow.InitAction.Name)) ? $"启动{workflow.Name}" : workflow.InitAction.Name) + "\r\n";
  585. }
  586. else
  587. {
  588. strReturn += (((entity.workflowDefine.Step)node.NodeObject).Name) + "\r\n";
  589. }
  590. strReturn += "</text>\r\n</a>\r\n";
  591. if (SelectedShape == node)
  592. {
  593. strReturn += $"<circle cx =\"{(node.x - node.width / 2)}\" cy=\"{(node.y)}\" r=\"3\" stroke=\"black\" stroke-width=\"1\" fill=\"white\"/>\r\n";
  594. strReturn += $"<circle cx =\"{(node.x + node.width / 2)}\"cy=\"{(node.y)}\" r=\"3\" stroke=\"black\" stroke-width=\"1\" fill=\"white\"/>\r\n";
  595. strReturn += $"<circle cx =\"{(node.x)}\" cy=\"{(node.y - node.height / 2)}\" r=\"3\" stroke=\"black\" stroke-width=\"1\" fill=\"white\"/>\r\n";
  596. strReturn += $"<circle cx =\"{(node.x)}\" cy=\"{(node.y + node.height / 2)}\" r=\"3\" stroke=\"black\" stroke-width=\"1\" fill=\"white\"/>\r\n";
  597. }
  598. }
  599. }
  600. }
  601. if (Transfers.Count > 0)
  602. {
  603. foreach (var t in Transfers)
  604. {
  605. dynamic ret = GetLineParater(t);
  606. strReturn += $"<line x1 =\"{ret.x1}\" y1=\"{ret.y1}\" x2=\"{ret.x2}\" y2=\"{ret.y2}\" stroke=\"black\" stroke-width=\"2\" marker-end=\"url(#idArrow)\"/>\r\n";
  607. strReturn += $"<circle cx =\"{((ret.x1 + ret.x2) / 2)}\" cy=\"{((ret.y1 + ret.y2) / 2)}\" r=\"7\" stroke=\"black\" stroke-width=\"1.5\" fill=\"white\"/>\r\n";
  608. strReturn += $"<a ondblclick =\"() => DoubleClickTrasfer(t)\" onclick=\"()=>ClickTrasfer(t)\">\r\n";
  609. strReturn += $"<text x =\"{((ret.x1 + ret.x2) / 2)}\" y=\"{((ret.y1 + ret.y2) / 2)}\" fill=\"black\" alignment-baseline=\"middle\" text-anchor=\"middle\" font-size=\"12\">c</text>\r\n";
  610. strReturn += "</a>\r\n";
  611. }
  612. }
  613. else
  614. {
  615. dynamic ret = GetEndStepLine();
  616. strReturn += $"<line x1 =\"{ret.x1}\" y1=\"{ret.y1}\" x2=\"{ret.x2}\" y2=\"{ret.y2}\" stroke=\"black\" stroke-width=\"2\" marker-end=\"url(#idArrow)\"/>\r\n";
  617. }
  618. //dynamic endLine = GetEndStepLine();
  619. //strReturn += $"<line x1 =\"{endLine.x1}\" y1=\"{endLine.y1}\" x2=\"{endLine.x2}\" y2=\"{endLine.y2}\" stroke=\"black\" stroke-width=\"2\" marker-end=\"url(#idArrow)\"/>\r\n";
  620. }
  621. return strReturn + "</svg>";
  622. }
  623. }
  624. }