From 616c5e6914c063af5d6c1db5696cc031ab44568c Mon Sep 17 00:00:00 2001 From: Nikolay Rozhkov Date: Tue, 27 Jun 2023 14:43:35 +0300 Subject: [PATCH] Move UID to separate file, refine run sh --- .../src/diagrams/sankey/sankeyRenderer.ts | 12 +++++---- .../src/diagrams/sankey/sankeyUtils.ts | 19 ------------- packages/mermaid/src/rendering-util/uid.ts | 18 +++++++++++++ run | 27 ++++++++++--------- 4 files changed, 39 insertions(+), 37 deletions(-) create mode 100644 packages/mermaid/src/rendering-util/uid.ts diff --git a/packages/mermaid/src/diagrams/sankey/sankeyRenderer.ts b/packages/mermaid/src/diagrams/sankey/sankeyRenderer.ts index a480b4b3e..6a4c5fdcf 100644 --- a/packages/mermaid/src/diagrams/sankey/sankeyRenderer.ts +++ b/packages/mermaid/src/diagrams/sankey/sankeyRenderer.ts @@ -16,7 +16,7 @@ import { sankeyJustify as d3SankeyJustify, } from 'd3-sankey'; import { configureSvgSize } from '../../setupGraphViewbox.js'; -import { Uid } from './sankeyUtils.js'; +import { Uid } from '../../rendering-util/uid.js'; import { SankeyLinkColor, SankeyNodeAlignment } from '../../config.type.js'; /** @@ -30,7 +30,7 @@ import { SankeyLinkColor, SankeyNodeAlignment } from '../../config.type.js'; export const draw = function (text: string, id: string, _version: string, diagObj: Diagram): void { // Get Sankey config const { securityLevel, sankey: conf } = configApi.getConfig(); - + // TODO: // This code repeats for every diagram // Figure out what is happening there, probably it should be separated @@ -66,14 +66,16 @@ export const draw = function (text: string, id: string, _version: string, diagOb // } // const graph = diagObj.db.getGraph(); - - const alignmentsMap: Record, n: number) => number> = new Map([ + const alignmentsMap: Map< + SankeyNodeAlignment, + (node: SankeyNode<{}, {}>, n: number) => number + > = new Map([ [SankeyNodeAlignment.left, d3SankeyLeft], [SankeyNodeAlignment.right, d3SankeyRight], [SankeyNodeAlignment.center, d3SankeyCenter], [SankeyNodeAlignment.justify, d3SankeyJustify], ]); - const nodeAlignment = alignmentsMap[conf?.nodeAlignment]; + const nodeAlignment = alignmentsMap.get(conf?.nodeAlignment || SankeyNodeAlignment.justify); // Construct and configure a Sankey generator // That will be a function that calculates nodes and links dimensions diff --git a/packages/mermaid/src/diagrams/sankey/sankeyUtils.ts b/packages/mermaid/src/diagrams/sankey/sankeyUtils.ts index 08e4c547f..45ecf21dd 100644 --- a/packages/mermaid/src/diagrams/sankey/sankeyUtils.ts +++ b/packages/mermaid/src/diagrams/sankey/sankeyUtils.ts @@ -6,22 +6,3 @@ export const prepareTextForParsing = (text: string): string => { return textToParse; }; - -export class Uid { - private static count = 0; - id: string; - href: string; - - public static next(name: string): Uid { - return new Uid(name + ++Uid.count); - } - - constructor(id: string) { - this.id = id; - this.href = `#${id}`; - } - - toString(): string { - return 'url(' + this.href + ')'; - } -} diff --git a/packages/mermaid/src/rendering-util/uid.ts b/packages/mermaid/src/rendering-util/uid.ts new file mode 100644 index 000000000..9f581faa7 --- /dev/null +++ b/packages/mermaid/src/rendering-util/uid.ts @@ -0,0 +1,18 @@ +export class Uid { + private static count = 0; + id: string; + href: string; + + public static next(name: string): Uid { + return new Uid(name + ++Uid.count); + } + + constructor(id: string) { + this.id = id; + this.href = `#${id}`; + } + + toString(): string { + return 'url(' + this.href + ')'; + } +} diff --git a/run b/run index b5e589e6e..18a544312 100755 --- a/run +++ b/run @@ -30,27 +30,28 @@ Run commands within docker containers. Development quick start guide: -\033[1m$name pnpm install\033[0m # Install packages -\033[1m$name dev\033[0m # Run dev server with examples, open http://localhost:9000 -\033[1m$name docs:dev\033[0m # For docs contributions, open http://localhost:3333 +\033[1m$name pnpm install\033[0m # Install packages +\033[1m$name dev\033[0m # Run dev server with examples, open http://localhost:9000 +\033[1m$name docs:dev\033[0m # For docs contributions, open http://localhost:3333 Commands: -$name pnpm # Run any 'pnpm' command -$name dev # Run dev server with examples, open http://localhost:9000 -$name docs:dev # For docs contributions, open http://localhost:3333 +$name pnpm # Run any 'pnpm' command +$name dev # Run dev server with examples, open http://localhost:9000 +$name docs:dev # For docs contributions, open http://localhost:3333 -$name sh # Open 'sh' inside docker container for development +$name sh # Open 'sh' inside docker container for development -$name help # Show this help +$name help # Show this help Examples of frequiently used commands: -$name pnpm add # Add package, 'run add d3-sankey' -$name pnpm prettier # Prettify a file 'run prettier ' -$name pnpm test # Run unit tests -$name pnpm vitest # Run watcher for unit tests -$name pnpm e2e # Run integration tests +$name pnpm add # Add package, 'run add d3-sankey' +$name pnpm prettier --write # Prettify a file 'run prettier ' + # git diff --name-only develop | xargs run pnpm prettier --write +$name pnpm test # Run unit tests +$name pnpm vitest # Run watcher for unit tests +$name pnpm e2e # Run integration tests $name pnpm -w run lint:fix EOF )