mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-07 14:24:13 +01:00
Change: use Map for notes
This commit is contained in:
@@ -27,7 +27,7 @@ const MERMAID_DOM_ID_PREFIX = 'classId-';
|
|||||||
|
|
||||||
let relations: ClassRelation[] = [];
|
let relations: ClassRelation[] = [];
|
||||||
let classes = new Map<string, ClassNode>();
|
let classes = new Map<string, ClassNode>();
|
||||||
let notes: ClassNote[] = [];
|
let notes = new Map<string, ClassNote>();
|
||||||
let classCounter = 0;
|
let classCounter = 0;
|
||||||
let namespaces = new Map<string, NamespaceNode>();
|
let namespaces = new Map<string, NamespaceNode>();
|
||||||
let namespaceCounter = 0;
|
let namespaceCounter = 0;
|
||||||
@@ -108,7 +108,7 @@ export const lookUpDomId = function (_id: string): string {
|
|||||||
export const clear = function () {
|
export const clear = function () {
|
||||||
relations = [];
|
relations = [];
|
||||||
classes = new Map();
|
classes = new Map();
|
||||||
notes = [];
|
notes = new Map();
|
||||||
functions = [];
|
functions = [];
|
||||||
functions.push(setupToolTips);
|
functions.push(setupToolTips);
|
||||||
namespaces = new Map();
|
namespaces = new Map();
|
||||||
@@ -129,6 +129,11 @@ export const getRelations = function (): ClassRelation[] {
|
|||||||
return relations;
|
return relations;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getNote = function (id: string | number) {
|
||||||
|
const key = typeof id === 'number' ? `note${id}` : id;
|
||||||
|
return notes.get(key)!;
|
||||||
|
}
|
||||||
|
|
||||||
export const getNotes = function () {
|
export const getNotes = function () {
|
||||||
return notes;
|
return notes;
|
||||||
};
|
};
|
||||||
@@ -200,12 +205,15 @@ export const addMembers = function (className: string, members: string[]) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const addNote = function (text: string, className: string) {
|
export const addNote = function (text: string, className: string) {
|
||||||
|
const index = notes.size;
|
||||||
const note = {
|
const note = {
|
||||||
id: `note${notes.length}`,
|
id: `note${index}`,
|
||||||
class: className,
|
class: className,
|
||||||
text: text,
|
text: text,
|
||||||
|
index: index,
|
||||||
};
|
};
|
||||||
notes.push(note);
|
notes.set(note.id, note);
|
||||||
|
return note.id;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const cleanupLabel = function (label: string) {
|
export const cleanupLabel = function (label: string) {
|
||||||
@@ -427,6 +435,7 @@ export const addNamespace = function (id: string) {
|
|||||||
namespaces.set(id, {
|
namespaces.set(id, {
|
||||||
id: id,
|
id: id,
|
||||||
classes: new Map(),
|
classes: new Map(),
|
||||||
|
notes: new Map(),
|
||||||
children: {},
|
children: {},
|
||||||
domId: MERMAID_DOM_ID_PREFIX + id + '-' + namespaceCounter,
|
domId: MERMAID_DOM_ID_PREFIX + id + '-' + namespaceCounter,
|
||||||
} as NamespaceNode);
|
} as NamespaceNode);
|
||||||
@@ -485,6 +494,7 @@ export default {
|
|||||||
clear,
|
clear,
|
||||||
getClass,
|
getClass,
|
||||||
getClasses,
|
getClasses,
|
||||||
|
getNote,
|
||||||
getNotes,
|
getNotes,
|
||||||
addAnnotation,
|
addAnnotation,
|
||||||
addNote,
|
addNote,
|
||||||
|
|||||||
@@ -327,7 +327,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)(
|
||||||
@@ -337,7 +337,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}`);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -351,7 +351,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)(
|
||||||
@@ -366,7 +366,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());
|
||||||
@@ -144,7 +144,7 @@ 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
|
||||||
@@ -329,7 +329,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);
|
||||||
|
|||||||
@@ -136,6 +136,7 @@ export interface ClassNote {
|
|||||||
id: string;
|
id: string;
|
||||||
class: string;
|
class: string;
|
||||||
text: string;
|
text: string;
|
||||||
|
index: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ClassRelation {
|
export interface ClassRelation {
|
||||||
@@ -158,8 +159,10 @@ export interface NamespaceNode {
|
|||||||
id: string;
|
id: string;
|
||||||
domId: string;
|
domId: string;
|
||||||
classes: ClassMap;
|
classes: ClassMap;
|
||||||
|
notes: ClassNoteMap;
|
||||||
children: NamespaceMap;
|
children: NamespaceMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
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>;
|
||||||
|
|||||||
Reference in New Issue
Block a user