From c2f9cccbb4aa2cc5781aa3ae33a7e06b8f90b452 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Mon, 2 Jan 2023 08:51:19 -0500 Subject: [PATCH] Update id type --- .../d3-state-visualizer/src/charts/tree/tree.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/d3-state-visualizer/src/charts/tree/tree.ts b/packages/d3-state-visualizer/src/charts/tree/tree.ts index e71440b3..2522076c 100644 --- a/packages/d3-state-visualizer/src/charts/tree/tree.ts +++ b/packages/d3-state-visualizer/src/charts/tree/tree.ts @@ -183,7 +183,7 @@ export interface InternalNode { name: string; children?: this[] | null; value?: unknown; - id: string; + id: string | number; } export interface HierarchyPointNodeWithPrivateChildren @@ -192,8 +192,8 @@ export interface HierarchyPointNodeWithPrivateChildren } interface NodePosition { - parentId: string | null; - id: string; + parentId: string | number | null; + id: string | number; x: number; y: number; } @@ -285,8 +285,8 @@ export default function ( // of parent ids; once a parent that matches the given filter is found, // the parent position gets returned function findParentNodePosition( - nodePositionsById: { [nodeId: string]: NodePosition }, - nodeId: string, + nodePositionsById: { [nodeId: string | number]: NodePosition }, + nodeId: string | number, filter: (nodePosition: NodePosition) => boolean ) { let currentPosition = nodePositionsById[nodeId]; @@ -383,7 +383,7 @@ export default function ( x: n.x, y: n.y, })); - const nodePositionsById: { [nodeId: string]: NodePosition } = {}; + const nodePositionsById: { [nodeId: string | number]: NodePosition } = {}; nodePositions.forEach((node) => (nodePositionsById[node.id] = node)); // process the node selection @@ -393,10 +393,7 @@ export default function ( HierarchyPointNodeWithPrivateChildren >('g.node') .property('__oldData__', (d) => d) - .data( - nodes, - (d) => d.data.id || (d.data.id = ++nodeIndex as unknown as string) - ); + .data(nodes, (d) => d.data.id || (d.data.id = ++nodeIndex)); const nodeEnter = node .enter() .append('g')