This commit is contained in:
Sidharth Vinod 2024-01-29 12:27:17 +05:30
parent b51d8ff7ba
commit d21461fba0
No known key found for this signature in database
GPG Key ID: FB5CCD378D3907CD
2 changed files with 36 additions and 14 deletions

View File

@ -5,7 +5,12 @@ import { MermaidConfigWithDefaults } from '../../config.js';
import { Point } from '../../types.js'; import { Point } from '../../types.js';
const MAX_SECTIONS = 12; const MAX_SECTIONS = 12;
type ShapeFunction = (db: MindmapDB, elem: D3Element, node: FilledMindMapNode, section?: number) => void; type ShapeFunction = (
db: MindmapDB,
elem: D3Element,
node: FilledMindMapNode,
section?: number
) => void;
const defaultBkg: ShapeFunction = function (db, elem, node, section) { const defaultBkg: ShapeFunction = function (db, elem, node, section) {
const rd = 5; const rd = 5;
@ -15,7 +20,8 @@ const defaultBkg: ShapeFunction = function(db, elem, node, section) {
.attr('class', 'node-bkg node-' + db.type2Str(node.type)) .attr('class', 'node-bkg node-' + db.type2Str(node.type))
.attr( .attr(
'd', 'd',
`M0 ${node.height - rd} v${-node.height + 2 * rd} q0,-5 5,-5 h${node.width - 2 * rd `M0 ${node.height - rd} v${-node.height + 2 * rd} q0,-5 5,-5 h${
node.width - 2 * rd
} q5,0 5,5 v${node.height - rd} H0 Z` } q5,0 5,5 v${node.height - rd} H0 Z`
); );
@ -116,7 +122,13 @@ const circleBkg: ShapeFunction = function(db, elem, node) {
* @param points * @param points
* @param node * @param node
*/ */
function insertPolygonShape(parent: D3Element, w: number, h: number, points: Point[], node: FilledMindMapNode) { function insertPolygonShape(
parent: D3Element,
w: number,
h: number,
points: Point[],
node: FilledMindMapNode
) {
return parent return parent
.insert('polygon', ':first-child') .insert('polygon', ':first-child')
.attr( .attr(
@ -130,7 +142,11 @@ function insertPolygonShape(parent: D3Element, w: number, h: number, points: Poi
.attr('transform', 'translate(' + (node.width - w) / 2 + ', ' + h + ')'); .attr('transform', 'translate(' + (node.width - w) / 2 + ', ' + h + ')');
} }
const hexagonBkg: ShapeFunction = function(_db: MindmapDB, elem: D3Element, node: FilledMindMapNode) { const hexagonBkg: ShapeFunction = function (
_db: MindmapDB,
elem: D3Element,
node: FilledMindMapNode
) {
const h = node.height; const h = node.height;
const f = 4; const f = 4;
const m = h / f; const m = h / f;
@ -165,7 +181,13 @@ const roundedRectBkg: ShapeFunction = function(db, elem, node) {
* @param conf The configuration object * @param conf The configuration object
* @returns The height nodes dom element * @returns The height nodes dom element
*/ */
export const drawNode = function(db: MindmapDB, elem: D3Element, node: FilledMindMapNode, fullSection: number, conf: MermaidConfigWithDefaults): number { export const drawNode = function (
db: MindmapDB,
elem: D3Element,
node: FilledMindMapNode,
fullSection: number,
conf: MermaidConfigWithDefaults
): number {
const htmlLabels = conf.htmlLabels; const htmlLabels = conf.htmlLabels;
const section = fullSection % (MAX_SECTIONS - 1); const section = fullSection % (MAX_SECTIONS - 1);
const nodeElem = elem.append('g'); const nodeElem = elem.append('g');