mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-22 01:36:43 +02:00
Compare commits
2 Commits
@mermaid-j
...
sidv/class
Author | SHA1 | Date | |
---|---|---|---|
![]() |
345b75cc0e | ||
![]() |
0ebea7744b |
@@ -368,7 +368,20 @@ const cutPathAtIntersect = (_points, boundryNode) => {
|
|||||||
return points;
|
return points;
|
||||||
};
|
};
|
||||||
|
|
||||||
//(edgePaths, e, edge, clusterDb, diagramtype, graph)
|
/**
|
||||||
|
* Calculate the deltas and angle between two points
|
||||||
|
* @param {{x: number, y:number}} point1
|
||||||
|
* @param {{x: number, y:number}} point2
|
||||||
|
* @returns {{angle: number, deltaX: number, deltaY: number}}
|
||||||
|
*/
|
||||||
|
function calculateDeltaAndAngle(point1, point2) {
|
||||||
|
const [x1, y1] = [point1.x, point1.y];
|
||||||
|
const [x2, y2] = [point2.x, point2.y];
|
||||||
|
const deltaX = x2 - x1;
|
||||||
|
const deltaY = y2 - y1;
|
||||||
|
return { angle: Math.atan(deltaY / deltaX), deltaX, deltaY };
|
||||||
|
}
|
||||||
|
|
||||||
export const insertEdge = function (elem, e, edge, clusterDb, diagramType, graph) {
|
export const insertEdge = function (elem, e, edge, clusterDb, diagramType, graph) {
|
||||||
let points = edge.points;
|
let points = edge.points;
|
||||||
let pointsHasChanged = false;
|
let pointsHasChanged = false;
|
||||||
@@ -435,22 +448,52 @@ export const insertEdge = function (elem, e, edge, clusterDb, diagramType, graph
|
|||||||
const lineData = points.filter((p) => !Number.isNaN(p.y));
|
const lineData = points.filter((p) => !Number.isNaN(p.y));
|
||||||
|
|
||||||
// This is the accessor function we talked about above
|
// This is the accessor function we talked about above
|
||||||
let curve;
|
let curve = curveBasis;
|
||||||
// Currently only flowcharts get the curve from the settings, perhaps this should
|
// Currently only flowcharts get the curve from the settings, perhaps this should
|
||||||
// be expanded to a common setting? Restricting it for now in order not to cause side-effects that
|
// be expanded to a common setting? Restricting it for now in order not to cause side-effects that
|
||||||
// have not been thought through
|
// have not been thought through
|
||||||
if (diagramType === 'graph' || diagramType === 'flowchart') {
|
if (edge.curve && (diagramType === 'graph' || diagramType === 'flowchart')) {
|
||||||
curve = edge.curve || curveBasis;
|
curve = edge.curve;
|
||||||
} else {
|
|
||||||
curve = curveBasis;
|
|
||||||
}
|
}
|
||||||
// curve = curveLinear;
|
|
||||||
|
const markerOffsets = {
|
||||||
|
aggregation: 18,
|
||||||
|
extension: 18,
|
||||||
|
composition: 18,
|
||||||
|
dependency: 6,
|
||||||
|
lollipop: 13.5,
|
||||||
|
};
|
||||||
|
|
||||||
const lineFunction = line()
|
const lineFunction = line()
|
||||||
.x(function (d) {
|
.x(function (d, i, data) {
|
||||||
return d.x;
|
let offset = 0;
|
||||||
|
if (i === 0 && Object.hasOwn(markerOffsets, edge.arrowTypeStart)) {
|
||||||
|
const { angle, deltaX } = calculateDeltaAndAngle(data[0], data[1]);
|
||||||
|
offset = markerOffsets[edge.arrowTypeStart] * Math.cos(angle) * (deltaX >= 0 ? 1 : -1) || 0;
|
||||||
|
} else if (i === data.length - 1 && Object.hasOwn(markerOffsets, edge.arrowTypeEnd)) {
|
||||||
|
const { angle, deltaX } = calculateDeltaAndAngle(
|
||||||
|
data[data.length - 1],
|
||||||
|
data[data.length - 2]
|
||||||
|
);
|
||||||
|
offset = markerOffsets[edge.arrowTypeEnd] * Math.cos(angle) * (deltaX >= 0 ? 1 : -1) || 0;
|
||||||
|
}
|
||||||
|
return d.x + offset;
|
||||||
})
|
})
|
||||||
.y(function (d) {
|
.y(function (d, i, data) {
|
||||||
return d.y;
|
let offset = 0;
|
||||||
|
if (i === 0 && Object.hasOwn(markerOffsets, edge.arrowTypeStart)) {
|
||||||
|
const { angle, deltaY } = calculateDeltaAndAngle(data[0], data[1]);
|
||||||
|
offset =
|
||||||
|
markerOffsets[edge.arrowTypeStart] * Math.abs(Math.sin(angle)) * (deltaY >= 0 ? 1 : -1);
|
||||||
|
} else if (i === data.length - 1 && Object.hasOwn(markerOffsets, edge.arrowTypeEnd)) {
|
||||||
|
const { angle, deltaY } = calculateDeltaAndAngle(
|
||||||
|
data[data.length - 1],
|
||||||
|
data[data.length - 2]
|
||||||
|
);
|
||||||
|
offset =
|
||||||
|
markerOffsets[edge.arrowTypeEnd] * Math.abs(Math.sin(angle)) * (deltaY >= 0 ? 1 : -1);
|
||||||
|
}
|
||||||
|
return d.y + offset;
|
||||||
})
|
})
|
||||||
.curve(curve);
|
.curve(curve);
|
||||||
|
|
||||||
@@ -489,15 +532,15 @@ export const insertEdge = function (elem, e, edge, clusterDb, diagramType, graph
|
|||||||
.attr('style', edge.style);
|
.attr('style', edge.style);
|
||||||
|
|
||||||
// DEBUG code, adds a red circle at each edge coordinate
|
// DEBUG code, adds a red circle at each edge coordinate
|
||||||
// edge.points.forEach((point) => {
|
edge.points.forEach((point) => {
|
||||||
// elem
|
elem
|
||||||
// .append('circle')
|
.append('circle')
|
||||||
// .style('stroke', 'red')
|
.style('stroke', 'red')
|
||||||
// .style('fill', 'red')
|
.style('fill', 'red')
|
||||||
// .attr('r', 1)
|
.attr('r', 1)
|
||||||
// .attr('cx', point.x)
|
.attr('cx', point.x)
|
||||||
// .attr('cy', point.y);
|
.attr('cy', point.y);
|
||||||
// });
|
});
|
||||||
|
|
||||||
let url = '';
|
let url = '';
|
||||||
// // TODO: Can we load this config only from the rendered graph type?
|
// // TODO: Can we load this config only from the rendered graph type?
|
||||||
|
@@ -155,7 +155,7 @@ export const render = async (elem, graph, markers, diagramtype, id) => {
|
|||||||
clearClusters();
|
clearClusters();
|
||||||
clearGraphlib();
|
clearGraphlib();
|
||||||
|
|
||||||
log.warn('Graph at first:', graphlibJson.write(graph));
|
log.warn('Graph at first:', JSON.stringify(graphlibJson.write(graph)));
|
||||||
adjustClustersAndEdges(graph);
|
adjustClustersAndEdges(graph);
|
||||||
log.warn('Graph after:', graphlibJson.write(graph));
|
log.warn('Graph after:', graphlibJson.write(graph));
|
||||||
// log.warn('Graph ever after:', graphlibJson.write(graph.node('A').graph));
|
// log.warn('Graph ever after:', graphlibJson.write(graph.node('A').graph));
|
||||||
|
@@ -16,7 +16,7 @@ const extension = (elem, type, id) => {
|
|||||||
.append('marker')
|
.append('marker')
|
||||||
.attr('id', type + '-extensionStart')
|
.attr('id', type + '-extensionStart')
|
||||||
.attr('class', 'marker extension ' + type)
|
.attr('class', 'marker extension ' + type)
|
||||||
.attr('refX', 0)
|
.attr('refX', 18)
|
||||||
.attr('refY', 7)
|
.attr('refY', 7)
|
||||||
.attr('markerWidth', 190)
|
.attr('markerWidth', 190)
|
||||||
.attr('markerHeight', 240)
|
.attr('markerHeight', 240)
|
||||||
@@ -29,7 +29,7 @@ const extension = (elem, type, id) => {
|
|||||||
.append('marker')
|
.append('marker')
|
||||||
.attr('id', type + '-extensionEnd')
|
.attr('id', type + '-extensionEnd')
|
||||||
.attr('class', 'marker extension ' + type)
|
.attr('class', 'marker extension ' + type)
|
||||||
.attr('refX', 19)
|
.attr('refX', 1)
|
||||||
.attr('refY', 7)
|
.attr('refY', 7)
|
||||||
.attr('markerWidth', 20)
|
.attr('markerWidth', 20)
|
||||||
.attr('markerHeight', 28)
|
.attr('markerHeight', 28)
|
||||||
@@ -44,7 +44,7 @@ const composition = (elem, type) => {
|
|||||||
.append('marker')
|
.append('marker')
|
||||||
.attr('id', type + '-compositionStart')
|
.attr('id', type + '-compositionStart')
|
||||||
.attr('class', 'marker composition ' + type)
|
.attr('class', 'marker composition ' + type)
|
||||||
.attr('refX', 0)
|
.attr('refX', 18)
|
||||||
.attr('refY', 7)
|
.attr('refY', 7)
|
||||||
.attr('markerWidth', 190)
|
.attr('markerWidth', 190)
|
||||||
.attr('markerHeight', 240)
|
.attr('markerHeight', 240)
|
||||||
@@ -57,7 +57,7 @@ const composition = (elem, type) => {
|
|||||||
.append('marker')
|
.append('marker')
|
||||||
.attr('id', type + '-compositionEnd')
|
.attr('id', type + '-compositionEnd')
|
||||||
.attr('class', 'marker composition ' + type)
|
.attr('class', 'marker composition ' + type)
|
||||||
.attr('refX', 19)
|
.attr('refX', 1)
|
||||||
.attr('refY', 7)
|
.attr('refY', 7)
|
||||||
.attr('markerWidth', 20)
|
.attr('markerWidth', 20)
|
||||||
.attr('markerHeight', 28)
|
.attr('markerHeight', 28)
|
||||||
@@ -71,7 +71,7 @@ const aggregation = (elem, type) => {
|
|||||||
.append('marker')
|
.append('marker')
|
||||||
.attr('id', type + '-aggregationStart')
|
.attr('id', type + '-aggregationStart')
|
||||||
.attr('class', 'marker aggregation ' + type)
|
.attr('class', 'marker aggregation ' + type)
|
||||||
.attr('refX', 0)
|
.attr('refX', 18)
|
||||||
.attr('refY', 7)
|
.attr('refY', 7)
|
||||||
.attr('markerWidth', 190)
|
.attr('markerWidth', 190)
|
||||||
.attr('markerHeight', 240)
|
.attr('markerHeight', 240)
|
||||||
@@ -84,7 +84,7 @@ const aggregation = (elem, type) => {
|
|||||||
.append('marker')
|
.append('marker')
|
||||||
.attr('id', type + '-aggregationEnd')
|
.attr('id', type + '-aggregationEnd')
|
||||||
.attr('class', 'marker aggregation ' + type)
|
.attr('class', 'marker aggregation ' + type)
|
||||||
.attr('refX', 19)
|
.attr('refX', 1)
|
||||||
.attr('refY', 7)
|
.attr('refY', 7)
|
||||||
.attr('markerWidth', 20)
|
.attr('markerWidth', 20)
|
||||||
.attr('markerHeight', 28)
|
.attr('markerHeight', 28)
|
||||||
@@ -98,7 +98,7 @@ const dependency = (elem, type) => {
|
|||||||
.append('marker')
|
.append('marker')
|
||||||
.attr('id', type + '-dependencyStart')
|
.attr('id', type + '-dependencyStart')
|
||||||
.attr('class', 'marker dependency ' + type)
|
.attr('class', 'marker dependency ' + type)
|
||||||
.attr('refX', 0)
|
.attr('refX', 6)
|
||||||
.attr('refY', 7)
|
.attr('refY', 7)
|
||||||
.attr('markerWidth', 190)
|
.attr('markerWidth', 190)
|
||||||
.attr('markerHeight', 240)
|
.attr('markerHeight', 240)
|
||||||
@@ -111,7 +111,7 @@ const dependency = (elem, type) => {
|
|||||||
.append('marker')
|
.append('marker')
|
||||||
.attr('id', type + '-dependencyEnd')
|
.attr('id', type + '-dependencyEnd')
|
||||||
.attr('class', 'marker dependency ' + type)
|
.attr('class', 'marker dependency ' + type)
|
||||||
.attr('refX', 19)
|
.attr('refX', 13)
|
||||||
.attr('refY', 7)
|
.attr('refY', 7)
|
||||||
.attr('markerWidth', 20)
|
.attr('markerWidth', 20)
|
||||||
.attr('markerHeight', 28)
|
.attr('markerHeight', 28)
|
||||||
@@ -125,15 +125,31 @@ const lollipop = (elem, type) => {
|
|||||||
.append('marker')
|
.append('marker')
|
||||||
.attr('id', type + '-lollipopStart')
|
.attr('id', type + '-lollipopStart')
|
||||||
.attr('class', 'marker lollipop ' + type)
|
.attr('class', 'marker lollipop ' + type)
|
||||||
.attr('refX', 0)
|
.attr('refX', 13)
|
||||||
.attr('refY', 7)
|
.attr('refY', 7)
|
||||||
.attr('markerWidth', 190)
|
.attr('markerWidth', 190)
|
||||||
.attr('markerHeight', 240)
|
.attr('markerHeight', 240)
|
||||||
.attr('orient', 'auto')
|
.attr('orient', 'auto')
|
||||||
.append('circle')
|
.append('circle')
|
||||||
.attr('stroke', 'black')
|
.attr('stroke', 'black')
|
||||||
.attr('fill', 'white')
|
.attr('fill', 'transparent')
|
||||||
.attr('cx', 6)
|
.attr('cx', 7)
|
||||||
|
.attr('cy', 7)
|
||||||
|
.attr('r', 6);
|
||||||
|
elem
|
||||||
|
.append('defs')
|
||||||
|
.append('marker')
|
||||||
|
.attr('id', type + '-lollipopEnd')
|
||||||
|
.attr('class', 'marker lollipop ' + type)
|
||||||
|
.attr('refX', 1)
|
||||||
|
.attr('refY', 7)
|
||||||
|
.attr('markerWidth', 190)
|
||||||
|
.attr('markerHeight', 240)
|
||||||
|
.attr('orient', 'auto')
|
||||||
|
.append('circle')
|
||||||
|
.attr('stroke', 'black')
|
||||||
|
.attr('fill', 'transparent')
|
||||||
|
.attr('cx', 7)
|
||||||
.attr('cy', 7)
|
.attr('cy', 7)
|
||||||
.attr('r', 6);
|
.attr('r', 6);
|
||||||
};
|
};
|
||||||
|
@@ -291,8 +291,8 @@ export const adjustClustersAndEdges = (graph, depth) => {
|
|||||||
shape: 'labelRect',
|
shape: 'labelRect',
|
||||||
style: '',
|
style: '',
|
||||||
});
|
});
|
||||||
const edge1 = JSON.parse(JSON.stringify(edge));
|
const edge1 = structuredClone(edge);
|
||||||
const edge2 = JSON.parse(JSON.stringify(edge));
|
const edge2 = structuredClone(edge);
|
||||||
edge1.label = '';
|
edge1.label = '';
|
||||||
edge1.arrowTypeEnd = 'none';
|
edge1.arrowTypeEnd = 'none';
|
||||||
edge2.label = '';
|
edge2.label = '';
|
||||||
|
@@ -91,7 +91,7 @@ g.classGroup line {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#compositionEnd, .composition {
|
#compositionEnd, .composition {
|
||||||
fill: ${options.lineColor} !important;
|
fill: transparent !important;
|
||||||
stroke: ${options.lineColor} !important;
|
stroke: ${options.lineColor} !important;
|
||||||
stroke-width: 1;
|
stroke-width: 1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user