Fixed lint and used selectSvgElement

This commit is contained in:
Subhash Halder
2023-08-20 18:22:34 +05:30
parent 5a64cec9ca
commit 2b4c2e4ca9
3 changed files with 4 additions and 20 deletions

View File

@@ -26,7 +26,7 @@ import {
} from './chartBuilder/Interfaces.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();

View File

@@ -10,6 +10,7 @@ import {
TextVerticalPos,
} from './chartBuilder/Interfaces.js';
import XYChartDB from './xychartDb.js';
import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
export const draw = (txt: string, id: string, _version: string, diagObj: Diagram) => {
function getDominantBaseLine(horizontalPos: TextHorizontalPos) {
@@ -23,20 +24,10 @@ export const draw = (txt: string, id: string, _version: string, diagObj: Diagram
function getTextTransformation(data: TextElem) {
return `translate(${data.x}, ${data.y}) rotate(${data.rotation || 0})`;
}
const conf = configApi.getConfig();
log.debug('Rendering xychart chart\n' + txt);
const securityLevel = conf.securityLevel;
// 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 svg = selectSvgElement(id);
const group = svg.append('g').attr('class', 'main');
const width = 700;

View File

@@ -76,14 +76,7 @@ function computeWidthOfText(parentNode: any, lineHeight: number, line: MarkdownL
return textLength;
}
/**
* 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) {
export function computeDimensionOfText(parentNode: any, lineHeight: number, text: string) {
const testElement = parentNode.append('text');
const testSpan = createTspan(testElement, 1, lineHeight);
updateTextContentAndStyles(testSpan, [{ content: text, type: 'normal' }]);