Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: flowchart rendering issues #61

Merged
merged 12 commits into from May 16, 2024

Conversation

igorwessel
Copy link
Contributor

@igorwessel igorwessel commented May 6, 2024

Closes #45

Revision

8d58faa

There are cases where one entity can have multiple relationships to another entity, we were only considering that there was just one relationship.

31fea66

The filter condition was updated to include points that change in either the x or y direction.
This ensures that points on a straight line in the same direction are included in the reflectionPoints array, and ensures line commands when only changes direction.

By ignoring the directions that a line command can make we were only having straight lines.

Before After
Captura de Tela 2024-05-06 às 13 48 26 Captura de Tela 2024-05-06 às 13 48 48

Testcases

Captura de Tela 2024-05-06 às 07 18 48

This commit modifies the computeEdgePositions function in utils.ts to keep points that are on a straight line in the same direction.
The filter condition is updated to only remove points that have both the same x and y coordinates as the previous point.
This ensures that points on a straight line in the same direction are maintained.
Copy link

vercel bot commented May 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
mermaid-to-excalidraw ✅ Ready (Inspect) Visit Preview May 16, 2024 5:20am

Copy link
Member

@ad1992 ad1992 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igorwessel lets add a testcase for the same in playground

@igorwessel
Copy link
Contributor Author

@ad1992 It was also mentioned about escaping HTML. Does it make sense for mermaid-to-excalidraw to bring this as well? I see that this is a bit out of the scope of this PR, it has to be something a bit more global for all diagrams.

@@ -228,9 +240,12 @@ export const parseMermaidFlowChartDiagram = (
Object.keys(vertices).forEach((id) => {
vertices[id] = parseVertex(vertices[id], containerEl);
});

const processedEdges = new Set<string>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: ‏I feel there's a better way to do this but I haven't figured it out yet, the same happens in the state diagram.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made into a function closure for better encapsulation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a map with the aim of avoiding a for loop inside parseEdges, and the only way I thought to encapsulate it was to create a kind of factory haha.

function createEdgeParser() {
  const edgeCountMap = new Map<string, number>();

  return function parseEdge(data: any, containerEl: HTMLElement) {
    const edgeIdentifier = `${data.start}-${data.end}`;
    const count = edgeCountMap.get(edgeIdentifier) || 0;
    edgeCountMap.set(edgeIdentifier, count + 1);

    // Rest of parseEdge implementation...

    return {

    };
  };
}

Copy link
Member

@ad1992 ad1992 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @igorwessel
I have turned processedEdges into a function closure for better encapsulation

The arrows seems to be breaking in this PR 👇🏻

image

@ad1992
Copy link
Member

ad1992 commented May 7, 2024

@ad1992 It was also mentioned about escaping HTML. Does it make sense for mermaid-to-excalidraw to bring this as well? I see that this is a bit out of the scope of this PR, it has to be something a bit more global for all diagrams.

I guess you meant font awesome support ? we don't support it yet, it's out of scope of this PR. We can look into that later.

@igorwessel
Copy link
Contributor Author

I guess you meant font awesome support ? we don't support it yet, it's out of scope of this PR. We can look into that later.

No but basic support for some HTML tags, for example: <br>, although you could use \n. I don't know to what extent we have possibilities here.

In this issue #45, we have some entities using HTML tags to format labels, although I believe we should not support this.
Captura de Tela 2024-05-07 às 07 03 14

@igorwessel
Copy link
Contributor Author

The arrows seems to be breaking in this PR 👇🏻

@ad1992 Apparently, the problem is that the penultimate point is very close to the last point. It may be solved by calculating the distance between the penultimate point and the last point, and only including the penultimate point when it is greater than some limit we define.
But I feel there might be something more that I'm not seeing at the moment.

Captura de Tela 2024-05-07 às 07 46 06

@igorwessel igorwessel requested a review from ad1992 May 7, 2024 10:46
@ad1992
Copy link
Member

ad1992 commented May 7, 2024

The arrows seems to be breaking in this PR 👇🏻

@ad1992 Apparently, the problem is that the penultimate point is very close to the last point. It may be solved by calculating the distance between the penultimate point and the last point, and only including the penultimate point when it is greater than some limit we define. But I feel there might be something more that I'm not seeing at the moment.

Captura de Tela 2024-05-07 às 07 46 06

@igorwessel this was working earlier for all arrows but not anymore. Since it is breaking post the changes in this PR, we should be able to fix it in this PR itself.

@igorwessel
Copy link
Contributor Author

igorwessel commented May 7, 2024

@ad1992 I implemented two solutions but I'm still undecided about which is the best approach:

  1. In the second from the last, we check if the previous point in some axis remains the same, if it remains the same we can affirm that it is a straight line either on the X or Y axis. In this case we can just return as false.
  2. In the second from the last the same check for first solution, but we set a minimum distance for it. In this example only second from the last with a distance greather than 50 is included in reflection points.

I sent the commit with both solutions, both have their pros/cons but should work in the majority of cases. Only comment the check for distance for 1 solution (testing some values I think I reached the ideal of 50.)

https://github.com/igorwessel/mermaid-to-excalidraw/blob/13e2a3f50ee891b22cbdb146d15209a0a3692d51/src/utils.ts#L131-L138

And we could check the closure because the problem of repeated edges has returned 😢

@igorwessel
Copy link
Contributor Author

I'm will pull the updates from main, and create some tests to ensure.

@igorwessel
Copy link
Contributor Author

@ad1992 friendly reminder, you think this distance calculation solution is enough?

@ad1992
Copy link
Member

ad1992 commented May 14, 2024

@ad1992 friendly reminder, you think this distance calculation solution is enough?

Hi @igorwessel sorry for the delayed response! I am gonna check this soon either tonight or tomorrow morning

Copy link
Member

@ad1992 ad1992 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igorwessel looks good!
I have pushed some tweaks and improvements in e7e9f65, let me know if this looks good and we can update the tests then accordingly.

@igorwessel
Copy link
Contributor Author

@ad1992 it's great! I didn't remember there was a function for hypotenuse in Math haha

@ad1992
Copy link
Member

ad1992 commented May 16, 2024

Pushed a fix for excluding point when its same as prev point
Merging, thanks @igorwessel

Copy link
Member

@ad1992 ad1992 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@ad1992 ad1992 merged commit d541e54 into excalidraw:master May 16, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flowchart rendering issues
2 participants