Skip to content

Commit

Permalink
standardize info diagram definition
Browse files Browse the repository at this point in the history
* create types
* remove unnessery db attributes
* convert js files to ts
* remove empty styles.js
  • Loading branch information
Yokozuna59 committed Jun 12, 2023
1 parent 372b57d commit e6a48f8
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 77 deletions.
16 changes: 0 additions & 16 deletions packages/mermaid/src/diagrams/info/info.spec.js

This file was deleted.

24 changes: 24 additions & 0 deletions packages/mermaid/src/diagrams/info/info.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @ts-ignore Jison doesn't export types
import { parser } from './parser/info.jison';
import infoDb from './infoDb.js';

describe('info graph', () => {
beforeEach(() => {
parser.yy = infoDb;
parser.yy.clear();
});

it('should handle an info definition', () => {
const str = `info`;
parser.parse(str);

expect(infoDb.getInfo()).toBeFalsy();
});

it('should handle an info definition with showInfo', () => {
const str = `info showInfo`;
parser.parse(str);

expect(infoDb.getInfo()).toBeTruthy();
});
});
36 changes: 0 additions & 36 deletions packages/mermaid/src/diagrams/info/infoDb.js

This file was deleted.

19 changes: 19 additions & 0 deletions packages/mermaid/src/diagrams/info/infoDb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** Created by knut on 15-01-14. */
import { clear } from '../../commonDb.js';
import { InfoDb } from './infoTypes.js';

let info = false;

export const setInfo = (inf: boolean): void => {
info = inf;
};

export const getInfo = (): boolean => info;

const db: InfoDb = {
clear,
setInfo,
getInfo,
};

export default db;
9 changes: 4 additions & 5 deletions packages/mermaid/src/diagrams/info/infoDiagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { DiagramDefinition } from '../../diagram-api/types.js';
// @ts-ignore: TODO Fix ts errors
import parser from './parser/info.jison';
import db from './infoDb.js';
import styles from './styles.js';
import renderer from './infoRenderer.js';

export const diagram: DiagramDefinition = {
parser,
db,
renderer,
styles,
parser: parser,
db: db,
renderer: renderer,
styles: () => '',
};
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/** Created by knut on 14-12-11. */
// @ts-ignore - TODO: why
import { select } from 'd3';
import { log } from '../../logger.js';
import { getConfig } from '../../config.js';
import { DrawDefinition } from '../../diagram-api/types.js';

/**
* Draws a an info picture in the tag with id: id based on the graph definition in text.
*
* @param {any} text
* @param {any} id
* @param {any} version
* @param text - The text of the diagram.
* @param id - The id of the diagram which will be used as a DOM element id.
* @param version - MermaidJS version.
*/
export const draw = (text, id, version) => {
export const draw: DrawDefinition = (text, id, version) => {
try {
// const parser = infoParser.parser;
// parser.yy = db;
log.debug('Rendering info diagram\n' + text);

const securityLevel = getConfig().securityLevel;
Expand All @@ -27,10 +27,6 @@ export const draw = (text, id, version) => {
? select(sandboxElement.nodes()[0].contentDocument.body)
: select('body');

// Parse the graph definition
// parser.parse(text);
// log.debug('Parsed info diagram');
// Fetch the default direction, use TD if none was found
const svg = root.select('#' + id);

const g = svg.append('g');
Expand All @@ -45,13 +41,14 @@ export const draw = (text, id, version) => {

svg.attr('height', 100);
svg.attr('width', 400);
// svg.attr('viewBox', '0 0 300 150');
} catch (e) {
log.error('Error while rendering info diagram');
log.error(e.message);
if (e instanceof Error) {
log.error(e.message);
} else {
log.error('Unexpected error', e);
}
}
};

export default {
draw,
};
export default draw;
10 changes: 10 additions & 0 deletions packages/mermaid/src/diagrams/info/infoTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { DiagramDb } from '../../diagram-api/types.js';

/**
* Info diagram DB.
*/
export interface InfoDb extends DiagramDb {
clear: () => void;
setInfo: (info: boolean) => void;
getInfo: () => boolean;
}
3 changes: 0 additions & 3 deletions packages/mermaid/src/diagrams/info/styles.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/mermaid/src/styles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import er from './diagrams/er/styles.js';
import error from './diagrams/error/styles.js';
import git from './diagrams/git/styles.js';
import gantt from './diagrams/gantt/styles.js';
import info from './diagrams/info/styles.js';
import pie from './diagrams/pie/styles.js';
import requirement from './diagrams/requirement/styles.js';
import sequence from './diagrams/sequence/styles.js';
Expand Down Expand Up @@ -92,7 +91,6 @@ describe('styles', () => {
flowchartElk,
gantt,
git,
info,
journey,
mindmap,
pie,
Expand Down

0 comments on commit e6a48f8

Please sign in to comment.