From e28a766e7df82e7a3be73f7ba77a3067c502a793 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Wed, 11 Jan 2023 19:56:04 +0100 Subject: [PATCH] Cleanup, updating the module name and description for flowchart in package.json --- cypress/platform/knsv2.html | 9 +- packages/mermaid-flowchart-v3/package.json | 13 +-- .../mermaid-flowchart-v3/src/render-utils.js | 99 ------------------- .../src/render-utils.spec.js | 15 --- pnpm-lock.yaml | 28 ------ 5 files changed, 13 insertions(+), 151 deletions(-) diff --git a/cypress/platform/knsv2.html b/cypress/platform/knsv2.html index 87ca1fd9b..5e1f4d76b 100644 --- a/cypress/platform/knsv2.html +++ b/cypress/platform/knsv2.html @@ -54,7 +54,14 @@ -
Security check
+
+%%{init: {"flowchart": {"defaultRenderer": "elk"}} }%%
+graph TB
+      a --> b
+      a --> c
+      b --> d
+      c --> d
+    
 %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%%
 flowchart TB
diff --git a/packages/mermaid-flowchart-v3/package.json b/packages/mermaid-flowchart-v3/package.json
index 0074f4bbe..4b1c42853 100644
--- a/packages/mermaid-flowchart-v3/package.json
+++ b/packages/mermaid-flowchart-v3/package.json
@@ -1,8 +1,8 @@
 {
   "name": "@mermaid-js/mermaid-flowchart-v3",
   "version": "9.4.0",
-  "description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
-  "module": "dist/mermaid-mindmap.core.mjs",
+  "description": "An extension for the Mermaid diagramming library that utilizes elkjs for layout, enabling the creation of visually appealing and easy-to-understand flowcharts.",
+  "module": "dist/mermaid-flowchart-v3.core.mjs",
   "types": "dist/detector.d.ts",
   "type": "module",
   "exports": {
@@ -15,8 +15,9 @@
   "keywords": [
     "diagram",
     "markdown",
-    "mindmap",
-    "mermaid"
+    "flowchart",
+    "mermaid",
+    "elkjs"
   ],
   "scripts": {
     "prepublishOnly": "pnpm -w run build"
@@ -39,12 +40,8 @@
   },
   "dependencies": {
     "@braintree/sanitize-url": "^6.0.0",
-    "cytoscape": "^3.23.0",
-    "cytoscape-cose-bilkent": "^4.1.0",
-    "cytoscape-fcose": "^2.1.0",
     "graphlib": "^2.1.0",
     "dagre-d3-es": "7.0.4",
-    "cytoscape-dagre": "^2.1.0",
     "elkjs": "^0.8.2",
     "d3": "^7.0.0",
     "khroma": "^2.0.0",
diff --git a/packages/mermaid-flowchart-v3/src/render-utils.js b/packages/mermaid-flowchart-v3/src/render-utils.js
index 20f6483d2..f838e174d 100644
--- a/packages/mermaid-flowchart-v3/src/render-utils.js
+++ b/packages/mermaid-flowchart-v3/src/render-utils.js
@@ -1,43 +1,3 @@
-export const findCommonAncestorCoPilot = (id1, id2, treeData) => {
-  const { parentById, childrenById } = treeData;
-  const parents1 = [];
-  const parents2 = [];
-  let cnt = 0;
-  let currentId = id1;
-  while (currentId) {
-    parents1.push(currentId);
-    currentId = parentById[currentId];
-    cnt++;
-    if (cnt > 200) {
-      throw new Error('Infinite loop detected!');
-    }
-  }
-  currentId = id2;
-  while (currentId) {
-    parents2.push(currentId);
-    currentId = parentById[currentId];
-    cnt++;
-    if (cnt > 200) {
-      throw new Error('Infinite loop detected!');
-    }
-  }
-  let commonAncestor = 'root';
-  while (parents1.length && parents2.length) {
-    cnt++;
-    if (cnt > 200) {
-      throw new Error('Infinite loop detected!');
-    }
-    const p1 = parents1.pop();
-    const p2 = parents2.pop();
-    if (p1 === p2) {
-      commonAncestor = p1;
-    } else {
-      break;
-    }
-  }
-  return commonAncestor;
-};
-
 export const findCommonAncestor = (id1, id2, treeData) => {
   const { parentById } = treeData;
   const visited = new Set();
@@ -58,62 +18,3 @@ export const findCommonAncestor = (id1, id2, treeData) => {
   }
   return 'root';
 };
-
-export const findCommonAncestorKnut = (id1, id2, treeData) => {
-  const { parentById, childrenById } = treeData;
-  const parents1 = [];
-  const parents2 = [];
-  let cnt = 0;
-  let currentId = id1;
-  while (currentId) {
-    parents1.push(currentId);
-    currentId = parentById[currentId];
-    cnt++;
-    if (cnt > 200) {
-      throw new Error('Infinite loop detected!');
-    }
-  }
-  currentId = id2;
-  while (currentId) {
-    parents2.push(currentId);
-    currentId = parentById[currentId];
-    if (currentId === 'root') {
-      return 'root';
-    }
-
-    if (parents1.includes(currentId)) {
-      return currentId;
-    }
-
-    cnt++;
-    if (cnt > 200) {
-      throw new Error('Infinite loop detected!');
-    }
-  }
-  return 'root';
-};
-
-export const findCommonAncestorRecursive = (id1, id2, treeData) => {
-  const { parentById, childrenById } = treeData;
-
-  // Base case: return the current node if it is the common ancestor
-  if (id1 === id2) {
-    return id1;
-  }
-
-  // Recursive case: search for the common ancestor in the parent nodes
-  const parent1 = parentById[id1];
-  const parent2 = parentById[id2];
-  if (parent1 && parent2) {
-    return findCommonAncestor(parent1, parent2, treeData);
-  }
-
-  // Edge case: one of the nodes is the root of the tree
-  if (parent1) {
-    return parent1;
-  }
-  if (parent2) {
-    return parent2;
-  }
-  return 'root';
-};
diff --git a/packages/mermaid-flowchart-v3/src/render-utils.spec.js b/packages/mermaid-flowchart-v3/src/render-utils.spec.js
index fcc04b4ee..62bd682d2 100644
--- a/packages/mermaid-flowchart-v3/src/render-utils.spec.js
+++ b/packages/mermaid-flowchart-v3/src/render-utils.spec.js
@@ -2,21 +2,6 @@ import { findCommonAncestor } from './render-utils';
 describe('when rendering a flowchart using elk ', function () {
   let lookupDb;
   beforeEach(function () {
-    /**
-     * root:
-     *   B1
-     *   outer
-     *     B6
-     *   Ugge
-     *     B2
-     *     B3
-     *     inner
-     *       B4
-     *       B5
-     *     inner2
-     *       C4
-     *       C5
-     */
     lookupDb = JSON.parse(
       '{"parentById":{"B4":"inner","B5":"inner","C4":"inner2","C5":"inner2","B2":"Ugge","B3":"Ugge","inner":"Ugge","inner2":"Ugge","B6":"outer"},"childrenById":{"inner":["B4","B5"],"inner2":["C4","C5"],"Ugge":["B2","B3","inner","inner2"],"outer":["B6"]}}'
     );
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 54a8cac32..21f56cb50 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -311,18 +311,6 @@ importers:
       '@braintree/sanitize-url':
         specifier: ^6.0.0
         version: 6.0.0
-      cytoscape:
-        specifier: ^3.23.0
-        version: 3.23.0
-      cytoscape-cose-bilkent:
-        specifier: ^4.1.0
-        version: 4.1.0_cytoscape@3.23.0
-      cytoscape-dagre:
-        specifier: ^2.1.0
-        version: 2.5.0_cytoscape@3.23.0
-      cytoscape-fcose:
-        specifier: ^2.1.0
-        version: 2.1.0_cytoscape@3.23.0
       d3:
         specifier: ^7.0.0
         version: 7.6.1
@@ -4946,15 +4934,6 @@ packages:
       cytoscape: 3.23.0
     dev: false
 
-  /cytoscape-dagre/2.5.0_cytoscape@3.23.0:
-    resolution: {integrity: sha512-VG2Knemmshop4kh5fpLO27rYcyUaaDkRw+6PiX4bstpB+QFt0p2oauMrsjVbUamGWQ6YNavh7x2em2uZlzV44g==}
-    peerDependencies:
-      cytoscape: ^3.2.22
-    dependencies:
-      cytoscape: 3.23.0
-      dagre: 0.8.5
-    dev: false
-
   /cytoscape-fcose/2.1.0_cytoscape@3.23.0:
     resolution: {integrity: sha512-Q3apPl66jf8/2sMsrCjNP247nbDkyIPjA9g5iPMMWNLZgP3/mn9aryF7EFY/oRPEpv7bKJ4jYmCoU5r5/qAc1Q==}
     peerDependencies:
@@ -5270,13 +5249,6 @@ packages:
       lodash-es: 4.17.21
     dev: false
 
-  /dagre/0.8.5:
-    resolution: {integrity: sha512-/aTqmnRta7x7MCCpExk7HQL2O4owCT2h8NT//9I1OQ9vt29Pa0BzSAkR5lwFUcQ7491yVi/3CXU9jQ5o0Mn2Sw==}
-    dependencies:
-      graphlib: 2.1.8
-      lodash: 4.17.21
-    dev: false
-
   /dargs/7.0.0:
     resolution: {integrity: sha512-2iy1EkLdlBzQGvbweYRFxmFath8+K7+AKB0TlhHWkNuH+TmovaMH/Wp7V7R4u7f4SnX3OgLsU9t1NI9ioDnUpg==}
     engines: {node: '>=8'}