Move UID to separate file, refine run sh

This commit is contained in:
Nikolay Rozhkov
2023-06-27 14:43:35 +03:00
parent 605e8d4a92
commit 616c5e6914
4 changed files with 39 additions and 37 deletions

View File

@@ -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<SankeyNodeAlignment, (node: SankeyNode<{}, {}>, 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

View File

@@ -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 + ')';
}
}

View 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 + ')';
}
}