mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-12-05 12:04:45 +01:00
Merge pull request #5814 from kairi003/feature/4706_allow_notes_in_namespace
feat: allow to put notes in namespaces on classDiagram
This commit is contained in:
5
.changeset/short-seals-sort.md
Normal file
5
.changeset/short-seals-sort.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'mermaid': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: allow to put notes in namespaces on classDiagram
|
||||||
@@ -5,7 +5,7 @@ USER 0:0
|
|||||||
RUN corepack enable \
|
RUN corepack enable \
|
||||||
&& corepack enable pnpm
|
&& corepack enable pnpm
|
||||||
|
|
||||||
RUN apk add --no-cache git~=2.43.4 \
|
RUN apk add --no-cache git~=2.43 \
|
||||||
&& git config --add --system safe.directory /mermaid
|
&& git config --add --system safe.directory /mermaid
|
||||||
|
|
||||||
ENV NODE_OPTIONS="--max_old_space_size=8192"
|
ENV NODE_OPTIONS="--max_old_space_size=8192"
|
||||||
|
|||||||
@@ -562,6 +562,20 @@ class C13["With Città foreign language"]
|
|||||||
`
|
`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('should add notes in namespaces', function () {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
classDiagram
|
||||||
|
note "This is a outer note"
|
||||||
|
note for C1 "This is a outer note for C1"
|
||||||
|
namespace Namespace1 {
|
||||||
|
note "This is a inner note"
|
||||||
|
note for C1 "This is a inner note for C1"
|
||||||
|
class C1
|
||||||
|
}
|
||||||
|
`
|
||||||
|
);
|
||||||
|
});
|
||||||
it('should render a simple class diagram with no members', () => {
|
it('should render a simple class diagram with no members', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -709,6 +709,20 @@ class C13["With Città foreign language"]
|
|||||||
`
|
`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('should add notes in namespaces', function () {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
classDiagram
|
||||||
|
note "This is a outer note"
|
||||||
|
note for C1 "This is a outer note for C1"
|
||||||
|
namespace Namespace1 {
|
||||||
|
note "This is a inner note"
|
||||||
|
note for C1 "This is a inner note for C1"
|
||||||
|
class C1
|
||||||
|
}
|
||||||
|
`
|
||||||
|
);
|
||||||
|
});
|
||||||
it('should render a simple class diagram with no members', () => {
|
it('should render a simple class diagram with no members', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -184,6 +184,7 @@
|
|||||||
}
|
}
|
||||||
Admin --> Report : generates
|
Admin --> Report : generates
|
||||||
</pre>
|
</pre>
|
||||||
|
<hr />
|
||||||
<pre class="mermaid">
|
<pre class="mermaid">
|
||||||
classDiagram
|
classDiagram
|
||||||
namespace Company.Project.Module {
|
namespace Company.Project.Module {
|
||||||
@@ -240,6 +241,20 @@
|
|||||||
Bike --> Square : "Logo Shape"
|
Bike --> Square : "Logo Shape"
|
||||||
|
|
||||||
</pre>
|
</pre>
|
||||||
|
<hr />
|
||||||
|
<pre class="mermaid">
|
||||||
|
classDiagram
|
||||||
|
note "This is a outer note"
|
||||||
|
note for Class1 "This is a outer note for Class1"
|
||||||
|
namespace ns {
|
||||||
|
note "This is a inner note"
|
||||||
|
note for Class1 "This is a inner note for Class1"
|
||||||
|
class Class1
|
||||||
|
class Class2
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
<hr />
|
||||||
|
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import mermaid from './mermaid.esm.mjs';
|
import mermaid from './mermaid.esm.mjs';
|
||||||
mermaid.initialize({
|
mermaid.initialize({
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import type {
|
|||||||
ClassRelation,
|
ClassRelation,
|
||||||
ClassNode,
|
ClassNode,
|
||||||
ClassNote,
|
ClassNote,
|
||||||
|
ClassNoteMap,
|
||||||
ClassMap,
|
ClassMap,
|
||||||
NamespaceMap,
|
NamespaceMap,
|
||||||
NamespaceNode,
|
NamespaceNode,
|
||||||
@@ -33,15 +34,16 @@ const sanitizeText = (txt: string) => common.sanitizeText(txt, getConfig());
|
|||||||
|
|
||||||
export class ClassDB implements DiagramDB {
|
export class ClassDB implements DiagramDB {
|
||||||
private relations: ClassRelation[] = [];
|
private relations: ClassRelation[] = [];
|
||||||
private classes = new Map<string, ClassNode>();
|
private classes: ClassMap = new Map<string, ClassNode>();
|
||||||
private readonly styleClasses = new Map<string, StyleClass>();
|
private readonly styleClasses = new Map<string, StyleClass>();
|
||||||
private notes: ClassNote[] = [];
|
private notes: ClassNoteMap = new Map<string, ClassNote>();
|
||||||
private interfaces: Interface[] = [];
|
private interfaces: Interface[] = [];
|
||||||
// private static classCounter = 0;
|
// private static classCounter = 0;
|
||||||
private namespaces = new Map<string, NamespaceNode>();
|
private namespaces = new Map<string, NamespaceNode>();
|
||||||
private namespaceCounter = 0;
|
private namespaceCounter = 0;
|
||||||
|
|
||||||
private functions: any[] = [];
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
||||||
|
private functions: Function[] = [];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.functions.push(this.setupToolTips.bind(this));
|
this.functions.push(this.setupToolTips.bind(this));
|
||||||
@@ -124,7 +126,7 @@ export class ClassDB implements DiagramDB {
|
|||||||
annotations: [],
|
annotations: [],
|
||||||
styles: [],
|
styles: [],
|
||||||
domId: MERMAID_DOM_ID_PREFIX + name + '-' + classCounter,
|
domId: MERMAID_DOM_ID_PREFIX + name + '-' + classCounter,
|
||||||
} as ClassNode);
|
});
|
||||||
|
|
||||||
classCounter++;
|
classCounter++;
|
||||||
}
|
}
|
||||||
@@ -155,12 +157,12 @@ export class ClassDB implements DiagramDB {
|
|||||||
|
|
||||||
public clear() {
|
public clear() {
|
||||||
this.relations = [];
|
this.relations = [];
|
||||||
this.classes = new Map();
|
this.classes = new Map<string, ClassNode>();
|
||||||
this.notes = [];
|
this.notes = new Map<string, ClassNote>();
|
||||||
this.interfaces = [];
|
this.interfaces = [];
|
||||||
this.functions = [];
|
this.functions = [];
|
||||||
this.functions.push(this.setupToolTips.bind(this));
|
this.functions.push(this.setupToolTips.bind(this));
|
||||||
this.namespaces = new Map();
|
this.namespaces = new Map<string, NamespaceNode>();
|
||||||
this.namespaceCounter = 0;
|
this.namespaceCounter = 0;
|
||||||
this.direction = 'TB';
|
this.direction = 'TB';
|
||||||
commonClear();
|
commonClear();
|
||||||
@@ -178,7 +180,12 @@ export class ClassDB implements DiagramDB {
|
|||||||
return this.relations;
|
return this.relations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getNotes() {
|
public getNote(id: string | number): ClassNote {
|
||||||
|
const key = typeof id === 'number' ? `note${id}` : id;
|
||||||
|
return this.notes.get(key)!;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getNotes(): ClassNoteMap {
|
||||||
return this.notes;
|
return this.notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,16 +286,19 @@ export class ClassDB implements DiagramDB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public addNote(text: string, className: string) {
|
public addNote(text: string, className: string): string {
|
||||||
|
const index = this.notes.size;
|
||||||
const note = {
|
const note = {
|
||||||
id: `note${this.notes.length}`,
|
id: `note${index}`,
|
||||||
class: className,
|
class: className,
|
||||||
text: text,
|
text: text,
|
||||||
|
index: index,
|
||||||
};
|
};
|
||||||
this.notes.push(note);
|
this.notes.set(note.id, note);
|
||||||
|
return note.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public cleanupLabel(label: string) {
|
public cleanupLabel(label: string): string {
|
||||||
if (label.startsWith(':')) {
|
if (label.startsWith(':')) {
|
||||||
label = label.substring(1);
|
label = label.substring(1);
|
||||||
}
|
}
|
||||||
@@ -354,7 +364,7 @@ export class ClassDB implements DiagramDB {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public getTooltip(id: string, namespace?: string) {
|
public getTooltip(id: string, namespace?: string): string | undefined {
|
||||||
if (namespace && this.namespaces.has(namespace)) {
|
if (namespace && this.namespaces.has(namespace)) {
|
||||||
return this.namespaces.get(namespace)!.classes.get(id)!.tooltip;
|
return this.namespaces.get(namespace)!.classes.get(id)!.tooltip;
|
||||||
}
|
}
|
||||||
@@ -534,10 +544,11 @@ export class ClassDB implements DiagramDB {
|
|||||||
|
|
||||||
this.namespaces.set(id, {
|
this.namespaces.set(id, {
|
||||||
id: id,
|
id: id,
|
||||||
classes: new Map(),
|
classes: new Map<string, ClassNode>(),
|
||||||
children: {},
|
notes: new Map<string, ClassNote>(),
|
||||||
|
children: new Map<string, NamespaceNode>(),
|
||||||
domId: MERMAID_DOM_ID_PREFIX + id + '-' + this.namespaceCounter,
|
domId: MERMAID_DOM_ID_PREFIX + id + '-' + this.namespaceCounter,
|
||||||
} as NamespaceNode);
|
});
|
||||||
|
|
||||||
this.namespaceCounter++;
|
this.namespaceCounter++;
|
||||||
}
|
}
|
||||||
@@ -555,16 +566,23 @@ export class ClassDB implements DiagramDB {
|
|||||||
*
|
*
|
||||||
* @param id - ID of the namespace to add
|
* @param id - ID of the namespace to add
|
||||||
* @param classNames - IDs of the class to add
|
* @param classNames - IDs of the class to add
|
||||||
|
* @param noteNames - IDs of the notes to add
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
public addClassesToNamespace(id: string, classNames: string[]) {
|
public addClassesToNamespace(id: string, classNames: string[], noteNames: string[]) {
|
||||||
if (!this.namespaces.has(id)) {
|
if (!this.namespaces.has(id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (const name of classNames) {
|
for (const name of classNames) {
|
||||||
const { className } = this.splitClassNameAndType(name);
|
const { className } = this.splitClassNameAndType(name);
|
||||||
this.classes.get(className)!.parent = id;
|
const classNode = this.getClass(className);
|
||||||
this.namespaces.get(id)!.classes.set(className, this.classes.get(className)!);
|
classNode.parent = id;
|
||||||
|
this.namespaces.get(id)!.classes.set(className, classNode);
|
||||||
|
}
|
||||||
|
for (const noteName of noteNames) {
|
||||||
|
const noteNode = this.getNote(noteName);
|
||||||
|
noteNode.parent = id;
|
||||||
|
this.namespaces.get(id)!.notes.set(noteName, noteNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -617,36 +635,32 @@ export class ClassDB implements DiagramDB {
|
|||||||
const edges: Edge[] = [];
|
const edges: Edge[] = [];
|
||||||
const config = getConfig();
|
const config = getConfig();
|
||||||
|
|
||||||
for (const namespaceKey of this.namespaces.keys()) {
|
for (const namespace of this.namespaces.values()) {
|
||||||
const namespace = this.namespaces.get(namespaceKey);
|
const node: Node = {
|
||||||
if (namespace) {
|
id: namespace.id,
|
||||||
const node: Node = {
|
label: namespace.id,
|
||||||
id: namespace.id,
|
isGroup: true,
|
||||||
label: namespace.id,
|
padding: config.class!.padding ?? 16,
|
||||||
isGroup: true,
|
// parent node must be one of [rect, roundedWithTitle, noteGroup, divider]
|
||||||
padding: config.class!.padding ?? 16,
|
shape: 'rect',
|
||||||
// parent node must be one of [rect, roundedWithTitle, noteGroup, divider]
|
cssStyles: [],
|
||||||
shape: 'rect',
|
look: config.look,
|
||||||
cssStyles: [],
|
};
|
||||||
look: config.look,
|
nodes.push(node);
|
||||||
};
|
|
||||||
nodes.push(node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const classKey of this.classes.keys()) {
|
for (const classNode of this.classes.values()) {
|
||||||
const classNode = this.classes.get(classKey);
|
const node: Node = {
|
||||||
if (classNode) {
|
...classNode,
|
||||||
const node = classNode as unknown as Node;
|
type: undefined,
|
||||||
node.parentId = classNode.parent;
|
isGroup: false,
|
||||||
node.look = config.look;
|
parentId: classNode.parent,
|
||||||
nodes.push(node);
|
look: config.look,
|
||||||
}
|
};
|
||||||
|
nodes.push(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
let cnt = 0;
|
for (const note of this.notes.values()) {
|
||||||
for (const note of this.notes) {
|
|
||||||
cnt++;
|
|
||||||
const noteNode: Node = {
|
const noteNode: Node = {
|
||||||
id: note.id,
|
id: note.id,
|
||||||
label: note.text,
|
label: note.text,
|
||||||
@@ -660,14 +674,15 @@ export class ClassDB implements DiagramDB {
|
|||||||
`stroke: ${config.themeVariables.noteBorderColor}`,
|
`stroke: ${config.themeVariables.noteBorderColor}`,
|
||||||
],
|
],
|
||||||
look: config.look,
|
look: config.look,
|
||||||
|
parentId: note.parent,
|
||||||
};
|
};
|
||||||
nodes.push(noteNode);
|
nodes.push(noteNode);
|
||||||
|
|
||||||
const noteClassId = this.classes.get(note.class)?.id ?? '';
|
const noteClassId = this.classes.get(note.class)?.id;
|
||||||
|
|
||||||
if (noteClassId) {
|
if (noteClassId) {
|
||||||
const edge: Edge = {
|
const edge: Edge = {
|
||||||
id: `edgeNote${cnt}`,
|
id: `edgeNote${note.index}`,
|
||||||
start: note.id,
|
start: note.id,
|
||||||
end: noteClassId,
|
end: noteClassId,
|
||||||
type: 'normal',
|
type: 'normal',
|
||||||
@@ -697,7 +712,7 @@ export class ClassDB implements DiagramDB {
|
|||||||
nodes.push(interfaceNode);
|
nodes.push(interfaceNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
cnt = 0;
|
let cnt = 0;
|
||||||
for (const classRelation of this.relations) {
|
for (const classRelation of this.relations) {
|
||||||
cnt++;
|
cnt++;
|
||||||
const edge: Edge = {
|
const edge: Edge = {
|
||||||
|
|||||||
@@ -417,7 +417,7 @@ class C13["With Città foreign language"]
|
|||||||
note "This is a keyword: ${keyword}. It truly is."
|
note "This is a keyword: ${keyword}. It truly is."
|
||||||
`;
|
`;
|
||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
expect(classDb.getNotes()[0].text).toEqual(`This is a keyword: ${keyword}. It truly is.`);
|
expect(classDb.getNote(0).text).toEqual(`This is a keyword: ${keyword}. It truly is.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each(keywords)(
|
it.each(keywords)(
|
||||||
@@ -427,7 +427,7 @@ class C13["With Città foreign language"]
|
|||||||
note "${keyword}"`;
|
note "${keyword}"`;
|
||||||
|
|
||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
expect(classDb.getNotes()[0].text).toEqual(`${keyword}`);
|
expect(classDb.getNote(0).text).toEqual(`${keyword}`);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -441,7 +441,7 @@ class C13["With Città foreign language"]
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
expect(classDb.getNotes()[0].text).toEqual(`This is a keyword: ${keyword}. It truly is.`);
|
expect(classDb.getNote(0).text).toEqual(`This is a keyword: ${keyword}. It truly is.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each(keywords)(
|
it.each(keywords)(
|
||||||
@@ -456,7 +456,7 @@ class C13["With Città foreign language"]
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
expect(classDb.getNotes()[0].text).toEqual(`${keyword}`);
|
expect(classDb.getNote(0).text).toEqual(`${keyword}`);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import utils, { getEdgeId } from '../../utils.js';
|
|||||||
import { interpolateToCurve, getStylesFromArray } from '../../utils.js';
|
import { interpolateToCurve, getStylesFromArray } from '../../utils.js';
|
||||||
import { setupGraphViewbox } from '../../setupGraphViewbox.js';
|
import { setupGraphViewbox } from '../../setupGraphViewbox.js';
|
||||||
import common from '../common/common.js';
|
import common from '../common/common.js';
|
||||||
import type { ClassRelation, ClassNote, ClassMap, NamespaceMap } from './classTypes.js';
|
import type { ClassRelation, ClassMap, ClassNoteMap, NamespaceMap } from './classTypes.js';
|
||||||
import type { EdgeData } from '../../types.js';
|
import type { EdgeData } from '../../types.js';
|
||||||
|
|
||||||
const sanitizeText = (txt: string) => common.sanitizeText(txt, getConfig());
|
const sanitizeText = (txt: string) => common.sanitizeText(txt, getConfig());
|
||||||
@@ -65,6 +65,9 @@ export const addNamespaces = function (
|
|||||||
|
|
||||||
g.setNode(vertex.id, node);
|
g.setNode(vertex.id, node);
|
||||||
addClasses(vertex.classes, g, _id, diagObj, vertex.id);
|
addClasses(vertex.classes, g, _id, diagObj, vertex.id);
|
||||||
|
const classes: ClassMap = diagObj.db.getClasses();
|
||||||
|
const relations: ClassRelation[] = diagObj.db.getRelations();
|
||||||
|
addNotes(vertex.notes, g, relations.length + 1, classes, vertex.id);
|
||||||
|
|
||||||
log.info('setNode', node);
|
log.info('setNode', node);
|
||||||
});
|
});
|
||||||
@@ -144,69 +147,74 @@ export const addClasses = function (
|
|||||||
* @param classes - Classes
|
* @param classes - Classes
|
||||||
*/
|
*/
|
||||||
export const addNotes = function (
|
export const addNotes = function (
|
||||||
notes: ClassNote[],
|
notes: ClassNoteMap,
|
||||||
g: graphlib.Graph,
|
g: graphlib.Graph,
|
||||||
startEdgeId: number,
|
startEdgeId: number,
|
||||||
classes: ClassMap
|
classes: ClassMap,
|
||||||
|
parent?: string
|
||||||
) {
|
) {
|
||||||
log.info(notes);
|
log.info(notes);
|
||||||
|
|
||||||
notes.forEach(function (note, i) {
|
[...notes.values()]
|
||||||
const vertex = note;
|
.filter((note) => note.parent === parent)
|
||||||
|
.forEach(function (vertex) {
|
||||||
|
const cssNoteStr = '';
|
||||||
|
|
||||||
const cssNoteStr = '';
|
const styles = { labelStyle: '', style: '' };
|
||||||
|
|
||||||
const styles = { labelStyle: '', style: '' };
|
const vertexText = vertex.text;
|
||||||
|
|
||||||
const vertexText = vertex.text;
|
const radius = 0;
|
||||||
|
const shape = 'note';
|
||||||
|
const node = {
|
||||||
|
labelStyle: styles.labelStyle,
|
||||||
|
shape: shape,
|
||||||
|
labelText: sanitizeText(vertexText),
|
||||||
|
noteData: vertex,
|
||||||
|
rx: radius,
|
||||||
|
ry: radius,
|
||||||
|
class: cssNoteStr,
|
||||||
|
style: styles.style,
|
||||||
|
id: vertex.id,
|
||||||
|
domId: vertex.id,
|
||||||
|
tooltip: '',
|
||||||
|
type: 'note',
|
||||||
|
// TODO V10: Flowchart ? Keeping flowchart for backwards compatibility. Remove in next major release
|
||||||
|
padding: getConfig().flowchart?.padding ?? getConfig().class?.padding,
|
||||||
|
};
|
||||||
|
g.setNode(vertex.id, node);
|
||||||
|
log.info('setNode', node);
|
||||||
|
|
||||||
const radius = 0;
|
if (parent) {
|
||||||
const shape = 'note';
|
g.setParent(vertex.id, parent);
|
||||||
const node = {
|
}
|
||||||
labelStyle: styles.labelStyle,
|
|
||||||
shape: shape,
|
|
||||||
labelText: sanitizeText(vertexText),
|
|
||||||
noteData: vertex,
|
|
||||||
rx: radius,
|
|
||||||
ry: radius,
|
|
||||||
class: cssNoteStr,
|
|
||||||
style: styles.style,
|
|
||||||
id: vertex.id,
|
|
||||||
domId: vertex.id,
|
|
||||||
tooltip: '',
|
|
||||||
type: 'note',
|
|
||||||
// TODO V10: Flowchart ? Keeping flowchart for backwards compatibility. Remove in next major release
|
|
||||||
padding: getConfig().flowchart?.padding ?? getConfig().class?.padding,
|
|
||||||
};
|
|
||||||
g.setNode(vertex.id, node);
|
|
||||||
log.info('setNode', node);
|
|
||||||
|
|
||||||
if (!vertex.class || !classes.has(vertex.class)) {
|
if (!vertex.class || !classes.has(vertex.class)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const edgeId = startEdgeId + i;
|
const edgeId = startEdgeId + vertex.index;
|
||||||
|
|
||||||
const edgeData: EdgeData = {
|
const edgeData: EdgeData = {
|
||||||
id: `edgeNote${edgeId}`,
|
id: `edgeNote${edgeId}`,
|
||||||
//Set relationship style and line type
|
//Set relationship style and line type
|
||||||
classes: 'relation',
|
classes: 'relation',
|
||||||
pattern: 'dotted',
|
pattern: 'dotted',
|
||||||
// Set link type for rendering
|
// Set link type for rendering
|
||||||
arrowhead: 'none',
|
arrowhead: 'none',
|
||||||
//Set edge extra labels
|
//Set edge extra labels
|
||||||
startLabelRight: '',
|
startLabelRight: '',
|
||||||
endLabelLeft: '',
|
endLabelLeft: '',
|
||||||
//Set relation arrow types
|
//Set relation arrow types
|
||||||
arrowTypeStart: 'none',
|
arrowTypeStart: 'none',
|
||||||
arrowTypeEnd: 'none',
|
arrowTypeEnd: 'none',
|
||||||
style: 'fill:none',
|
style: 'fill:none',
|
||||||
labelStyle: '',
|
labelStyle: '',
|
||||||
curve: interpolateToCurve(conf.curve, curveLinear),
|
curve: interpolateToCurve(conf.curve, curveLinear),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add the edge to the graph
|
// Add the edge to the graph
|
||||||
g.setEdge(vertex.id, vertex.class, edgeData, edgeId);
|
g.setEdge(vertex.id, vertex.class, edgeData, edgeId);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -329,7 +337,7 @@ export const draw = async function (text: string, id: string, _version: string,
|
|||||||
const namespaces: NamespaceMap = diagObj.db.getNamespaces();
|
const namespaces: NamespaceMap = diagObj.db.getNamespaces();
|
||||||
const classes: ClassMap = diagObj.db.getClasses();
|
const classes: ClassMap = diagObj.db.getClasses();
|
||||||
const relations: ClassRelation[] = diagObj.db.getRelations();
|
const relations: ClassRelation[] = diagObj.db.getRelations();
|
||||||
const notes: ClassNote[] = diagObj.db.getNotes();
|
const notes: ClassNoteMap = diagObj.db.getNotes();
|
||||||
log.info(relations);
|
log.info(relations);
|
||||||
addNamespaces(namespaces, g, id, diagObj);
|
addNamespaces(namespaces, g, id, diagObj);
|
||||||
addClasses(classes, g, id, diagObj);
|
addClasses(classes, g, id, diagObj);
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ export const draw = function (text, id, _version, diagObj) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const notes = diagObj.db.getNotes();
|
const notes = diagObj.db.getNotes().values();
|
||||||
notes.forEach(function (note) {
|
notes.forEach(function (note) {
|
||||||
log.debug(`Adding note: ${JSON.stringify(note)}`);
|
log.debug(`Adding note: ${JSON.stringify(note)}`);
|
||||||
const node = svgDraw.drawNote(diagram, note, conf, diagObj);
|
const node = svgDraw.drawNote(diagram, note, conf, diagObj);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export interface ClassNode {
|
|||||||
id: string;
|
id: string;
|
||||||
type: string;
|
type: string;
|
||||||
label: string;
|
label: string;
|
||||||
shape: string;
|
shape: 'classBox';
|
||||||
text: string;
|
text: string;
|
||||||
cssClasses: string;
|
cssClasses: string;
|
||||||
methods: ClassMember[];
|
methods: ClassMember[];
|
||||||
@@ -149,6 +149,8 @@ export interface ClassNote {
|
|||||||
id: string;
|
id: string;
|
||||||
class: string;
|
class: string;
|
||||||
text: string;
|
text: string;
|
||||||
|
index: number;
|
||||||
|
parent?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ClassRelation {
|
export interface ClassRelation {
|
||||||
@@ -177,6 +179,7 @@ export interface NamespaceNode {
|
|||||||
id: string;
|
id: string;
|
||||||
domId: string;
|
domId: string;
|
||||||
classes: ClassMap;
|
classes: ClassMap;
|
||||||
|
notes: ClassNoteMap;
|
||||||
children: NamespaceMap;
|
children: NamespaceMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,4 +190,5 @@ export interface StyleClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type ClassMap = Map<string, ClassNode>;
|
export type ClassMap = Map<string, ClassNode>;
|
||||||
|
export type ClassNoteMap = Map<string, ClassNote>;
|
||||||
export type NamespaceMap = Map<string, NamespaceNode>;
|
export type NamespaceMap = Map<string, NamespaceNode>;
|
||||||
|
|||||||
@@ -275,8 +275,8 @@ statement
|
|||||||
;
|
;
|
||||||
|
|
||||||
namespaceStatement
|
namespaceStatement
|
||||||
: namespaceIdentifier STRUCT_START classStatements STRUCT_STOP { yy.addClassesToNamespace($1, $3); }
|
: namespaceIdentifier STRUCT_START classStatements STRUCT_STOP { yy.addClassesToNamespace($1, $3[0], $3[1]); }
|
||||||
| namespaceIdentifier STRUCT_START NEWLINE classStatements STRUCT_STOP { yy.addClassesToNamespace($1, $4); }
|
| namespaceIdentifier STRUCT_START NEWLINE classStatements STRUCT_STOP { yy.addClassesToNamespace($1, $4[0], $4[1]); }
|
||||||
;
|
;
|
||||||
|
|
||||||
namespaceIdentifier
|
namespaceIdentifier
|
||||||
@@ -284,9 +284,12 @@ namespaceIdentifier
|
|||||||
;
|
;
|
||||||
|
|
||||||
classStatements
|
classStatements
|
||||||
: classStatement {$$=[$1]}
|
: classStatement {$$=[[$1], []]}
|
||||||
| classStatement NEWLINE {$$=[$1]}
|
| classStatement NEWLINE {$$=[[$1], []]}
|
||||||
| classStatement NEWLINE classStatements {$3.unshift($1); $$=$3}
|
| classStatement NEWLINE classStatements {$3[0].unshift($1); $$=$3}
|
||||||
|
| noteStatement {$$=[[], [$1]]}
|
||||||
|
| noteStatement NEWLINE {$$=[[], [$1]]}
|
||||||
|
| noteStatement NEWLINE classStatements {$3[1].unshift($1); $$=$3}
|
||||||
;
|
;
|
||||||
|
|
||||||
classStatement
|
classStatement
|
||||||
@@ -333,8 +336,8 @@ relationStatement
|
|||||||
;
|
;
|
||||||
|
|
||||||
noteStatement
|
noteStatement
|
||||||
: NOTE_FOR className noteText { yy.addNote($3, $2); }
|
: NOTE_FOR className noteText { $$ = yy.addNote($3, $2); }
|
||||||
| NOTE noteText { yy.addNote($2); }
|
| NOTE noteText { $$ = yy.addNote($2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
classDefStatement
|
classDefStatement
|
||||||
|
|||||||
Reference in New Issue
Block a user