From 552184e9e69df67819122848dfed7223dcf26fa0 Mon Sep 17 00:00:00 2001 From: Sam Washington Date: Sun, 7 Mar 2021 23:23:03 -0600 Subject: [PATCH 1/2] fixed issue with forces --- package.json | 2 +- src/data/types/datum.ts | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 654f1f6..a4d8914 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@spwashi/react-d3", - "version": "0.2.2", + "version": "0.2.3", "dependencies": { "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", diff --git a/src/data/types/datum.ts b/src/data/types/datum.ts index bcad6a9..3a9b95d 100644 --- a/src/data/types/datum.ts +++ b/src/data/types/datum.ts @@ -23,16 +23,10 @@ export type Datum = dragBehavior?: { savePos?: boolean }, radiusMultiplier?: number, - forces: { - boundary: { - smallest: { - x: number, - y: number - }, - largest: { - x: number, - y: number - } + forces?: { + boundary?: { + smallest?: { x?: number, y?: number }, + largest?: { x?: number, y?: number } } }, From e6fe09bf55fa5e419bbbfa5b2266a1a1bb43ef2e Mon Sep 17 00:00:00 2001 From: Sam Washington Date: Sun, 7 Mar 2021 23:25:25 -0600 Subject: [PATCH 2/2] fixed type error --- src/_default/callbacks/updateForces.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/_default/callbacks/updateForces.ts b/src/_default/callbacks/updateForces.ts index 541cf34..7a8dba3 100644 --- a/src/_default/callbacks/updateForces.ts +++ b/src/_default/callbacks/updateForces.ts @@ -103,17 +103,17 @@ export function updateForces(forces: ForceConfiguration | undefined, const smallest_x = curr_node?.forces?.boundary?.smallest?.x; const largest_x = curr_node?.forces?.boundary?.largest?.x; - if ((smallest_x ?? false) && (curr_node.x < smallest_x)) { + if (typeof smallest_x !== 'undefined' && (curr_node.x < smallest_x)) { curr_node.x = smallest_x; - } else if ((largest_x ?? false) && (curr_node.x > largest_x)) { + } else if (typeof largest_x !== 'undefined' && (curr_node.x > largest_x)) { curr_node.x = largest_x; } const smallest_y = curr_node?.forces?.boundary?.smallest?.y; const largest_y = curr_node?.forces?.boundary?.largest?.y; - if ((smallest_y ?? false) && (curr_node.y < smallest_y)) { + if (typeof smallest_y !== 'undefined' && (curr_node.y < smallest_y)) { curr_node.y = smallest_y; - } else if ((largest_y ?? false) && (curr_node.y > largest_y)) { + } else if (typeof largest_y !== 'undefined' && (curr_node.y > largest_y)) { curr_node.y = largest_y; } }