mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-15 06:19:24 +02:00
Introduce stricter linting
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
dist/**
|
||||
.github/**
|
||||
docs/Setup.md
|
||||
cypress.config.js
|
||||
cypress/plugins/index.js
|
||||
|
@@ -5,7 +5,7 @@
|
||||
"jest/globals": true,
|
||||
"node": true
|
||||
},
|
||||
"parser": "@babel/eslint-parser",
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaFeatures": {
|
||||
"experimentalObjectRestSpread": true,
|
||||
@@ -15,12 +15,13 @@
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:jsdoc/recommended",
|
||||
"plugin:json/recommended",
|
||||
"plugin:markdown/recommended",
|
||||
"plugin:prettier/recommended"
|
||||
],
|
||||
"plugins": ["html", "jest", "jsdoc", "json", "prettier"],
|
||||
"plugins": ["@typescript-eslint", "html", "jest", "jsdoc", "json", "prettier"],
|
||||
"rules": {
|
||||
"no-prototype-builtins": "off",
|
||||
"no-unused-vars": "off",
|
||||
@@ -31,6 +32,16 @@
|
||||
"jsdoc/newline-after-description": "off",
|
||||
"jsdoc/tag-lines": "off",
|
||||
"cypress/no-async-tests": "off",
|
||||
"@typescript-eslint/ban-ts-comment": [
|
||||
"error",
|
||||
{
|
||||
"ts-expect-error": "allow-with-description",
|
||||
"ts-ignore": "allow-with-description",
|
||||
"ts-nocheck": "allow-with-description",
|
||||
"ts-check": "allow-with-description",
|
||||
"minimumDescriptionLength": 10
|
||||
}
|
||||
],
|
||||
"json/*": ["error", "allowComments"],
|
||||
"no-empty": ["error", { "allowEmptyCatch": true }]
|
||||
},
|
||||
|
2
cypress/support/eyes-index.d.ts
vendored
2
cypress/support/eyes-index.d.ts
vendored
@@ -1 +1 @@
|
||||
import "@applitools/eyes-cypress"
|
||||
import '@applitools/eyes-cypress';
|
||||
|
@@ -1087,7 +1087,9 @@ Enterprise_Boundary(b0, "BankBoundary0") {
|
||||
<script>
|
||||
const testLineEndings = (test, input) => {
|
||||
try {
|
||||
mermaid.render(test, input, () => {});
|
||||
mermaid.render(test, input, () => {
|
||||
//no-op
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Error in %s:\n\n%s', test, err);
|
||||
}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const path = require('path');
|
||||
|
||||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
||||
|
@@ -29,7 +29,7 @@
|
||||
"postbuild": "documentation build src/mermaidAPI.ts src/config.ts src/defaultConfig.ts --shallow -f md --markdown-toc false > docs/Setup.md",
|
||||
"build:watch": "yarn build:dev --watch",
|
||||
"release": "yarn build",
|
||||
"lint": "eslint --cache ./ --ext .js,.json,.html,.md",
|
||||
"lint": "eslint --cache ./ --ext .js,.json,.html,.md,.ts",
|
||||
"lint:fix": "yarn lint --fix",
|
||||
"e2e:depr": "yarn lint && jest e2e --config e2e/jest.config.js",
|
||||
"cypress": "cypress run",
|
||||
@@ -83,6 +83,8 @@
|
||||
"@types/dompurify": "^2.3.3",
|
||||
"@types/jest": "^28.1.7",
|
||||
"@types/stylis": "^4.0.2",
|
||||
"@typescript-eslint/eslint-plugin": "^5.36.1",
|
||||
"@typescript-eslint/parser": "^5.36.1",
|
||||
"babel-jest": "^29.0.1",
|
||||
"babel-loader": "^8.2.2",
|
||||
"concurrently": "^7.0.0",
|
||||
|
@@ -8,6 +8,7 @@ export class Diagram {
|
||||
parser;
|
||||
renderer;
|
||||
db;
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
constructor(public txt: string, parseError?: Function) {
|
||||
const cnf = configApi.getConfig();
|
||||
this.txt = txt;
|
||||
@@ -33,6 +34,7 @@ export class Diagram {
|
||||
this.parse(this.txt, parseError);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
parse(text: string, parseError?: Function): boolean {
|
||||
try {
|
||||
text = text + '\n';
|
||||
|
@@ -62,9 +62,9 @@ export const setSiteConfig = (conf: MermaidConfig): MermaidConfig => {
|
||||
siteConfig = assignWithDepth({}, defaultConfig);
|
||||
siteConfig = assignWithDepth(siteConfig, conf);
|
||||
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
if (conf.theme && theme[conf.theme]) {
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
siteConfig.themeVariables = theme[conf.theme].getThemeVariables(conf.themeVariables);
|
||||
}
|
||||
|
||||
@@ -216,6 +216,8 @@ export const addDirective = (directive: any) => {
|
||||
* | conf | base set of values, which currentConfig could be **reset** to. | Dictionary | Required | Any Values, with respect to the secure Array |
|
||||
*
|
||||
* **Notes**: (default: current siteConfig ) (optional, default `getSiteConfig()`)
|
||||
*
|
||||
* @param config
|
||||
*/
|
||||
export const reset = (config = siteConfig): void => {
|
||||
// Replace current config with siteConfig
|
||||
|
@@ -212,7 +212,7 @@ export interface RequirementDiagramConfig extends BaseDiagramConfig {
|
||||
line_height?: number;
|
||||
}
|
||||
|
||||
export interface PieDiagramConfig extends BaseDiagramConfig {}
|
||||
export type PieDiagramConfig = BaseDiagramConfig;
|
||||
|
||||
export interface ErDiagramConfig extends BaseDiagramConfig {
|
||||
diagramPadding?: number;
|
||||
|
@@ -6,7 +6,7 @@ import { registerDiagram } from './diagramAPI';
|
||||
|
||||
import gitGraphDb from '../diagrams/git/gitGraphAst';
|
||||
import gitGraphRenderer from '../diagrams/git/gitGraphRenderer';
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
import gitGraphParser from '../diagrams/git/parser/gitGraph';
|
||||
import { gitGraphDetector } from '../diagrams/git/gitGraphDetector';
|
||||
|
||||
|
@@ -1,49 +1,49 @@
|
||||
import c4Db from '../diagrams/c4/c4Db';
|
||||
import c4Renderer from '../diagrams/c4/c4Renderer';
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
import c4Parser from '../diagrams/c4/parser/c4Diagram';
|
||||
import classDb from '../diagrams/class/classDb';
|
||||
import classRenderer from '../diagrams/class/classRenderer';
|
||||
import classRendererV2 from '../diagrams/class/classRenderer-v2';
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
import classParser from '../diagrams/class/parser/classDiagram';
|
||||
import erDb from '../diagrams/er/erDb';
|
||||
import erRenderer from '../diagrams/er/erRenderer';
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
import erParser from '../diagrams/er/parser/erDiagram';
|
||||
import flowDb from '../diagrams/flowchart/flowDb';
|
||||
import flowRenderer from '../diagrams/flowchart/flowRenderer';
|
||||
import flowRendererV2 from '../diagrams/flowchart/flowRenderer-v2';
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
import flowParser from '../diagrams/flowchart/parser/flow';
|
||||
import ganttDb from '../diagrams/gantt/ganttDb';
|
||||
import ganttRenderer from '../diagrams/gantt/ganttRenderer';
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
import ganttParser from '../diagrams/gantt/parser/gantt';
|
||||
import infoDb from '../diagrams/info/infoDb';
|
||||
import infoRenderer from '../diagrams/info/infoRenderer';
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
import infoParser from '../diagrams/info/parser/info';
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
import pieParser from '../diagrams/pie/parser/pie';
|
||||
import pieDb from '../diagrams/pie/pieDb';
|
||||
import pieRenderer from '../diagrams/pie/pieRenderer';
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
import requirementParser from '../diagrams/requirement/parser/requirementDiagram';
|
||||
import requirementDb from '../diagrams/requirement/requirementDb';
|
||||
import requirementRenderer from '../diagrams/requirement/requirementRenderer';
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
import sequenceParser from '../diagrams/sequence/parser/sequenceDiagram';
|
||||
import sequenceDb from '../diagrams/sequence/sequenceDb';
|
||||
import sequenceRenderer from '../diagrams/sequence/sequenceRenderer';
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
import stateParser from '../diagrams/state/parser/stateDiagram';
|
||||
import stateDb from '../diagrams/state/stateDb';
|
||||
import stateRenderer from '../diagrams/state/stateRenderer';
|
||||
import stateRendererV2 from '../diagrams/state/stateRenderer-v2';
|
||||
import journeyDb from '../diagrams/user-journey/journeyDb';
|
||||
import journeyRenderer from '../diagrams/user-journey/journeyRenderer';
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
import journeyParser from '../diagrams/user-journey/parser/journey';
|
||||
import { addDetector, DiagramDetector } from './detectType';
|
||||
import { log } from '../logger';
|
||||
|
@@ -1,3 +1,4 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const fs = require('fs');
|
||||
|
||||
import { LALRGenerator } from 'jison';
|
||||
|
@@ -173,7 +173,9 @@ export const getCommits = () => {
|
||||
},
|
||||
};
|
||||
};
|
||||
export const clear = () => {};
|
||||
export const clear = () => {
|
||||
//no-op
|
||||
};
|
||||
export const getBranchesAsObjArray = () => [
|
||||
{
|
||||
name: 'master',
|
||||
|
@@ -1,12 +1,14 @@
|
||||
import { parser } from './parser/info';
|
||||
import infoDb from './infoDb';
|
||||
describe('when parsing an info graph it', function () {
|
||||
var ex;
|
||||
let ex;
|
||||
beforeEach(function () {
|
||||
ex = require('./parser/info').parser;
|
||||
ex.yy = require('./infoDb');
|
||||
ex = parser;
|
||||
ex.yy = infoDb;
|
||||
});
|
||||
|
||||
it('should handle an info definition', function () {
|
||||
var str = `info
|
||||
let str = `info
|
||||
showInfo`;
|
||||
|
||||
ex.parse(str);
|
||||
|
@@ -1,6 +1,7 @@
|
||||
describe('when parsing an info graph it', function () {
|
||||
var ex;
|
||||
beforeEach(function () {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
ex = require('./parser/info').parser;
|
||||
ex.yy = require('./infoDb');
|
||||
});
|
||||
|
@@ -95,6 +95,7 @@ export const bounds = {
|
||||
}
|
||||
},
|
||||
updateBounds: function (startx, starty, stopx, stopy) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||
const _self = this;
|
||||
let cnt = 0;
|
||||
/** @param {any} type */
|
||||
@@ -653,7 +654,7 @@ export const draw = function (_text, id, _version, diagObj) {
|
||||
// Draw the messages/signals
|
||||
let sequenceIndex = 1;
|
||||
let sequenceIndexStep = 1;
|
||||
let messagesToDraw = Array();
|
||||
let messagesToDraw = [];
|
||||
messages.forEach(function (msg) {
|
||||
let loopModel, noteModel, msgModel;
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
const svgDraw = require('./svgDraw').default;
|
||||
const { MockD3 } = require('d3');
|
||||
import svgDraw from './svgDraw';
|
||||
import { MockD3 } from 'd3';
|
||||
|
||||
describe('svgDraw', function () {
|
||||
describe('drawRect', function () {
|
||||
|
@@ -13,7 +13,9 @@ let conf;
|
||||
|
||||
const transformationLog = {};
|
||||
|
||||
export const setConf = function () {};
|
||||
export const setConf = function () {
|
||||
//no-op
|
||||
};
|
||||
|
||||
/**
|
||||
* Setup arrow head and define the marker. The result is appended to the svg.
|
||||
|
@@ -151,6 +151,7 @@ export const bounds = {
|
||||
},
|
||||
updateBounds: function (startx, starty, stopx, stopy) {
|
||||
const conf = getConfig().journey;
|
||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||
const _self = this;
|
||||
let cnt = 0;
|
||||
/** @param {any} type */
|
||||
|
@@ -1,5 +1,5 @@
|
||||
let interactionFunctions: (() => {})[] = [];
|
||||
export const addFunction = (func: () => {}) => {
|
||||
let interactionFunctions: (() => void)[] = [];
|
||||
export const addFunction = (func: () => void) => {
|
||||
interactionFunctions.push(func);
|
||||
};
|
||||
export const attachFunctions = () => {
|
||||
|
@@ -1,3 +1,4 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const { Generator } = require('jison');
|
||||
|
||||
module.exports = {
|
||||
|
@@ -1,3 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
/* eslint-disable @typescript-eslint/no-empty-function */
|
||||
import moment from 'moment-mini';
|
||||
|
||||
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
||||
|
@@ -30,10 +30,15 @@ import { isDetailedError } from './utils';
|
||||
* ```
|
||||
*
|
||||
* Renders the mermaid diagrams
|
||||
*
|
||||
* @param config
|
||||
* @param nodes
|
||||
* @param callback
|
||||
*/
|
||||
const init = function (
|
||||
config?: MermaidConfig,
|
||||
nodes?: string | HTMLElement | NodeListOf<HTMLElement>,
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
callback?: Function
|
||||
) {
|
||||
try {
|
||||
@@ -52,13 +57,14 @@ const init = function (
|
||||
const initThrowsErrors = function (
|
||||
config?: MermaidConfig,
|
||||
nodes?: string | HTMLElement | NodeListOf<HTMLElement>,
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
callback?: Function
|
||||
) {
|
||||
const conf = mermaidAPI.getConfig();
|
||||
// console.log('Starting rendering diagrams (init) - mermaid.init', conf);
|
||||
if (config) {
|
||||
// This is a legacy way of setting config. It is not documented and should be removed in the future.
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
mermaid.sequenceConfig = config;
|
||||
}
|
||||
|
||||
@@ -126,7 +132,7 @@ const initThrowsErrors = function (
|
||||
);
|
||||
} catch (error) {
|
||||
log.warn('Catching Error (bootstrap)');
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
// TODO: We should be throwing an error object.
|
||||
throw { error, message: error.str };
|
||||
}
|
||||
@@ -188,6 +194,7 @@ const parse = (txt: string) => {
|
||||
const mermaid: {
|
||||
startOnLoad: boolean;
|
||||
diagrams: any;
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
parseError?: Function;
|
||||
mermaidAPI: typeof mermaidAPI;
|
||||
parse: typeof parse;
|
||||
|
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
import { select } from 'd3';
|
||||
import { compile, serialize, stringify } from 'stylis';
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
import pkg from '../package.json';
|
||||
import * as configApi from './config';
|
||||
import { addDiagrams } from './diagram-api/diagram-orchestration';
|
||||
@@ -38,6 +38,11 @@ import { evaluate } from './diagrams/common/common';
|
||||
|
||||
let hasLoadedDiagrams = false;
|
||||
|
||||
/**
|
||||
* @param text
|
||||
* @param parseError
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
function parse(text: string, parseError?: Function): boolean {
|
||||
if (!hasLoadedDiagrams) {
|
||||
addDiagrams();
|
||||
@@ -126,7 +131,7 @@ const render = function (
|
||||
directiveSanitizer(graphInit);
|
||||
configApi.addDirective(graphInit);
|
||||
}
|
||||
let cnf = configApi.getConfig();
|
||||
const cnf = configApi.getConfig();
|
||||
|
||||
log.debug(cnf);
|
||||
|
||||
@@ -319,8 +324,8 @@ const render = function (
|
||||
svgCode = svgCode.replace(/<br>/g, '<br/>');
|
||||
|
||||
if (cnf.securityLevel === 'sandbox') {
|
||||
let svgEl = root.select('#d' + id + ' svg').node();
|
||||
let width = '100%';
|
||||
const svgEl = root.select('#d' + id + ' svg').node();
|
||||
const width = '100%';
|
||||
let height = '100%';
|
||||
if (svgEl) {
|
||||
height = svgEl.viewBox.baseVal.height + 'px';
|
||||
@@ -397,7 +402,7 @@ const parseDirective = function (p: any, statement: string, context: string, typ
|
||||
log.error(
|
||||
`Error while rendering sequenceDiagram directive: ${statement} jison context: ${context}`
|
||||
);
|
||||
// @ts-ignore
|
||||
// @ts-ignore: TODO Fix ts errors
|
||||
log.error(error.message);
|
||||
}
|
||||
};
|
||||
|
@@ -45,7 +45,7 @@ const getStyles = (
|
||||
lineColor: string;
|
||||
} & FlowChartStyleOptions
|
||||
) => {
|
||||
let diagramStyles: string = '';
|
||||
let diagramStyles = '';
|
||||
if (type in themes && themes[type as keyof typeof themes]) {
|
||||
diagramStyles = themes[type as keyof typeof themes](options);
|
||||
} else {
|
||||
|
76
src/utils.ts
76
src/utils.ts
@@ -1,4 +1,4 @@
|
||||
// @ts-nocheck
|
||||
// @ts-nocheck: TODO Fix ts errors
|
||||
import { sanitizeUrl } from '@braintree/sanitize-url';
|
||||
import {
|
||||
curveBasis,
|
||||
@@ -43,17 +43,19 @@ const anyComment = /\s*%%.*\n/gm;
|
||||
|
||||
/**
|
||||
* @function detectInit Detects the init config object from the text
|
||||
* @param config
|
||||
*
|
||||
* ```mermaid
|
||||
*
|
||||
* %%{init: {"theme": "debug", "logLevel": 1 }}%%
|
||||
* graph LR
|
||||
* a-->b
|
||||
* b-->c
|
||||
* c-->d
|
||||
* d-->e
|
||||
* e-->f
|
||||
* f-->g
|
||||
* g-->h
|
||||
* a-->b
|
||||
* b-->c
|
||||
* c-->d
|
||||
* d-->e
|
||||
* e-->f
|
||||
* f-->g
|
||||
* g-->h
|
||||
* ```
|
||||
*
|
||||
* Or
|
||||
@@ -74,11 +76,11 @@ const anyComment = /\s*%%.*\n/gm;
|
||||
* @returns {object} The json object representing the init passed to mermaid.initialize()
|
||||
*/
|
||||
export const detectInit = function (text: string, config?: MermaidConfig): MermaidConfig {
|
||||
let inits = detectDirective(text, /(?:init\b)|(?:initialize\b)/);
|
||||
const inits = detectDirective(text, /(?:init\b)|(?:initialize\b)/);
|
||||
let results = {};
|
||||
|
||||
if (Array.isArray(inits)) {
|
||||
let args = inits.map((init) => init.args);
|
||||
const args = inits.map((init) => init.args);
|
||||
directiveSanitizer(args);
|
||||
|
||||
results = assignWithDepth(results, [...args]);
|
||||
@@ -133,8 +135,8 @@ export const detectDirective = function (text, type = null) {
|
||||
log.debug(
|
||||
`Detecting diagram directive${type !== null ? ' type:' + type : ''} based on the text:${text}`
|
||||
);
|
||||
let match,
|
||||
result = [];
|
||||
let match;
|
||||
const result = [];
|
||||
while ((match = directive.exec(text)) !== null) {
|
||||
// This is necessary to avoid infinite loops with zero-width matches
|
||||
if (match.index === directive.lastIndex) {
|
||||
@@ -145,8 +147,8 @@ export const detectDirective = function (text, type = null) {
|
||||
(type && match[1] && match[1].match(type)) ||
|
||||
(type && match[2] && match[2].match(type))
|
||||
) {
|
||||
let type = match[1] ? match[1] : match[2];
|
||||
let args = match[3] ? match[3].trim() : match[4] ? JSON.parse(match[4].trim()) : null;
|
||||
const type = match[1] ? match[1] : match[2];
|
||||
const args = match[3] ? match[3].trim() : match[4] ? JSON.parse(match[4].trim()) : null;
|
||||
result.push({ type, args });
|
||||
}
|
||||
}
|
||||
@@ -172,13 +174,13 @@ export const detectDirective = function (text, type = null) {
|
||||
* @returns {Function} An optimized caching function
|
||||
*/
|
||||
const memoize = (fn, resolver) => {
|
||||
let cache = {};
|
||||
const cache = {};
|
||||
return (...args) => {
|
||||
let n = resolver ? resolver.apply(this, args) : args[0];
|
||||
const n = resolver ? resolver.apply(this, args) : args[0];
|
||||
if (n in cache) {
|
||||
return cache[n];
|
||||
} else {
|
||||
let result = fn(...args);
|
||||
const result = fn(...args);
|
||||
cache[n] = result;
|
||||
return result;
|
||||
}
|
||||
@@ -221,7 +223,7 @@ export const interpolateToCurve = (interpolate, defaultCurve) => {
|
||||
* @returns {string | undefined} The formatted URL
|
||||
*/
|
||||
export const formatUrl = (linkStr, config) => {
|
||||
let url = linkStr.trim();
|
||||
const url = linkStr.trim();
|
||||
|
||||
if (url) {
|
||||
if (config.securityLevel !== 'loose') {
|
||||
@@ -364,10 +366,10 @@ const calcCardinalityPosition = (isRelationTypePresent, points, initialPosition)
|
||||
prevPoint = point;
|
||||
});
|
||||
// if relation is present (Arrows will be added), change cardinality point off-set distance (d)
|
||||
let d = isRelationTypePresent ? 10 : 5;
|
||||
const d = isRelationTypePresent ? 10 : 5;
|
||||
//Calculate Angle for x and y axis
|
||||
let angle = Math.atan2(points[0].y - center.y, points[0].x - center.x);
|
||||
let cardinalityPosition = { x: 0, y: 0 };
|
||||
const angle = Math.atan2(points[0].y - center.y, points[0].x - center.x);
|
||||
const cardinalityPosition = { x: 0, y: 0 };
|
||||
//Calculation cardinality position using angle, center point on the line/curve but pendicular and with offset-distance
|
||||
cardinalityPosition.x = Math.sin(angle) * d + (points[0].x + center.x) / 2;
|
||||
cardinalityPosition.y = -Math.cos(angle) * d + (points[0].y + center.y) / 2;
|
||||
@@ -425,11 +427,11 @@ const calcTerminalLabelPosition = (terminalMarkerSize, position, _points) => {
|
||||
prevPoint = point;
|
||||
});
|
||||
// if relation is present (Arrows will be added), change cardinality point off-set distance (d)
|
||||
let d = 10 + terminalMarkerSize * 0.5;
|
||||
const d = 10 + terminalMarkerSize * 0.5;
|
||||
//Calculate Angle for x and y axis
|
||||
let angle = Math.atan2(points[0].y - center.y, points[0].x - center.x);
|
||||
const angle = Math.atan2(points[0].y - center.y, points[0].x - center.x);
|
||||
|
||||
let cardinalityPosition = { x: 0, y: 0 };
|
||||
const cardinalityPosition = { x: 0, y: 0 };
|
||||
|
||||
//Calculation cardinality position using angle, center point on the line/curve but pendicular and with offset-distance
|
||||
|
||||
@@ -485,10 +487,10 @@ export const generateId = () => {
|
||||
* @returns {any}
|
||||
*/
|
||||
function makeid(length) {
|
||||
var result = '';
|
||||
var characters = '0123456789abcdef';
|
||||
var charactersLength = characters.length;
|
||||
for (var i = 0; i < length; i++) {
|
||||
let result = '';
|
||||
const characters = '0123456789abcdef';
|
||||
const charactersLength = characters.length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||
}
|
||||
return result;
|
||||
@@ -675,7 +677,7 @@ export const calculateTextDimensions = memoize(
|
||||
// of sans-serif.
|
||||
const fontFamilies = ['sans-serif', fontFamily];
|
||||
const lines = text.split(common.lineBreakRegex);
|
||||
let dims = [];
|
||||
const dims = [];
|
||||
|
||||
const body = select('body');
|
||||
// We don't want to leak DOM elements - if a removal operation isn't available
|
||||
@@ -686,10 +688,10 @@ export const calculateTextDimensions = memoize(
|
||||
|
||||
const g = body.append('svg');
|
||||
|
||||
for (let fontFamily of fontFamilies) {
|
||||
for (const fontFamily of fontFamilies) {
|
||||
let cheight = 0;
|
||||
let dim = { width: 0, height: 0, lineHeight: 0 };
|
||||
for (let line of lines) {
|
||||
const dim = { width: 0, height: 0, lineHeight: 0 };
|
||||
for (const line of lines) {
|
||||
const textObj = getTextObj();
|
||||
textObj.text = line;
|
||||
const textElem = drawSimpleText(g, textObj)
|
||||
@@ -697,7 +699,7 @@ export const calculateTextDimensions = memoize(
|
||||
.style('font-weight', fontWeight)
|
||||
.style('font-family', fontFamily);
|
||||
|
||||
let bBox = (textElem._groups || textElem)[0][0].getBBox();
|
||||
const bBox = (textElem._groups || textElem)[0][0].getBBox();
|
||||
dim.width = Math.round(Math.max(dim.width, bBox.width));
|
||||
cheight = Math.round(bBox.height);
|
||||
dim.height += cheight;
|
||||
@@ -708,7 +710,7 @@ export const calculateTextDimensions = memoize(
|
||||
|
||||
g.remove();
|
||||
|
||||
let index =
|
||||
const index =
|
||||
isNaN(dims[1].height) ||
|
||||
isNaN(dims[1].width) ||
|
||||
isNaN(dims[1].lineHeight) ||
|
||||
@@ -729,7 +731,7 @@ export const calculateTextDimensions = memoize(
|
||||
* @param {[string, string][]} attrs Object.keys equivalent format of key to value mapping of attributes
|
||||
*/
|
||||
const d3Attrs = function (d3Elem, attrs) {
|
||||
for (let attr of attrs) {
|
||||
for (const attr of attrs) {
|
||||
d3Elem.attr(attr[0], attr[1]);
|
||||
}
|
||||
};
|
||||
@@ -743,7 +745,7 @@ const d3Attrs = function (d3Elem, attrs) {
|
||||
* @returns {Map<'height' | 'width' | 'style', string>} Attributes for the SVG
|
||||
*/
|
||||
export const calculateSvgSizeAttrs = function (height, width, useMaxWidth) {
|
||||
let attrs = new Map();
|
||||
const attrs = new Map();
|
||||
// attrs.set('height', height);
|
||||
if (useMaxWidth) {
|
||||
attrs.set('width', '100%');
|
||||
@@ -945,10 +947,12 @@ export interface DetailedError {
|
||||
hash: any;
|
||||
}
|
||||
|
||||
/** @param error */
|
||||
export function isDetailedError(error: unknown): error is DetailedError {
|
||||
return 'str' in error;
|
||||
}
|
||||
|
||||
/** @param error */
|
||||
export function getErrorMessage(error: unknown): string {
|
||||
if (error instanceof Error) return error.message;
|
||||
return String(error);
|
||||
|
81
yarn.lock
81
yarn.lock
@@ -2795,6 +2795,31 @@
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@typescript-eslint/eslint-plugin@^5.36.1":
|
||||
version "5.36.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.36.1.tgz#471f64dc53600025e470dad2ca4a9f2864139019"
|
||||
integrity sha512-iC40UK8q1tMepSDwiLbTbMXKDxzNy+4TfPWgIL661Ym0sD42vRcQU93IsZIrmi+x292DBr60UI/gSwfdVYexCA==
|
||||
dependencies:
|
||||
"@typescript-eslint/scope-manager" "5.36.1"
|
||||
"@typescript-eslint/type-utils" "5.36.1"
|
||||
"@typescript-eslint/utils" "5.36.1"
|
||||
debug "^4.3.4"
|
||||
functional-red-black-tree "^1.0.1"
|
||||
ignore "^5.2.0"
|
||||
regexpp "^3.2.0"
|
||||
semver "^7.3.7"
|
||||
tsutils "^3.21.0"
|
||||
|
||||
"@typescript-eslint/parser@^5.36.1":
|
||||
version "5.36.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.36.1.tgz#931c22c7bacefd17e29734628cdec8b2acdcf1ce"
|
||||
integrity sha512-/IsgNGOkBi7CuDfUbwt1eOqUXF9WGVBW9dwEe1pi+L32XrTsZIgmDFIi2RxjzsvB/8i+MIf5JIoTEH8LOZ368A==
|
||||
dependencies:
|
||||
"@typescript-eslint/scope-manager" "5.36.1"
|
||||
"@typescript-eslint/types" "5.36.1"
|
||||
"@typescript-eslint/typescript-estree" "5.36.1"
|
||||
debug "^4.3.4"
|
||||
|
||||
"@typescript-eslint/scope-manager@5.10.1":
|
||||
version "5.10.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.10.1.tgz#f0539c73804d2423506db2475352a4dec36cd809"
|
||||
@@ -2803,11 +2828,34 @@
|
||||
"@typescript-eslint/types" "5.10.1"
|
||||
"@typescript-eslint/visitor-keys" "5.10.1"
|
||||
|
||||
"@typescript-eslint/scope-manager@5.36.1":
|
||||
version "5.36.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.36.1.tgz#23c49b7ddbcffbe09082e6694c2524950766513f"
|
||||
integrity sha512-pGC2SH3/tXdu9IH3ItoqciD3f3RRGCh7hb9zPdN2Drsr341zgd6VbhP5OHQO/reUqihNltfPpMpTNihFMarP2w==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "5.36.1"
|
||||
"@typescript-eslint/visitor-keys" "5.36.1"
|
||||
|
||||
"@typescript-eslint/type-utils@5.36.1":
|
||||
version "5.36.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.36.1.tgz#016fc2bff6679f54c0b2df848a493f0ca3d4f625"
|
||||
integrity sha512-xfZhfmoQT6m3lmlqDvDzv9TiCYdw22cdj06xY0obSznBsT///GK5IEZQdGliXpAOaRL34o8phEvXzEo/VJx13Q==
|
||||
dependencies:
|
||||
"@typescript-eslint/typescript-estree" "5.36.1"
|
||||
"@typescript-eslint/utils" "5.36.1"
|
||||
debug "^4.3.4"
|
||||
tsutils "^3.21.0"
|
||||
|
||||
"@typescript-eslint/types@5.10.1":
|
||||
version "5.10.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.10.1.tgz#dca9bd4cb8c067fc85304a31f38ec4766ba2d1ea"
|
||||
integrity sha512-ZvxQ2QMy49bIIBpTqFiOenucqUyjTQ0WNLhBM6X1fh1NNlYAC6Kxsx8bRTY3jdYsYg44a0Z/uEgQkohbR0H87Q==
|
||||
|
||||
"@typescript-eslint/types@5.36.1":
|
||||
version "5.36.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.36.1.tgz#1cf0e28aed1cb3ee676917966eb23c2f8334ce2c"
|
||||
integrity sha512-jd93ShpsIk1KgBTx9E+hCSEuLCUFwi9V/urhjOWnOaksGZFbTOxAT47OH2d4NLJnLhkVD+wDbB48BuaycZPLBg==
|
||||
|
||||
"@typescript-eslint/typescript-estree@5.10.1":
|
||||
version "5.10.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.10.1.tgz#b268e67be0553f8790ba3fe87113282977adda15"
|
||||
@@ -2821,6 +2869,31 @@
|
||||
semver "^7.3.5"
|
||||
tsutils "^3.21.0"
|
||||
|
||||
"@typescript-eslint/typescript-estree@5.36.1":
|
||||
version "5.36.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.36.1.tgz#b857f38d6200f7f3f4c65cd0a5afd5ae723f2adb"
|
||||
integrity sha512-ih7V52zvHdiX6WcPjsOdmADhYMDN15SylWRZrT2OMy80wzKbc79n8wFW0xpWpU0x3VpBz/oDgTm2xwDAnFTl+g==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "5.36.1"
|
||||
"@typescript-eslint/visitor-keys" "5.36.1"
|
||||
debug "^4.3.4"
|
||||
globby "^11.1.0"
|
||||
is-glob "^4.0.3"
|
||||
semver "^7.3.7"
|
||||
tsutils "^3.21.0"
|
||||
|
||||
"@typescript-eslint/utils@5.36.1":
|
||||
version "5.36.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.36.1.tgz#136d5208cc7a3314b11c646957f8f0b5c01e07ad"
|
||||
integrity sha512-lNj4FtTiXm5c+u0pUehozaUWhh7UYKnwryku0nxJlYUEWetyG92uw2pr+2Iy4M/u0ONMKzfrx7AsGBTCzORmIg==
|
||||
dependencies:
|
||||
"@types/json-schema" "^7.0.9"
|
||||
"@typescript-eslint/scope-manager" "5.36.1"
|
||||
"@typescript-eslint/types" "5.36.1"
|
||||
"@typescript-eslint/typescript-estree" "5.36.1"
|
||||
eslint-scope "^5.1.1"
|
||||
eslint-utils "^3.0.0"
|
||||
|
||||
"@typescript-eslint/utils@^5.10.0":
|
||||
version "5.10.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.10.1.tgz#fa682a33af47080ba2c4368ee0ad2128213a1196"
|
||||
@@ -2841,6 +2914,14 @@
|
||||
"@typescript-eslint/types" "5.10.1"
|
||||
eslint-visitor-keys "^3.0.0"
|
||||
|
||||
"@typescript-eslint/visitor-keys@5.36.1":
|
||||
version "5.36.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.36.1.tgz#7731175312d65738e501780f923896d200ad1615"
|
||||
integrity sha512-ojB9aRyRFzVMN3b5joSYni6FAS10BBSCAfKJhjJAV08t/a95aM6tAhz+O1jF+EtgxktuSO3wJysp2R+Def/IWQ==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "5.36.1"
|
||||
eslint-visitor-keys "^3.3.0"
|
||||
|
||||
"@wdio/config@7.16.11":
|
||||
version "7.16.11"
|
||||
resolved "https://registry.yarnpkg.com/@wdio/config/-/config-7.16.11.tgz#c35a0efb9c7ec6c80e3324e9818f636010087e97"
|
||||
|
Reference in New Issue
Block a user