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

feat: Add support for styling Journey Diagram title (color, font-family, and font-size) #6225

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

Conversation

Shahir-47
Copy link

@Shahir-47 Shahir-47 commented Jan 26, 2025

📑 Summary

This PR introduces additional customization options for the title in Journey Diagrams. Users can now define titleColor, titleFontFamily, and titleFontSize in the themeVariables configuration to style the title's color, font family, and font size. If these properties are not defined, they default to textColor, "trebuchet ms, verdana, arial, sans-serif", and 16px, respectively. The feature includes corresponding updates in the rendering logic and documentation.

Resolves #3508

📏 Design Decisions

  1. New Theme Variables:

    • titleColor: Sets the color of the Journey Diagram title. Defaults to textColor.
    • titleFontFamily: Sets the font family for the title. Defaults to "trebuchet ms, verdana, arial, sans-serif".
    • titleFontSize: Sets the font size for the title. Defaults to 16px.
  2. Renderer Updates:

    • The Journey Diagram renderer now fetches these new properties using getConfig() and applies them during rendering.
    • Relevant code changes:
      const titleColor = getConfig().themeVariables.titleColor;
      const titleFontSize = getConfig().themeVariables.titleFontSize;
      const titleFontFamily = getConfig().themeVariables.titleFontFamily;
      
      if (title) {
        diagram
          .append('text')
          .text(title)
          .attr('x', LEFT_MARGIN)
          .attr('font-size', titleFontSize)
          .attr('font-weight', 'bold')
          .attr('y', 25)
          .attr('fill', titleColor)
          .attr('font-family', titleFontFamily);
      }
  3. Default Values:

    • In packages/mermaid/src/themes/theme-default.js:
      this.titleColor = this.titleColor === 'calculated' ? this.textColor : this.titleColor;
      this.titleFontFamily = this.titleFontFamily || '"trebuchet ms", verdana, arial, sans-serif';
      this.titleFontSize = this.titleFontSize || '16px';
  4. Documentation Updates:

    • Updated the Theme Variables section in packages/mermaid/src/docs/config/theming.md to include titleColor, titleFontFamily, and titleFontSize.

📋 Tasks

Make sure you

  • [ x ] 📖 have read the contribution guidelines
  • [ x ] 💻 have added necessary unit/e2e tests.
  • [ x ] 📓 have added documentation. Make sure MERMAID_RELEASE_VERSION is used for all new features.
  • [ x ] 🦋 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:.

Updated Documentation

File Updated: packages/mermaid/src/docs/config/theming.md

Added the following rows to the Theme Variables table:

| Variable             | Default value                      | Description                                                                                                                      |
| -------------------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| titleColor           | calculated from textColor          | Color to be used for the title text in Journey Diagrams.                                                                         |
| titleFontFamily      | trebuchet ms, verdana, arial       | Font family to be used for the title text in Journey Diagrams.                                                                   |
| titleFontSize        | 16px                               | Font size in pixels to be used for the title text in Journey Diagrams.                                                           |

Example Configuration

Users can customize the Journey Diagram title using the following configuration:

---
config:
  themeVariables:
    titleColor: "#ff0"
    titleFontFamily: "Arial, sans-serif"
    titleFontSize: "20px"
---

journey
    title User Journey Example
    section Onboarding
        Sign Up: 5: John, Sam
        Complete Profile: 4: John
    section Engagement
        Browse Features: 3: John
        Use Core Functionality: 4: John
    section Retention
        Revisit Application: 5: John
        Invite Friends: 3: John

With this configuration, the title "User Journey Example" will have a yellow color, Arial font, and 20px font size.


Shahir-47 and others added 4 commits January 25, 2025 20:33
Copy link

changeset-bot bot commented Jan 26, 2025

⚠️ No Changeset found

Latest commit: d81ddf2

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

@github-actions github-actions bot added the Type: Enhancement New feature or request label Jan 26, 2025
Copy link

netlify bot commented Jan 26, 2025

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit d81ddf2
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/679d55835b3ce0000839f921
😎 Deploy Preview https://deploy-preview-6225--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 Jan 26, 2025

Open in Stackblitz

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

commit: d81ddf2

Co-authored-by: Pranav Mishra <mishrap@dickinson.edu>
Copy link
Contributor

autofix-ci bot commented Jan 26, 2025

Hi! I'm autofix logoautofix.ci, a bot that automatically fixes trivial issues such as code formatting in pull requests.

I would like to apply some automated changes to this pull request, but it looks like I don't have the necessary permissions to do so. To get this pull request into a mergeable state, please do one of the following two things:

  1. Allow edits by maintainers for your pull request, and then re-trigger CI (for example by pushing a new commit).
  2. Manually fix the issues identified for your pull request (see the GitHub Actions output for details on what I would like to change).

Copy link
Member

@sidharthv96 sidharthv96 left a comment

Choose a reason for hiding this comment

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

Please add visual tests that verify the parameters work.

pranavm2109 and others added 4 commits January 29, 2025 14:45
…where within

Co-authored-by: Shahir Ahmed <ahmeds@dickinson.edu>
Co-authored-by: Pranav Mishra <mishrap@dickinson.edu>
Co-authored-by: Pranav Mishra <mishrap@dickinson.edu>
Co-authored-by: Pranav Mishra <mishrap@dickinson.edu>
@Shahir-47
Copy link
Author

@sidharthv96 We’ve implemented the requested changes:

Optimized getConfig() calls – Now, getConfig() is called once and stored in configObject, and its values are reused in draw().

Added visual tests – We've included a test to verify that the User Journey Diagram title correctly applies the expected color, font family, and font size based on themeVariables.

Let us know if you have any feedback!

@pranavm2109 and I appreciate your guidance.

@Shahir-47 Shahir-47 requested a review from sidharthv96 January 29, 2025 21:47
@Shahir-47 Shahir-47 marked this pull request as ready for review January 29, 2025 21:49
@Shahir-47 Shahir-47 marked this pull request as draft January 29, 2025 21:50
Shahir-47 and others added 3 commits January 31, 2025 17:28
Co-authored-by: Pranav Mishra <mishrap@dickinson.edu>
Co-authored-by: Pranav Mishra <mishrap@dickinson.edu>
Co-authored-by: Pranav Mishra <mishrap@dickinson.edu>
Copy link

codecov bot commented Jan 31, 2025

Codecov Report

Attention: Patch coverage is 26.66667% with 11 lines in your changes missing coverage. Please review.

Project coverage is 4.48%. Comparing base (8dd0e7a) to head (d81ddf2).

Files with missing lines Patch % Lines
...rmaid/src/diagrams/user-journey/journeyRenderer.ts 0.00% 10 Missing ⚠️
...aid/src/diagrams/architecture/architectureTypes.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #6225   +/-   ##
=======================================
  Coverage     4.47%   4.48%           
=======================================
  Files          385     384    -1     
  Lines        54191   54186    -5     
  Branches       598     627   +29     
=======================================
+ Hits          2425    2430    +5     
+ Misses       51766   51756   -10     
Flag Coverage Δ
unit 4.48% <26.66%> (+<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/config.ts 51.60% <100.00%> (ø)
packages/mermaid/src/themes/theme-default.js 94.55% <100.00%> (+0.02%) ⬆️
...aid/src/diagrams/architecture/architectureTypes.ts 0.00% <0.00%> (ø)
...rmaid/src/diagrams/user-journey/journeyRenderer.ts 0.00% <0.00%> (ø)

... and 2 files with indirect coverage changes

@Shahir-47 Shahir-47 marked this pull request as ready for review January 31, 2025 23:13
@Shahir-47
Copy link
Author

Hey @sidharthv96, this PR is good to go—passes all GitHub Actions checks and CI/CD tests!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Let style the title of Journey Diagram
3 participants