add parial parts to info graph

This commit is contained in:
Yokozuna59 2023-06-13 18:50:08 +03:00
parent daee545e78
commit ae14f6a947
2 changed files with 15 additions and 11 deletions

View File

@ -77,3 +77,5 @@ export type DrawDefinition = (
* @param type -
*/
export type ParseDirectiveDefinition = (statement: string, context: string, type: string) => void;
export type SVG = d3.Selection<HTMLFrameElement, unknown, HTMLElement, unknown>;

View File

@ -2,7 +2,7 @@
import { select } from 'd3';
import { log } from '../../logger.js';
import { getConfig } from '../../config.js';
import type { DrawDefinition } from '../../diagram-api/types.js';
import type { DrawDefinition, SVG } from '../../diagram-api/types.js';
/**
* Draws a an info picture in the tag with id: id based on the graph definition in text.
@ -13,20 +13,25 @@ import type { DrawDefinition } from '../../diagram-api/types.js';
*/
export const draw: DrawDefinition = (text, id, version) => {
try {
log.debug('Rendering info diagram\n' + text);
log.debug('rendering info diagram\n' + text);
const securityLevel = getConfig().securityLevel;
// Handle root and Document for when rendering in sandbox mode
let sandboxElement;
// handle root and document for when rendering in sandbox mode
let sandboxElement: SVG | undefined;
if (securityLevel === 'sandbox') {
sandboxElement = select('#i' + id);
}
const root =
securityLevel === 'sandbox'
? select(sandboxElement.nodes()[0].contentDocument.body)
: select('body');
let root;
if (securityLevel === 'sandbox' && sandboxElement !== undefined) {
root = select(sandboxElement.nodes()[0].contentDocument!.body);
} else {
root = select('body');
}
// @ts-ignore - TODO: figure out how to resolve this
const svg = root.select('#' + id);
svg.attr('height', 100);
svg.attr('width', 400);
const g = svg.append('g');
@ -37,9 +42,6 @@ export const draw: DrawDefinition = (text, id, version) => {
.attr('font-size', '32px')
.style('text-anchor', 'middle')
.text('v ' + version);
svg.attr('height', 100);
svg.attr('width', 400);
} catch (e) {
log.error('error while rendering info diagram', e);
}