Replaced hard-coded node.look by checking diagram config and cleanup styling a bit

This commit is contained in:
Per Brolin
2024-06-07 15:14:26 +02:00
parent 544d17db95
commit 51da34b831
10 changed files with 42 additions and 23 deletions

View File

@@ -68,7 +68,7 @@ export interface MermaidConfig {
* Defines which main look to use for the diagram. * Defines which main look to use for the diagram.
* *
*/ */
look?: 'classic' | 'handdrawn' | 'slick'; look?: 'classic' | 'handdrawn' | 'slick' | 'neo';
/** /**
* Defines the seed to be used when using handdrawn look. This is important for the automated tests as they will always find differences without the seed. The default value is 0 which gives a random seed. * Defines the seed to be used when using handdrawn look. This is important for the automated tests as they will always find differences without the seed. The default value is 0 which gives a random seed.
* *

View File

@@ -29,6 +29,7 @@ const arrowTypesMap = {
arrow_cross: 'cross', arrow_cross: 'cross',
arrow_point: 'point', arrow_point: 'point',
arrow_barb: 'barb', arrow_barb: 'barb',
arrow_neo: 'barbNeo',
arrow_circle: 'circle', arrow_circle: 'circle',
aggregation: 'aggregation', aggregation: 'aggregation',
extension: 'extension', extension: 'extension',

View File

@@ -79,7 +79,12 @@ export const draw = async function (
data4Layout.nodeSpacing = conf?.nodeSpacing || 50; data4Layout.nodeSpacing = conf?.nodeSpacing || 50;
// @ts-expect-error TODO: Will be fixed after config refactor // @ts-expect-error TODO: Will be fixed after config refactor
data4Layout.rankSpacing = conf?.rankSpacing || 50; data4Layout.rankSpacing = conf?.rankSpacing || 50;
data4Layout.markers = ['barb']; const config = getConfig();
if (config.look === 'neo') {
data4Layout.markers = ['barbNeo'];
} else {
data4Layout.markers = ['barb'];
}
data4Layout.diagramId = id; data4Layout.diagramId = id;
// console.log('REF1:', data4Layout); // console.log('REF1:', data4Layout);
await render(data4Layout, svg, element, positions); await render(data4Layout, svg, element, positions);

View File

@@ -129,7 +129,6 @@ g.stateGroup line {
.statediagram-cluster rect.outer { .statediagram-cluster rect.outer {
rx: 2px; rx: 2px;
ry: 2px; ry: 2px;
filter: drop-shadow( 1px 2px 2px rgba(185,185,185,1.0) );
} }
.statediagram-state .divider { .statediagram-state .divider {
stroke: ${options.stateBorder || options.nodeBorder}; stroke: ${options.stateBorder || options.nodeBorder};

View File

@@ -187,7 +187,7 @@ const roundedWithTitle = (parent, node) => {
const innerY = node.y - node.height / 2 - halfPadding + bbox.height - 1; const innerY = node.y - node.height / 2 - halfPadding + bbox.height - 1;
const height = node.height + padding; const height = node.height + padding;
const innerHeight = node.height + padding - bbox.height - 3; const innerHeight = node.height + padding - bbox.height - 3;
const look = siteConfig.look;
// add the rect // add the rect
let rect; let rect;
if (node.useRough) { if (node.useRough) {
@@ -216,9 +216,15 @@ const roundedWithTitle = (parent, node) => {
innerRect = shapeSvg.insert(() => roughInnerNode); innerRect = shapeSvg.insert(() => roughInnerNode);
} else { } else {
rect = outerRectG.insert('rect', ':first-child'); rect = outerRectG.insert('rect', ':first-child');
let outerRectClass = 'outer';
if (look === 'neo') {
outerRectClass = 'outer state-shadow';
} else {
outerRectClass = 'outer';
}
// center the rect around its coordinate // center the rect around its coordinate
rect rect
.attr('class', 'outer') .attr('class', outerRectClass)
.attr('x', x) .attr('x', x)
.attr('y', y) .attr('y', y)
.attr('width', width) .attr('width', width)

View File

@@ -263,21 +263,21 @@ const cross = (elem, type, id) => {
.style('stroke-width', 2) .style('stroke-width', 2)
.style('stroke-dasharray', '1,0'); .style('stroke-dasharray', '1,0');
}; };
// const barb = (elem, type, id) => {
// elem
// .append('defs')
// .append('marker')
// .attr('id', id + '_' + type + '-barbEnd')
// .attr('refX', 19)
// .attr('refY', 7)
// .attr('markerWidth', 20)
// .attr('markerHeight', 14)
// .attr('markerUnits', 'strokeWidth')
// .attr('orient', 'auto')
// .append('path')
// .attr('d', 'M 19,7 L9,13 L14,7 L9,1 Z');
// };
const barb = (elem, type, id) => { const barb = (elem, type, id) => {
elem
.append('defs')
.append('marker')
.attr('id', id + '_' + type + '-barbEnd')
.attr('refX', 19)
.attr('refY', 7)
.attr('markerWidth', 20)
.attr('markerHeight', 14)
.attr('markerUnits', 'strokeWidth')
.attr('orient', 'auto')
.append('path')
.attr('d', 'M 19,7 L9,13 L14,7 L9,1 Z');
};
const barbNeo = (elem, type, id) => {
elem elem
.append('defs') .append('defs')
.append('marker') .append('marker')
@@ -303,5 +303,6 @@ const markers = {
circle, circle,
cross, cross,
barb, barb,
barbNeo,
}; };
export default insertMarkers; export default insertMarkers;

View File

@@ -1,4 +1,3 @@
import { log } from '$root/logger.js';
import { labelHelper, updateNodeBounds, getNodeClasses } from './util.js'; import { labelHelper, updateNodeBounds, getNodeClasses } from './util.js';
import intersect from '../intersect/index.js'; import intersect from '../intersect/index.js';
import type { Node, RectOptions } from '$root/rendering-util/types.d.ts'; import type { Node, RectOptions } from '$root/rendering-util/types.d.ts';
@@ -8,7 +7,7 @@ import rough from 'roughjs';
import { getConfig } from '$root/diagram-api/diagramAPI.js'; import { getConfig } from '$root/diagram-api/diagramAPI.js';
export const drawRect = async (parent: SVGAElement, node: Node, options: RectOptions) => { export const drawRect = async (parent: SVGAElement, node: Node, options: RectOptions) => {
const { themeVariables, handdrawnSeed } = getConfig(); const { themeVariables, handdrawnSeed, look } = getConfig();
const { nodeBorder, mainBkg } = themeVariables; const { nodeBorder, mainBkg } = themeVariables;
const { shapeSvg, bbox, halfPadding } = await labelHelper( const { shapeSvg, bbox, halfPadding } = await labelHelper(
@@ -24,6 +23,7 @@ export const drawRect = async (parent: SVGAElement, node: Node, options: RectOpt
const y = -totalHeight / 2; const y = -totalHeight / 2;
let rect; let rect;
node.look = look;
let { rx, ry } = node; let { rx, ry } = node;
const { cssStyles, useRough } = node; const { cssStyles, useRough } = node;

View File

@@ -1,8 +1,10 @@
import type { Node, RectOptions } from '$root/rendering-util/types.d.ts'; import type { Node, RectOptions } from '$root/rendering-util/types.d.ts';
import { drawRect } from './drawRect.js'; import { drawRect } from './drawRect.js';
import { getConfig } from '$root/diagram-api/diagramAPI.js';
export const roundedRect = async (parent: SVGAElement, node: Node) => { export const roundedRect = async (parent: SVGAElement, node: Node) => {
node.look = 'neo'; const { look } = getConfig();
node.look = look;
const options = { const options = {
rx: node.look === 'neo' ? 1 : 1, rx: node.look === 'neo' ? 1 : 1,
ry: node.look === 'neo' ? 1 : 1, ry: node.look === 'neo' ? 1 : 1,

View File

@@ -1,8 +1,10 @@
import type { Node } from '$root/rendering-util/types.d.ts'; import type { Node } from '$root/rendering-util/types.d.ts';
import { drawRect } from './drawRect.js'; import { drawRect } from './drawRect.js';
import { getConfig } from '$root/diagram-api/diagramAPI.js';
export const state = async (parent: SVGAElement, node: Node) => { export const state = async (parent: SVGAElement, node: Node) => {
node.look = 'neo'; const { look } = getConfig();
node.look = look;
const options = { const options = {
rx: node.look === 'neo' ? 2 : 5, rx: node.look === 'neo' ? 2 : 5,

View File

@@ -61,6 +61,9 @@ interface Node {
// Flowchart specific properties // Flowchart specific properties
x?: number; x?: number;
y?: number; y?: number;
// Added look to handle
look?: string;
} }
// Common properties for any edge in the system // Common properties for any edge in the system