mermaid
Version:
Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graphs and more.
8 lines (7 loc) • 33.7 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../../../node_modules/.pnpm/dagre-d3-es@7.0.14/node_modules/dagre-d3-es/src/graphlib/json.js", "../../../src/rendering-util/layout-algorithms/dagre/mermaid-graphlib.js"],
"sourcesContent": ["import * as _ from 'lodash-es';\nimport { Graph } from './graph.js';\n\n/**\n * @import { NodeID, EdgeObj, GraphOptions } from './graph.js';\n */\n\nexport { write, read };\n\n/**\n * @template [GraphLabel=any] - Label of the graph.\n * @template [NodeLabel=any] - Label of a node.\n * @template [EdgeLabel=any] - Label of an edge.\n *\n * @typedef {object} GraphJSON\n * @property {Required<GraphOptions>} options - The options used to create the graph.\n * @property {Array<{ v: NodeID; value?: NodeLabel; parent?: NodeID }>} nodes - The nodes in the graph.\n * @property {Array<EdgeObj & { value?: EdgeLabel }>} edges - The edges in the graph.\n * @property {GraphLabel} [value] - The graph's value, if any.\n */\n\n/**\n * Creates a JSON representation of the graph that can be serialized to a\n * string with\n * [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).\n * The graph can later be restored using {@link read}.\n *\n * @example\n *\n * ```js\n * var g = new graphlib.Graph();\n * g.setNode(\"a\", { label: \"node a\" });\n * g.setNode(\"b\", { label: \"node b\" });\n * g.setEdge(\"a\", \"b\", { label: \"edge a->b\" });\n * graphlib.json.write(g);\n * // Returns the object:\n * //\n * // {\n * // \"options\": {\n * // \"directed\": true,\n * // \"multigraph\": false,\n * // \"compound\": false\n * // },\n * // \"nodes\": [\n * // { \"v\": \"a\", \"value\": { \"label\": \"node a\" } },\n * // { \"v\": \"b\", \"value\": { \"label\": \"node b\" } }\n * // ],\n * // \"edges\": [\n * // { \"v\": \"a\", \"w\": \"b\", \"value\": { \"label\": \"edge a->b\" } }\n * // ]\n * // }\n * ```\n *\n * @template [GraphLabel=any] - Label of the graph.\n * @template [NodeLabel=any] - Label of a node.\n * @template [EdgeLabel=any] - Label of an edge.\n * @param {Graph<GraphLabel, NodeLabel, EdgeLabel>} g - The graph to serialize.\n * @returns {GraphJSON<GraphLabel, NodeLabel, EdgeLabel>} The JSON representation of the graph.\n */\nfunction write(g) {\n /** @type {GraphJSON<GraphLabel, NodeLabel, EdgeLabel>} */\n var json = {\n options: {\n directed: g.isDirected(),\n multigraph: g.isMultigraph(),\n compound: g.isCompound(),\n },\n nodes: writeNodes(g),\n edges: writeEdges(g),\n };\n if (!_.isUndefined(g.graph())) {\n json.value = _.clone(g.graph());\n }\n return json;\n}\n\n/**\n * @template NodeLabel - Label of a node.\n *\n * @param {Graph<unknown, NodeLabel, unknown>} g - The graph to serialize.\n * @returns {Array<{ v: NodeID; value?: NodeLabel; parent?: NodeID }>} The nodes in the graph.\n */\nfunction writeNodes(g) {\n return _.map(g.nodes(), function (v) {\n var nodeValue = g.node(v);\n var parent = g.parent(v);\n /** @type {{ v: NodeID; value?: NodeLabel; parent?: NodeID }} */\n var node = { v: v };\n if (!_.isUndefined(nodeValue)) {\n node.value = nodeValue;\n }\n if (!_.isUndefined(parent)) {\n node.parent = parent;\n }\n return node;\n });\n}\n\n/**\n * @template EdgeLabel - Label of a node.\n *\n * @param {Graph<unknown, unknown, EdgeLabel>} g - The graph to serialize.\n * @returns {Array<EdgeObj & { value?: EdgeLabel }>} The edges in the graph.\n */\nfunction writeEdges(g) {\n return _.map(g.edges(), function (e) {\n var edgeValue = g.edge(e);\n /** @type {EdgeObj & { value?: EdgeLabel }} */\n var edge = { v: e.v, w: e.w };\n if (!_.isUndefined(e.name)) {\n edge.name = e.name;\n }\n if (!_.isUndefined(edgeValue)) {\n edge.value = edgeValue;\n }\n return edge;\n });\n}\n\n/**\n * Takes JSON as input and returns the graph representation.\n *\n * @example\n *\n * For example, if we have serialized the graph in {@link write}\n * to a string named `str`, we can restore it to a graph as follows:\n *\n * ```js\n * var g2 = graphlib.json.read(JSON.parse(str));\n * // or, in order to copy the graph\n * var g3 = graphlib.json.read(graphlib.json.write(g))\n *\n * g2.nodes();\n * // ['a', 'b']\n * g2.edges()\n * // [ { v: 'a', w: 'b' } ]\n * ```\n *\n * @template [GraphLabel=any] - Label of the graph.\n * @template [NodeLabel=any] - Label of a node.\n * @template [EdgeLabel=any] - Label of an edge.\n * @param {GraphJSON<GraphLabel, NodeLabel, EdgeLabel>} json - The JSON representation of the graph.\n * @returns {Graph<GraphLabel, NodeLabel, EdgeLabel>} The restored graph.\n */\nfunction read(json) {\n var g = new Graph(json.options).setGraph(json.value);\n _.each(json.nodes, function (entry) {\n g.setNode(entry.v, entry.value);\n if (entry.parent) {\n g.setParent(entry.v, entry.parent);\n }\n });\n _.each(json.edges, function (entry) {\n g.setEdge({ v: entry.v, w: entry.w, name: entry.name }, entry.value);\n });\n return g;\n}\n", "/** Decorates with functions required by mermaids dagre-wrapper. */\nimport { log } from '../../../logger.js';\nimport * as graphlib from 'dagre-d3-es/src/graphlib/index.js';\nimport * as graphlibJson from 'dagre-d3-es/src/graphlib/json.js';\n\nexport let clusterDb = new Map();\nlet descendants = new Map();\nlet parents = new Map();\n\nexport const clear = () => {\n descendants.clear();\n parents.clear();\n clusterDb.clear();\n};\n\nconst isDescendant = (id, ancestorId) => {\n const ancestorDescendants = descendants.get(ancestorId) || [];\n log.trace('In isDescendant', ancestorId, ' ', id, ' = ', ancestorDescendants.includes(id));\n return ancestorDescendants.includes(id);\n};\n\nconst edgeInCluster = (edge, clusterId) => {\n const clusterDescendants = descendants.get(clusterId) || [];\n log.info('Descendants of ', clusterId, ' is ', clusterDescendants);\n log.info('Edge is ', edge);\n if (edge.v === clusterId || edge.w === clusterId) {\n return false;\n }\n\n if (!clusterDescendants) {\n log.debug('Tilt, ', clusterId, ',not in descendants');\n return false;\n }\n\n return (\n clusterDescendants.includes(edge.v) ||\n isDescendant(edge.v, clusterId) ||\n isDescendant(edge.w, clusterId) ||\n clusterDescendants.includes(edge.w)\n );\n};\n\nconst copy = (clusterId, graph, newGraph, rootId) => {\n log.warn(\n 'Copying children of ',\n clusterId,\n 'root',\n rootId,\n 'data',\n graph.node(clusterId),\n rootId\n );\n const nodes = graph.children(clusterId) || [];\n\n if (clusterId !== rootId) {\n nodes.push(clusterId);\n }\n\n log.warn('Copying (nodes) clusterId', clusterId, 'nodes', nodes);\n\n nodes.forEach((node) => {\n if (graph.children(node).length > 0) {\n copy(node, graph, newGraph, rootId);\n } else {\n const data = graph.node(node);\n log.info('cp ', node, ' to ', rootId, ' with parent ', clusterId);\n newGraph.setNode(node, data);\n if (rootId !== graph.parent(node)) {\n log.warn('Setting parent', node, graph.parent(node));\n newGraph.setParent(node, graph.parent(node));\n }\n\n if (clusterId !== rootId && node !== clusterId) {\n log.debug('Setting parent', node, clusterId);\n newGraph.setParent(node, clusterId);\n } else {\n log.info('In copy ', clusterId, 'root', rootId, 'data', graph.node(clusterId), rootId);\n log.debug(\n 'Not Setting parent for node=',\n node,\n 'cluster!==rootId',\n clusterId !== rootId,\n 'node!==clusterId',\n node !== clusterId\n );\n }\n const edges = graph.edges(node);\n log.debug('Copying Edges', edges);\n edges.forEach((edge) => {\n log.info('Edge', edge);\n const data = graph.edge(edge.v, edge.w, edge.name);\n log.info('Edge data', data, rootId);\n try {\n if (edgeInCluster(edge, rootId)) {\n // Determine whether BOTH endpoints are strictly inside the cluster.\n // edgeInCluster uses OR logic (either endpoint inside), so a\n // cross-boundary edge (one endpoint outside rootId) also passes.\n // Copying such an edge into newGraph would auto-create the external\n // node as an orphan with no layout data, crashing the renderer.\n // Instead, rebind cross-boundary edges in the outer graph as\n // rootId \u2192 externalNode\n // so the connection is preserved after the leaf is removed.\n const rootDescendants = descendants.get(rootId) || [];\n const vIn =\n rootDescendants.includes(edge.v) || isDescendant(edge.v, rootId) || edge.v === rootId;\n const wIn =\n rootDescendants.includes(edge.w) || isDescendant(edge.w, rootId) || edge.w === rootId;\n if (vIn && wIn) {\n log.info('Copying as ', edge.v, edge.w, data, edge.name);\n newGraph.setEdge(edge.v, edge.w, data, edge.name);\n log.info('newGraph edges ', newGraph.edges(), newGraph.edge(newGraph.edges()[0]));\n } else {\n // Cross-boundary: rebind to the cluster root in the outer graph.\n const newV = vIn ? rootId : edge.v;\n const newW = wIn ? rootId : edge.w;\n log.info('Rebinding cross-boundary edge as ', newV, newW, data, edge.name);\n graph.setEdge(newV, newW, data, edge.name);\n }\n } else {\n log.info(\n 'Skipping copy of edge ',\n edge.v,\n '-->',\n edge.w,\n ' rootId: ',\n rootId,\n ' clusterId:',\n clusterId\n );\n }\n } catch (e) {\n log.error(e);\n }\n });\n }\n log.debug('Removing node', node);\n graph.removeNode(node);\n });\n};\n\nexport const extractDescendants = (id, graph) => {\n const children = graph.children(id);\n let res = [...children];\n\n for (const child of children) {\n parents.set(child, id);\n res = [...res, ...extractDescendants(child, graph)];\n }\n\n return res;\n};\n\nexport const validate = (graph) => {\n const edges = graph.edges();\n log.trace('Edges: ', edges);\n for (const edge of edges) {\n if (graph.children(edge.v).length > 0) {\n log.trace('The node ', edge.v, ' is part of and edge even though it has children');\n return false;\n }\n if (graph.children(edge.w).length > 0) {\n log.trace('The node ', edge.w, ' is part of and edge even though it has children');\n return false;\n }\n }\n return true;\n};\n\nconst findCommonEdges = (graph, id1, id2) => {\n const edges1 = graph.edges().filter((edge) => edge.v === id1 || edge.w === id1);\n const edges2 = graph.edges().filter((edge) => edge.v === id2 || edge.w === id2);\n const edges1Prim = edges1.map((edge) => {\n return { v: edge.v === id1 ? id2 : edge.v, w: edge.w === id1 ? id1 : edge.w };\n });\n const edges2Prim = edges2.map((edge) => {\n return { v: edge.v, w: edge.w };\n });\n const result = edges1Prim.filter((edgeIn1) => {\n return edges2Prim.some((edge) => edgeIn1.v === edge.v && edgeIn1.w === edge.w);\n });\n\n return result;\n};\n\nexport const findNonClusterChild = (id, graph, clusterId) => {\n const children = graph.children(id);\n log.trace('Searching children of id ', id, children);\n if (children.length < 1) {\n return id;\n }\n let reserve;\n for (const child of children) {\n const _id = findNonClusterChild(child, graph, clusterId);\n\n const commonEdges = findCommonEdges(graph, clusterId, _id);\n\n if (_id) {\n if (commonEdges.length > 0) {\n reserve = _id;\n } else {\n return _id;\n }\n }\n }\n return reserve;\n};\n\nconst getAnchorId = (id) => {\n if (!clusterDb.has(id)) {\n return id;\n }\n if (!clusterDb.get(id).externalConnections) {\n return id;\n }\n\n if (clusterDb.has(id)) {\n return clusterDb.get(id).id;\n }\n return id;\n};\n\nexport const adjustClustersAndEdges = (graph, depth) => {\n if (!graph || depth > 10) {\n log.debug('Opting out, no graph ');\n return;\n } else {\n log.debug('Opting in, graph ');\n }\n\n graph.nodes().forEach(function (id) {\n const children = graph.children(id);\n if (children.length > 0) {\n log.warn(\n 'Cluster identified',\n id,\n ' Replacement id in edges: ',\n findNonClusterChild(id, graph, id)\n );\n descendants.set(id, extractDescendants(id, graph));\n clusterDb.set(id, { id: findNonClusterChild(id, graph, id), clusterData: graph.node(id) });\n }\n });\n\n graph.nodes().forEach(function (id) {\n const children = graph.children(id);\n const edges = graph.edges();\n if (children.length > 0) {\n log.debug('Cluster identified', id, descendants);\n edges.forEach((edge) => {\n const d1 = isDescendant(edge.v, id);\n const d2 = isDescendant(edge.w, id);\n\n if (d1 ^ d2) {\n log.warn('Edge: ', edge, ' leaves cluster ', id);\n log.warn('Descendants of XXX ', id, ': ', descendants.get(id));\n clusterDb.get(id).externalConnections = true;\n }\n });\n } else {\n log.debug('Not a cluster ', id, descendants);\n }\n });\n\n for (let id of clusterDb.keys()) {\n const nonClusterChild = clusterDb.get(id).id;\n const parent = graph.parent(nonClusterChild);\n\n if (parent !== id && clusterDb.has(parent) && !clusterDb.get(parent).externalConnections) {\n clusterDb.get(id).id = parent;\n }\n // When this cluster has a direct outgoing edge AND its current anchor sits inside\n // a sibling subgraph that will be extracted (collapsed into a clusterNode), the\n // anchor will disappear by render time and the edge endpoint becomes undefined.\n // Re-anchor onto a node that survives extraction.\n const hasDirectOutgoingEdge = graph.edges().some((edge) => edge.v === id);\n if (\n nonClusterChild &&\n clusterDb.get(id)?.externalConnections &&\n hasDirectOutgoingEdge &&\n isNodeInExtractableCluster(graph, nonClusterChild, id)\n ) {\n const safeAnchor = findSafeAnchorNode(graph, id, graph.parent(nonClusterChild));\n if (safeAnchor) {\n clusterDb.get(id).id = safeAnchor;\n }\n }\n }\n\n graph.edges().forEach(function (e) {\n const edge = graph.edge(e);\n log.warn('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(e));\n log.warn('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(graph.edge(e)));\n\n let v = e.v;\n let w = e.w;\n log.warn(\n 'Fix XXX',\n clusterDb,\n 'ids:',\n e.v,\n e.w,\n 'Translating: ',\n clusterDb.get(e.v),\n ' --- ',\n clusterDb.get(e.w)\n );\n if (clusterDb.get(e.v) || clusterDb.get(e.w)) {\n log.warn('Fixing and trying - removing XXX', e.v, e.w, e.name);\n v = getAnchorId(e.v);\n w = getAnchorId(e.w);\n graph.removeEdge(e.v, e.w, e.name);\n if (v !== e.v) {\n const parent = graph.parent(v);\n clusterDb.get(parent).externalConnections = true;\n edge.fromCluster = e.v;\n }\n if (w !== e.w) {\n const parent = graph.parent(w);\n clusterDb.get(parent).externalConnections = true;\n edge.toCluster = e.w;\n }\n log.warn('Fix Replacing with XXX', v, w, e.name);\n graph.setEdge(v, w, edge, e.name);\n }\n });\n log.warn('Adjusted Graph', graphlibJson.write(graph));\n extractor(graph, 0);\n\n log.trace(clusterDb);\n};\n\nexport const extractor = (graph, depth) => {\n log.warn('extractor - ', depth, graphlibJson.write(graph), graph.children('D'));\n if (depth > 10) {\n log.error('Bailing out');\n return;\n }\n let nodes = graph.nodes();\n let hasChildren = false;\n for (const node of nodes) {\n const children = graph.children(node);\n hasChildren = hasChildren || children.length > 0;\n }\n\n if (!hasChildren) {\n log.debug('Done, no node has children', graph.nodes());\n return;\n }\n log.debug('Nodes = ', nodes, depth);\n for (const node of nodes) {\n log.debug(\n 'Extracting node',\n node,\n clusterDb,\n clusterDb.has(node) && !clusterDb.get(node).externalConnections,\n !graph.parent(node),\n graph.node(node),\n graph.children('D'),\n ' Depth ',\n depth\n );\n if (!clusterDb.has(node)) {\n log.debug('Not a cluster', node, depth);\n } else if (\n clusterDb.get(node)?.clusterData?.explicitDir &&\n graph.children(node) &&\n graph.children(node).length > 0\n ) {\n // Cluster with an explicit direction keyword \u2014 always create a subgraph,\n // even when it has external connections (fixes issue #4648).\n log.warn('Cluster with explicit dir, creating subgraph for children', node, depth);\n\n const dir = clusterDb.get(node).clusterData.dir;\n const clusterGraph = new graphlib.Graph({\n multigraph: true,\n compound: true,\n })\n .setGraph({\n rankdir: dir,\n nodesep: 50,\n ranksep: 50,\n marginx: 8,\n marginy: 8,\n })\n .setDefaultEdgeLabel(function () {\n return {};\n });\n\n // Copy the cluster (and any nested sub-clusters) into the subgraph\n copy(node, graph, clusterGraph, node);\n // Attach the subgraph to the cluster node for internal layout\n const clusterNodeData = graph.node(node) || {};\n graph.setNode(node, {\n ...clusterNodeData,\n clusterNode: true,\n id: node,\n clusterData: clusterDb.get(node).clusterData,\n label: clusterDb.get(node).label,\n graph: clusterGraph,\n });\n log.warn(\n 'Subgraph for cluster with explicit dir created:',\n node,\n graphlibJson.write(clusterGraph)\n );\n } else if (\n !clusterDb.get(node).externalConnections &&\n graph.children(node) &&\n graph.children(node).length > 0\n ) {\n // Original behaviour: cluster without external connections gets its own sub-graph.\n log.warn(\n 'Cluster without external connections, without a parent and with children',\n node,\n depth\n );\n\n const graphSettings = graph.graph();\n let dir = graphSettings.rankdir === 'TB' ? 'LR' : 'TB';\n if (clusterDb.get(node)?.clusterData?.dir) {\n dir = clusterDb.get(node).clusterData.dir;\n log.warn('Fixing dir', clusterDb.get(node).clusterData.dir, dir);\n }\n\n const clusterGraph = new graphlib.Graph({\n multigraph: true,\n compound: true,\n })\n .setGraph({\n rankdir: dir,\n nodesep: 50,\n ranksep: 50,\n marginx: 8,\n marginy: 8,\n })\n .setDefaultEdgeLabel(function () {\n return {};\n });\n\n copy(node, graph, clusterGraph, node);\n const clusterNodeData = graph.node(node) || {};\n graph.setNode(node, {\n ...clusterNodeData,\n clusterNode: true,\n id: node,\n clusterData: clusterDb.get(node).clusterData,\n label: clusterDb.get(node).label,\n graph: clusterGraph,\n });\n log.debug('Old graph after copy', graphlibJson.write(graph));\n } else {\n log.warn(\n 'Cluster ** ',\n node,\n ' **not meeting the criteria !externalConnections:',\n !clusterDb.get(node).externalConnections,\n ' no parent: ',\n !graph.parent(node),\n ' children ',\n graph.children(node) && graph.children(node).length > 0,\n graph.children('D'),\n depth\n );\n log.debug(clusterDb);\n }\n }\n\n nodes = graph.nodes();\n log.warn('New list of nodes', nodes);\n for (const node of nodes) {\n const data = graph.node(node);\n log.warn(' Now next level', node, data);\n if (data?.clusterNode) {\n extractor(data.graph, depth + 1);\n }\n }\n};\n\nconst sorter = (graph, nodes) => {\n if (nodes.length === 0) {\n return [];\n }\n let result = Object.assign([], nodes);\n nodes.forEach((node) => {\n const children = graph.children(node);\n const sorted = sorter(graph, children);\n result = [...result, ...sorted];\n });\n\n return result;\n};\n\nexport const sortNodesByHierarchy = (graph) => sorter(graph, graph.children());\n\n/** Checks if a node is inside a cluster that will be extracted (has no external connections). */\nconst isNodeInExtractableCluster = (graph, node, rootId) => {\n let parent = graph.parent(node);\n\n while (parent && parent !== rootId) {\n const cluster = clusterDb.get(parent);\n if (cluster && !cluster.externalConnections) {\n return true;\n }\n parent = graph.parent(parent);\n }\n\n return false;\n};\n\n/** Finds an alternative anchor node for a cluster that is not inside an extractable cluster. */\nconst findSafeAnchorNode = (graph, clusterId, excludedCluster) => {\n const children = graph.children(clusterId) ?? [];\n\n for (const child of children) {\n if (child === excludedCluster || isDescendant(child, excludedCluster)) {\n continue;\n }\n\n // findNonClusterChild returns the leaf itself when child is a leaf, or drills\n // into a subgraph to find a non-cluster descendant. A returned leaf sibling is\n // a perfectly valid anchor \u2014 only skip when the lookup found nothing usable.\n const candidate = findNonClusterChild(child, graph, clusterId);\n if (!candidate) {\n continue;\n }\n\n if (!isNodeInExtractableCluster(graph, candidate, clusterId)) {\n return candidate;\n }\n }\n\n return null;\n};\n"],
"mappings": "gJA2DA,SAASA,EAAMC,EAAG,CAEhB,IAAIC,EAAO,CACT,QAAS,CACP,SAAUD,EAAE,WAAW,EACvB,WAAYA,EAAE,aAAa,EAC3B,SAAUA,EAAE,WAAW,CACzB,EACA,MAAOE,EAAWF,CAAC,EACnB,MAAOG,EAAWH,CAAC,CACrB,EACA,OAAOI,EAAYJ,EAAE,MAAM,CAAC,IAC1BC,EAAK,MAAUI,EAAML,EAAE,MAAM,CAAC,GAEzBC,CACT,CAfSK,EAAAP,EAAA,SAuBT,SAASG,EAAWF,EAAG,CACrB,OAASO,EAAIP,EAAE,MAAM,EAAG,SAAUQ,EAAG,CACnC,IAAIC,EAAYT,EAAE,KAAKQ,CAAC,EACpBE,EAASV,EAAE,OAAOQ,CAAC,EAEnBG,EAAO,CAAE,EAAGH,CAAE,EAClB,OAAOJ,EAAYK,CAAS,IAC1BE,EAAK,MAAQF,GAERL,EAAYM,CAAM,IACvBC,EAAK,OAASD,GAETC,CACT,CAAC,CACH,CAdSL,EAAAJ,EAAA,cAsBT,SAASC,EAAWH,EAAG,CACrB,OAASO,EAAIP,EAAE,MAAM,EAAG,SAAUY,EAAG,CACnC,IAAIC,EAAYb,EAAE,KAAKY,CAAC,EAEpBE,EAAO,CAAE,EAAGF,EAAE,EAAG,EAAGA,EAAE,CAAE,EAC5B,OAAOR,EAAYQ,EAAE,IAAI,IACvBE,EAAK,KAAOF,EAAE,MAETR,EAAYS,CAAS,IAC1BC,EAAK,MAAQD,GAERC,CACT,CAAC,CACH,CAbSR,EAAAH,EAAA,cCnGF,IAAIY,EAAY,IAAI,IACvBC,EAAc,IAAI,IAClBC,EAAU,IAAI,IAELC,EAAQC,EAAA,IAAM,CACzBH,EAAY,MAAM,EAClBC,EAAQ,MAAM,EACdF,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2B/B,EAAOuD,EAAW5C,CAAS,EACzD,OAAO4C,CAEX,CAEA,OAAO,IACT,EAtB2B",
"names": ["write", "g", "json", "writeNodes", "writeEdges", "isUndefined_default", "clone_default", "__name", "map_default", "v", "nodeValue", "parent", "node", "e", "edgeValue", "edge", "clusterDb", "descendants", "parents", "clear", "__name", "isDescendant", "id", "ancestorId", "ancestorDescendants", "log", "edgeInCluster", "edge", "clusterId", "clusterDescendants", "copy", "graph", "newGraph", "rootId", "nodes", "node", "data", "edges", "rootDescendants", "vIn", "wIn", "newV", "newW", "e", "extractDescendants", "children", "res", "child", "findCommonEdges", "__name", "graph", "id1", "id2", "edges1", "edge", "edges2", "edges1Prim", "edges2Prim", "edgeIn1", "findNonClusterChild", "id", "clusterId", "children", "log", "reserve", "child", "_id", "commonEdges", "getAnchorId", "clusterDb", "adjustClustersAndEdges", "depth", "descendants", "extractDescendants", "edges", "d1", "isDescendant", "d2", "nonClusterChild", "parent", "hasDirectOutgoingEdge", "isNodeInExtractableCluster", "safeAnchor", "findSafeAnchorNode", "e", "v", "w", "write", "extractor", "nodes", "hasChildren", "node", "dir", "clusterGraph", "Graph", "copy", "clusterNodeData", "data", "sorter", "result", "sorted", "sortNodesByHierarchy", "rootId", "cluster", "excludedCluster", "candidate"]
}