Skip to content

Commit

Permalink
Fix fill style detection to ensure cypress ci tests pass; limit regex…
Browse files Browse the repository at this point in the history
… search for transition stops to necessary cases
  • Loading branch information
enourbakhsh committed Nov 13, 2024
1 parent 79c07dc commit 616dcd5
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions packages/mermaid/src/diagrams/flowchart/flowRenderer-v3-unified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const draw = async function (text: string, id: string, _version: string,
log.debug(`Working on node ${vertex.id}->${vertex.domId}`);

// Combine style arrays, defaulting to empty arrays if missing
// Note that `cssCompiledStyles` (from `classDef`) apply first, with `cssStyles` (from `style`)
// Note that `cssCompiledStyles` (from `classDef`) applies first, with `cssStyles` (from `style`)
// rendered on top, allowing layered effects like multiple semi-transparent backgrounds
const styles = [...(vertex.cssCompiledStyles || []), ...(vertex.cssStyles || [])];

Expand All @@ -111,18 +111,7 @@ export const draw = async function (text: string, id: string, _version: string,
[]
);

// Get the user-defined number of transition stops (first match) for non-linear interpolation
const regex = /num-transition-stops\s*:\s*(\d+)/;
const numTransitionStops = parseInt(
styles.find((s) => regex.exec(s))?.match(regex)?.[1] || '5',
10
);

if (allFillStyles) {
// Remove any existing or default fill (e.g. from the theme) that might unexpectedly
// bleed through (semi-)transparent areas of the fills
shapeElement.style('fill', 'none');

if (allFillStyles.length != 0) {
// Iterate over each fill style in the order it appears
allFillStyles.forEach((style, index) => {
// Clone the shape element to apply each fill as an overlay
Expand All @@ -134,6 +123,13 @@ export const draw = async function (text: string, id: string, _version: string,
const gradientId = `gradient-${vertex.id}-${index}`;
log.debug(`Found gradient style ${index + 1} for node ${vertex.id}: "${style}"`);

// Get the user-defined number of transition stops (first match) for non-linear interpolation
const transitionRegex = /num-transition-stops\s*:\s*(\d+)/;
const numTransitionStops = parseInt(
styles.find((s) => transitionRegex.exec(s))?.match(transitionRegex)?.[1] || '5',
10
);

// Create the linear gradient for each occurrence
createLinearGradient(
svg,
Expand All @@ -144,6 +140,10 @@ export const draw = async function (text: string, id: string, _version: string,
numTransitionStops
);

// Remove any existing or default fill (e.g. from the theme) that might unexpectedly
// bleed through (semi-)transparent areas of the gradient
shapeElement.style('fill', 'none');

// Apply the gradient fill to the cloned shape
shapeClone.style('fill', `url(#${gradientId})`);
log.debug(
Expand Down

0 comments on commit 616dcd5

Please sign in to comment.