瀏覽代碼

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)) {
     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({
       nodes.push({
         id: el.id,
         id: el.id,
-        text: renderText(el.data.label),
+        text: text,
+        width: 35 + longestLine * 8,
+        height: 30 + lines.length * 10,
+        data: { type: "special" },
       });
       });
     } else {
     } else {
       edges.push({
       edges.push({