Browse Source

Merge branch 'yili' of http://gogsb.soaringnova.com/ylproj/jupyterlab into yili

Zhang Li 1 year ago
parent
commit
000c5ec6a4
1 changed files with 13 additions and 1 deletions
  1. 13 1
      packages/yili-dag/src/Dag.tsx

+ 13 - 1
packages/yili-dag/src/Dag.tsx

@@ -1120,10 +1120,11 @@ export default class Dag extends React.Component<any, any> {
 
 // 初始化节点数据
 function initNodeData(graph: Graph, newNode: Node<Node.Properties>) {
+  const baseNumber: number = nodeNumber(graph);
   // 节点id
   newNode.data.id = newNode.id;
   newNode.data.nodeId = nanoid();
-  newNode.data.nodeName = `node_${graph.getNodes().length + 1}`;
+  newNode.data.nodeName = `node_${baseNumber + 1}`;
   switch (newNode.data.type) {
     case 'datasource':
       newNode.data.inputSource = undefined;
@@ -1151,3 +1152,14 @@ function initNodeData(graph: Graph, newNode: Node<Node.Properties>) {
 function nanoid() {
   return 'YL' + Date.now();
 }
+
+// 节点名基数
+function nodeNumber(graph: Graph) {
+  let nodeNumber = 0;
+  graph.getNodes().map(node => {
+    const nodeName = node.data.nodeName.split('_');
+    nodeNumber =
+      parseInt(nodeName[1]) > nodeNumber ? parseInt(nodeName[1]) : nodeNumber;
+  });
+  return nodeNumber;
+}