mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-22 01:36:43 +02:00
Added support for row odd/even in different themes
This commit is contained in:
@@ -224,6 +224,7 @@ export class ErDB implements DiagramDB {
|
|||||||
counter: count++,
|
counter: count++,
|
||||||
}),
|
}),
|
||||||
type: 'normal',
|
type: 'normal',
|
||||||
|
curve: 'basis',
|
||||||
start: relationship.entityA,
|
start: relationship.entityA,
|
||||||
end: relationship.entityB,
|
end: relationship.entityB,
|
||||||
label: relationship.roleA,
|
label: relationship.roleA,
|
||||||
|
@@ -5,7 +5,8 @@ import { createText } from '../createText.js';
|
|||||||
import utils from '../../utils.js';
|
import utils from '../../utils.js';
|
||||||
import { getLineFunctionsWithOffset } from '../../utils/lineWithOffset.js';
|
import { getLineFunctionsWithOffset } from '../../utils/lineWithOffset.js';
|
||||||
import { getSubGraphTitleMargins } from '../../utils/subGraphTitleMargins.js';
|
import { getSubGraphTitleMargins } from '../../utils/subGraphTitleMargins.js';
|
||||||
import { curveBasis, line, select } from 'd3';
|
|
||||||
|
import { curveBasis, curveLinear, curveCardinal, line, select } from 'd3';
|
||||||
import rough from 'roughjs';
|
import rough from 'roughjs';
|
||||||
import createLabel from './createLabel.js';
|
import createLabel from './createLabel.js';
|
||||||
import { addEdgeMarkers } from './edgeMarker.ts';
|
import { addEdgeMarkers } from './edgeMarker.ts';
|
||||||
@@ -472,8 +473,19 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, startNod
|
|||||||
let lineData = points.filter((p) => !Number.isNaN(p.y));
|
let lineData = points.filter((p) => !Number.isNaN(p.y));
|
||||||
lineData = fixCorners(lineData);
|
lineData = fixCorners(lineData);
|
||||||
let curve = curveBasis;
|
let curve = curveBasis;
|
||||||
if (edge.curve) {
|
curve = curveLinear;
|
||||||
curve = edge.curve;
|
switch (edge.curve) {
|
||||||
|
case 'linear':
|
||||||
|
curve = curveLinear;
|
||||||
|
break;
|
||||||
|
case 'basis':
|
||||||
|
curve = curveBasis;
|
||||||
|
break;
|
||||||
|
case 'cardinal':
|
||||||
|
curve = curveCardinal;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
curve = curveBasis;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { x, y } = getLineFunctionsWithOffset(edge);
|
const { x, y } = getLineFunctionsWithOffset(edge);
|
||||||
|
@@ -228,7 +228,7 @@ export async function erBox<T extends SVGGraphicsElement>(parent: D3Selection<T>
|
|||||||
const rect = shapeSvg.insert(() => roughRect, ':first-child').attr('style', cssStyles!.join(''));
|
const rect = shapeSvg.insert(() => roughRect, ':first-child').attr('style', cssStyles!.join(''));
|
||||||
|
|
||||||
const { themeVariables } = getConfig();
|
const { themeVariables } = getConfig();
|
||||||
const { secondaryColor, tertiaryColor, nodeBorder } = themeVariables;
|
const { rowEven, rowOdd, nodeBorder } = themeVariables;
|
||||||
|
|
||||||
yOffsets.push(0);
|
yOffsets.push(0);
|
||||||
// Draw row rects
|
// Draw row rects
|
||||||
@@ -236,7 +236,7 @@ export async function erBox<T extends SVGGraphicsElement>(parent: D3Selection<T>
|
|||||||
const isEven = i % 2 === 0 && yOffset !== 0;
|
const isEven = i % 2 === 0 && yOffset !== 0;
|
||||||
const roughRect = rc.rectangle(x, nameBBox.height + y + yOffset, w, nameBBox.height, {
|
const roughRect = rc.rectangle(x, nameBBox.height + y + yOffset, w, nameBBox.height, {
|
||||||
...options,
|
...options,
|
||||||
fill: isEven ? tertiaryColor : secondaryColor,
|
fill: isEven ? rowEven : rowOdd,
|
||||||
stroke: nodeBorder,
|
stroke: nodeBorder,
|
||||||
});
|
});
|
||||||
shapeSvg
|
shapeSvg
|
||||||
|
@@ -110,6 +110,16 @@ class Theme {
|
|||||||
this.personBorder = this.personBorder || this.primaryBorderColor;
|
this.personBorder = this.personBorder || this.primaryBorderColor;
|
||||||
this.personBkg = this.personBkg || this.mainBkg;
|
this.personBkg = this.personBkg || this.mainBkg;
|
||||||
|
|
||||||
|
/* ER diagram */
|
||||||
|
|
||||||
|
if (this.darkMode) {
|
||||||
|
this.rowOdd = this.rowOdd || darken(this.mainBkg, 5) || '#ffffff';
|
||||||
|
this.rowEven = this.rowEven || darken(this.mainBkg, 10);
|
||||||
|
} else {
|
||||||
|
this.rowOdd = this.rowOdd || lighten(this.mainBkg, 75) || '#ffffff';
|
||||||
|
this.rowEven = this.rowEven || lighten(this.mainBkg, 5);
|
||||||
|
}
|
||||||
|
|
||||||
/* state colors */
|
/* state colors */
|
||||||
this.transitionColor = this.transitionColor || this.lineColor;
|
this.transitionColor = this.transitionColor || this.lineColor;
|
||||||
this.transitionLabelColor = this.transitionLabelColor || this.textColor;
|
this.transitionLabelColor = this.transitionLabelColor || this.textColor;
|
||||||
|
@@ -91,6 +91,10 @@ class Theme {
|
|||||||
this.archGroupBorderColor = this.primaryBorderColor;
|
this.archGroupBorderColor = this.primaryBorderColor;
|
||||||
this.archGroupBorderWidth = '2px';
|
this.archGroupBorderWidth = '2px';
|
||||||
|
|
||||||
|
/* Entity Relationship variables */
|
||||||
|
this.rowOdd = this.rowOdd || lighten(this.mainBkg, 5) || '#ffffff';
|
||||||
|
this.rowEven = this.rowEven || darken(this.mainBkg, 10);
|
||||||
|
|
||||||
/* state colors */
|
/* state colors */
|
||||||
this.labelColor = 'calculated';
|
this.labelColor = 'calculated';
|
||||||
|
|
||||||
|
@@ -119,6 +119,10 @@ class Theme {
|
|||||||
this.archGroupBorderColor = this.primaryBorderColor;
|
this.archGroupBorderColor = this.primaryBorderColor;
|
||||||
this.archGroupBorderWidth = '2px';
|
this.archGroupBorderWidth = '2px';
|
||||||
|
|
||||||
|
/* Entity Relationship variables */
|
||||||
|
this.rowOdd = 'calculated';
|
||||||
|
this.rowEven = 'calculated';
|
||||||
|
|
||||||
/* state colors */
|
/* state colors */
|
||||||
this.labelColor = 'black';
|
this.labelColor = 'black';
|
||||||
this.errorBkgColor = '#552222';
|
this.errorBkgColor = '#552222';
|
||||||
@@ -205,6 +209,9 @@ class Theme {
|
|||||||
this.archEdgeColor = this.lineColor;
|
this.archEdgeColor = this.lineColor;
|
||||||
this.archEdgeArrowColor = this.lineColor;
|
this.archEdgeArrowColor = this.lineColor;
|
||||||
|
|
||||||
|
/* Entity Relationship variables */
|
||||||
|
this.rowOdd = this.rowOdd || lighten(this.primaryColor, 75) || '#ffffff';
|
||||||
|
this.rowEven = this.rowEven || lighten(this.primaryColor, 1);
|
||||||
/* state colors */
|
/* state colors */
|
||||||
this.transitionColor = this.transitionColor || this.lineColor;
|
this.transitionColor = this.transitionColor || this.lineColor;
|
||||||
this.transitionLabelColor = this.transitionLabelColor || this.textColor;
|
this.transitionLabelColor = this.transitionLabelColor || this.textColor;
|
||||||
@@ -373,6 +380,13 @@ class Theme {
|
|||||||
/* -------------------------------------------------- */
|
/* -------------------------------------------------- */
|
||||||
}
|
}
|
||||||
calculate(overrides) {
|
calculate(overrides) {
|
||||||
|
// for all keys in this object, if it is 'calculated' then set it to undefined
|
||||||
|
Object.keys(this).forEach((k) => {
|
||||||
|
if (this[k] === 'calculated') {
|
||||||
|
this[k] = undefined;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (typeof overrides !== 'object') {
|
if (typeof overrides !== 'object') {
|
||||||
// Calculate colors form base colors
|
// Calculate colors form base colors
|
||||||
this.updateColors();
|
this.updateColors();
|
||||||
|
@@ -173,6 +173,10 @@ class Theme {
|
|||||||
this.archEdgeColor = this.lineColor;
|
this.archEdgeColor = this.lineColor;
|
||||||
this.archEdgeArrowColor = this.lineColor;
|
this.archEdgeArrowColor = this.lineColor;
|
||||||
|
|
||||||
|
/* ER diagram */
|
||||||
|
this.rowOdd = this.rowOdd || lighten(this.mainBkg, 75) || '#ffffff';
|
||||||
|
this.rowEven = this.rowEven || lighten(this.mainBkg, 20);
|
||||||
|
|
||||||
/* state colors */
|
/* state colors */
|
||||||
this.transitionColor = this.transitionColor || this.lineColor;
|
this.transitionColor = this.transitionColor || this.lineColor;
|
||||||
this.transitionLabelColor = this.transitionLabelColor || this.textColor;
|
this.transitionLabelColor = this.transitionLabelColor || this.textColor;
|
||||||
|
@@ -105,6 +105,10 @@ class Theme {
|
|||||||
this.archGroupBorderColor = this.primaryBorderColor;
|
this.archGroupBorderColor = this.primaryBorderColor;
|
||||||
this.archGroupBorderWidth = '2px';
|
this.archGroupBorderWidth = '2px';
|
||||||
|
|
||||||
|
/* ER diagram */
|
||||||
|
this.rowOdd = this.rowOdd || lighten(this.mainBkg, 75) || '#ffffff';
|
||||||
|
this.rowEven = this.rowEven || '#f4f4f4';
|
||||||
|
|
||||||
/* state colors */
|
/* state colors */
|
||||||
this.labelColor = 'black';
|
this.labelColor = 'black';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user