Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/1562 arrowheads in edges to cluster #1563

Merged
merged 3 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cypress/integration/rendering/flowchart-v2.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,22 @@ describe('Flowchart v2', () => {
{ flowchart: { diagramPadding: 0 } }
);
});

it('3: a link with correct arrowhead to a subgraph', () => {
imgSnapshotTest(
`flowchart TD
P1
P1 -->P1.5
subgraph P1.5
P2
P2.5(( A ))
P3
end
P2 --> P4
P3 --> P6
P1.5 --> P5
`,
{ flowchart: { diagramPadding: 0 } }
);
});
});
20 changes: 18 additions & 2 deletions cypress/platform/bundle-test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import mermaid from '../../dist/mermaid.core';

const code = `graph LR
let code = `flowchart LR
Power_Supply --> Transmitter_A
Power_Supply --> Transmitter_B
Transmitter_A --> D
Transmitter_B --> D`;

let code2 = `gantt
dateFormat YYYY-MM-DD
title Adding GANTT diagram functionality to mermaid
section A section
Completed task :done, des1, 2014-01-06,2014-01-08
Active task :active, des2, 2014-01-09, 3d
Future task : des3, after des2, 5d
Future task2 : des4, after des3, 5d
section Critical tasks
Completed task in the critical line :crit, done, 2014-01-06,24h
Implement parser and jison :crit, done, after des1, 2d
Create tests for parser :crit, active, 3d
Future task in critical line :crit, 5d
Create tests for renderer :2d
Add to mermaid :1d`;

mermaid.initialize({
theme: 'forest',
theme: 'default',
fontFamily: '"Lucida Console", Monaco, monospace',
startOnLoad: false,
flowchart: {
Expand Down
17 changes: 13 additions & 4 deletions src/dagre-wrapper/edges.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const intersection = (node, outsidePoint, insidePoint) => {
outsidePoint.y === edges.y1 ||
outsidePoint.y === edges.y2
) {
// logger.warn('calc equals on edge');
logger.warn('calc equals on edge');
return outsidePoint;
}

Expand Down Expand Up @@ -181,9 +181,18 @@ export const insertEdge = function(elem, e, edge, clusterDb, diagramType, graph)
logger.trace('inside', edge.toCluster, point, lastPointOutside);

// First point inside the rect
const insterection = intersection(node, lastPointOutside, point);
logger.trace('intersect', insterection);
points.push(insterection);
const inter = intersection(node, lastPointOutside, point);

let pointPresent = false;
points.forEach(p => {
pointPresent = pointPresent || (p.x === inter.x && p.y === inter.y);
});
// if (!pointPresent) {
if (!points.find(e => e.x === inter.x && e.y === inter.y)) {
points.push(inter);
} else {
logger.warn('no intersect', inter, points);
}
isInside = true;
} else {
if (!isInside) points.push(point);
Expand Down
13 changes: 9 additions & 4 deletions src/dagre-wrapper/intersect/intersect-polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ function intersectPolygon(node, polyPoints, point) {

var minX = Number.POSITIVE_INFINITY;
var minY = Number.POSITIVE_INFINITY;
polyPoints.forEach(function(entry) {
minX = Math.min(minX, entry.x);
minY = Math.min(minY, entry.y);
});
if (typeof polyPoints.forEach === 'function') {
polyPoints.forEach(function(entry) {
minX = Math.min(minX, entry.x);
minY = Math.min(minY, entry.y);
});
} else {
minX = Math.min(minX, polyPoints.x);
minY = Math.min(minY, polyPoints.y);
}

var left = x1 - node.width / 2 - minX;
var top = y1 - node.height / 2 - minY;
Expand Down
4 changes: 2 additions & 2 deletions src/mermaidAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ function updateRendererConfigs(conf) {
}

function reinitialize(options) {
console.warn(`mermaidAPI.reinitialize: v${pkg.version}`, options);
// console.warn(`mermaidAPI.reinitialize: v${pkg.version}`, options);
if (options.theme && themes[options.theme]) {
// Todo merge with user options
options.themeVariables = themes[options.theme].getThemeVariables(options.themeVariables);
Expand All @@ -537,7 +537,7 @@ function reinitialize(options) {
}

function initialize(options) {
console.log(`mermaidAPI.initialize: v${pkg.version} ${options}`);
// console.log(`mermaidAPI.initialize: v${pkg.version} ${options}`);
// Set default options

if (options && options.theme && themes[options.theme]) {
Expand Down