Skip to content

Commit

Permalink
refactor: adapt concentric node size
Browse files Browse the repository at this point in the history
  • Loading branch information
yvonneyx committed Nov 4, 2024
1 parent a9af1af commit 25cee7d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/layout/src/concentric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
} from './types';
import { cloneFormatData, isArray } from './util';
import { handleSingleNodeGraph } from './util/common';
import { parseSize } from './util/size';

const DEFAULTS_LAYOUT_OPTIONS: Partial<ConcentricLayoutOptions> = {
nodeSize: 30,
Expand All @@ -26,7 +27,7 @@ const DEFAULTS_LAYOUT_OPTIONS: Partial<ConcentricLayoutOptions> = {

/**
* <zh/> 同心圆布局
*
*
* <en/> Concentric layout
*/
export class ConcentricLayout implements Layout<ConcentricLayoutOptions> {
Expand All @@ -51,7 +52,7 @@ export class ConcentricLayout implements Layout<ConcentricLayoutOptions> {
* To directly assign the positions to the nodes.
*/
async assign(graph: Graph, options?: ConcentricLayoutOptions) {
await this.genericConcentricLayout(true, graph, options);
await this.genericConcentricLayout(true, graph, options);
}

private async genericConcentricLayout(
Expand Down Expand Up @@ -112,7 +113,7 @@ export class ConcentricLayout implements Layout<ConcentricLayoutOptions> {
} else if (isFunction(nodeSize)) {
maxNodeSize = -Infinity;
nodes.forEach((node) => {
const currentSize = nodeSize(node);
const currentSize = Math.max(...parseSize(nodeSize(node)));
if (currentSize > maxNodeSize) maxNodeSize = currentSize;
});
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/layout/src/util/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const formatNodeSizeToNumber = (
}

const func = (d: Node) => {
const nodeSize = nodeSizeFunc(d);
const nodeSize = nodeSizeFunc(d) as Size;
const nodeSpacing = nodeSpacingFunc(d);
return Math.max(...parseSize(nodeSize)) + nodeSpacing;
};
Expand Down

0 comments on commit 25cee7d

Please sign in to comment.