Skip to content

Commit 2fa93b8

Browse files
committed
Use regex to filter out 'none' from fill styles; improve docs
1 parent 842f756 commit 2fa93b8

File tree

3 files changed

+2
-32
lines changed

3 files changed

+2
-32
lines changed

docs/syntax/flowchart.md

-15
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,6 @@ or
18161816
##### Linear gradient examples
18171817

18181818
**1. Basic gradient**
1819-
18201819
Create a basic gradient from red to blue, flowing from top to bottom (default direction):
18211820

18221821
```mermaid-example
@@ -1848,7 +1847,6 @@ flowchart
18481847
In this example, the gradient starts with red at the top and transitions to blue at the bottom.
18491848

18501849
**2. Gradient with directional keywords**
1851-
18521850
Use directional keywords to define the gradient's direction:
18531851

18541852
```mermaid-example
@@ -1866,7 +1864,6 @@ flowchart LR
18661864
This gradient moves from the top-right corner to the bottom-left corner, starting with pink and ending with cyan.
18671865

18681866
**3. Gradient with angle**
1869-
18701867
Specify the gradient angle to control the direction:
18711868

18721869
```mermaid-example
@@ -1884,7 +1881,6 @@ flowchart BT
18841881
The gradient line is tilted at a 35-degree angle, starting with orange and transitioning to purple.
18851882

18861883
**4. Multiple color stops**
1887-
18881884
Include multiple color stops at specific positions:
18891885

18901886
```mermaid-example
@@ -1902,7 +1898,6 @@ flowchart LR
19021898
Here, the gradient starts with red at the top, transitions to yellow at 30%, green at 60%, brown at 90%, and ends with Deep Sky Blue at the bottom.
19031899

19041900
**5. Length Units for color stops**
1905-
19061901
Use length units for color stop positions (physical units like `cm` are calculated assuming _96dpi_):
19071902

19081903
```mermaid-example
@@ -1920,7 +1915,6 @@ flowchart LR
19201915
This gradient moves from left to right, using specific lengths and percentages to control where colors change.
19211916

19221917
**6. Gradients with opacity**
1923-
19241918
Apply gradients using colors with opacity:
19251919

19261920
```mermaid-example
@@ -1938,7 +1932,6 @@ flowchart TD
19381932
The gradient transitions from semi-transparent red to semi-transparent blue diagonally.
19391933

19401934
**7. Automatic positioning**
1941-
19421935
If positions for color stops are not specified, they are distributed evenly:
19431936

19441937
```mermaid-example
@@ -1956,7 +1949,6 @@ flowchart LR
19561949
In this example, the gradient begins with red from 0% to 10% (specified), transitions smoothly to green at 30%, then to orange at 50%, blue at 70%, and finally reaches cyan at 90% (specified), remaining cyan until the end, distributing the colors with missing positions evenly throughout.
19571950

19581951
**8. Overlapping positions**
1959-
19601952
If color stops have overlapping positions, Mermaid adjusts them to maintain the correct order:
19611953

19621954
```mermaid-example
@@ -1974,7 +1966,6 @@ flowchart RL
19741966
Here, since 40% comes after 60%, the white color stop at 40% is adjusted to 60% to keep positions ascending.
19751967

19761968
**9. Out-of-bounds positions**
1977-
19781969
Color stops set outside the 0% to 100% range cause the gradient to stretch beyond the edges.
19791970

19801971
```mermaid-example
@@ -1992,7 +1983,6 @@ flowchart TD
19921983
In this gradient, red at -20% blends toward yellow and appears as a red-yellow mix at 0%. Likewise, green at 145% blends with yellow near 100%, creating a yellow-green mix rather than pure green at the end. Yellow is centered because the 50% stop is explicitly defined.
19931984

19941985
**10. Sharp color transition**
1995-
19961986
Specifying two identical positions for consecutive colors creates a sharp transition:
19971987

19981988
```mermaid-example
@@ -2010,7 +2000,6 @@ flowchart LR
20102000
This results in a sharp change from red to blue exactly at the 50% mark.
20112001

20122002
**11. Double color stops**
2013-
20142003
Using double positions for a color creates a solid zone with that colors:
20152004

20162005
```mermaid-example
@@ -2042,7 +2031,6 @@ flowchart TD
20422031
In this example, the gradient transitions from yellow to red between 0% and 30%, remains solid red between 30% and 50%, and then transitions from red to blue after 50%.
20432032

20442033
**12. Color functions**
2045-
20462034
Mermaid supports CSS color functions, provided they are supported by the browser:
20472035

20482036
```mermaid-example
@@ -2058,7 +2046,6 @@ flowchart LR
20582046
```
20592047

20602048
**13. Applying gradients to different shapes**
2061-
20622049
Gradients adjust based on the node's shape and dimensions:
20632050

20642051
```mermaid-example
@@ -2087,7 +2074,6 @@ flowchart TD
20872074
Non-linear color transitions occur when using transition hints or colors with varying opacity. See the two scenarios below.
20882075

20892076
**Scenario I: interpolating between colors with color transition hint**
2090-
20912077
Transition hints are positional markers that can be placed between color stops to guide the gradient's interpolation.
20922078

20932079
```mermaid-example
@@ -2124,7 +2110,6 @@ In this gradient, the transition is from a semi-transparent red (90% opacity) to
21242110
> You are allowed to have both transition hints and opacity variations in the same gradient.
21252111
21262112
**Fine-tuning non-linear interpolation with custom transition stops**
2127-
21282113
You can specify `num-transition-stops` directly in the `style` or `classDef` to customize the number of segments that make up the gradient transition. The default is `5`, which provides a decent transition, but adjusting this number allows for finer control. This value must be odd to align with the symmetry logic used for interpolation. Here is an example:
21292114

21302115
```mermaid-example

packages/mermaid/src/diagrams/flowchart/flowRenderer-v3-unified.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const draw = async function (text: string, id: string, _version: string,
112112
);
113113

114114
// Filter out 'none' from fill styles
115-
const effectiveFillStyles = allFillStyles.filter((style) => style !== 'none');
115+
const effectiveFillStyles = allFillStyles.filter((style) => !/fill\s*:\s*none/.test(style));
116116

117117
// Layer fill styles if there’s more than one given or if any are gradients
118118
if (
@@ -124,7 +124,7 @@ export const draw = async function (text: string, id: string, _version: string,
124124
shapeElement.style('fill', 'none');
125125

126126
// Iterate over fill styles in the order they were defined
127-
allFillStyles.forEach((style, index) => {
127+
effectiveFillStyles.forEach((style, index) => {
128128
// Clone the shape element to apply each fill as an overlay
129129
const shapeClone = shapeElement.clone(true);
130130

packages/mermaid/src/docs/syntax/flowchart.md

-15
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,6 @@ A comprehensive collection of side-by-side examples comparing Mermaid and CSS li
11641164
##### Linear gradient examples
11651165

11661166
**1. Basic gradient**
1167-
11681167
Create a basic gradient from red to blue, flowing from top to bottom (default direction):
11691168

11701169
```mermaid-example
@@ -1184,7 +1183,6 @@ flowchart
11841183
In this example, the gradient starts with red at the top and transitions to blue at the bottom.
11851184

11861185
**2. Gradient with directional keywords**
1187-
11881186
Use directional keywords to define the gradient's direction:
11891187

11901188
```mermaid-example
@@ -1196,7 +1194,6 @@ flowchart LR
11961194
This gradient moves from the top-right corner to the bottom-left corner, starting with pink and ending with cyan.
11971195

11981196
**3. Gradient with angle**
1199-
12001197
Specify the gradient angle to control the direction:
12011198

12021199
```mermaid-example
@@ -1208,7 +1205,6 @@ flowchart BT
12081205
The gradient line is tilted at a 35-degree angle, starting with orange and transitioning to purple.
12091206

12101207
**4. Multiple color stops**
1211-
12121208
Include multiple color stops at specific positions:
12131209

12141210
```mermaid-example
@@ -1220,7 +1216,6 @@ flowchart LR
12201216
Here, the gradient starts with red at the top, transitions to yellow at 30%, green at 60%, brown at 90%, and ends with Deep Sky Blue at the bottom.
12211217

12221218
**5. Length Units for color stops**
1223-
12241219
Use length units for color stop positions (physical units like `cm` are calculated assuming _96dpi_):
12251220

12261221
```mermaid-example
@@ -1232,7 +1227,6 @@ flowchart LR
12321227
This gradient moves from left to right, using specific lengths and percentages to control where colors change.
12331228

12341229
**6. Gradients with opacity**
1235-
12361230
Apply gradients using colors with opacity:
12371231

12381232
```mermaid-example
@@ -1244,7 +1238,6 @@ flowchart TD
12441238
The gradient transitions from semi-transparent red to semi-transparent blue diagonally.
12451239

12461240
**7. Automatic positioning**
1247-
12481241
If positions for color stops are not specified, they are distributed evenly:
12491242

12501243
```mermaid-example
@@ -1256,7 +1249,6 @@ flowchart LR
12561249
In this example, the gradient begins with red from 0% to 10% (specified), transitions smoothly to green at 30%, then to orange at 50%, blue at 70%, and finally reaches cyan at 90% (specified), remaining cyan until the end, distributing the colors with missing positions evenly throughout.
12571250

12581251
**8. Overlapping positions**
1259-
12601252
If color stops have overlapping positions, Mermaid adjusts them to maintain the correct order:
12611253

12621254
```mermaid-example
@@ -1268,7 +1260,6 @@ flowchart RL
12681260
Here, since 40% comes after 60%, the white color stop at 40% is adjusted to 60% to keep positions ascending.
12691261

12701262
**9. Out-of-bounds positions**
1271-
12721263
Color stops set outside the 0% to 100% range cause the gradient to stretch beyond the edges.
12731264

12741265
```mermaid-example
@@ -1280,7 +1271,6 @@ flowchart TD
12801271
In this gradient, red at -20% blends toward yellow and appears as a red-yellow mix at 0%. Likewise, green at 145% blends with yellow near 100%, creating a yellow-green mix rather than pure green at the end. Yellow is centered because the 50% stop is explicitly defined.
12811272

12821273
**10. Sharp color transition**
1283-
12841274
Specifying two identical positions for consecutive colors creates a sharp transition:
12851275

12861276
```mermaid-example
@@ -1292,7 +1282,6 @@ flowchart LR
12921282
This results in a sharp change from red to blue exactly at the 50% mark.
12931283

12941284
**11. Double color stops**
1295-
12961285
Using double positions for a color creates a solid zone with that colors:
12971286

12981287
```mermaid-example
@@ -1312,7 +1301,6 @@ flowchart TD
13121301
In this example, the gradient transitions from yellow to red between 0% and 30%, remains solid red between 30% and 50%, and then transitions from red to blue after 50%.
13131302

13141303
**12. Color functions**
1315-
13161304
Mermaid supports CSS color functions, provided they are supported by the browser:
13171305

13181306
```mermaid-example
@@ -1322,7 +1310,6 @@ flowchart LR
13221310
```
13231311

13241312
**13. Applying gradients to different shapes**
1325-
13261313
Gradients adjust based on the node's shape and dimensions:
13271314

13281315
```mermaid-example
@@ -1343,7 +1330,6 @@ The gradient line length is determined by projecting a shape's dimensions along
13431330
Non-linear color transitions occur when using transition hints or colors with varying opacity. See the two scenarios below.
13441331

13451332
**Scenario I: interpolating between colors with color transition hint**
1346-
13471333
Transition hints are positional markers that can be placed between color stops to guide the gradient's interpolation.
13481334

13491335
```mermaid-example
@@ -1369,7 +1355,6 @@ You are allowed to have both transition hints and opacity variations in the same
13691355
```
13701356

13711357
**Fine-tuning non-linear interpolation with custom transition stops**
1372-
13731358
You can specify `num-transition-stops` directly in the `style` or `classDef` to customize the number of segments that make up the gradient transition. The default is `5`, which provides a decent transition, but adjusting this number allows for finer control. This value must be odd to align with the symmetry logic used for interpolation. Here is an example:
13741359

13751360
```mermaid-example

0 commit comments

Comments
 (0)