Revert state diagram class based architecture

This commit is contained in:
Saurabh Gore 2025-01-24 19:20:40 +05:30
parent c13d988392
commit cd9ca76e39
10 changed files with 581 additions and 692 deletions

View File

@ -1,4 +1,4 @@
import { StateDB } from '../stateDb.js';
import stateDb from '../stateDb.js';
import stateDiagram from './stateDiagram.jison';
import { setConfig } from '../../../config.js';
@ -7,9 +7,7 @@ setConfig({
});
describe('state parser can parse...', () => {
let stateDb;
beforeEach(function () {
stateDb = new StateDB();
stateDiagram.parser.yy = stateDb;
stateDiagram.parser.yy.clear();
});

View File

@ -1,4 +1,4 @@
import { StateDB } from '../stateDb.js';
import stateDb from '../stateDb.js';
import stateDiagram from './stateDiagram.jison';
import { setConfig } from '../../../config.js';
@ -7,9 +7,7 @@ setConfig({
});
describe('ClassDefs and classes when parsing a State diagram', () => {
let stateDb;
beforeEach(function () {
stateDb = new StateDB();
stateDiagram.parser.yy = stateDb;
stateDiagram.parser.yy.clear();
});

View File

@ -1,6 +1,6 @@
import { line, curveBasis } from 'd3';
import idCache from './id-cache.js';
import { StateDB } from './stateDb.js';
import stateDb from './stateDb.js';
import utils from '../../utils.js';
import common from '../common/common.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';
@ -414,13 +414,13 @@ let edgeCount = 0;
export const drawEdge = function (elem, path, relation) {
const getRelationType = function (type) {
switch (type) {
case StateDB.relationType.AGGREGATION:
case stateDb.relationType.AGGREGATION:
return 'aggregation';
case StateDB.relationType.EXTENSION:
case stateDb.relationType.EXTENSION:
return 'extension';
case StateDB.relationType.COMPOSITION:
case stateDb.relationType.COMPOSITION:
return 'composition';
case StateDB.relationType.DEPENDENCY:
case stateDb.relationType.DEPENDENCY:
return 'dependency';
}
};
@ -459,7 +459,7 @@ export const drawEdge = function (elem, path, relation) {
svgPath.attr(
'marker-end',
'url(' + url + '#' + getRelationType(StateDB.relationType.DEPENDENCY) + 'End' + ')'
'url(' + url + '#' + getRelationType(stateDb.relationType.DEPENDENCY) + 'End' + ')'
);
if (relation.title !== undefined) {

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,8 @@
import { StateDB } from './stateDb.js';
import stateDb from './stateDb.js';
describe('State Diagram stateDb', () => {
let stateDb;
beforeEach(() => {
stateDb = new StateDB();
stateDb.clear();
});
describe('addStyleClass', () => {
@ -21,9 +20,8 @@ describe('State Diagram stateDb', () => {
});
describe('addDescription to a state', () => {
let stateDb;
beforeEach(() => {
stateDb = new StateDB();
stateDb.clear();
stateDb.addState('state1');
});
@ -75,25 +73,3 @@ describe('State Diagram stateDb', () => {
});
});
});
describe('state db class', () => {
let stateDb;
beforeEach(() => {
stateDb = new StateDB();
});
// This is to ensure that functions used in state JISON are exposed as function from StateDb
it('should have functions used in flow JISON as own property', () => {
const functionsUsedInParser = [
'setRootDoc',
'trimColon',
'getDividerId',
'setAccTitle',
'setAccDescription',
'setDirection',
];
for (const fun of functionsUsedInParser) {
expect(Object.hasOwn(stateDb, fun)).toBe(true);
}
});
});

View File

@ -1,13 +1,11 @@
import { parser } from './parser/stateDiagram.jison';
import { StateDB } from './stateDb.js';
import stateDb from './stateDb.js';
import stateDiagram from './parser/stateDiagram.jison';
describe('state diagram V2, ', function () {
// TODO - these examples should be put into ./parser/stateDiagram.spec.js
describe('when parsing an info graph it', function () {
let stateDb;
beforeEach(function () {
stateDb = new StateDB();
parser.yy = stateDb;
stateDiagram.parser.yy = stateDb;
stateDiagram.parser.yy.clear();

View File

@ -1,15 +1,13 @@
import type { DiagramDefinition } from '../../diagram-api/types.js';
// @ts-ignore: JISON doesn't support types
import parser from './parser/stateDiagram.jison';
import { StateDB } from './stateDb.js';
import db from './stateDb.js';
import styles from './styles.js';
import renderer from './stateRenderer-v3-unified.js';
export const diagram: DiagramDefinition = {
parser,
get db() {
return new StateDB();
},
db,
renderer,
styles,
init: (cnf) => {

View File

@ -1,11 +1,9 @@
import { parser } from './parser/stateDiagram.jison';
import { StateDB } from './stateDb.js';
import stateDb from './stateDb.js';
describe('state diagram, ', function () {
describe('when parsing an info graph it', function () {
let stateDb;
beforeEach(function () {
stateDb = new StateDB();
parser.yy = stateDb;
});

View File

@ -1,15 +1,13 @@
import type { DiagramDefinition } from '../../diagram-api/types.js';
// @ts-ignore: JISON doesn't support types
import parser from './parser/stateDiagram.jison';
import { StateDB } from './stateDb.js';
import db from './stateDb.js';
import styles from './styles.js';
import renderer from './stateRenderer.js';
export const diagram: DiagramDefinition = {
parser,
get db() {
return new StateDB();
},
db,
renderer,
styles,
init: (cnf) => {

View File

@ -837,32 +837,6 @@ graph TD;A--x|text including URL space|B;`)
});
it('should not modify db when rendering different diagrams', async () => {
const stateDiagram1 = await mermaidAPI.getDiagramFromText(
`stateDiagram
direction LR
[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]`
);
const stateDiagram2 = await mermaidAPI.getDiagramFromText(
`stateDiagram
direction TB
[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]`
);
// Since stateDiagram will return new Db object each time, we can compare the db to be different.
expect(stateDiagram1.db).not.toBe(stateDiagram2.db);
assert(stateDiagram1.db instanceof StateDB);
assert(stateDiagram2.db instanceof StateDB);
expect(stateDiagram1.db.getDirection()).not.toEqual(stateDiagram2.db.getDirection());
const flowDiagram1 = await mermaidAPI.getDiagramFromText(
`flowchart LR
A -- text --> B -- text2 --> C`