mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-01 14:46:41 +02:00
Add fix for edge markers showing under node if handDrawn
This commit is contained in:
@@ -56,9 +56,12 @@
|
|||||||
config:
|
config:
|
||||||
htmlLabels: false
|
htmlLabels: false
|
||||||
layout: elk
|
layout: elk
|
||||||
|
look: handDrawn
|
||||||
|
theme: forest
|
||||||
---
|
---
|
||||||
erDiagram
|
erDiagram
|
||||||
"hi" }o..o{ ORDER : places
|
"hi" }o..o{ ORDER : places
|
||||||
|
style hi fill:lightblue
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
<div class="test">
|
<div class="test">
|
||||||
@@ -67,7 +70,8 @@
|
|||||||
---
|
---
|
||||||
config:
|
config:
|
||||||
htmlLabels: false
|
htmlLabels: false
|
||||||
look:
|
look: handDrawn
|
||||||
|
layout: elk
|
||||||
---
|
---
|
||||||
erDiagram
|
erDiagram
|
||||||
CAR ||--|{ NAMED-DRIVER : allows
|
CAR ||--|{ NAMED-DRIVER : allows
|
||||||
@@ -80,6 +84,8 @@
|
|||||||
---
|
---
|
||||||
config:
|
config:
|
||||||
htmlLabels: true
|
htmlLabels: true
|
||||||
|
look: handDrawn
|
||||||
|
theme: forest
|
||||||
---
|
---
|
||||||
erDiagram
|
erDiagram
|
||||||
CAR ||--o{ NAMED-DRIVER : allows
|
CAR ||--o{ NAMED-DRIVER : allows
|
||||||
|
@@ -6,6 +6,7 @@ import { setupViewPortForSVG } from '../../rendering-util/setupViewPortForSVG.js
|
|||||||
import type { LayoutData } from '../../rendering-util/types.js';
|
import type { LayoutData } from '../../rendering-util/types.js';
|
||||||
import { getDirection } from './erDb.js';
|
import { getDirection } from './erDb.js';
|
||||||
import utils from '../../utils.js';
|
import utils from '../../utils.js';
|
||||||
|
import { select } from 'd3';
|
||||||
|
|
||||||
export const draw = async function (text: string, id: string, _version: string, diag: any) {
|
export const draw = async function (text: string, id: string, _version: string, diag: any) {
|
||||||
log.info('REF0:');
|
log.info('REF0:');
|
||||||
@@ -34,6 +35,26 @@ export const draw = async function (text: string, id: string, _version: string,
|
|||||||
if (data4Layout.layoutAlgorithm === 'elk') {
|
if (data4Layout.layoutAlgorithm === 'elk') {
|
||||||
svg.select('.edges').lower();
|
svg.select('.edges').lower();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sets the background nodes to the same position as their original counterparts.
|
||||||
|
// Background nodes are created when the look is handDrawn so the ER diagram markers do not show underneath.
|
||||||
|
const backgroundNodes = svg.selectAll('[id*="-background"]');
|
||||||
|
// eslint-disable-next-line unicorn/prefer-spread
|
||||||
|
if (Array.from(backgroundNodes).length > 0) {
|
||||||
|
backgroundNodes.each(function (this: SVGElement) {
|
||||||
|
const backgroundNode = select(this);
|
||||||
|
const backgroundId = backgroundNode.attr('id');
|
||||||
|
|
||||||
|
const nonBackgroundId = backgroundId.replace('-background', '');
|
||||||
|
const nonBackgroundNode = svg.select(`#${CSS.escape(nonBackgroundId)}`);
|
||||||
|
|
||||||
|
if (!nonBackgroundNode.empty()) {
|
||||||
|
const transform = nonBackgroundNode.attr('transform');
|
||||||
|
backgroundNode.attr('transform', transform);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const padding = 8;
|
const padding = 8;
|
||||||
utils.insertTitle(
|
utils.insertTitle(
|
||||||
svg,
|
svg,
|
||||||
|
@@ -18,6 +18,21 @@ export const erBox = async (parent: SVGAElement, node: Node) => {
|
|||||||
if (entityNode.alias) {
|
if (entityNode.alias) {
|
||||||
node.label = entityNode.alias;
|
node.label = entityNode.alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Background shapes are drawn to fill in the background color and cover up the ER diagram edge markers.
|
||||||
|
// Draw background shape once.
|
||||||
|
if (node.look === 'handDrawn') {
|
||||||
|
const { themeVariables } = getConfig();
|
||||||
|
const { background } = themeVariables;
|
||||||
|
const backgroundNode = {
|
||||||
|
...node,
|
||||||
|
id: node.id + '-background',
|
||||||
|
look: 'default',
|
||||||
|
cssStyles: ['stroke: none', `fill: ${background}`],
|
||||||
|
};
|
||||||
|
await erBox(parent, backgroundNode);
|
||||||
|
}
|
||||||
|
|
||||||
const config = getConfig();
|
const config = getConfig();
|
||||||
node.useHtmlLabels = config.htmlLabels;
|
node.useHtmlLabels = config.htmlLabels;
|
||||||
let PADDING = config.er?.diagramPadding ?? 10;
|
let PADDING = config.er?.diagramPadding ?? 10;
|
||||||
@@ -62,8 +77,6 @@ export const erBox = async (parent: SVGAElement, node: Node) => {
|
|||||||
.attr('class', cssClasses)
|
.attr('class', cssClasses)
|
||||||
.attr('id', node.domId || node.id);
|
.attr('id', node.domId || node.id);
|
||||||
|
|
||||||
// TODO: Make padding better
|
|
||||||
|
|
||||||
const nameBBox = await addText(shapeSvg, node.label ?? '', config, 0, 0, ['name'], labelStyles);
|
const nameBBox = await addText(shapeSvg, node.label ?? '', config, 0, 0, ['name'], labelStyles);
|
||||||
nameBBox.height += TEXT_PADDING;
|
nameBBox.height += TEXT_PADDING;
|
||||||
let yOffset = 0;
|
let yOffset = 0;
|
||||||
@@ -203,7 +216,7 @@ export const erBox = async (parent: SVGAElement, node: Node) => {
|
|||||||
.select('.name')
|
.select('.name')
|
||||||
.attr('transform', 'translate(' + -nameBBox.width / 2 + ', ' + (y + TEXT_PADDING / 2) + ')');
|
.attr('transform', 'translate(' + -nameBBox.width / 2 + ', ' + (y + TEXT_PADDING / 2) + ')');
|
||||||
|
|
||||||
// Draw rect
|
// Draw shape
|
||||||
const roughRect = rc.rectangle(x, y, w, h, options);
|
const roughRect = rc.rectangle(x, y, w, h, options);
|
||||||
const rect = shapeSvg.insert(() => roughRect, ':first-child').attr('style', cssStyles);
|
const rect = shapeSvg.insert(() => roughRect, ':first-child').attr('style', cssStyles);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user