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 25 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a30705c
Enhance user journey diagram title color configuration
Shahir-47 Jan 26, 2025
f0a8ccb
Merge branch 'develop' into feature/3508_color-user-journey-title
Shahir-47 Jan 26, 2025
3221cbf
add titleColor theme variable to theming.md
Shahir-47 Jan 26, 2025
16a1a90
adds font family and font size to the title of the user journey diagram
Shahir-47 Jan 26, 2025
03ff28e
removes console.warn()
Shahir-47 Jan 26, 2025
384f59e
called getConfig() once in draw function and used returned value else…
pranavm2109 Jan 29, 2025
7c0af38
adds styling, font-weight and font-family tests for user jounrey title
Shahir-47 Jan 29, 2025
798fb98
Merge branch 'develop' into feature/3508_color-user-journey-title
Shahir-47 Jan 29, 2025
9fb46ae
improves description for user journey diagram title test
Shahir-47 Jan 29, 2025
88a39f8
update dependencies for CI/CD pipeline
Shahir-47 Jan 31, 2025
ffe1bb3
update pnpm-lock.yaml
Shahir-47 Jan 31, 2025
d81ddf2
fixes titleColor default value
Shahir-47 Jan 31, 2025
82d0192
chore: Cleanup
sidharthv96 Feb 13, 2025
add48da
modifed journey diagram config scheme to contain title specific style…
pranavm2109 Feb 14, 2025
2fb6ea7
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 14, 2025
7aef182
Merge branch 'develop' into feature/3508_color-user-journey-title
Shahir-47 Feb 14, 2025
9badfe7
Merge branch 'develop' into feature/3508_color-user-journey-title
sidharthv96 Feb 15, 2025
80c6b94
Removed title style documentation from theming.md
pranavm2109 Feb 18, 2025
eb7289a
Merge branch 'feature/3508_color-user-journey-title' of https://githu…
pranavm2109 Feb 18, 2025
99bd0c4
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 18, 2025
d6376ca
Reverted to using configObject in place of conf
pranavm2109 Feb 18, 2025
5ed2278
Merge branch 'feature/3508_color-user-journey-title' of https://githu…
pranavm2109 Feb 18, 2025
dffa689
updated documentation
pranavm2109 Feb 18, 2025
3122c3b
updated descriptions of parameters in schema
pranavm2109 Feb 18, 2025
4beed96
updated descriptions of parameters in schema
pranavm2109 Feb 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions cypress/integration/rendering/journey.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,41 @@ section Checkout from website
{ journey: { useMaxWidth: false } }
);
});

it('should correctly render the user journey diagram title with the specified styling', () => {
renderGraph(
`---
config:
theme: "forest"
themeVariables:
primaryColor: "#00ff00"
secondaryColor: "#fff"
titleColor: "#2900A5"
titleFontFamily: "Times New Roman"
titleFontSize: "5rem"
Copy link
Member

Choose a reason for hiding this comment

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

Need to update

---

journey
title User Journey Example
section Onboarding
Sign Up: 5: John, Shahir
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

size: 2rem
`
);

cy.get('text').contains('User Journey Example').as('title');
cy.get('@title').then(($title) => {
expect($title).to.have.attr('fill', '#2900A5');
expect($title).to.have.attr('font-family', 'Times New Roman');
expect($title).to.have.attr('font-size', '5rem');
});
});
});
3 changes: 3 additions & 0 deletions docs/config/theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ The theming engine will only recognize hex colors and not color names. So, the v
| background | #f4f4f4 | Used to calculate color for items that should either be background colored or contrasting to the background |
| fontFamily | trebuchet ms, verdana, arial | |
| fontSize | 16px | Font size in pixels |
| 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. |
| primaryColor | #fff4dd | Color to be used as background in nodes, other colors will be derived from this |
| primaryTextColor | calculated from darkMode #ddd/#333 | Color to be used as text color in nodes using `primaryColor` |
| secondaryColor | calculated from primaryColor | |
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ const ConfigWarning = {
} as const;

type ConfigWarningStrings = keyof typeof ConfigWarning;
const issuedWarnings: { [key in ConfigWarningStrings]?: boolean } = {};
const issuedWarnings: Partial<Record<ConfigWarningStrings, boolean>> = {};
const issueWarning = (warning: ConfigWarningStrings) => {
if (issuedWarnings[warning]) {
return;
Expand Down
12 changes: 12 additions & 0 deletions packages/mermaid/src/config.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,18 @@ export interface JourneyDiagramConfig extends BaseDiagramConfig {
actorColours?: string[];
sectionFills?: string[];
sectionColours?: string[];
/**
* Calculated from textColor
*/
titleColor?: string;
/**
* Font family to be used for the title text in Journey Diagrams
*/
titleFontFamily?: string;
/**
* Font size in pixels to be used for the title text in Journey Diagrams
*/
titleFontSize?: string;
}
/**
* This interface was referenced by `MermaidConfig`'s JSON-Schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ export const isValidArchitectureDirectionPair = function (
return x !== 'LL' && x !== 'RR' && x !== 'TT' && x !== 'BB';
};

export type ArchitectureDirectionPairMap = {
[key in ArchitectureDirectionPair]?: string;
};
export type ArchitectureDirectionPairMap = Partial<Record<ArchitectureDirectionPair, string>>;

/**
* Creates a pair of the directions of each side of an edge. This function should be used instead of manually creating it to ensure that the source is always the first character.
Expand Down
10 changes: 7 additions & 3 deletions packages/mermaid/src/diagrams/user-journey/journeyRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ function drawActorLegend(diagram) {
const conf = getConfig().journey;
const LEFT_MARGIN = conf.leftMargin;
export const draw = function (text, id, version, diagObj) {
const conf = getConfig().journey;
const titleColor = conf.titleColor;
const titleFontSize = conf.titleFontSize;
const titleFontFamily = conf.titleFontFamily;

const securityLevel = getConfig().securityLevel;
Copy link
Member

Choose a reason for hiding this comment

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

Using the conf object will cause issues, as it's only initialized during the initial load.
Please use the configObject as before, and remove the getConfig() call for securityLevel

// Handle root and Document for when rendering in sandbox mode
Expand Down Expand Up @@ -93,9 +95,11 @@ export const draw = function (text, id, version, diagObj) {
.append('text')
.text(title)
.attr('x', LEFT_MARGIN)
.attr('font-size', '4ex')
.attr('font-size', titleFontSize)
.attr('font-weight', 'bold')
.attr('y', 25);
.attr('y', 25)
.attr('fill', titleColor)
.attr('font-family', titleFontFamily);
}

const height = box.stopy - box.starty + 2 * conf.diagramMarginY;
Expand Down
3 changes: 3 additions & 0 deletions packages/mermaid/src/docs/config/theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ The theming engine will only recognize hex colors and not color names. So, the v
| background | #f4f4f4 | Used to calculate color for items that should either be background colored or contrasting to the background |
| fontFamily | trebuchet ms, verdana, arial | |
| fontSize | 16px | Font size in pixels |
| 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. |
Copy link
Member

Choose a reason for hiding this comment

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

We can't have diagram specific variables in the main config.

Please add them to the diagram's config, which you can find in packages/mermaid/src/schemas/config.schema.yaml

Copy link
Member

Choose a reason for hiding this comment

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

Remove from this file, you removed it from the auto generated file in the previous commit. :)

| primaryColor | #fff4dd | Color to be used as background in nodes, other colors will be derived from this |
| primaryTextColor | calculated from darkMode #ddd/#333 | Color to be used as text color in nodes using `primaryColor` |
| secondaryColor | calculated from primaryColor | |
Expand Down
15 changes: 15 additions & 0 deletions packages/mermaid/src/schemas/config.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,9 @@ $defs: # JSON Schema definition (maybe we should move these to a separate file)
- bottomMarginAdj
- useMaxWidth
- rightAngles
- titleColor
- titleFontFamily
- titleFontSize
properties:
diagramMarginX:
$ref: '#/$defs/C4DiagramConfig/properties/diagramMarginX'
Expand Down Expand Up @@ -1573,6 +1576,18 @@ $defs: # JSON Schema definition (maybe we should move these to a separate file)
items:
type: string
default: ['#fff']
titleColor:
description: Calculated from textColor
type: string
default: '#00ff00'
titleFontFamily:
description: Font family to be used for the title text in Journey Diagrams
type: string
default: '"Open Sans", sans-serif'
titleFontSize:
description: Font size in pixels to be used for the title text in Journey Diagrams
type: string
default: '32px'

TimelineDiagramConfig:
# added by https://github.com/mermaid-js/mermaid/commit/0d5246fbc730bf15463d7183fe4400a1e2fc492c
Expand Down
Loading