Skip to content

Commit

Permalink
#5237 First elk iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
knsv committed May 3, 2024
1 parent 703c25a commit 913b29d
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 47 deletions.
39 changes: 18 additions & 21 deletions cypress/platform/knsv2.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,20 @@
href="https://fonts.googleapis.com/css?family=Noto+Sans+SC&display=swap"
rel="stylesheet"
/>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Kalam:wght@300;400;700&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Kalam:wght@300;400;700&display=swap"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css2?family=Caveat:[email protected]&family=Kalam:wght@300;400;700&family=Rubik+Mono+One&display=swap"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css2?family=Kalam:wght@300;400;700&family=Rubik+Mono+One&display=swap"
rel="stylesheet"
/>

<style>
body {
Expand Down Expand Up @@ -58,28 +69,13 @@
/* tspan {
font-size: 6px !important;
} */

<style class="style-fonts">
@font-face {
font-family: "Virgil";
src: url("https://excalidraw.com/Virgil.woff2");
}
@font-face {
font-family: "Cascadia";
src: url("https://excalidraw.com/Cascadia.woff2");
}
@font-face {
font-family: "Assistant";
src: url("https://excalidraw.com/Assistant-Regular.woff2");
}
</style>
</style>
</head>
<body>
<pre id="diagram" class="mermaid">
stateDiagram-v2
stateId

Chimp --> Gorilla
Chimp --> Bonobo

</pre
>
Expand Down Expand Up @@ -469,7 +465,8 @@
// });
mermaid.initialize({
flowchart: { titleTopMargin: 10 },
fontFamily: 'Kalam',
/* fontFamily: 'Kalam', */
fontFamily: 'Caveat',
sequence: {
actorFontFamily: 'courier',
noteFontFamily: 'courier',
Expand Down
9 changes: 4 additions & 5 deletions packages/mermaid/src/diagrams/state/stateDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ const trimColon = (str) => (str && str[0] === ':' ? str.substr(1).trim() : str.t

const dataFetcher = (parent, parsedItem, diagramStates, nodes, edges, altFlag, useRough) => {
console.log(

Check failure on line 577 in packages/mermaid/src/diagrams/state/stateDb.js

View workflow job for this annotation

GitHub Actions / lint (18.x)

Unexpected console statement
'parent, parsedItemm, diagramStates, nodes, edges, altFlag, useRough:',
'abc88 parent, parsedItemm, diagramStates, nodes, edges, altFlag, useRough:',
parent,
parsedItem,
diagramStates,
Expand Down Expand Up @@ -716,9 +716,7 @@ const dataFetcher = (parent, parsedItem, diagramStates, nodes, edges, altFlag, u
//add parent id to noteData
noteData.parentId = parentId;

Check failure on line 717 in packages/mermaid/src/diagrams/state/stateDb.js

View workflow job for this annotation

GitHub Actions / lint (18.x)

'parentId' is not defined

nodes.push(groupData);
nodes.push(noteData);
nodes.push(nodeData);
nodes.push(groupData, noteData, nodeData);

let from = itemId;
let to = noteData.id;
Expand All @@ -741,6 +739,7 @@ const dataFetcher = (parent, parsedItem, diagramStates, nodes, edges, altFlag, u
labelpos: G_EDGE_LABELPOS,
labelType: G_EDGE_LABELTYPE,
thickness: G_EDGE_THICKNESS,
useRough,
});
} else {
nodes.push(nodeData);
Expand Down Expand Up @@ -836,7 +835,7 @@ export const getData = () => {
extract(getRootDocV2());
const diagramStates = getStates();

const useRough = false;
const useRough = true;
dataFetcher(undefined, getRootDocV2(), diagramStates, nodes, edges, true, useRough);

return { nodes, edges, other: {} };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ export const draw = async function (text: string, id: string, _version: string,

data4Layout.type = diag.type;

Check failure on line 89 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

Property 'type' does not exist on type 'LayoutData'.
data4Layout.layoutAlgorithm = 'dagre-wrapper';

Check failure on line 90 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

Property 'layoutAlgorithm' does not exist on type 'LayoutData'.
//data4Layout.layoutAlgorithm = 'elk';
data4Layout.skin = 'roughjs';
// data4Layout.layoutAlgorithm = 'elk';
data4Layout.direction = DIR;

Check failure on line 92 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

Property 'direction' does not exist on type 'LayoutData'.
data4Layout.nodeSpacing = conf.nodeSpacing || 50;

Check failure on line 93 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

Property 'nodeSpacing' does not exist on type 'LayoutData'.

Check failure on line 93 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

'conf' is possibly 'undefined'.

Check failure on line 93 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

Property 'nodeSpacing' does not exist on type 'StateDiagramConfig'.
data4Layout.rankSpacing = conf.rankSpacing || 50;

Check failure on line 94 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

Property 'rankSpacing' does not exist on type 'LayoutData'.

Check failure on line 94 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

'conf' is possibly 'undefined'.

Check failure on line 94 in packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts

View workflow job for this annotation

GitHub Actions / build-mermaid (18.x)

Property 'rankSpacing' does not exist on type 'StateDiagramConfig'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ const recursiveRender = async (_elem, graph, diagramtype, id, parentCluster, sit
};

export const render = async (data4Layout, svg, element) => {
console.warn('HERERERERERER');
// Create the input mermaid.graph
const graph = new graphlib.Graph({
multigraph: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export const addEdges = function (dataForLayout, graph, svg) {
// }

edges.forEach(function (edge) {
console.log('edge abc78', edge.id);
console.log('edge abc88', edge);
// Identify Link
const linkIdBase = edge.id; // 'L-' + edge.start + '-' + edge.end;
// count the links from+to the same node to give unique id
Expand Down Expand Up @@ -429,6 +429,7 @@ export const addEdges = function (dataForLayout, graph, svg) {
// Add the edge to the graph
graph.edges.push({
id: 'e' + edge.start + edge.end,
...edge,
sources: [source],
targets: [target],
sourceId,
Expand Down Expand Up @@ -515,6 +516,8 @@ export const render = async (data4Layout, svg, element) => {
const parentLookupDb = {};
graph = await addVertices(svg, data4Layout, parentLookupDb, graph);

console.log('graph', graph, data4Layout);

// Add the nodes and edges to the graph
// data4Layout.nodes.forEach((node) => {
// graph.setNode(node.id, { ...node });
Expand Down Expand Up @@ -600,6 +603,21 @@ export const render = async (data4Layout, svg, element) => {
console.log('after layout', g);
g.edges?.map((edge) => {
// (elem, edge, clusterDb, diagramType, graph, id)
edge.start = nodeDb[edge.sources[0]];
edge.end = nodeDb[edge.targets[0]];
const offset = { x: 0, y: 0 };
const src = edge.sections[0].startPoint;
const dest = edge.sections[0].endPoint;
const segments = edge.sections[0].bendPoints ? edge.sections[0].bendPoints : [];

const segPoints = segments.map((segment) => {
return { x: segment.x + offset.x, y: segment.y + offset.y };
});
edge.points = [
{ x: src.x + offset.x, y: src.y + offset.y },
...segPoints,
{ x: dest.x + offset.x, y: dest.y + offset.y },
];
insertEdge(edgesEl, edge, clusterDb, data4Layout.type, g, data4Layout.diagramId);
});
// setupGraphViewbox({}, svg, conf.diagramPadding, conf.useMaxWidth);
Expand Down
3 changes: 0 additions & 3 deletions packages/mermaid/src/rendering-util/render.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
export const render = async (data4Layout, svg, element) => {
switch (data4Layout.layoutAlgorithm) {
case 'dagre-wrapper': {
// const layoutRenderer = await import('../dagre-wrapper/index-refactored.js');

const layoutRenderer = await import('./layout-algorithms/dagre/index.js');

return layoutRenderer.render(data4Layout, svg, element);
}
case 'elk': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function addHtmlLabel(node) {

applyStyle(div, node.labelStyle);
div.style('display', 'inline-block');
div.style('padding-right', '1px');
// Fix for firefox
div.style('white-space', 'nowrap');
div.attr('xmlns', 'http://www.w3.org/1999/xhtml');
Expand Down
34 changes: 20 additions & 14 deletions packages/mermaid/src/rendering-util/rendering-elements/edges.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,18 +382,21 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, graph, i
const tail = edge.start;
var head = edge.end;

log.info('abc88 InsertEdge: ', edge);
log.info('abc88 InsertEdge: ', points);
if (head.intersect && tail.intersect) {
points = points.slice(1, edge.points.length - 1);
points.unshift(tail.intersect(points[0]));
log.info(
'Last point',
points[points.length - 1],
head,
head.intersect(points[points.length - 1])
);
points.push(head.intersect(points[points.length - 1]));
log.info('abc88 InsertEdge: 0.5', points);
// points = points.slice(1, edge.points.length - 1);
log.info('abc88 InsertEdge: 0.7', points);
// points.unshift(tail.intersect(points[0]));
// log.info(
// 'Last point abc88',
// points[points.length - 1],
// head,
// head.intersect(points[points.length - 1])
// );
// points.push(head.intersect(points[points.length - 1]));
}
log.info('abc88 InsertEdge 2: ', points);
if (edge.toCluster) {
log.info('to cluster abc88', clusterDb[edge.toCluster]);
points = cutPathAtIntersect(edge.points, clusterDb[edge.toCluster].node);
Expand Down Expand Up @@ -436,7 +439,7 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, graph, i
strokeClasses = 'edge-thickness-thick';
break;
default:
strokeClasses = '';
strokeClasses = 'edge-thickness-normal';
}
switch (edge.pattern) {
case 'solid':
Expand All @@ -448,6 +451,8 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, graph, i
case 'dashed':
strokeClasses += ' edge-pattern-dashed';
break;
default:
strokeClasses += ' edge-pattern-solid';
}
let useRough = edge.useRough;
let svgPath;
Expand All @@ -460,16 +465,17 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, graph, i

if (useRough) {
const rc = rough.svg(elem);
const svgPathNode = rc.curve(pointArr, { stroke: 'green' });
console.log('svgPathNode', svgPathNode);
const svgPathNode = rc.curve(pointArr, { roughness: 0.5, stroke: 'green' });
console.log('svgPathNode abc88', svgPathNode);
strokeClasses += ' transition';
// const svgPath2 = elem
// .append('path')
// .attr('d', lineFunction(lineData))
// .attr('id', edge.id)
// .attr('class', ' ' + strokeClasses + (edge.classes ? ' ' + edge.classes : ''))
// .attr('style', edge.style);

// console.log('svgPath2', svgPath2.node());
console.log('svgPath2 abc88', strokeClasses + (edge.classes ? ' ' + edge.classes : ''));
svgPath = select(svgPathNode)
.select('path')
.attr('id', edge.id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const intersectRect = (node, point) => {
console.log('intersect.rect abc88', node, point);
var x = node.x;
var y = node.y;

Expand Down

0 comments on commit 913b29d

Please sign in to comment.