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

Update class diagram to v3 using new renderer #5880

Open
wants to merge 35 commits into
base: develop
Choose a base branch
from

Conversation

yari-dewalt
Copy link
Collaborator

@yari-dewalt yari-dewalt commented Sep 19, 2024

📑 Summary

Updates the class diagram to the new unified way of rendering. Includes a new "classBox" shape to be used in diagrams as well as some other updates such as: the option to hide the empty members box in class diagrams, support for handDrawn look, the introduction of the classDef statement into class diagrams, support for styling the default class, and lollipop interfaces.

Includes fixes / additions for #5562 #3139 and #4037

📏 Design Decisions

  • The classDb gathers the necessary data and passes it to the v3 unified renderer.
  • The classBox shape is kind of complicated due to the placement and possibility of different text (annotations and members as opposed to just a plain label) as well as taking in classNode information, so it's made a little awkward. It utilizes some helper functions defined in shapeUtil to accomplish this, although I am not sure this is the best way to go about it.
  • The syntax of the class diagram and its use of specific symbols also conflicts with text creation in terms of how HTML and markdown is treated (opening and closing tags <>, - being used for lists, * being used at the end for a classifier, etc.) and so there are workarounds / hacks in place. I tried to not stray away from the typical process and so I am unsure about how acceptable these workarounds are and if they are the best method, but can revise and fix if needed.
  • The classDef statement works similarly as it does in other diagrams and defines a class that can be used in the diagram (either via the shorthand ::: or a cssClass statement).
  • Support for lollipop interfaces using ()-- and --(). This was already a supported relationship between classes, due to Class: interface realization / lollipop #1145 but now properly creates a lollipop interface instead. I left ()--() in as of right now which creates a lollipop "relation" between two classes, but it is not an official UML class relationship so unsure about leaving this in.

📋 Tasks

Make sure you

  • 📖 have read the contribution guidelines
  • 💻 have added necessary unit/e2e tests.
  • 📓 have added documentation. Make sure MERMAID_RELEASE_VERSION is used for all new features.
  • 🦋 If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Copy link

changeset-bot bot commented Sep 19, 2024

⚠️ No Changeset found

Latest commit: 91e3da1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

netlify bot commented Sep 19, 2024

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit 91e3da1
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/66f2fb3cf185940008c07713
😎 Deploy Preview https://deploy-preview-5880--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

pkg-pr-new bot commented Sep 19, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/mermaid-js/mermaid@5880
pnpm add https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/layout-elk@5880
pnpm add https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/mermaid-zenuml@5880
pnpm add https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/parser@5880

commit: 91e3da1

Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 0.40984% with 729 lines in your changes missing coverage. Please review.

Project coverage is 4.93%. Comparing base (a07f1f3) to head (91e3da1).

Files with missing lines Patch % Lines
packages/mermaid/src/diagrams/class/classDb.ts 0.00% 222 Missing ⚠️
packages/mermaid/src/diagrams/class/shapeUtil.ts 0.00% 219 Missing ⚠️
...ndering-util/rendering-elements/shapes/classBox.ts 0.00% 176 Missing ⚠️
...aid/src/diagrams/class/classRenderer-v3-unified.ts 0.00% 79 Missing ⚠️
packages/mermaid/src/diagrams/class/classTypes.ts 0.00% 26 Missing ⚠️
...mermaid/src/rendering-util/handle-markdown-text.ts 0.00% 2 Missing ⚠️
...aid/src/rendering-util/rendering-elements/nodes.js 0.00% 2 Missing ⚠️
...ages/mermaid/src/diagrams/class/classDiagram-v2.ts 0.00% 1 Missing ⚠️
...ackages/mermaid/src/diagrams/class/classDiagram.ts 0.00% 1 Missing ⚠️
packages/mermaid/src/utils.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #5880      +/-   ##
==========================================
- Coverage     5.00%   4.93%   -0.07%     
==========================================
  Files          337     341       +4     
  Lines        48209   48934     +725     
  Branches       576     554      -22     
==========================================
+ Hits          2413    2416       +3     
- Misses       45796   46518     +722     
Flag Coverage Δ
unit 4.93% <0.40%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/mermaid/src/defaultConfig.ts 45.18% <100.00%> (+0.61%) ⬆️
...aid/src/rendering-util/rendering-elements/edges.js 0.00% <ø> (ø)
...ages/mermaid/src/diagrams/class/classDiagram-v2.ts 0.00% <0.00%> (ø)
...ackages/mermaid/src/diagrams/class/classDiagram.ts 0.00% <0.00%> (ø)
packages/mermaid/src/utils.ts 41.67% <0.00%> (-0.05%) ⬇️
...mermaid/src/rendering-util/handle-markdown-text.ts 0.00% <0.00%> (ø)
...aid/src/rendering-util/rendering-elements/nodes.js 0.00% <0.00%> (ø)
packages/mermaid/src/diagrams/class/classTypes.ts 0.00% <0.00%> (ø)
...aid/src/diagrams/class/classRenderer-v3-unified.ts 0.00% <0.00%> (ø)
...ndering-util/rendering-elements/shapes/classBox.ts 0.00% <0.00%> (ø)
... and 2 more

... and 1 file with indirect coverage changes

Copy link

argos-ci bot commented Sep 19, 2024

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ⚠️ Changes detected (Review) 222 changed, 56 added Sep 24, 2024, 6:00 PM

Copy link
Contributor

@jgreywolf jgreywolf left a comment

Choose a reason for hiding this comment

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

Small comments from initial scan. Have not run through code in vscode for more feedback yet :)

@@ -91,6 +99,16 @@ export const addClass = function (_id: string) {
classCounter++;
};

const addInterface = function (label: string, classId: string) {
const _interface: Interface = {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just personal preference/nit, but Im not a fan of prefacing variables names with _

];

if (
relation.relation.type1 === relationType.LOLLIPOP &&
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe change relation variable to classRelation. Only because it looks odd to say relation.relation.

styleClasses.set(id, styleClass);
}

if (style !== undefined && style !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you should be able to just say if (style) {..}

});
}

for (const [, value] of classes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that the syntax is so that you can basically just "ignore" the key section of the KVP, but it always looks so weird to me

}

for (const [, value] of classes) {
if (value.cssClasses.includes(id)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Try and minimize nested loops where possible.

if (value.cssClasses.includes(id)) {
  value.styles.push(...style.flatMap(s => s.split(',')));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants