chore: Address review comments
Co-authored-by: Reda Al Sulais <u.yokozuna@gmail.com>
This commit is contained in:
parent
95dcd30324
commit
ff6988e875
|
@ -31,7 +31,7 @@ const getMindmap = () => {
|
|||
const addNode = (level: number, id: string, descr: string, type: number) => {
|
||||
log.info('addNode', level, id, descr, type);
|
||||
const conf = getConfig();
|
||||
let padding: number = conf.mindmap?.padding ?? 10;
|
||||
let padding: number = conf.mindmap.padding;
|
||||
switch (type) {
|
||||
case nodeType.ROUNDED_RECT:
|
||||
case nodeType.RECT:
|
||||
|
@ -61,10 +61,9 @@ const addNode = (level: number, id: string, descr: string, type: number) => {
|
|||
nodes.push(node);
|
||||
} else {
|
||||
// Syntax error ... there can only bee one root
|
||||
const error = new Error(
|
||||
throw new Error(
|
||||
'There can be only one root. No parent could be found for ("' + node.descr + '")'
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -11,6 +11,8 @@ import type { MermaidConfig } from '../../config.type.js';
|
|||
import type { Diagram } from '../../Diagram.js';
|
||||
import type { D3Element } from '../../mermaidAPI.js';
|
||||
import type { MermaidConfigWithDefaults } from '../../config.js';
|
||||
import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
|
||||
import { DiagramRenderer, DrawDefinition } from '../../diagram-api/types.js';
|
||||
|
||||
// Inject the layout algorithm into cytoscape
|
||||
cytoscape.use(coseBilkent);
|
||||
|
@ -158,34 +160,20 @@ function positionNodes(db: MindmapDB, cy: cytoscape.Core) {
|
|||
});
|
||||
}
|
||||
|
||||
export const draw = async (text: string, id: string, version: string, diagObj: Diagram) => {
|
||||
export const draw: DrawDefinition = async (text, id, _version, diagObj) => {
|
||||
const conf = getConfig();
|
||||
const db = diagObj.db as MindmapDB;
|
||||
conf.htmlLabels = false;
|
||||
|
||||
log.debug('Rendering mindmap diagram\n' + text, diagObj.parser);
|
||||
log.debug('Rendering mindmap diagram\n' + text);
|
||||
|
||||
const securityLevel = conf.securityLevel;
|
||||
// Handle root and Document for when rendering in sandbox mode
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let sandboxElement: any;
|
||||
if (securityLevel === 'sandbox') {
|
||||
sandboxElement = select('#i' + id);
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const root: any =
|
||||
securityLevel === 'sandbox'
|
||||
? select(sandboxElement.nodes()[0].contentDocument.body)
|
||||
: select('body');
|
||||
|
||||
const svg = root.select('#' + id);
|
||||
|
||||
svg.append('g');
|
||||
const mm = db.getMindmap();
|
||||
if (!mm) {
|
||||
return;
|
||||
}
|
||||
|
||||
const svg = selectSvgElement(id);
|
||||
|
||||
// Draw the graph and start with drawing the nodes without proper position
|
||||
// this gives us the size of the nodes and we can set the positions later
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ import { createText } from '../../rendering-util/createText.js';
|
|||
import type { FilledMindMapNode, MindmapDB } from './mindmapTypes.js';
|
||||
import type { MermaidConfigWithDefaults } from '../../config.js';
|
||||
import type { Point } from '../../types.js';
|
||||
import { parseFontSize } from '../../utils.js';
|
||||
|
||||
const MAX_SECTIONS = 12;
|
||||
|
||||
type ShapeFunction = (
|
||||
|
@ -207,11 +209,9 @@ export const drawNode = function (
|
|||
.attr('dominant-baseline', 'middle')
|
||||
.attr('text-anchor', 'middle');
|
||||
}
|
||||
// .call(wrap, node.width);
|
||||
const bbox = textElem.node().getBBox();
|
||||
// @ts-expect-error TODO: Check if fontSize can be string?
|
||||
const fontSize = conf.fontSize.replace ? conf.fontSize.replace('px', '') : conf.fontSize;
|
||||
node.height = bbox.height + fontSize * 1.1 * 0.5 + node.padding;
|
||||
const [fontSize] = parseFontSize(conf.fontSize);
|
||||
node.height = bbox.height + fontSize! * 1.1 * 0.5 + node.padding;
|
||||
node.width = bbox.width + 2 * node.padding;
|
||||
if (node.icon) {
|
||||
if (node.type === db.nodeType.CIRCLE) {
|
||||
|
|
|
@ -925,3 +925,7 @@ export const encodeEntities = function (text: string): string {
|
|||
export const decodeEntities = function (text: string): string {
|
||||
return text.replace(/fl°°/g, '&#').replace(/fl°/g, '&').replace(/¶ß/g, ';');
|
||||
};
|
||||
|
||||
export const isString = (value: unknown): value is string => {
|
||||
return typeof value === 'string';
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue