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

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

Shahir-47
Copy link

📑 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 || this.textColor;
      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.


Copy link

changeset-bot bot commented Jan 26, 2025

⚠️ No Changeset found

Latest commit: 03ff28e

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 03ff28e
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/6795a8238899550008cdb80c
😎 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: 03ff28e

Co-authored-by: Pranav Mishra <[email protected]>
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.

Comment on lines 51 to +54
const conf = getConfig().journey;
const titleColor = getConfig().themeVariables.titleColor;
const titleFontSize = getConfig().themeVariables.titleFontSize;
const titleFontFamily = getConfig().themeVariables.titleFontFamily;
Copy link
Member

Choose a reason for hiding this comment

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

Do not call getConfig() every time, call it once, and then use the value in other places.

Choose a reason for hiding this comment

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

@sidharthv96 Understood; we (@Shahir-47 and I) will make sure to update this by calling getConfig() once and then using the value in the other places. As for visual/unit testing, could you please direct us to resources that clarify what kinds of visual/unit tests are expected?

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