mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-17 03:04:07 +01:00
Merge branch 'master' into develop
* master: v10.0.2 fix: dayjs import extension Setting version to 10.0.1 #4168 Adding the correct offset for the edges Updated import of cytoscape for consistent behavior Use cytoscape esm Revert "chore: Defer elk loading" Revert "Split cytoscape" fix: Class with members and styles
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "mermaid-monorepo",
|
"name": "mermaid-monorepo",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "9.4.0",
|
"version": "10.0.2",
|
||||||
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"packageManager": "pnpm@7.27.0",
|
"packageManager": "pnpm@7.27.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mermaid",
|
"name": "mermaid",
|
||||||
"version": "10.0.0",
|
"version": "10.0.2",
|
||||||
"description": "Markdown-ish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
"description": "Markdown-ish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"module": "./dist/mermaid.core.mjs",
|
"module": "./dist/mermaid.core.mjs",
|
||||||
|
|||||||
@@ -190,6 +190,37 @@ describe('class diagram, ', function () {
|
|||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle cssClass shorthand with members', () => {
|
||||||
|
parser.parse(`classDiagram-v2
|
||||||
|
class Class10:::exClass2 {
|
||||||
|
int[] id
|
||||||
|
List~int~ ids
|
||||||
|
test(List~int~ ids) List~bool~
|
||||||
|
testArray() bool[]
|
||||||
|
}`);
|
||||||
|
|
||||||
|
expect(classDb.getClass('Class10')).toMatchInlineSnapshot(`
|
||||||
|
{
|
||||||
|
"annotations": [],
|
||||||
|
"cssClasses": [
|
||||||
|
"exClass2",
|
||||||
|
],
|
||||||
|
"domId": "classId-Class10-27",
|
||||||
|
"id": "Class10",
|
||||||
|
"label": "Class10",
|
||||||
|
"members": [
|
||||||
|
"int[] id",
|
||||||
|
"List~int~ ids",
|
||||||
|
],
|
||||||
|
"methods": [
|
||||||
|
"test(List~int~ ids) List~bool~",
|
||||||
|
"testArray() bool[]",
|
||||||
|
],
|
||||||
|
"type": "",
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle method statements', function () {
|
it('should handle method statements', function () {
|
||||||
const str =
|
const str =
|
||||||
'classDiagram\n' +
|
'classDiagram\n' +
|
||||||
@@ -1023,6 +1054,7 @@ C1 --> C2
|
|||||||
const c1 = classDb.getClass('C1');
|
const c1 = classDb.getClass('C1');
|
||||||
expect(c1.label).toBe('Class 1 with text label');
|
expect(c1.label).toBe('Class 1 with text label');
|
||||||
expect(c1.cssClasses.length).toBe(1);
|
expect(c1.cssClasses.length).toBe(1);
|
||||||
|
expect(c1.members[0]).toBe('+member1');
|
||||||
expect(c1.cssClasses[0]).toBe('styleClass');
|
expect(c1.cssClasses[0]).toBe('styleClass');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1038,6 +1070,7 @@ cssClass "C1" styleClass
|
|||||||
const c1 = classDb.getClass('C1');
|
const c1 = classDb.getClass('C1');
|
||||||
expect(c1.label).toBe('Class 1 with text label');
|
expect(c1.label).toBe('Class 1 with text label');
|
||||||
expect(c1.cssClasses.length).toBe(1);
|
expect(c1.cssClasses.length).toBe(1);
|
||||||
|
expect(c1.members[0]).toBe('+member1');
|
||||||
expect(c1.cssClasses[0]).toBe('styleClass');
|
expect(c1.cssClasses[0]).toBe('styleClass');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ classStatement
|
|||||||
: classIdentifier
|
: classIdentifier
|
||||||
| classIdentifier STYLE_SEPARATOR alphaNumToken {yy.setCssClass($1, $3);}
|
| classIdentifier STYLE_SEPARATOR alphaNumToken {yy.setCssClass($1, $3);}
|
||||||
| classIdentifier STRUCT_START members STRUCT_STOP {yy.addMembers($1,$3);}
|
| classIdentifier STRUCT_START members STRUCT_STOP {yy.addMembers($1,$3);}
|
||||||
| classIdentifier STYLE_SEPARATOR alphaNumToken STRUCT_START members STRUCT_STOP {yy.setCssClass($1, $3);yy.addMembers($1,$3);}
|
| classIdentifier STYLE_SEPARATOR alphaNumToken STRUCT_START members STRUCT_STOP {yy.setCssClass($1, $3);yy.addMembers($1,$5);}
|
||||||
;
|
;
|
||||||
|
|
||||||
classIdentifier
|
classIdentifier
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import { log } from '../../../logger';
|
|||||||
import { setupGraphViewbox } from '../../../setupGraphViewbox';
|
import { setupGraphViewbox } from '../../../setupGraphViewbox';
|
||||||
import common, { evaluate } from '../../common/common';
|
import common, { evaluate } from '../../common/common';
|
||||||
import { interpolateToCurve, getStylesFromArray } from '../../../utils';
|
import { interpolateToCurve, getStylesFromArray } from '../../../utils';
|
||||||
|
import ELK from 'elkjs/lib/elk.bundled.js';
|
||||||
let elk;
|
const elk = new ELK();
|
||||||
|
|
||||||
const portPos = {};
|
const portPos = {};
|
||||||
|
|
||||||
@@ -371,6 +371,10 @@ const getEdgeStartEndPoint = (edge, dir) => {
|
|||||||
let source = edge.start;
|
let source = edge.start;
|
||||||
let target = edge.end;
|
let target = edge.end;
|
||||||
|
|
||||||
|
// Save the original source and target
|
||||||
|
const sourceId = source;
|
||||||
|
const targetId = target;
|
||||||
|
|
||||||
const startNode = nodeDb[source];
|
const startNode = nodeDb[source];
|
||||||
const endNode = nodeDb[target];
|
const endNode = nodeDb[target];
|
||||||
|
|
||||||
@@ -387,7 +391,7 @@ const getEdgeStartEndPoint = (edge, dir) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the edge to the graph
|
// Add the edge to the graph
|
||||||
return { source, target };
|
return { source, target, sourceId, targetId };
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -530,14 +534,17 @@ export const addEdges = function (edges, diagObj, graph, svg) {
|
|||||||
|
|
||||||
const labelEl = insertEdgeLabel(labelsEl, edgeData);
|
const labelEl = insertEdgeLabel(labelsEl, edgeData);
|
||||||
|
|
||||||
// calculate start and end points of the edge
|
// calculate start and end points of the edge, note that the source and target
|
||||||
const { source, target } = getEdgeStartEndPoint(edge, dir);
|
// can be modified for shapes that have ports
|
||||||
|
const { source, target, sourceId, targetId } = getEdgeStartEndPoint(edge, dir);
|
||||||
log.debug('abc78 source and target', source, target);
|
log.debug('abc78 source and target', source, target);
|
||||||
// Add the edge to the graph
|
// Add the edge to the graph
|
||||||
graph.edges.push({
|
graph.edges.push({
|
||||||
id: 'e' + edge.start + edge.end,
|
id: 'e' + edge.start + edge.end,
|
||||||
sources: [source],
|
sources: [source],
|
||||||
targets: [target],
|
targets: [target],
|
||||||
|
sourceId,
|
||||||
|
targetId,
|
||||||
labelEl: labelEl,
|
labelEl: labelEl,
|
||||||
labels: [
|
labels: [
|
||||||
{
|
{
|
||||||
@@ -698,7 +705,7 @@ const calcOffset = function (src, dest, parentLookupDb) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const insertEdge = function (edgesEl, edge, edgeData, diagObj, parentLookupDb) {
|
const insertEdge = function (edgesEl, edge, edgeData, diagObj, parentLookupDb) {
|
||||||
const offset = calcOffset(edge.sources[0], edge.targets[0], parentLookupDb);
|
const offset = calcOffset(edge.sourceId, edge.targetId, parentLookupDb);
|
||||||
|
|
||||||
const src = edge.sections[0].startPoint;
|
const src = edge.sections[0].startPoint;
|
||||||
const dest = edge.sections[0].endPoint;
|
const dest = edge.sections[0].endPoint;
|
||||||
@@ -765,10 +772,6 @@ const insertChildren = (nodeArray, parentLookupDb) => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export const draw = async function (text, id, _version, diagObj) {
|
export const draw = async function (text, id, _version, diagObj) {
|
||||||
if (!elk) {
|
|
||||||
const ELK = (await import('elkjs/lib/elk.bundled.js')).default;
|
|
||||||
elk = new ELK();
|
|
||||||
}
|
|
||||||
// Add temporary render element
|
// Add temporary render element
|
||||||
diagObj.db.clear();
|
diagObj.db.clear();
|
||||||
nodeDb = {};
|
nodeDb = {};
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { sanitizeUrl } from '@braintree/sanitize-url';
|
import { sanitizeUrl } from '@braintree/sanitize-url';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import dayjsIsoWeek from 'dayjs/plugin/isoWeek';
|
import dayjsIsoWeek from 'dayjs/plugin/isoWeek.js';
|
||||||
import dayjsCustomParseFormat from 'dayjs/plugin/customParseFormat';
|
import dayjsCustomParseFormat from 'dayjs/plugin/customParseFormat.js';
|
||||||
import dayjsAdvancedFormat from 'dayjs/plugin/advancedFormat';
|
import dayjsAdvancedFormat from 'dayjs/plugin/advancedFormat.js';
|
||||||
import { log } from '../../logger';
|
import { log } from '../../logger';
|
||||||
import * as configApi from '../../config';
|
import * as configApi from '../../config';
|
||||||
import utils from '../../utils';
|
import utils from '../../utils';
|
||||||
|
|||||||
@@ -4,9 +4,13 @@ import { log } from '../../logger';
|
|||||||
import { getConfig } from '../../config';
|
import { getConfig } from '../../config';
|
||||||
import { setupGraphViewbox } from '../../setupGraphViewbox';
|
import { setupGraphViewbox } from '../../setupGraphViewbox';
|
||||||
import svgDraw from './svgDraw';
|
import svgDraw from './svgDraw';
|
||||||
|
import cytoscape from 'cytoscape/dist/cytoscape.umd.js';
|
||||||
|
import coseBilkent from 'cytoscape-cose-bilkent';
|
||||||
import * as db from './mindmapDb';
|
import * as db from './mindmapDb';
|
||||||
|
|
||||||
let cytoscape;
|
// Inject the layout algorithm into cytoscape
|
||||||
|
cytoscape.use(coseBilkent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {any} svg The svg element to draw the diagram onto
|
* @param {any} svg The svg element to draw the diagram onto
|
||||||
* @param {object} mindmap The mindmap data and hierarchy
|
* @param {object} mindmap The mindmap data and hierarchy
|
||||||
@@ -89,14 +93,7 @@ function addNodes(mindmap, cy, conf, level) {
|
|||||||
* @param conf
|
* @param conf
|
||||||
* @param cy
|
* @param cy
|
||||||
*/
|
*/
|
||||||
async function layoutMindmap(node, conf) {
|
function layoutMindmap(node, conf) {
|
||||||
if (!cytoscape) {
|
|
||||||
cytoscape = (await import('cytoscape')).default;
|
|
||||||
const coseBilkent = (await import('cytoscape-cose-bilkent')).default;
|
|
||||||
// Inject the layout algorithm into cytoscape
|
|
||||||
cytoscape.use(coseBilkent);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
// Add temporary render element
|
// Add temporary render element
|
||||||
const renderEl = select('body').append('div').attr('id', 'cy').attr('style', 'display:none');
|
const renderEl = select('body').append('div').attr('id', 'cy').attr('style', 'display:none');
|
||||||
|
|||||||
Reference in New Issue
Block a user