From d10717bdc1f6dfdaf8daa028550192645d96cd44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Vy=C4=8D=C3=ADtal?= Date: Sat, 18 Jan 2020 21:30:26 +0100 Subject: [PATCH] fix(rng)!: use better seedable RNG (#352) * fix(rng)!: use better seedable RNG BREAKING CHANGE: The layout for the same graph and seed is different when compared to the previous version. This replaces the Math.sin() based ones and Math.random() with Alea based RNG from Vis Util. * test(physics): add simple pinning tests This simply runs some basic physics configurations on a few sets of data and tests that the positions of the nodes after stabilization didn't change from the last time. * test(snapshots): remove only I had to change Math.pow to **. No idea why but without this change it didn't want to output the same values. I just hope this is not going to break in CI or other people's machines. --- __snapshots__/test/snapshots.test.ts.js | 771 ++++++++ examples/network/basic_usage/standalone.html | 2 +- examples/network/data/importingFromGephi.html | 6 +- examples/network/exampleUtil.js | 10 +- .../network/layout/hierarchicalLayout.html | 5 +- examples/network/other/animationShowcase.html | 5 +- examples/network/other/configuration.html | 6 +- examples/network/other/manipulation.html | 6 +- .../other/manipulationEditEdgeNoDrag.html | 6 +- examples/network/other/navigation.html | 5 +- examples/network/other/performance.html | 5 +- examples/network/other/saveAndLoad.html | 5 +- .../network/physics/physicsConfiguration.html | 5 +- lib/network/modules/KamadaKawai.js | 16 +- lib/network/modules/LayoutEngine.js | 39 +- .../components/physics/BarnesHutSolver.js | 18 +- .../physics/FA2BasedRepulsionSolver.js | 5 +- .../components/physics/RepulsionSolver.js | 8 +- package-lock.json | 1595 ++++++++++++----- package.json | 7 + test/snapshots.test.ts | 200 +++ 21 files changed, 2202 insertions(+), 523 deletions(-) create mode 100644 __snapshots__/test/snapshots.test.ts.js create mode 100644 test/snapshots.test.ts diff --git a/__snapshots__/test/snapshots.test.ts.js b/__snapshots__/test/snapshots.test.ts.js new file mode 100644 index 0000000000..6e88496d21 --- /dev/null +++ b/__snapshots__/test/snapshots.test.ts.js @@ -0,0 +1,771 @@ +exports['Physics snapshots Barnes Hut defaults 2 connected nodes 1'] = { + "1": { + "x": -34, + "y": 68 + }, + "2": { + "x": -30, + "y": -92 + } +} + +exports['Physics snapshots Barnes Hut defaults 2 disconnected nodes 1'] = { + "1": { + "x": 13, + "y": -39 + }, + "2": { + "x": -10, + "y": 37 + } +} + +exports['Physics snapshots Barnes Hut defaults 2 doubly connected nodes 1'] = { + "1": { + "x": -32, + "y": 29 + }, + "2": { + "x": 32, + "y": -30 + } +} + +exports['Physics snapshots Barnes Hut defaults 6 node circle 1'] = { + "1": { + "x": -15, + "y": -130 + }, + "2": { + "x": -110, + "y": -45 + }, + "3": { + "x": -84, + "y": 79 + }, + "4": { + "x": 33, + "y": 127 + }, + "5": { + "x": 123, + "y": 37 + }, + "6": { + "x": 104, + "y": -87 + } +} + +exports['Physics snapshots Barnes Hut defaults 6 node complete graph 1'] = { + "1": { + "x": -24, + "y": -61 + }, + "2": { + "x": 48, + "y": 99 + }, + "3": { + "x": -58, + "y": 60 + }, + "4": { + "x": 54, + "y": -49 + }, + "5": { + "x": -66, + "y": 6 + }, + "6": { + "x": 88, + "y": -7 + } +} + +exports['Physics snapshots Barnes Hut defaults 6 node star 1'] = { + "1": { + "x": -1, + "y": 0 + }, + "2": { + "x": 87, + "y": 100 + }, + "3": { + "x": -67, + "y": 119 + }, + "4": { + "x": -6, + "y": -135 + }, + "5": { + "x": -131, + "y": -34 + }, + "6": { + "x": 126, + "y": -48 + } +} + +exports['Physics snapshots Barnes Hut defaults binary tree 1'] = { + "1": { + "x": 46, + "y": -2 + }, + "2": { + "x": -84, + "y": 30 + }, + "3": { + "x": 174, + "y": -33 + }, + "4": { + "x": -126, + "y": -7 + }, + "5": { + "x": -253, + "y": 80 + }, + "6": { + "x": 191, + "y": -179 + }, + "7": { + "x": 262, + "y": 86 + }, + "8": { + "x": -179, + "y": -157 + }, + "9": { + "x": -76, + "y": 169 + }, + "10": { + "x": -379, + "y": 22 + }, + "11": { + "x": -332, + "y": 195 + }, + "12": { + "x": 118, + "y": -294 + }, + "13": { + "x": 319, + "y": -222 + }, + "14": { + "x": 393, + "y": 56 + }, + "15": { + "x": 258, + "y": 222 + }, + "16": { + "x": -307, + "y": -209 + }, + "17": { + "x": -125, + "y": -282 + }, + "18": { + "x": -131, + "y": 298 + }, + "19": { + "x": 30, + "y": 257 + } +} + +exports['Physics snapshots Force Atlas 2 defaults 2 connected nodes 1'] = { + "1": { + "x": -11, + "y": 58 + }, + "2": { + "x": -8, + "y": -68 + } +} + +exports['Physics snapshots Force Atlas 2 defaults 2 disconnected nodes 1'] = { + "1": { + "x": -7, + "y": -48 + }, + "2": { + "x": -32, + "y": 33 + } +} + +exports['Physics snapshots Force Atlas 2 defaults 2 doubly connected nodes 1'] = { + "1": { + "x": -18, + "y": 64 + }, + "2": { + "x": 3, + "y": -65 + } +} + +exports['Physics snapshots Force Atlas 2 defaults 6 node circle 1'] = { + "1": { + "x": -23, + "y": -151 + }, + "2": { + "x": -133, + "y": -48 + }, + "3": { + "x": -111, + "y": 102 + }, + "4": { + "x": 34, + "y": 147 + }, + "5": { + "x": 145, + "y": 45 + }, + "6": { + "x": 120, + "y": -104 + } +} + +exports['Physics snapshots Force Atlas 2 defaults 6 node complete graph 1'] = { + "1": { + "x": -146, + "y": -117 + }, + "2": { + "x": 143, + "y": 138 + }, + "3": { + "x": -120, + "y": 85 + }, + "4": { + "x": 37, + "y": -193 + }, + "5": { + "x": -61, + "y": 146 + }, + "6": { + "x": 195, + "y": -54 + } +} + +exports['Physics snapshots Force Atlas 2 defaults 6 node star 1'] = { + "1": { + "x": 6, + "y": 0 + }, + "2": { + "x": 108, + "y": 123 + }, + "3": { + "x": -80, + "y": 137 + }, + "4": { + "x": -4, + "y": -156 + }, + "5": { + "x": -150, + "y": -25 + }, + "6": { + "x": 157, + "y": -51 + } +} + +exports['Physics snapshots Force Atlas 2 defaults binary tree 1'] = { + "1": { + "x": 74, + "y": -53 + }, + "2": { + "x": -33, + "y": 63 + }, + "3": { + "x": 231, + "y": -49 + }, + "4": { + "x": -135, + "y": -29 + }, + "5": { + "x": -246, + "y": 80 + }, + "6": { + "x": 163, + "y": -217 + }, + "7": { + "x": 240, + "y": 130 + }, + "8": { + "x": -144, + "y": -206 + }, + "9": { + "x": -54, + "y": 201 + }, + "10": { + "x": -366, + "y": -14 + }, + "11": { + "x": -305, + "y": 217 + }, + "12": { + "x": 92, + "y": -345 + }, + "13": { + "x": 310, + "y": -213 + }, + "14": { + "x": 371, + "y": 61 + }, + "15": { + "x": 226, + "y": 276 + }, + "16": { + "x": -291, + "y": -218 + }, + "17": { + "x": -92, + "y": -343 + }, + "18": { + "x": -130, + "y": 334 + }, + "19": { + "x": 50, + "y": 322 + } +} + +exports['Physics snapshots Repulstion defaults 2 connected nodes 1'] = { + "1": { + "x": -25, + "y": 103 + }, + "2": { + "x": -19, + "y": -108 + } +} + +exports['Physics snapshots Repulstion defaults 2 disconnected nodes 1'] = { + "1": { + "x": -28, + "y": -25 + }, + "2": { + "x": -36, + "y": 1 + } +} + +exports['Physics snapshots Repulstion defaults 2 doubly connected nodes 1'] = { + "1": { + "x": -14, + "y": 78 + }, + "2": { + "x": -8, + "y": -85 + } +} + +exports['Physics snapshots Repulstion defaults 6 node circle 1'] = { + "1": { + "x": -17, + "y": -196 + }, + "2": { + "x": -147, + "y": -51 + }, + "3": { + "x": -132, + "y": 119 + }, + "4": { + "x": 38, + "y": 181 + }, + "5": { + "x": 161, + "y": 46 + }, + "6": { + "x": 147, + "y": -119 + } +} + +exports['Physics snapshots Repulstion defaults 6 node complete graph 1'] = { + "1": { + "x": -82, + "y": -73 + }, + "2": { + "x": 86, + "y": 77 + }, + "3": { + "x": -105, + "y": 35 + }, + "4": { + "x": 27, + "y": -109 + }, + "5": { + "x": -20, + "y": 112 + }, + "6": { + "x": 110, + "y": -34 + } +} + +exports['Physics snapshots Repulstion defaults 6 node star 1'] = { + "1": { + "x": 2, + "y": 0 + }, + "2": { + "x": 142, + "y": 177 + }, + "3": { + "x": -124, + "y": 182 + }, + "4": { + "x": -13, + "y": -222 + }, + "5": { + "x": -216, + "y": -23 + }, + "6": { + "x": 218, + "y": -66 + } +} + +exports['Physics snapshots Repulstion defaults binary tree 1'] = { + "1": { + "x": 45, + "y": -11 + }, + "2": { + "x": -64, + "y": 35 + }, + "3": { + "x": 175, + "y": -58 + }, + "4": { + "x": -140, + "y": -10 + }, + "5": { + "x": -291, + "y": 90 + }, + "6": { + "x": 153, + "y": -231 + }, + "7": { + "x": 291, + "y": 104 + }, + "8": { + "x": -173, + "y": -201 + }, + "9": { + "x": -70, + "y": 218 + }, + "10": { + "x": -458, + "y": -7 + }, + "11": { + "x": -370, + "y": 265 + }, + "12": { + "x": 143, + "y": -417 + }, + "13": { + "x": 344, + "y": -158 + }, + "14": { + "x": 446, + "y": 5 + }, + "15": { + "x": 247, + "y": 291 + }, + "16": { + "x": -358, + "y": -201 + }, + "17": { + "x": -85, + "y": -351 + }, + "18": { + "x": -210, + "y": 378 + }, + "19": { + "x": 69, + "y": 344 + } +} + +exports['Physics snapshots defaults 2 connected nodes 1'] = { + "1": { + "x": -34, + "y": 68 + }, + "2": { + "x": -30, + "y": -92 + } +} + +exports['Physics snapshots defaults 2 disconnected nodes 1'] = { + "1": { + "x": 13, + "y": -39 + }, + "2": { + "x": -10, + "y": 37 + } +} + +exports['Physics snapshots defaults 2 doubly connected nodes 1'] = { + "1": { + "x": -32, + "y": 29 + }, + "2": { + "x": 32, + "y": -30 + } +} + +exports['Physics snapshots defaults 6 node circle 1'] = { + "1": { + "x": -15, + "y": -130 + }, + "2": { + "x": -110, + "y": -45 + }, + "3": { + "x": -84, + "y": 79 + }, + "4": { + "x": 33, + "y": 127 + }, + "5": { + "x": 123, + "y": 37 + }, + "6": { + "x": 104, + "y": -87 + } +} + +exports['Physics snapshots defaults 6 node complete graph 1'] = { + "1": { + "x": -24, + "y": -61 + }, + "2": { + "x": 48, + "y": 99 + }, + "3": { + "x": -58, + "y": 60 + }, + "4": { + "x": 54, + "y": -49 + }, + "5": { + "x": -66, + "y": 6 + }, + "6": { + "x": 88, + "y": -7 + } +} + +exports['Physics snapshots defaults 6 node star 1'] = { + "1": { + "x": -1, + "y": 0 + }, + "2": { + "x": 87, + "y": 100 + }, + "3": { + "x": -67, + "y": 119 + }, + "4": { + "x": -6, + "y": -135 + }, + "5": { + "x": -131, + "y": -34 + }, + "6": { + "x": 126, + "y": -48 + } +} + +exports['Physics snapshots defaults binary tree 1'] = { + "1": { + "x": 46, + "y": -2 + }, + "2": { + "x": -84, + "y": 30 + }, + "3": { + "x": 174, + "y": -33 + }, + "4": { + "x": -126, + "y": -7 + }, + "5": { + "x": -253, + "y": 80 + }, + "6": { + "x": 191, + "y": -179 + }, + "7": { + "x": 262, + "y": 86 + }, + "8": { + "x": -179, + "y": -157 + }, + "9": { + "x": -76, + "y": 169 + }, + "10": { + "x": -379, + "y": 22 + }, + "11": { + "x": -332, + "y": 195 + }, + "12": { + "x": 118, + "y": -294 + }, + "13": { + "x": 319, + "y": -222 + }, + "14": { + "x": 393, + "y": 56 + }, + "15": { + "x": 258, + "y": 222 + }, + "16": { + "x": -307, + "y": -209 + }, + "17": { + "x": -125, + "y": -282 + }, + "18": { + "x": -131, + "y": 298 + }, + "19": { + "x": 30, + "y": 257 + } +} diff --git a/examples/network/basic_usage/standalone.html b/examples/network/basic_usage/standalone.html index 36ffed12c1..c15f02a420 100644 --- a/examples/network/basic_usage/standalone.html +++ b/examples/network/basic_usage/standalone.html @@ -38,7 +38,7 @@ diff --git a/examples/network/data/importingFromGephi.html b/examples/network/data/importingFromGephi.html index 70cb4b6613..94864ceeb2 100644 --- a/examples/network/data/importingFromGephi.html +++ b/examples/network/data/importingFromGephi.html @@ -7,10 +7,12 @@ + - - + - - - - - - - - diff --git a/examples/network/physics/physicsConfiguration.html b/examples/network/physics/physicsConfiguration.html index d8e3a950fa..f882c1b126 100644 --- a/examples/network/physics/physicsConfiguration.html +++ b/examples/network/physics/physicsConfiguration.html @@ -22,8 +22,11 @@ + -