mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-09 00:59:37 +02:00
#1031 Adding stricter code checks
This commit is contained in:
@@ -2,7 +2,7 @@ import * as d3 from 'd3';
|
||||
import idCache from './id-cache.js';
|
||||
import stateDb from './stateDb';
|
||||
import utils from '../../utils';
|
||||
import { getConfig, conf } from '../../config';
|
||||
import { getConfig } from '../../config';
|
||||
|
||||
// let conf;
|
||||
|
||||
@@ -131,15 +131,15 @@ export const drawDescrState = (g, stateDef) => {
|
||||
*/
|
||||
export const addIdAndBox = (g, stateDef) => {
|
||||
// TODO Move hardcodings to conf
|
||||
const addTspan = function(textEl, txt, isFirst) {
|
||||
const tSpan = textEl
|
||||
.append('tspan')
|
||||
.attr('x', 2 * getConfig().state.padding)
|
||||
.text(txt);
|
||||
if (!isFirst) {
|
||||
tSpan.attr('dy', getConfig().state.textHeight);
|
||||
}
|
||||
};
|
||||
// const addTspan = function(textEl, txt, isFirst) {
|
||||
// const tSpan = textEl
|
||||
// .append('tspan')
|
||||
// .attr('x', 2 * getConfig().state.padding)
|
||||
// .text(txt);
|
||||
// if (!isFirst) {
|
||||
// tSpan.attr('dy', getConfig().state.textHeight);
|
||||
// }
|
||||
// };
|
||||
const title = g
|
||||
.append('text')
|
||||
.attr('x', 2 * getConfig().state.padding)
|
||||
@@ -148,7 +148,7 @@ export const addIdAndBox = (g, stateDef) => {
|
||||
.attr('class', 'state-title')
|
||||
.text(stateDef.id);
|
||||
|
||||
const titleHeight = title.node().getBBox().height;
|
||||
const titleBox = title.node().getBBox();
|
||||
|
||||
const lineY = 1 - getConfig().state.textHeight;
|
||||
const descrLine = g
|
||||
@@ -159,7 +159,7 @@ export const addIdAndBox = (g, stateDef) => {
|
||||
.attr('class', 'descr-divider');
|
||||
|
||||
const graphBox = g.node().getBBox();
|
||||
title.attr('x', graphBox.width / 2 - title.node().getBBox().width / 2);
|
||||
title.attr('x', graphBox.width / 2 - titleBox.width / 2);
|
||||
descrLine.attr('x2', graphBox.width + getConfig().state.padding);
|
||||
|
||||
// White color
|
||||
@@ -241,7 +241,7 @@ const drawForkJoinState = (g, stateDef) => {
|
||||
.attr('y', getConfig().state.padding);
|
||||
};
|
||||
|
||||
export const drawText = function(elem, textData, width) {
|
||||
export const drawText = function(elem, textData) {
|
||||
// Remove and ignore br:s
|
||||
const nText = textData.text.replace(/<br\/?>/gi, ' ');
|
||||
|
||||
@@ -264,7 +264,7 @@ export const drawText = function(elem, textData, width) {
|
||||
|
||||
const _drawLongText = (_text, x, y, g) => {
|
||||
let textHeight = 0;
|
||||
let textWidth = 0;
|
||||
|
||||
const textElem = g.append('text');
|
||||
textElem.style('text-anchor', 'start');
|
||||
textElem.attr('class', 'noteText');
|
||||
@@ -317,8 +317,7 @@ export const drawNote = (text, g) => {
|
||||
* @param {*} stateDef
|
||||
*/
|
||||
|
||||
let cnt = 0;
|
||||
export const drawState = function(elem, stateDef, graph, doc) {
|
||||
export const drawState = function(elem, stateDef) {
|
||||
const id = stateDef.id;
|
||||
const stateInfo = {
|
||||
id: id,
|
||||
|
@@ -9,7 +9,7 @@ const setRootDoc = o => {
|
||||
const getRootDoc = () => rootDoc;
|
||||
|
||||
const extract = doc => {
|
||||
const res = { states: [], relations: [] };
|
||||
// const res = { states: [], relations: [] };
|
||||
clear();
|
||||
|
||||
doc.forEach(item => {
|
||||
@@ -37,8 +37,8 @@ let documents = {
|
||||
let currentDocument = documents.root;
|
||||
|
||||
let startCnt = 0;
|
||||
let endCnt = 0;
|
||||
let stateCnt = 0;
|
||||
let endCnt = 0; // eslint-disable-line
|
||||
// let stateCnt = 0;
|
||||
|
||||
/**
|
||||
* Function called by parser when a node definition has been found.
|
||||
|
@@ -4,15 +4,12 @@ import graphlib from 'graphlib';
|
||||
import { logger } from '../../logger';
|
||||
import stateDb from './stateDb';
|
||||
import { parser } from './parser/stateDiagram';
|
||||
import utils from '../../utils';
|
||||
import idCache from './id-cache';
|
||||
import { drawState, addIdAndBox, drawEdge, drawNote } from './shapes';
|
||||
// import idCache from './id-cache';
|
||||
import { drawState, addIdAndBox, drawEdge } from './shapes';
|
||||
import { getConfig } from '../../config';
|
||||
|
||||
parser.yy = stateDb;
|
||||
|
||||
let total = 0;
|
||||
|
||||
// TODO Move conf object to main conf in mermaidAPI
|
||||
let conf;
|
||||
// {
|
||||
@@ -28,20 +25,20 @@ let conf;
|
||||
|
||||
const transformationLog = {};
|
||||
|
||||
export const setConf = function(cnf) {};
|
||||
export const setConf = function() {};
|
||||
|
||||
// Todo optimize
|
||||
const getGraphId = function(label) {
|
||||
const keys = idCache.keys();
|
||||
// const getGraphId = function(label) {
|
||||
// const keys = idCache.keys();
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
if (idCache.get(keys[i]).label === label) {
|
||||
return keys[i];
|
||||
}
|
||||
}
|
||||
// for (let i = 0; i < keys.length; i++) {
|
||||
// if (idCache.get(keys[i]).label === label) {
|
||||
// return keys[i];
|
||||
// }
|
||||
// }
|
||||
|
||||
return undefined;
|
||||
};
|
||||
// return undefined;
|
||||
// };
|
||||
|
||||
/**
|
||||
* Setup arrow head and define the marker. The result is appended to the svg.
|
||||
@@ -90,7 +87,7 @@ export const draw = function(text, id) {
|
||||
});
|
||||
|
||||
const rootDoc = stateDb.getRootDoc();
|
||||
const n = renderDoc(rootDoc, diagram);
|
||||
renderDoc(rootDoc, diagram);
|
||||
|
||||
const bounds = diagram.node().getBBox();
|
||||
|
||||
@@ -129,7 +126,6 @@ const renderDoc = (doc, diagram, parentId) => {
|
||||
// multigraph: false,
|
||||
compound: true,
|
||||
// acyclicer: 'greedy',
|
||||
rankdir: 'LR',
|
||||
ranker: 'tight-tree',
|
||||
ranksep: conf.edgeLengthFactor
|
||||
// isMultiGraph: false
|
||||
@@ -159,7 +155,6 @@ const renderDoc = (doc, diagram, parentId) => {
|
||||
|
||||
const keys = Object.keys(states);
|
||||
|
||||
total = keys.length;
|
||||
let first = true;
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
|
Reference in New Issue
Block a user