浏览代码

dynamic node width & height

Aykut Saraç 3 年之前
父节点
当前提交
8cee959751
共有 1 个文件被更改,包括 9 次插入1 次删除
  1. 9 1
      src/containers/LiveEditor/helpers.ts

+ 9 - 1
src/containers/LiveEditor/helpers.ts

@@ -30,9 +30,17 @@ export function getEdgeNodes(graph: any): any {
     };
 
     if (isNode(el)) {
+      const text = renderText(el.data.label);
+      const lines = text.split("\n");
+      const lineLength = lines.map((line) => line.length);
+      const longestLine = lineLength.sort()[lineLength.length - 1];
+
       nodes.push({
         id: el.id,
-        text: renderText(el.data.label),
+        text: text,
+        width: 35 + longestLine * 8,
+        height: 30 + lines.length * 10,
+        data: { type: "special" },
       });
     } else {
       edges.push({