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 - * @param type -
*/ */
export type ParseDirectiveDefinition = (statement: string, context: string, type: string) => void; 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 { select } from 'd3';
import { log } from '../../logger.js'; import { log } from '../../logger.js';
import { getConfig } from '../../config.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. * 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) => { export const draw: DrawDefinition = (text, id, version) => {
try { try {
log.debug('Rendering info diagram\n' + text); log.debug('rendering info diagram\n' + text);
const securityLevel = getConfig().securityLevel; const securityLevel = getConfig().securityLevel;
// Handle root and Document for when rendering in sandbox mode // handle root and document for when rendering in sandbox mode
let sandboxElement; let sandboxElement: SVG | undefined;
if (securityLevel === 'sandbox') { if (securityLevel === 'sandbox') {
sandboxElement = select('#i' + id); sandboxElement = select('#i' + id);
} }
const root = let root;
securityLevel === 'sandbox' if (securityLevel === 'sandbox' && sandboxElement !== undefined) {
? select(sandboxElement.nodes()[0].contentDocument.body) root = select(sandboxElement.nodes()[0].contentDocument!.body);
: select('body'); } else {
root = select('body');
}
// @ts-ignore - TODO: figure out how to resolve this
const svg = root.select('#' + id); const svg = root.select('#' + id);
svg.attr('height', 100);
svg.attr('width', 400);
const g = svg.append('g'); const g = svg.append('g');
@@ -37,9 +42,6 @@ export const draw: DrawDefinition = (text, id, version) => {
.attr('font-size', '32px') .attr('font-size', '32px')
.style('text-anchor', 'middle') .style('text-anchor', 'middle')
.text('v ' + version); .text('v ' + version);
svg.attr('height', 100);
svg.attr('width', 400);
} catch (e) { } catch (e) {
log.error('error while rendering info diagram', e); log.error('error while rendering info diagram', e);
} }