Fixes after review

This commit is contained in:
Nikolay Rozhkov
2023-06-29 15:39:50 +03:00
parent 408c32781e
commit 8e3f8b1a57
3 changed files with 17 additions and 15 deletions

View File

@@ -43,12 +43,11 @@ class SankeyNode {
const findOrCreateNode = (ID: string): SankeyNode => { const findOrCreateNode = (ID: string): SankeyNode => {
ID = common.sanitizeText(ID, configApi.getConfig()); ID = common.sanitizeText(ID, configApi.getConfig());
if (nodesMap[ID]) {
return nodesMap[ID];
}
if (!nodesMap[ID]) {
nodesMap[ID] = new SankeyNode(ID); nodesMap[ID] = new SankeyNode(ID);
nodes.push(nodesMap[ID]); nodes.push(nodesMap[ID]);
}
return nodesMap[ID]; return nodesMap[ID];
}; };

View File

@@ -20,6 +20,17 @@ import { configureSvgSize } from '../../setupGraphViewbox.js';
import { Uid } from '../../rendering-util/uid.js'; import { Uid } from '../../rendering-util/uid.js';
import { SankeyLinkColor, SankeyNodeAlignment } from '../../config.type.js'; import { SankeyLinkColor, SankeyNodeAlignment } from '../../config.type.js';
// Map config options to alignment functions
const alignmentsMap: Record<
SankeyNodeAlignment,
(node: d3SankeyNode<object, object>, n: number) => number
> = {
[SankeyNodeAlignment.left]: d3SankeyLeft,
[SankeyNodeAlignment.right]: d3SankeyRight,
[SankeyNodeAlignment.center]: d3SankeyCenter,
[SankeyNodeAlignment.justify]: d3SankeyJustify,
};
/** /**
* Draws Sankey diagram. * Draws Sankey diagram.
* *
@@ -73,16 +84,7 @@ export const draw = function (text: string, id: string, _version: string, diagOb
// @ts-ignore TODO: db should be coerced to sankey DB type // @ts-ignore TODO: db should be coerced to sankey DB type
const graph = diagObj.db.getGraph(); const graph = diagObj.db.getGraph();
// Map config options to alignment functions // Get alignment function
const alignmentsMap: Record<
SankeyNodeAlignment,
(node: d3SankeyNode<object, object>, n: number) => number
> = {
[SankeyNodeAlignment.left]: d3SankeyLeft,
[SankeyNodeAlignment.right]: d3SankeyRight,
[SankeyNodeAlignment.center]: d3SankeyCenter,
[SankeyNodeAlignment.justify]: d3SankeyJustify,
};
const nodeAlign = alignmentsMap[nodeAlignment]; const nodeAlign = alignmentsMap[nodeAlignment];
// Construct and configure a Sankey generator // Construct and configure a Sankey generator

View File

@@ -138,6 +138,7 @@ function sidebarSyntax() {
{ text: 'Mindmaps 🔥', link: '/syntax/mindmap' }, { text: 'Mindmaps 🔥', link: '/syntax/mindmap' },
{ text: 'Timeline 🔥', link: '/syntax/timeline' }, { text: 'Timeline 🔥', link: '/syntax/timeline' },
{ text: 'Zenuml 🔥', link: '/syntax/zenuml' }, { text: 'Zenuml 🔥', link: '/syntax/zenuml' },
{ text: 'Sankey 🔥', link: '/syntax/sankey' },
{ text: 'Other Examples', link: '/syntax/examples' }, { text: 'Other Examples', link: '/syntax/examples' },
], ],
}, },