Skip to content

Commit 1341e3d

Browse files
Added support for row odd/even in different themes
1 parent 00ca7ac commit 1341e3d

File tree

8 files changed

+54
-5
lines changed

8 files changed

+54
-5
lines changed

packages/mermaid/src/diagrams/er/erDb.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ export class ErDB implements DiagramDB {
224224
counter: count++,
225225
}),
226226
type: 'normal',
227+
curve: 'basis',
227228
start: relationship.entityA,
228229
end: relationship.entityB,
229230
label: relationship.roleA,

packages/mermaid/src/rendering-util/rendering-elements/edges.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { createText } from '../createText.js';
55
import utils from '../../utils.js';
66
import { getLineFunctionsWithOffset } from '../../utils/lineWithOffset.js';
77
import { getSubGraphTitleMargins } from '../../utils/subGraphTitleMargins.js';
8-
import { curveBasis, line, select } from 'd3';
8+
9+
import { curveBasis, curveLinear, curveCardinal, line, select } from 'd3';
910
import rough from 'roughjs';
1011
import createLabel from './createLabel.js';
1112
import { addEdgeMarkers } from './edgeMarker.ts';
@@ -472,8 +473,19 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, startNod
472473
let lineData = points.filter((p) => !Number.isNaN(p.y));
473474
lineData = fixCorners(lineData);
474475
let curve = curveBasis;
475-
if (edge.curve) {
476-
curve = edge.curve;
476+
curve = curveLinear;
477+
switch (edge.curve) {
478+
case 'linear':
479+
curve = curveLinear;
480+
break;
481+
case 'basis':
482+
curve = curveBasis;
483+
break;
484+
case 'cardinal':
485+
curve = curveCardinal;
486+
break;
487+
default:
488+
curve = curveBasis;
477489
}
478490

479491
const { x, y } = getLineFunctionsWithOffset(edge);

packages/mermaid/src/rendering-util/rendering-elements/shapes/erBox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,15 @@ export async function erBox<T extends SVGGraphicsElement>(parent: D3Selection<T>
228228
const rect = shapeSvg.insert(() => roughRect, ':first-child').attr('style', cssStyles!.join(''));
229229

230230
const { themeVariables } = getConfig();
231-
const { secondaryColor, tertiaryColor, nodeBorder } = themeVariables;
231+
const { rowEven, rowOdd, nodeBorder } = themeVariables;
232232

233233
yOffsets.push(0);
234234
// Draw row rects
235235
for (const [i, yOffset] of yOffsets.entries()) {
236236
const isEven = i % 2 === 0 && yOffset !== 0;
237237
const roughRect = rc.rectangle(x, nameBBox.height + y + yOffset, w, nameBBox.height, {
238238
...options,
239-
fill: isEven ? tertiaryColor : secondaryColor,
239+
fill: isEven ? rowEven : rowOdd,
240240
stroke: nodeBorder,
241241
});
242242
shapeSvg

packages/mermaid/src/themes/theme-base.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ class Theme {
110110
this.personBorder = this.personBorder || this.primaryBorderColor;
111111
this.personBkg = this.personBkg || this.mainBkg;
112112

113+
/* ER diagram */
114+
115+
if (this.darkMode) {
116+
this.rowOdd = this.rowOdd || darken(this.mainBkg, 5) || '#ffffff';
117+
this.rowEven = this.rowEven || darken(this.mainBkg, 10);
118+
} else {
119+
this.rowOdd = this.rowOdd || lighten(this.mainBkg, 75) || '#ffffff';
120+
this.rowEven = this.rowEven || lighten(this.mainBkg, 5);
121+
}
122+
113123
/* state colors */
114124
this.transitionColor = this.transitionColor || this.lineColor;
115125
this.transitionLabelColor = this.transitionLabelColor || this.textColor;

packages/mermaid/src/themes/theme-dark.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ class Theme {
9191
this.archGroupBorderColor = this.primaryBorderColor;
9292
this.archGroupBorderWidth = '2px';
9393

94+
/* Entity Relationship variables */
95+
this.rowOdd = this.rowOdd || lighten(this.mainBkg, 5) || '#ffffff';
96+
this.rowEven = this.rowEven || darken(this.mainBkg, 10);
97+
9498
/* state colors */
9599
this.labelColor = 'calculated';
96100

packages/mermaid/src/themes/theme-default.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ class Theme {
119119
this.archGroupBorderColor = this.primaryBorderColor;
120120
this.archGroupBorderWidth = '2px';
121121

122+
/* Entity Relationship variables */
123+
this.rowOdd = 'calculated';
124+
this.rowEven = 'calculated';
125+
122126
/* state colors */
123127
this.labelColor = 'black';
124128
this.errorBkgColor = '#552222';
@@ -205,6 +209,9 @@ class Theme {
205209
this.archEdgeColor = this.lineColor;
206210
this.archEdgeArrowColor = this.lineColor;
207211

212+
/* Entity Relationship variables */
213+
this.rowOdd = this.rowOdd || lighten(this.primaryColor, 75) || '#ffffff';
214+
this.rowEven = this.rowEven || lighten(this.primaryColor, 1);
208215
/* state colors */
209216
this.transitionColor = this.transitionColor || this.lineColor;
210217
this.transitionLabelColor = this.transitionLabelColor || this.textColor;
@@ -373,6 +380,13 @@ class Theme {
373380
/* -------------------------------------------------- */
374381
}
375382
calculate(overrides) {
383+
// for all keys in this object, if it is 'calculated' then set it to undefined
384+
Object.keys(this).forEach((k) => {
385+
if (this[k] === 'calculated') {
386+
this[k] = undefined;
387+
}
388+
});
389+
376390
if (typeof overrides !== 'object') {
377391
// Calculate colors form base colors
378392
this.updateColors();

packages/mermaid/src/themes/theme-forest.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ class Theme {
173173
this.archEdgeColor = this.lineColor;
174174
this.archEdgeArrowColor = this.lineColor;
175175

176+
/* ER diagram */
177+
this.rowOdd = this.rowOdd || lighten(this.mainBkg, 75) || '#ffffff';
178+
this.rowEven = this.rowEven || lighten(this.mainBkg, 20);
179+
176180
/* state colors */
177181
this.transitionColor = this.transitionColor || this.lineColor;
178182
this.transitionLabelColor = this.transitionLabelColor || this.textColor;

packages/mermaid/src/themes/theme-neutral.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ class Theme {
105105
this.archGroupBorderColor = this.primaryBorderColor;
106106
this.archGroupBorderWidth = '2px';
107107

108+
/* ER diagram */
109+
this.rowOdd = this.rowOdd || lighten(this.mainBkg, 75) || '#ffffff';
110+
this.rowEven = this.rowEven || '#f4f4f4';
111+
108112
/* state colors */
109113
this.labelColor = 'black';
110114

0 commit comments

Comments
 (0)