Modify margin logic to avoid creating unnecessary space in subgraph

This commit is contained in:
Matheus B
2023-11-27 22:10:05 -03:00
parent ce875c9a33
commit a807a58a29
2 changed files with 11 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ import { getConfig } from '../diagram-api/diagramAPI.js';
import utils from '../utils.js'; import utils from '../utils.js';
import { evaluate } from '../diagrams/common/common.js'; import { evaluate } from '../diagrams/common/common.js';
import { getLineFunctionsWithOffset } from '../utils/lineWithOffset.js'; import { getLineFunctionsWithOffset } from '../utils/lineWithOffset.js';
import { getSubGraphTitleMargins } from '../utils/subGraphTitleMargins.js';
let edgeLabels = {}; let edgeLabels = {};
let terminalLabels = {}; let terminalLabels = {};
@@ -135,6 +136,8 @@ function setTerminalWidth(fo, value) {
export const positionEdgeLabel = (edge, paths) => { export const positionEdgeLabel = (edge, paths) => {
log.info('Moving label abc78 ', edge.id, edge.label, edgeLabels[edge.id]); log.info('Moving label abc78 ', edge.id, edge.label, edgeLabels[edge.id]);
let path = paths.updatedPath ? paths.updatedPath : paths.originalPath; let path = paths.updatedPath ? paths.updatedPath : paths.originalPath;
const siteConfig = getConfig();
const { subGraphTitleTotalMargin } = getSubGraphTitleMargins(siteConfig);
if (edge.label) { if (edge.label) {
const el = edgeLabels[edge.id]; const el = edgeLabels[edge.id];
let x = edge.x; let x = edge.x;
@@ -158,7 +161,7 @@ export const positionEdgeLabel = (edge, paths) => {
y = pos.y; y = pos.y;
} }
} }
el.attr('transform', 'translate(' + x + ', ' + y + ')'); el.attr('transform', `translate(${x}, ${y + subGraphTitleTotalMargin / 2})`);
} }
//let path = paths.updatedPath ? paths.updatedPath : paths.originalPath; //let path = paths.updatedPath ? paths.updatedPath : paths.originalPath;
@@ -172,7 +175,7 @@ export const positionEdgeLabel = (edge, paths) => {
x = pos.x; x = pos.x;
y = pos.y; y = pos.y;
} }
el.attr('transform', 'translate(' + x + ', ' + y + ')'); el.attr('transform', `translate(${x}, ${y})`);
} }
if (edge.startLabelRight) { if (edge.startLabelRight) {
const el = terminalLabels[edge.id].startRight; const el = terminalLabels[edge.id].startRight;
@@ -188,7 +191,7 @@ export const positionEdgeLabel = (edge, paths) => {
x = pos.x; x = pos.x;
y = pos.y; y = pos.y;
} }
el.attr('transform', 'translate(' + x + ', ' + y + ')'); el.attr('transform', `translate(${x}, ${y})`);
} }
if (edge.endLabelLeft) { if (edge.endLabelLeft) {
const el = terminalLabels[edge.id].endLeft; const el = terminalLabels[edge.id].endLeft;
@@ -200,7 +203,7 @@ export const positionEdgeLabel = (edge, paths) => {
x = pos.x; x = pos.x;
y = pos.y; y = pos.y;
} }
el.attr('transform', 'translate(' + x + ', ' + y + ')'); el.attr('transform', `translate(${x}, ${y})`);
} }
if (edge.endLabelRight) { if (edge.endLabelRight) {
const el = terminalLabels[edge.id].endRight; const el = terminalLabels[edge.id].endRight;
@@ -212,7 +215,7 @@ export const positionEdgeLabel = (edge, paths) => {
x = pos.x; x = pos.x;
y = pos.y; y = pos.y;
} }
el.attr('transform', 'translate(' + x + ', ' + y + ')'); el.attr('transform', `translate(${x}, ${y})`);
} }
}; };

View File

@@ -131,10 +131,11 @@ const recursiveRender = async (_elem, graph, diagramtype, id, parentCluster, sit
if (graph.children(v).length > 0) { if (graph.children(v).length > 0) {
// A cluster in the non-recursive way // A cluster in the non-recursive way
// positionCluster(node); // positionCluster(node);
node.height += subGraphTitleTotalMargin * 2; node.height += subGraphTitleTotalMargin;
insertCluster(clusters, node); insertCluster(clusters, node);
clusterDb[node.id].node = node; clusterDb[node.id].node = node;
} else { } else {
node.y += subGraphTitleTotalMargin / 2;
positionNode(node); positionNode(node);
} }
} }
@@ -145,6 +146,7 @@ const recursiveRender = async (_elem, graph, diagramtype, id, parentCluster, sit
const edge = graph.edge(e); const edge = graph.edge(e);
log.info('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(edge), edge); log.info('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(edge), edge);
edge.points.forEach((point) => (point.y += subGraphTitleTotalMargin / 2));
const paths = insertEdge(edgePaths, e, edge, clusterDb, diagramtype, graph, id); const paths = insertEdge(edgePaths, e, edge, clusterDb, diagramtype, graph, id);
positionEdgeLabel(edge, paths); positionEdgeLabel(edge, paths);
}); });