#5237 Fix of alignment issues

This commit is contained in:
Knut Sveidqvist 2024-06-25 13:20:05 +02:00
parent 881a68241c
commit c221350d59
6 changed files with 7953 additions and 10036 deletions

View File

@ -1,7 +1,7 @@
// @ts-ignore: JISON doesn't support types // @ts-ignore: JISON doesn't support types
import flowParser from './parser/flow.jison'; import flowParser from './parser/flow.jison';
import flowDb from './flowDb.js'; import flowDb from './flowDb.js';
import flowRendererV2 from './flowRenderer-v2.js'; //import flowRendererV2 from './flowRenderer-v2.js';
import flowRendererV3 from './flowRenderer-v3-unified.js'; import flowRendererV3 from './flowRenderer-v3-unified.js';
import flowStyles from './styles.js'; import flowStyles from './styles.js';
import type { MermaidConfig } from '../../config.type.js'; import type { MermaidConfig } from '../../config.type.js';

View File

@ -72,6 +72,16 @@ const recursiveRender = async (_elem, graph, diagramType, id, parentCluster, sit
if (node && node.clusterNode) { if (node && node.clusterNode) {
// const children = graph.children(v); // const children = graph.children(v);
log.info('Cluster identified XBX', v, node.width, graph.node(v)); log.info('Cluster identified XBX', v, node.width, graph.node(v));
// `node.graph.setGraph` applies the graph configurations such as nodeSpacing to subgraphs as without this the default values would be used
// We override only the `ranksep` and `nodesep` configurations to allow for setting subgraph spacing while avoiding overriding other properties
const { ranksep, nodesep } = graph.graph();
node.graph.setGraph({
...node.graph.graph(),
ranksep: 75,
nodesep,
});
// "o" will contain the full cluster not just the children // "o" will contain the full cluster not just the children
const o = await recursiveRender( const o = await recursiveRender(
nodes, nodes,
@ -83,6 +93,7 @@ const recursiveRender = async (_elem, graph, diagramType, id, parentCluster, sit
); );
const newEl = o.elem; const newEl = o.elem;
updateNodeBounds(node, newEl); updateNodeBounds(node, newEl);
// node.height = o.diff;
node.diff = o.diff || 0; node.diff = o.diff || 0;
log.info( log.info(
'New compound node after recursive render XAX', 'New compound node after recursive render XAX',
@ -190,14 +201,13 @@ const recursiveRender = async (_elem, graph, diagramType, id, parentCluster, sit
log.info('Graph after layout:', graphlibJson.write(graph)); log.info('Graph after layout:', graphlibJson.write(graph));
// Move the nodes to the correct place // Move the nodes to the correct place
let diff = 0; let diff = 0;
log.info('Need the size here XAX', graph.node('T1')?.height);
let { subGraphTitleTotalMargin } = getSubGraphTitleMargins(siteConfig); let { subGraphTitleTotalMargin } = getSubGraphTitleMargins(siteConfig);
subGraphTitleTotalMargin = 0; // subGraphTitleTotalMargin = 0;
await Promise.all( await Promise.all(
sortNodesByHierarchy(graph).map(async function (v) { sortNodesByHierarchy(graph).map(async function (v) {
const node = graph.node(v); const node = graph.node(v);
const p = graph.node(node?.parentId); const p = graph.node(node?.parentId);
subGraphTitleTotalMargin = p?.offsetY || subGraphTitleTotalMargin; // subGraphTitleTotalMargin = p?.offsetY || subGraphTitleTotalMargin;
log.info( log.info(
'Position XBX => ' + v + ': (' + node.x, 'Position XBX => ' + v + ': (' + node.x,
@ -210,8 +220,9 @@ const recursiveRender = async (_elem, graph, diagramType, id, parentCluster, sit
if (node && node.clusterNode) { if (node && node.clusterNode) {
const parentId = graph.parent(v); const parentId = graph.parent(v);
// Adjust for padding when on root level // Adjust for padding when on root level
node.y = parentId ? node.y - 8 : node.y - 8; node.y += subGraphTitleTotalMargin;
node.x -= 8; // node.y = parentId ? node.y - 8 : node.y - 8;
// node.x -= 8;
log.info( log.info(
'A tainted cluster node XBX1', 'A tainted cluster node XBX1',
@ -225,7 +236,7 @@ const recursiveRender = async (_elem, graph, diagramType, id, parentCluster, sit
); );
clusterDb[node.id].node = node; clusterDb[node.id].node = node;
// node.y += subGraphTitleTotalMargin - 10; // node.y += subGraphTitleTotalMargin - 10;
node.y -= (node.offsetY || 0) / 2; // node.y -= (node.offsetY || 0) / 2;
// node.y -= 10; // node.y -= 10;
positionNode(node); positionNode(node);
} else { } else {

View File

@ -213,9 +213,9 @@ const roundedWithTitle = async (parent, node) => {
const width = const width =
(node.width <= bbox.width + node.padding ? bbox.width + node.padding : node.width) + padding; (node.width <= bbox.width + node.padding ? bbox.width + node.padding : node.width) + padding;
if (node.width <= bbox.width + node.padding) { if (node.width <= bbox.width + node.padding) {
node.diff = (bbox.width + node.padding * 0 - node.width) / 2; node.diff = (width - node.width) / 2 - node.padding;
} else { } else {
node.diff = -node.padding / 2; node.diff = -node.padding;
} }
// if (node.id === 'Apa0') { // if (node.id === 'Apa0') {
@ -224,11 +224,13 @@ const roundedWithTitle = async (parent, node) => {
// } else { // } else {
// console.log('XBX there', node); // console.log('XBX there', node);
// } // }
const x = node.x - width / 2 - halfPadding;
const y = node.y - node.height / 2 - halfPadding;
const innerY = node.y - node.height / 2 - halfPadding + bbox.height + 2;
const height = node.height + padding; const height = node.height + padding;
// const height = node.height + padding;
const innerHeight = node.height + padding - bbox.height - 6; const innerHeight = node.height + padding - bbox.height - 6;
const x = node.x - width / 2;
const y = node.y - height / 2;
const innerY = node.y - node.height / 2 - halfPadding + bbox.height + 2;
const look = siteConfig.look; const look = siteConfig.look;
// add the rect // add the rect
@ -272,7 +274,7 @@ const roundedWithTitle = async (parent, node) => {
.attr('x', x) .attr('x', x)
.attr('y', y) .attr('y', y)
.attr('width', width) .attr('width', width)
.attr('height', node.height + padding); .attr('height', height);
innerRect innerRect
.attr('class', 'inner') .attr('class', 'inner')
.attr('x', x) .attr('x', x)
@ -311,8 +313,8 @@ const divider = (parent, node) => {
const padding = 0 * node.padding; const padding = 0 * node.padding;
const halfPadding = padding / 2; const halfPadding = padding / 2;
const x = node.x - node.width / 2 - halfPadding; const x = node.x - node.width / 2 - node.padding;
const y = node.y - node.height / 2; const y = node.y - node.height / 2 + node.padding;
const width = node.width + padding; const width = node.width + padding;
const height = node.height + padding; const height = node.height + padding;
if (node.look === 'handdrawn') { if (node.look === 'handdrawn') {

View File

@ -101,20 +101,22 @@ export const clear = () => {
export const positionNode = (node) => { export const positionNode = (node) => {
const el = nodeElems[node.id]; const el = nodeElems[node.id];
log.trace(
log.debug( 'Transforming node',
'Position node',
node.id,
node.diff, node.diff,
node, node,
'translate(' + (node.x - node.width / 2 - 5) + ', ' + node.width / 2 + ')' 'translate(' + (node.x - node.width / 2 - 5) + ', ' + node.width / 2 + ')'
); );
// Handling of the case where teh label grows the cluster const padding = 8;
const diff = node.diff || 0; const diff = node.diff || 0;
if (node.clusterNode) { if (node.clusterNode) {
el.attr( el.attr(
'transform', 'transform',
'translate(' + (node.x - node.width / 2) + ', ' + (node.y - node.height / 2) + ')' 'translate(' +
(node.x + diff - node.width / 2) +
', ' +
(node.y - node.height / 2 - padding) +
')'
); );
} else { } else {
el.attr('transform', 'translate(' + node.x + ', ' + node.y + ')'); el.attr('transform', 'translate(' + node.x + ', ' + node.y + ')');

View File

@ -44,7 +44,6 @@ interface Node {
height?: number; height?: number;
// Specific properties for State Diagram nodes TODO remove and use generic properties // Specific properties for State Diagram nodes TODO remove and use generic properties
intersect?: (point: any) => any; intersect?: (point: any) => any;
intersect2?: (node: Node, point: any) => any;
// Non-generic properties // Non-generic properties
rx?: number; // Used for rounded corners in Rect, Ellipse, etc.Maybe it to specialized RectNode, EllipseNode, etc. rx?: number; // Used for rounded corners in Rect, Ellipse, etc.Maybe it to specialized RectNode, EllipseNode, etc.

17931
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff