force-graph 1.44.1 → 1.45.0

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
@@ -176,8 +176,8 @@ myGraph(<myDOMElement>)
176
176
  | <b>nodePointerAreaPaint</b>([<i>fn</i>]) | Callback function for painting a canvas area used to detect node pointer interactions. The provided paint color uniquely identifies the node and should be used to perform drawing operations on the provided canvas context. This painted area will not be visible, but instead be used to detect pointer interactions with the node. The callback function has the signature: `.nodePointerAreaPaint(<node>, <color>, <canvas context>, <current global scale>)`. | *default interaction area is a circle centered on the node and sized according to `val`.* |
177
177
  | <b>linkPointerAreaPaint</b>([<i>fn</i>]) | Callback function for painting a canvas area used to detect link pointer interactions. The provided paint color uniquely identifies the link and should be used to perform drawing operations on the provided canvas context. This painted area will not be visible, but instead be used to detect pointer interactions with the link. The callback function has the signature: `.linkPointerAreaPaint(<link>, <color>, <canvas context>, <current global scale>)`. | *default interaction area is a straight line between the source and target nodes.* |
178
178
  | <b>enableNodeDrag</b>([<i>boolean</i>]) | Getter/setter for whether to enable the user interaction to drag nodes by click-dragging. If enabled, every time a node is dragged the simulation is re-heated so the other nodes react to the changes. Only applicable if enablePointerInteraction is `true`. | `true` |
179
- | <b>enableZoomInteraction</b>([<i>boolean</i>]) | Getter/setter for whether to enable zooming user interactions. | `true` |
180
- | <b>enablePanInteraction</b>([<i>boolean</i>]) | Getter/setter for whether to enable panning user interactions. | `true` |
179
+ | <b>enableZoomInteraction</b>([<i>boolean</i> or <i>fn</i>]) | Getter/setter for whether to enable zooming user interactions. When a predicate function is provided, the mouse event is passed as an argument.| `true` |
180
+ | <b>enablePanInteraction</b>([<i>boolean</i> or <i>fn</i>]) | Getter/setter for whether to enable panning user interactions. When a predicate function is provided, the mouse event is passed as an argument.| `true` |
181
181
  | <b>enablePointerInteraction</b>([<i>boolean</i>]) | Getter/setter for whether to enable the mouse tracking events. This activates an internal tracker of the canvas mouse position and enables the functionality of object hover/click/drag and tooltip labels, at the cost of performance. If you're looking for maximum gain in your graph performance it's recommended to switch off this property. | `true` |
182
182
 
183
183
  ### Utility
@@ -177,9 +177,9 @@ interface ForceGraphGenericInstance<ChainableInstance> {
177
177
  enableNodeDrag(): boolean;
178
178
  enableNodeDrag(enable: boolean): ChainableInstance;
179
179
  enableZoomInteraction(): boolean;
180
- enableZoomInteraction(enable: boolean): ChainableInstance;
180
+ enableZoomInteraction(enable: boolean | ((event: MouseEvent) => boolean)): ChainableInstance;
181
181
  enablePanInteraction(): boolean;
182
- enablePanInteraction(enable: boolean): ChainableInstance;
182
+ enablePanInteraction(enable: boolean | ((event: MouseEvent) => boolean)): ChainableInstance;
183
183
  enablePointerInteraction(): boolean;
184
184
  enablePointerInteraction(enable?: boolean): ChainableInstance;
185
185
 
@@ -1,4 +1,4 @@
1
- // Version 1.44.1 force-graph - https://github.com/vasturiano/force-graph
1
+ // Version 1.45.0 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) :
@@ -11612,7 +11612,7 @@
11612
11612
  // Main canvas object to manipulate
11613
11613
  state.ctx = canvasCtx;
11614
11614
  },
11615
- update: function update(state) {
11615
+ update: function update(state, changedProps) {
11616
11616
  state.engineRunning = false; // Pause simulation
11617
11617
  state.onUpdate();
11618
11618
  if (state.nodeAutoColorBy !== null) {
@@ -11652,18 +11652,23 @@
11652
11652
  var maxDepth = Math.max.apply(Math, _toConsumableArray$2(Object.values(nodeDepths || [])));
11653
11653
  var dagLevelDistance = state.dagLevelDistance || state.graphData.nodes.length / (maxDepth || 1) * DAG_LEVEL_NODE_RATIO * (['radialin', 'radialout'].indexOf(state.dagMode) !== -1 ? 0.7 : 1);
11654
11654
 
11655
+ // Reset relevant fx/fy when swapping dag modes
11656
+ if (['lr', 'rl', 'td', 'bu'].includes(changedProps.dagMode)) {
11657
+ var resetProp = ['lr', 'rl'].includes(changedProps.dagMode) ? 'fx' : 'fy';
11658
+ state.graphData.nodes.filter(state.dagNodeFilter).forEach(function (node) {
11659
+ return delete node[resetProp];
11660
+ });
11661
+ }
11662
+
11655
11663
  // Fix nodes to x,y for dag mode
11656
- if (state.dagMode) {
11657
- var getFFn = function getFFn(fix, invert) {
11658
- return function (node) {
11659
- return !fix ? undefined : (nodeDepths[node[state.nodeId]] - maxDepth / 2) * dagLevelDistance * (invert ? -1 : 1);
11660
- };
11664
+ if (['lr', 'rl', 'td', 'bu'].includes(state.dagMode)) {
11665
+ var invert = ['rl', 'bu'].includes(state.dagMode);
11666
+ var fixFn = function fixFn(node) {
11667
+ return (nodeDepths[node[state.nodeId]] - maxDepth / 2) * dagLevelDistance * (invert ? -1 : 1);
11661
11668
  };
11662
- var fxFn = getFFn(['lr', 'rl'].indexOf(state.dagMode) !== -1, state.dagMode === 'rl');
11663
- var fyFn = getFFn(['td', 'bu'].indexOf(state.dagMode) !== -1, state.dagMode === 'bu');
11669
+ var _resetProp = ['lr', 'rl'].includes(state.dagMode) ? 'fx' : 'fy';
11664
11670
  state.graphData.nodes.filter(state.dagNodeFilter).forEach(function (node) {
11665
- node.fx = fxFn(node);
11666
- node.fy = fyFn(node);
11671
+ return node[_resetProp] = fixFn(node);
11667
11672
  });
11668
11673
  }
11669
11674
 
@@ -12248,7 +12253,7 @@
12248
12253
  state.zoom.filter(function (ev) {
12249
12254
  return (
12250
12255
  // disable zoom interaction
12251
- !ev.button && state.enableZoomPanInteraction && (state.enableZoomInteraction || ev.type !== 'wheel') && (state.enablePanInteraction || ev.type === 'wheel')
12256
+ !ev.button && state.enableZoomPanInteraction && (ev.type !== 'wheel' || index$2(state.enableZoomInteraction)(ev)) && (ev.type === 'wheel' || index$2(state.enablePanInteraction)(ev))
12252
12257
  );
12253
12258
  }).on('zoom', function (ev) {
12254
12259
  var t = ev.transform;