use backtick for cleaner variable string and the DOM document for default values

This commit is contained in:
Yokozuna59
2023-06-23 23:26:45 +03:00
parent b0ae0708e1
commit 30a66533bc

View File

@@ -17,17 +17,15 @@ const draw: DrawDefinition = (text, id, version) => {
const { securityLevel } = getConfig(); const { securityLevel } = getConfig();
// handle root and document for when rendering in sandbox mode // handle root and document for when rendering in sandbox mode
let document: Document | null | undefined; let doc: Document = document;
if (securityLevel === 'sandbox') { if (securityLevel === 'sandbox') {
const sandboxElement: HTML = select('#i' + id); const sandboxElement: HTML = select(`#i${id}`);
document = sandboxElement.node()?.contentDocument; doc = sandboxElement.node()?.contentDocument ?? doc;
} }
const root: HTML = const root: HTML =
document !== undefined && document !== null securityLevel === 'sandbox' ? select(doc.body as HTMLIFrameElement) : select('body');
? select(document.body as HTMLIFrameElement)
: select('body');
const svg: SVG = root.select('#' + id); const svg: SVG = root.select(`#${id}`);
svg.attr('height', 100); svg.attr('height', 100);
svg.attr('width', 400); svg.attr('width', 400);
@@ -38,7 +36,7 @@ const draw: DrawDefinition = (text, id, version) => {
.attr('class', 'version') .attr('class', 'version')
.attr('font-size', '32px') .attr('font-size', '32px')
.style('text-anchor', 'middle') .style('text-anchor', 'middle')
.text('v ' + version); .text(`v${version}`);
} catch (e) { } catch (e) {
log.error('error while rendering info diagram\n', e); log.error('error while rendering info diagram\n', e);
} }