Update id type

This commit is contained in:
Nathan Bierema 2023-01-02 08:51:19 -05:00
parent 866b69bef6
commit c2f9cccbb4

View File

@ -183,7 +183,7 @@ export interface InternalNode {
name: string; name: string;
children?: this[] | null; children?: this[] | null;
value?: unknown; value?: unknown;
id: string; id: string | number;
} }
export interface HierarchyPointNodeWithPrivateChildren<Datum> export interface HierarchyPointNodeWithPrivateChildren<Datum>
@ -192,8 +192,8 @@ export interface HierarchyPointNodeWithPrivateChildren<Datum>
} }
interface NodePosition { interface NodePosition {
parentId: string | null; parentId: string | number | null;
id: string; id: string | number;
x: number; x: number;
y: number; y: number;
} }
@ -285,8 +285,8 @@ export default function (
// of parent ids; once a parent that matches the given filter is found, // of parent ids; once a parent that matches the given filter is found,
// the parent position gets returned // the parent position gets returned
function findParentNodePosition( function findParentNodePosition(
nodePositionsById: { [nodeId: string]: NodePosition }, nodePositionsById: { [nodeId: string | number]: NodePosition },
nodeId: string, nodeId: string | number,
filter: (nodePosition: NodePosition) => boolean filter: (nodePosition: NodePosition) => boolean
) { ) {
let currentPosition = nodePositionsById[nodeId]; let currentPosition = nodePositionsById[nodeId];
@ -383,7 +383,7 @@ export default function (
x: n.x, x: n.x,
y: n.y, y: n.y,
})); }));
const nodePositionsById: { [nodeId: string]: NodePosition } = {}; const nodePositionsById: { [nodeId: string | number]: NodePosition } = {};
nodePositions.forEach((node) => (nodePositionsById[node.id] = node)); nodePositions.forEach((node) => (nodePositionsById[node.id] = node));
// process the node selection // process the node selection
@ -393,10 +393,7 @@ export default function (
HierarchyPointNodeWithPrivateChildren<InternalNode> HierarchyPointNodeWithPrivateChildren<InternalNode>
>('g.node') >('g.node')
.property('__oldData__', (d) => d) .property('__oldData__', (d) => d)
.data( .data(nodes, (d) => d.data.id || (d.data.id = ++nodeIndex));
nodes,
(d) => d.data.id || (d.data.id = ++nodeIndex as unknown as string)
);
const nodeEnter = node const nodeEnter = node
.enter() .enter()
.append('g') .append('g')