mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-10 17:49:40 +02:00
Fixed lint and used selectSvgElement
This commit is contained in:
@@ -26,7 +26,7 @@ import {
|
|||||||
} from './chartBuilder/Interfaces.js';
|
} from './chartBuilder/Interfaces.js';
|
||||||
import { getThemeVariables } from '../../themes/theme-default.js';
|
import { getThemeVariables } from '../../themes/theme-default.js';
|
||||||
|
|
||||||
export type SVGGType = Selection<SVGGElement, unknown, HTMLElement, any>;
|
export type SVGGType = Selection<SVGGElement, unknown, Element | null, unknown>;
|
||||||
|
|
||||||
const defaultThemeVariables = getThemeVariables();
|
const defaultThemeVariables = getThemeVariables();
|
||||||
|
|
||||||
|
@@ -10,6 +10,7 @@ import {
|
|||||||
TextVerticalPos,
|
TextVerticalPos,
|
||||||
} from './chartBuilder/Interfaces.js';
|
} from './chartBuilder/Interfaces.js';
|
||||||
import XYChartDB from './xychartDb.js';
|
import XYChartDB from './xychartDb.js';
|
||||||
|
import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
|
||||||
|
|
||||||
export const draw = (txt: string, id: string, _version: string, diagObj: Diagram) => {
|
export const draw = (txt: string, id: string, _version: string, diagObj: Diagram) => {
|
||||||
function getDominantBaseLine(horizontalPos: TextHorizontalPos) {
|
function getDominantBaseLine(horizontalPos: TextHorizontalPos) {
|
||||||
@@ -23,20 +24,10 @@ export const draw = (txt: string, id: string, _version: string, diagObj: Diagram
|
|||||||
function getTextTransformation(data: TextElem) {
|
function getTextTransformation(data: TextElem) {
|
||||||
return `translate(${data.x}, ${data.y}) rotate(${data.rotation || 0})`;
|
return `translate(${data.x}, ${data.y}) rotate(${data.rotation || 0})`;
|
||||||
}
|
}
|
||||||
const conf = configApi.getConfig();
|
|
||||||
|
|
||||||
log.debug('Rendering xychart chart\n' + txt);
|
log.debug('Rendering xychart chart\n' + txt);
|
||||||
|
|
||||||
const securityLevel = conf.securityLevel;
|
const svg = selectSvgElement(id);
|
||||||
// Handle root and Document for when rendering in sandbox mode
|
|
||||||
let sandboxElement;
|
|
||||||
if (securityLevel === 'sandbox') {
|
|
||||||
sandboxElement = select('#i' + id);
|
|
||||||
}
|
|
||||||
const root = sandboxElement ? sandboxElement : select('body');
|
|
||||||
|
|
||||||
const svg = root.select(`[id="${id}"]`);
|
|
||||||
|
|
||||||
const group = svg.append('g').attr('class', 'main');
|
const group = svg.append('g').attr('class', 'main');
|
||||||
|
|
||||||
const width = 700;
|
const width = 700;
|
||||||
|
@@ -76,14 +76,7 @@ function computeWidthOfText(parentNode: any, lineHeight: number, line: MarkdownL
|
|||||||
return textLength;
|
return textLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export function computeDimensionOfText(parentNode: any, lineHeight: number, text: string) {
|
||||||
* Compute the width of rendered text
|
|
||||||
* @param {object} parentNode
|
|
||||||
* @param {number} lineHeight
|
|
||||||
* @param {string} text
|
|
||||||
* @returns {{width: number, height: number}}
|
|
||||||
*/
|
|
||||||
export function computeDimensionOfText(parentNode, lineHeight, text) {
|
|
||||||
const testElement = parentNode.append('text');
|
const testElement = parentNode.append('text');
|
||||||
const testSpan = createTspan(testElement, 1, lineHeight);
|
const testSpan = createTspan(testElement, 1, lineHeight);
|
||||||
updateTextContentAndStyles(testSpan, [{ content: text, type: 'normal' }]);
|
updateTextContentAndStyles(testSpan, [{ content: text, type: 'normal' }]);
|
||||||
|
Reference in New Issue
Block a user