Explorar o código

dynamic node width & height

Aykut Saraç %!s(int64=3) %!d(string=hai) anos
pai
achega
8cee959751
Modificáronse 1 ficheiros con 9 adicións e 1 borrados
  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({