mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 06:49:47 +02:00
Move UID to separate file, refine run sh
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
|||||||
sankeyJustify as d3SankeyJustify,
|
sankeyJustify as d3SankeyJustify,
|
||||||
} from 'd3-sankey';
|
} from 'd3-sankey';
|
||||||
import { configureSvgSize } from '../../setupGraphViewbox.js';
|
import { configureSvgSize } from '../../setupGraphViewbox.js';
|
||||||
import { Uid } from './sankeyUtils.js';
|
import { Uid } from '../../rendering-util/uid.js';
|
||||||
import { SankeyLinkColor, SankeyNodeAlignment } from '../../config.type.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 {
|
export const draw = function (text: string, id: string, _version: string, diagObj: Diagram): void {
|
||||||
// Get Sankey config
|
// Get Sankey config
|
||||||
const { securityLevel, sankey: conf } = configApi.getConfig();
|
const { securityLevel, sankey: conf } = configApi.getConfig();
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// This code repeats for every diagram
|
// This code repeats for every diagram
|
||||||
// Figure out what is happening there, probably it should be separated
|
// 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 graph = diagObj.db.getGraph();
|
||||||
|
const alignmentsMap: Map<
|
||||||
const alignmentsMap: Record<SankeyNodeAlignment, (node: SankeyNode<{}, {}>, n: number) => number> = new Map([
|
SankeyNodeAlignment,
|
||||||
|
(node: SankeyNode<{}, {}>, n: number) => number
|
||||||
|
> = new Map([
|
||||||
[SankeyNodeAlignment.left, d3SankeyLeft],
|
[SankeyNodeAlignment.left, d3SankeyLeft],
|
||||||
[SankeyNodeAlignment.right, d3SankeyRight],
|
[SankeyNodeAlignment.right, d3SankeyRight],
|
||||||
[SankeyNodeAlignment.center, d3SankeyCenter],
|
[SankeyNodeAlignment.center, d3SankeyCenter],
|
||||||
[SankeyNodeAlignment.justify, d3SankeyJustify],
|
[SankeyNodeAlignment.justify, d3SankeyJustify],
|
||||||
]);
|
]);
|
||||||
const nodeAlignment = alignmentsMap[conf?.nodeAlignment];
|
const nodeAlignment = alignmentsMap.get(conf?.nodeAlignment || SankeyNodeAlignment.justify);
|
||||||
|
|
||||||
// Construct and configure a Sankey generator
|
// Construct and configure a Sankey generator
|
||||||
// That will be a function that calculates nodes and links dimensions
|
// That will be a function that calculates nodes and links dimensions
|
||||||
|
@@ -6,22 +6,3 @@ export const prepareTextForParsing = (text: string): string => {
|
|||||||
|
|
||||||
return textToParse;
|
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 + ')';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
18
packages/mermaid/src/rendering-util/uid.ts
Normal file
18
packages/mermaid/src/rendering-util/uid.ts
Normal file
@@ -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 + ')';
|
||||||
|
}
|
||||||
|
}
|
27
run
27
run
@@ -30,27 +30,28 @@ Run commands within docker containers.
|
|||||||
|
|
||||||
Development quick start guide:
|
Development quick start guide:
|
||||||
|
|
||||||
\033[1m$name pnpm install\033[0m # Install packages
|
\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 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 docs:dev\033[0m # For docs contributions, open http://localhost:3333
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
|
|
||||||
$name pnpm # Run any 'pnpm' command
|
$name pnpm # Run any 'pnpm' command
|
||||||
$name dev # Run dev server with examples, open http://localhost:9000
|
$name dev # Run dev server with examples, open http://localhost:9000
|
||||||
$name docs:dev # For docs contributions, open http://localhost:3333
|
$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:
|
Examples of frequiently used commands:
|
||||||
|
|
||||||
$name pnpm add # Add package, 'run add d3-sankey'
|
$name pnpm add # Add package, 'run add d3-sankey'
|
||||||
$name pnpm prettier # Prettify a file 'run prettier <path-to-file>'
|
$name pnpm prettier --write # Prettify a file 'run prettier <path-to-file>'
|
||||||
$name pnpm test # Run unit tests
|
# git diff --name-only develop | xargs run pnpm prettier --write
|
||||||
$name pnpm vitest # Run watcher for unit tests
|
$name pnpm test # Run unit tests
|
||||||
$name pnpm e2e # Run integration tests
|
$name pnpm vitest # Run watcher for unit tests
|
||||||
|
$name pnpm e2e # Run integration tests
|
||||||
$name pnpm -w run lint:fix
|
$name pnpm -w run lint:fix
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user