force-graph 1.42.5 → 1.42.8

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.
package/README.md CHANGED
@@ -3,7 +3,7 @@ force-graph
3
3
 
4
4
  [![NPM package][npm-img]][npm-url]
5
5
  [![Build Size][build-size-img]][build-size-url]
6
- [![Dependencies][dependencies-img]][dependencies-url]
6
+ [![NPM Downloads][npm-downloads-img]][npm-downloads-url]
7
7
 
8
8
  Force-directed graph rendered on HTML5 canvas.
9
9
 
@@ -15,7 +15,12 @@ A web component to represent a graph data structure in a 2-dimensional canvas us
15
15
  Uses HTML5 canvas for rendering and [d3-force](https://github.com/d3/d3-force) for the underlying physics engine.
16
16
  Supports canvas zooming/panning, node dragging and node/link hover/click interactions.
17
17
 
18
- Check out the examples:
18
+ See also the [3D version](https://github.com/vasturiano/3d-force-graph).
19
+
20
+ And check out the [React bindings](https://github.com/vasturiano/react-force-graph).
21
+
22
+ ## Examples
23
+
19
24
  * [Basic](https://vasturiano.github.io/force-graph/example/basic/) ([source](https://github.com/vasturiano/force-graph/blob/master/example/basic/index.html))
20
25
  * [Load JSON](https://vasturiano.github.io/force-graph/example/load-json/) ([source](https://github.com/vasturiano/force-graph/blob/master/example/load-json/index.html))
21
26
  * [Medium size graph (~4k elements)](https://vasturiano.github.io/force-graph/example/medium-graph/) ([source](https://github.com/vasturiano/force-graph/blob/master/example/medium-graph/index.html))
@@ -46,28 +51,24 @@ Check out the examples:
46
51
  * [yarn.lock dependency graph (DAG mode)](https://vasturiano.github.io/force-graph/example/dag-yarn/) ([source](https://github.com/vasturiano/force-graph/blob/master/example/dag-yarn/index.html))
47
52
  * [Usage as UI to construct graphs](https://vasturiano.github.io/force-graph/example/build-a-graph/) ([source](https://github.com/vasturiano/force-graph/blob/master/example/build-a-graph/index.html))
48
53
 
49
- See also the [3D version](https://github.com/vasturiano/3d-force-graph).
50
-
51
- And check out the [React bindings](https://github.com/vasturiano/react-force-graph).
52
-
53
54
  ## Quick start
54
55
 
55
- ```
56
+ ```js
56
57
  import ForceGraph from 'force-graph';
57
58
  ```
58
59
  or
59
- ```
60
- var ForceGraph = require('force-graph');
60
+ ```js
61
+ const ForceGraph = require('force-graph');
61
62
  ```
62
63
  or even
63
- ```
64
+ ```html
64
65
  <script src="//unpkg.com/force-graph"></script>
65
66
  ```
66
67
  then
67
- ```
68
- var myGraph = ForceGraph();
68
+ ```js
69
+ const myGraph = ForceGraph();
69
70
  myGraph(<myDOMElement>)
70
- .graphData(<myData>);
71
+ .graphData(<myData>);
71
72
  ```
72
73
 
73
74
  ## API reference
@@ -191,7 +192,7 @@ myGraph(<myDOMElement>)
191
192
  | <b>graph2ScreenCoords</b>(<i>x</i>, <i>y</i>) | Utility method to translate node coordinates to the viewport domain. Given a pair of `x`,`y` graph coordinates, returns the current equivalent `{x, y}` in viewport coordinates. |
192
193
 
193
194
  ### Input JSON syntax
194
- ```
195
+ ```json
195
196
  {
196
197
  "nodes": [
197
198
  {
@@ -204,14 +205,14 @@ myGraph(<myDOMElement>)
204
205
  "name": "name2",
205
206
  "val": 10
206
207
  },
207
- (...)
208
+ ...
208
209
  ],
209
210
  "links": [
210
211
  {
211
212
  "source": "id1",
212
213
  "target": "id2"
213
214
  },
214
- (...)
215
+ ...
215
216
  ]
216
217
  }
217
218
  ```
@@ -220,9 +221,9 @@ myGraph(<myDOMElement>)
220
221
 
221
222
  [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=L398E7PKP47E8&currency_code=USD&source=url) If this project has helped you and you'd like to contribute back, you can always [buy me a ☕](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=L398E7PKP47E8&currency_code=USD&source=url)!
222
223
 
223
- [npm-img]: https://img.shields.io/npm/v/force-graph.svg
224
+ [npm-img]: https://img.shields.io/npm/v/force-graph
224
225
  [npm-url]: https://npmjs.org/package/force-graph
225
- [build-size-img]: https://img.shields.io/bundlephobia/minzip/force-graph.svg
226
+ [build-size-img]: https://img.shields.io/bundlephobia/minzip/force-graph
226
227
  [build-size-url]: https://bundlephobia.com/result?p=force-graph
227
- [dependencies-img]: https://img.shields.io/david/vasturiano/force-graph.svg
228
- [dependencies-url]: https://david-dm.org/vasturiano/force-graph
228
+ [npm-downloads-img]: https://img.shields.io/npm/dt/force-graph
229
+ [npm-downloads-url]: https://www.npmtrends.com/force-graph
@@ -72,8 +72,8 @@ interface ForceGraphGenericInstance<ChainableInstance> {
72
72
  nodeAutoColorBy(colorByAccessor: NodeAccessor<string | null>): ChainableInstance;
73
73
  nodeCanvasObject(): CanvasCustomRenderFn<NodeObject>;
74
74
  nodeCanvasObject(renderFn: CanvasCustomRenderFn<NodeObject>): ChainableInstance;
75
- nodeCanvasObjectMode(): string | ((obj: NodeObject) => CanvasCustomRenderMode);
76
- nodeCanvasObjectMode(modeAccessor: string | ((obj: NodeObject) => CanvasCustomRenderMode)): ChainableInstance;
75
+ nodeCanvasObjectMode(): string | ((obj: NodeObject) => CanvasCustomRenderMode | any);
76
+ nodeCanvasObjectMode(modeAccessor: string | ((obj: NodeObject) => CanvasCustomRenderMode | any)): ChainableInstance;
77
77
  nodePointerAreaPaint(): CanvasPointerAreaPaintFn<NodeObject>;
78
78
  nodePointerAreaPaint(renderFn: CanvasPointerAreaPaintFn<NodeObject>): ChainableInstance;
79
79
 
@@ -1,4 +1,4 @@
1
- // Version 1.42.5 force-graph - https://github.com/vasturiano/force-graph
1
+ // Version 1.42.8 force-graph - https://github.com/vasturiano/force-graph
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -9166,12 +9166,16 @@
9166
9166
  return [];
9167
9167
  }
9168
9168
 
9169
- const trm = v2 * v2 - 4 * v1 * v3,
9170
- sq = Math.sqrt(trm),
9171
- d2 = 2 * v1;
9169
+ const d2 = 2 * v1;
9172
9170
 
9173
9171
  if (utils.approximately(d2, 0)) return [];
9174
9172
 
9173
+ const trm = v2 * v2 - 4 * v1 * v3;
9174
+
9175
+ if (trm < 0) return [];
9176
+
9177
+ const sq = Math.sqrt(trm);
9178
+
9175
9179
  return [(sq - v2) / d2, -(v2 + sq) / d2].filter(function (r) {
9176
9180
  return 0 <= r && r <= 1;
9177
9181
  });
@@ -9760,7 +9764,7 @@
9760
9764
  __normal2(t) {
9761
9765
  const d = this.derivative(t);
9762
9766
  const q = sqrt(d.x * d.x + d.y * d.y);
9763
- return { x: -d.y / q, y: d.x / q };
9767
+ return { t, x: -d.y / q, y: d.x / q };
9764
9768
  }
9765
9769
 
9766
9770
  __normal3(t) {
@@ -9799,6 +9803,7 @@
9799
9803
  ];
9800
9804
  // normal vector:
9801
9805
  const n = {
9806
+ t,
9802
9807
  x: R[0] * r1.x + R[1] * r1.y + R[2] * r1.z,
9803
9808
  y: R[3] * r1.x + R[4] * r1.y + R[5] * r1.z,
9804
9809
  z: R[6] * r1.x + R[7] * r1.y + R[8] * r1.z,