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

Refactor fontawesome icon usage. #6282

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

Conversation

saurabhg772244
Copy link
Collaborator

@saurabhg772244 saurabhg772244 commented Feb 14, 2025

📑 Summary

  • FontAwesome icons can now be embedded as SVG when the FontAwesome icon pack is registered in the Mermaid configuration. Otherwise, the icon will still be rendered using FontAwesome CSS (<i> tag).
  • Updated styles to properly set fill color and positioning for registered SVG icons. No extra styles are needed for FontAwesome CSS-based icons, as they inherit styles from FontAwesome.
  • Only the flowchart diagram supports registered FontAwesome icons.

See mermaid-js/mermaid-cli#474

📏 Design Decisions

When text contains a FontAwesome icon reference:

  • Check if the FontAwesome icon pack is registered in the Mermaid configuration.
  • If the icon is registered, replace it with a stringified SVG representation.
  • If the icon is not found, fallback to rendering it with FontAwesome CSS (<i> tag with the appropriate class).

Update to styles.

  • We had a style defined that adds fill to all path elements inside node class. Now we are overriding this style to have fill: currentColor also reverting stroke and stroke-width to default

📋 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 Feb 14, 2025

🦋 Changeset detected

Latest commit: a31adc6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mermaid Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link

netlify bot commented Feb 14, 2025

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit a31adc6
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/67c1bcb528911e0008826f23
😎 Deploy Preview https://deploy-preview-6282--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 Feb 14, 2025

Open in Stackblitz

npm i https://pkg.pr.new/mermaid-js/mermaid@6282
npm i https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/mermaid-zenuml@6282
npm i https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/layout-elk@6282
npm i https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/parser@6282

commit: a31adc6

@saurabhg772244
Copy link
Collaborator Author

Note: Some e2e tests are failing as they were using fontawesome icon in them but the test file was not importing fontawesome cdn

Copy link

codecov bot commented Feb 14, 2025

Codecov Report

Attention: Patch coverage is 0% with 80 lines in your changes missing coverage. Please review.

Project coverage is 3.88%. Comparing base (0518e9c) to head (a31adc6).
Report is 87 commits behind head on develop.

Files with missing lines Patch % Lines
packages/mermaid/src/rendering-util/createText.ts 0.00% 20 Missing ⚠️
packages/mermaid/src/dagre-wrapper/nodes.js 0.00% 15 Missing ⚠️
packages/mermaid/src/dagre-wrapper/clusters.js 0.00% 10 Missing ⚠️
packages/mermaid/src/dagre-wrapper/edges.js 0.00% 6 Missing ⚠️
packages/mermaid/src/dagre-wrapper/shapes/util.js 0.00% 6 Missing ⚠️
packages/mermaid/src/rendering-util/icons.ts 0.00% 6 Missing ⚠️
packages/mermaid/src/dagre-wrapper/createLabel.js 0.00% 3 Missing ⚠️
packages/mermaid/src/dagre-wrapper/index.js 0.00% 3 Missing ⚠️
packages/mermaid/src/diagrams/block/styles.ts 0.00% 2 Missing ⚠️
packages/mermaid/src/diagrams/class/styles.js 0.00% 2 Missing ⚠️
... and 4 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #6282      +/-   ##
==========================================
- Coverage     4.46%   3.88%   -0.59%     
==========================================
  Files          384     399      +15     
  Lines        54262   42085   -12177     
  Branches       623     639      +16     
==========================================
- Hits          2425    1635     -790     
+ Misses       51837   40450   -11387     
Flag Coverage Δ
unit 3.88% <0.00%> (-0.59%) ⬇️

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

Files with missing lines Coverage Δ
packages/mermaid/src/diagrams/globalStyles.ts 0.00% <0.00%> (ø)
packages/mermaid/src/diagrams/block/styles.ts 0.00% <0.00%> (ø)
packages/mermaid/src/diagrams/class/styles.js 0.00% <0.00%> (ø)
packages/mermaid/src/diagrams/flowchart/styles.ts 2.22% <0.00%> (+2.22%) ⬆️
packages/mermaid/src/diagrams/kanban/styles.ts 2.04% <0.00%> (+2.04%) ⬆️
...ckages/mermaid/src/diagrams/user-journey/styles.js 0.00% <0.00%> (ø)
packages/mermaid/src/dagre-wrapper/createLabel.js 0.00% <0.00%> (ø)
packages/mermaid/src/dagre-wrapper/index.js 0.00% <0.00%> (ø)
packages/mermaid/src/dagre-wrapper/edges.js 0.00% <0.00%> (ø)
packages/mermaid/src/dagre-wrapper/shapes/util.js 0.00% <0.00%> (ø)
... and 4 more

... and 377 files with indirect coverage changes

@sidharthv96
Copy link
Member

image

This increases the size of our bundle significantly!

Copy link

argos-ci bot commented Feb 19, 2025

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

Build Status Details Updated (UTC)
default (Inspect) ⚠️ Changes detected (Review) 14 changed, 465 added, 455 removed Feb 28, 2025, 1:52 PM

aloisklink

This comment was marked as resolved.

aloisklink

This comment was marked as resolved.

Copy link
Member

@aloisklink aloisklink left a comment

Choose a reason for hiding this comment

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

I've still got two things in the E2E tests that I'm a bit uncomfortable with, but it's non-blocking, so if you and/or Sid feel it's better to leave them how it is, I'm happy!

Since adding FontAwesome to cypress/platform/viewer.js is causing ~500 changed E2E screenshot changes (and two tests to fail, see comment below), do you think it's worth making a separate PR for this?

I'm mainly asking @sidharthv96 here, since I don't really know how @argos-ci works, but it might make it easier to review the changes!

Comment on lines 37 to 38
await loadFontAwesomeCSS();
await Promise.all(Array.from(document.fonts, (font) => font.load()));
Copy link
Member

Choose a reason for hiding this comment

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

issue(blocking):

This change now causes the following E2E tests to fail

it('7: should render a flowchart when useMaxWidth is true (default)', () => {
renderGraph(
`flowchart TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
`,
{ flowchart: { useMaxWidth: true } }
);
cy.get('svg').should((svg) => {
expect(svg).to.have.attr('width', '100%');
// expect(svg).to.have.attr('height');
// use within because the absolute value can be slightly different depending on the environment ±5%
// const height = parseFloat(svg.attr('height'));
// expect(height).to.be.within(446 * 0.95, 446 * 1.05);
const style = svg.attr('style');
expect(style).to.match(/^max-width: [\d.]+px;$/);
const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join(''));
expect(maxWidthValue).to.be.within(417 * 0.95, 417 * 1.05);
});
});
it('8: should render a flowchart when useMaxWidth is false', () => {
renderGraph(
`flowchart TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
`,
{ flowchart: { useMaxWidth: false } }
);
cy.get('svg').should((svg) => {
// const height = parseFloat(svg.attr('height'));
const width = parseFloat(svg.attr('width'));
// use within because the absolute value can be slightly different depending on the environment ±5%
// expect(height).to.be.within(446 * 0.95, 446 * 1.05);
expect(width).to.be.within(417 * 0.95, 417 * 1.05);
expect(svg).to.not.have.attr('style');
});
});

We could remove the fa:fa-car icon? Or update the widths to the new value.

Copy link
Member

Choose a reason for hiding this comment

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

The change in the images seems to be the /rendering prefix in the test name. Please fix that as well.

image image

Comment on lines 37 to 38
await loadFontAwesomeCSS();
await Promise.all(Array.from(document.fonts, (font) => font.load()));
Copy link
Member

Choose a reason for hiding this comment

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

The change in the images seems to be the /rendering prefix in the test name. Please fix that as well.

image image

Co-authored-by: Alois Klink <alois@aloisklink.com>
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.

3 participants