force-3d-graph 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,17 +3,18 @@ var it = (h, e, s) => e in h ? st(h, e, { enumerable: !0, configurable: !0, writ
3
3
  var l = (h, e, s) => it(h, typeof e != "symbol" ? e + "" : e, s);
4
4
  import * as m from "three";
5
5
  import { EventDispatcher as ot, Vector3 as S, MOUSE as $, TOUCH as G, Spherical as Ne, Quaternion as Se, Vector2 as k, Ray as nt, Plane as at, MathUtils as rt } from "three";
6
- const R = {
6
+ const T = {
7
7
  backgroundColor: 657930,
8
8
  cameraPosition: { x: 0, y: 0, z: 80 },
9
9
  cameraFov: 75,
10
- repulsionStrength: 100,
11
- attractionStrength: 0.01,
12
- damping: 0.9,
13
- useBarnesHut: !1,
14
- // Auto-enabled for large graphs
10
+ repulsionStrength: 200,
11
+ attractionStrength: 8e-3,
12
+ damping: 0.95,
13
+ useBarnesHut: !0,
14
+ // Enabled by default for better performance
15
15
  barnesHutTheta: 0.5,
16
- defaultNodeColor: 4886754,
16
+ defaultNodeColor: 16750950,
17
+ // Tangerine to match the premium glass material
17
18
  nodeRadius: 2,
18
19
  nodeSegments: 32,
19
20
  enableLOD: !0,
@@ -97,8 +98,8 @@ class gt extends ot {
97
98
  return function(tt = null) {
98
99
  const Ce = t.object.position;
99
100
  n.copy(Ce).sub(t.target), n.applyQuaternion(p), r.setFromVector3(n), t.autoRotate && i === o.NONE && B(He(tt)), t.enableDamping ? (r.theta += c.theta * t.dampingFactor, r.phi += c.phi * t.dampingFactor) : (r.theta += c.theta, r.phi += c.phi);
100
- let L = t.minAzimuthAngle, I = t.maxAzimuthAngle;
101
- isFinite(L) && isFinite(I) && (L < -Math.PI ? L += z : L > Math.PI && (L -= z), I < -Math.PI ? I += z : I > Math.PI && (I -= z), L <= I ? r.theta = Math.max(L, Math.min(I, r.theta)) : r.theta = r.theta > (L + I) / 2 ? Math.max(L, r.theta) : Math.min(I, r.theta)), r.phi = Math.max(t.minPolarAngle, Math.min(t.maxPolarAngle, r.phi)), r.makeSafe(), t.enableDamping === !0 ? t.target.addScaledVector(g, t.dampingFactor) : t.target.add(g), t.target.sub(t.cursor), t.target.clampLength(t.minTargetRadius, t.maxTargetRadius), t.target.add(t.cursor), t.zoomToCursor && H || t.object.isOrthographicCamera ? r.radius = ie(r.radius) : r.radius = ie(r.radius * d), n.setFromSpherical(r), n.applyQuaternion(b), Ce.copy(t.target).add(n), t.object.lookAt(t.target), t.enableDamping === !0 ? (c.theta *= 1 - t.dampingFactor, c.phi *= 1 - t.dampingFactor, g.multiplyScalar(1 - t.dampingFactor)) : (c.set(0, 0, 0), g.set(0, 0, 0));
101
+ let I = t.minAzimuthAngle, R = t.maxAzimuthAngle;
102
+ isFinite(I) && isFinite(R) && (I < -Math.PI ? I += z : I > Math.PI && (I -= z), R < -Math.PI ? R += z : R > Math.PI && (R -= z), I <= R ? r.theta = Math.max(I, Math.min(R, r.theta)) : r.theta = r.theta > (I + R) / 2 ? Math.max(I, r.theta) : Math.min(R, r.theta)), r.phi = Math.max(t.minPolarAngle, Math.min(t.maxPolarAngle, r.phi)), r.makeSafe(), t.enableDamping === !0 ? t.target.addScaledVector(g, t.dampingFactor) : t.target.add(g), t.target.sub(t.cursor), t.target.clampLength(t.minTargetRadius, t.maxTargetRadius), t.target.add(t.cursor), t.zoomToCursor && H || t.object.isOrthographicCamera ? r.radius = ie(r.radius) : r.radius = ie(r.radius * d), n.setFromSpherical(r), n.applyQuaternion(b), Ce.copy(t.target).add(n), t.object.lookAt(t.target), t.enableDamping === !0 ? (c.theta *= 1 - t.dampingFactor, c.phi *= 1 - t.dampingFactor, g.multiplyScalar(1 - t.dampingFactor)) : (c.set(0, 0, 0), g.set(0, 0, 0));
102
103
  let ae = !1;
103
104
  if (t.zoomToCursor && H) {
104
105
  let X = null;
@@ -134,7 +135,7 @@ class gt extends ot {
134
135
  let i = o.NONE;
135
136
  const a = 1e-6, r = new Ne(), c = new Ne();
136
137
  let d = 1;
137
- const g = new S(), u = new k(), y = new k(), f = new k(), x = new k(), v = new k(), M = new k(), N = new k(), O = new k(), T = new k(), Y = new S(), P = new k();
138
+ const g = new S(), u = new k(), y = new k(), f = new k(), x = new k(), v = new k(), M = new k(), N = new k(), O = new k(), L = new k(), Y = new S(), P = new k();
138
139
  let H = !1;
139
140
  const E = [], _ = {};
140
141
  let ee = !1;
@@ -204,7 +205,7 @@ class gt extends ot {
204
205
  B(2 * Math.PI * f.x / p.clientHeight), W(2 * Math.PI * f.y / p.clientHeight), u.copy(y), t.update();
205
206
  }
206
207
  function je(n) {
207
- O.set(n.clientX, n.clientY), T.subVectors(O, N), T.y > 0 ? te(q(T.y)) : T.y < 0 && he(q(T.y)), N.copy(O), t.update();
208
+ O.set(n.clientX, n.clientY), L.subVectors(O, N), L.y > 0 ? te(q(L.y)) : L.y < 0 && he(q(L.y)), N.copy(O), t.update();
208
209
  }
209
210
  function $e(n) {
210
211
  v.set(n.clientX, n.clientY), M.subVectors(v, x).multiplyScalar(t.panSpeed), A(M.x, M.y), x.copy(v), t.update();
@@ -278,7 +279,7 @@ class gt extends ot {
278
279
  }
279
280
  function xe(n) {
280
281
  const p = j(n), b = n.pageX - p.x, w = n.pageY - p.y, C = Math.sqrt(b * b + w * w);
281
- O.set(0, C), T.set(0, Math.pow(O.y / N.y, t.zoomSpeed)), te(T.y), N.copy(O);
282
+ O.set(0, C), L.set(0, Math.pow(O.y / N.y, t.zoomSpeed)), te(L.y), N.copy(O);
282
283
  const F = (n.pageX + p.x) * 0.5, z = (n.pageY + p.y) * 0.5;
283
284
  se(F, z);
284
285
  }
@@ -1307,12 +1308,13 @@ class bt {
1307
1308
  }
1308
1309
  }
1309
1310
  class vt {
1310
- constructor(e, s = 2, t = [32, 16, 8]) {
1311
+ constructor(e, s = 2, t = [32, 16, 8], o = 16750950) {
1311
1312
  l(this, "materialFactory");
1312
1313
  l(this, "geometryCache", /* @__PURE__ */ new Map());
1313
1314
  l(this, "nodeRadius");
1314
1315
  l(this, "lodSegments");
1315
- this.materialFactory = e, this.nodeRadius = s, this.lodSegments = t, this.initGeometryCache();
1316
+ l(this, "defaultNodeColor");
1317
+ this.materialFactory = e, this.nodeRadius = s, this.lodSegments = t, this.defaultNodeColor = o, this.initGeometryCache();
1316
1318
  }
1317
1319
  /**
1318
1320
  * Pre-create geometries for each LOD level
@@ -1340,7 +1342,7 @@ class vt {
1340
1342
  const t = new m.Group();
1341
1343
  t.name = `node-${e.id}`, t.userData = { nodeId: e.id, nodeData: e };
1342
1344
  const o = this.getGeometry(s), i = this.materialFactory.createGlassMaterial(
1343
- e.color ?? 4886754
1345
+ e.color ?? this.defaultNodeColor
1344
1346
  ), a = new m.Mesh(o, i);
1345
1347
  a.castShadow = !0, a.receiveShadow = !0, t.add(a);
1346
1348
  const r = this.materialFactory.createLabelMaterial(e.label), c = new m.Sprite(r);
@@ -2607,8 +2609,8 @@ const Tt = {
2607
2609
  nodeRadius: 24,
2608
2610
  edgeColor: "rgba(255, 255, 255, 0.15)",
2609
2611
  edgeOpacity: 0.4,
2610
- repulsionStrength: 500,
2611
- // Full repulsion
2612
+ repulsionStrength: 5e3,
2613
+ // Strong repulsion for spread out layout
2612
2614
  attractionStrength: 1e-3,
2613
2615
  // Very low attraction
2614
2616
  damping: 0.85
@@ -2981,21 +2983,22 @@ class Ft {
2981
2983
  l(this, "devControls", null);
2982
2984
  l(this, "viewMode", "3d");
2983
2985
  l(this, "graphData", null);
2984
- this.options = { ...R, ...s }, this.container = ct(e), this.materialFactory = new bt(), this.nodeFactory = new vt(
2986
+ this.options = { ...T, ...s }, this.container = ct(e), this.materialFactory = new bt(), this.nodeFactory = new vt(
2985
2987
  this.materialFactory,
2986
- this.options.nodeRadius ?? R.nodeRadius,
2987
- this.options.lodSegments ?? R.lodSegments
2988
+ this.options.nodeRadius ?? T.nodeRadius,
2989
+ this.options.lodSegments ?? T.lodSegments,
2990
+ this.options.defaultNodeColor ?? T.defaultNodeColor
2988
2991
  ), this.edgeFactory = new Mt(
2989
2992
  this.materialFactory,
2990
- this.options.edgeColor ?? R.edgeColor,
2991
- this.options.edgeOpacity ?? R.edgeOpacity
2993
+ this.options.edgeColor ?? T.edgeColor,
2994
+ this.options.edgeOpacity ?? T.edgeOpacity
2992
2995
  ), this.sceneManager = new ut(this.container, this.options), this.lodManager = new wt(
2993
2996
  this.sceneManager.camera,
2994
- this.options.lodDistances ?? R.lodDistances,
2995
- this.options.enableLOD ?? R.enableLOD
2997
+ this.options.lodDistances ?? T.lodDistances,
2998
+ this.options.enableLOD ?? T.enableLOD
2996
2999
  ), this.frustumCuller = new Et(
2997
3000
  this.sceneManager.camera,
2998
- this.options.enableEdgeCulling ?? R.enableEdgeCulling
3001
+ this.options.enableEdgeCulling ?? T.enableEdgeCulling
2999
3002
  ), this.nodeManager = new ft(this.sceneManager, this.nodeFactory), this.edgeManager = new mt(this.sceneManager, this.nodeManager, this.edgeFactory), this.graphEngine = new Le(
3000
3003
  this.nodeManager.getAllNodes(),
3001
3004
  this.edgeManager.getAllEdges(),
@@ -3010,7 +3013,7 @@ class Ft {
3010
3013
  this.sceneManager,
3011
3014
  () => this.onSimulate(),
3012
3015
  () => this.onRender(),
3013
- this.options.targetFPS ?? R.targetFPS
3016
+ this.options.targetFPS ?? T.targetFPS
3014
3017
  ), this.raycasterManager = new Ct(this.sceneManager, this.container), this.panelManager = new Nt(this.container), this.edgePanelManager = new St(this.container), this.edgeTooltipManager = new zt(), this.edgePanelManager.setNodeClickCallback((t) => {
3015
3018
  this.edgePanelManager.hide(), this.focusOnNode(t), setTimeout(() => {
3016
3019
  this.showNodePanel(t);
@@ -3255,8 +3258,8 @@ class Ft {
3255
3258
  x: c.x + x.x * f,
3256
3259
  y: c.y + x.y * f,
3257
3260
  z: c.z + x.z * f
3258
- }, M = { x: a.position.x, y: a.position.y, z: a.position.z }, N = { x: r.target.x, y: r.target.y, z: r.target.z }, O = 800, T = performance.now(), Y = () => {
3259
- const P = performance.now() - T, H = Math.min(P / O, 1), E = 1 - Math.pow(1 - H, 3);
3261
+ }, M = { x: a.position.x, y: a.position.y, z: a.position.z }, N = { x: r.target.x, y: r.target.y, z: r.target.z }, O = 800, L = performance.now(), Y = () => {
3262
+ const P = performance.now() - L, H = Math.min(P / O, 1), E = 1 - Math.pow(1 - H, 3);
3260
3263
  a.position.x = M.x + (v.x - M.x) * E, a.position.y = M.y + (v.y - M.y) * E, a.position.z = M.z + (v.z - M.z) * E, r.target.x = N.x + (c.x - N.x) * E, r.target.y = N.y + (c.y - N.y) * E, r.target.z = N.z + (c.z - N.z) * E, r.update(), H < 1 && requestAnimationFrame(Y);
3261
3264
  };
3262
3265
  Y();
@@ -3600,7 +3603,7 @@ function Dt(h = 1e3) {
3600
3603
  return { nodes: e, edges: s };
3601
3604
  }
3602
3605
  export {
3603
- R as DEFAULT_OPTIONS,
3606
+ T as DEFAULT_OPTIONS,
3604
3607
  Ft as ForceGraph3D,
3605
3608
  U as LODLevel,
3606
3609
  D as createEdgeKey,