Skip to content

Refactor fontawesome icon usage. #6282

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

Merged
merged 23 commits into from
Apr 20, 2025

Conversation

saurabhg772244
Copy link
Contributor

@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: 4077088

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/layout-elk@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/parser@6282

commit: 4077088

@saurabhg772244
Copy link
Contributor 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.87%. Comparing base (59b4006) to head (4077088).
Report is 55 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     3.87%   3.87%   -0.01%     
==========================================
  Files          412     413       +1     
  Lines        43134   43175      +41     
  Branches       664     665       +1     
==========================================
  Hits          1672    1672              
- Misses       41462   41503      +41     
Flag Coverage Δ
unit 3.87% <0.00%> (-0.01%) ⬇️

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%> (-0.11%) ⬇️
packages/mermaid/src/diagrams/kanban/styles.ts 2.04% <0.00%> (-0.09%) ⬇️
...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
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@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 approved 16 changed, 353 added, 343 removed Apr 19, 2025, 1:00 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

Copy link

netlify bot commented Apr 15, 2025

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit 4077088
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/68039bec1f35b80008e09370
😎 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.

@sidharthv96 sidharthv96 self-assigned this Apr 15, 2025
@sidharthv96
Copy link
Member

Verified the snapshots after 867484a, everything looked good.

@sidharthv96 sidharthv96 merged commit 1c1d7d0 into develop Apr 20, 2025
24 of 25 checks passed
@sidharthv96 sidharthv96 deleted the saurabh/refactor-fontawesome-icon-usage branch April 20, 2025 08:04
@github-actions github-actions bot mentioned this pull request Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants