@krainovsd/graph 0.12.0-beta.4 → 0.12.0-beta.5

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/lib/cjs/index.cjs CHANGED
@@ -436,7 +436,7 @@ function pointerGetter(mouseEvent, areaRect, areaTransform) {
436
436
  }
437
437
 
438
438
  function isOverlapsNode(node, pointerX, pointerY, radius) {
439
- if (node.x == undefined || node.y == undefined)
439
+ if (node.x == undefined || node.y == undefined || node.visible === false)
440
440
  return false;
441
441
  switch (node._shape) {
442
442
  case "circle": {
@@ -932,7 +932,10 @@ function linkByPointerGetter({ areaRect, areaTransform, mouseEvent, links, linkH
932
932
  });
933
933
  }
934
934
  function isNearLink(mouseX, mouseY, link, threshold = 2) {
935
- if (!jsHelpers.isObject(link.source) || !jsHelpers.isObject(link.target))
935
+ if (!jsHelpers.isObject(link.source) ||
936
+ !jsHelpers.isObject(link.target) ||
937
+ link.source.visible === false ||
938
+ link.target.visible === false)
936
939
  return false;
937
940
  const x1 = link.source.x;
938
941
  const y1 = link.source.y;
@@ -1493,8 +1496,12 @@ function getDrawNode(nodeRenders, textRenders) {
1493
1496
  return function drawNode(node) {
1494
1497
  if (!this.context || !node.x || !node.y)
1495
1498
  return;
1496
- if (node.visible != undefined && !node.visible)
1499
+ if (node.visible != undefined && !node.visible) {
1500
+ node._radius = 0;
1501
+ node._width = 0;
1502
+ node._height = 0;
1497
1503
  return;
1504
+ }
1498
1505
  const nodeOptions = this.nodeOptionsCache[node.id];
1499
1506
  if (!nodeOptions)
1500
1507
  return;
@@ -2236,87 +2243,29 @@ function initCollideForce(forceUpdate) {
2236
2243
  else if (!this.simulation.force("collide") || forceUpdate) {
2237
2244
  this.simulation.force("collide", d3Force.forceCollide()
2238
2245
  .radius((node, index) => {
2239
- const nodeOptions = nodeIterationExtractor(node, index, this.nodes, this, this.nodeSettings.options ?? {}, nodeOptionsGetter);
2246
+ const nodeOptions = this.nodeOptionsCache[node.id];
2247
+ if (!nodeOptions)
2248
+ return 0;
2240
2249
  switch (nodeOptions.shape) {
2241
2250
  case "circle": {
2242
2251
  if (this.forceSettings.collideRadius) {
2243
2252
  return nodeIterationExtractor(node, index, this.nodes, this, this.forceSettings.collideRadius, undefined);
2244
2253
  }
2245
- const radius = nodeRadiusGetter({
2246
- radiusFlexible: this.nodeSettings.nodeRadiusFlexible,
2247
- radiusInitial: nodeOptions.radius,
2248
- linkCount: node.linkCount,
2249
- radiusIncrementByStep: this.nodeSettings.nodeRadiusIncrementByStep,
2250
- radiusLinkCountForStep: this.nodeSettings.nodeRadiusLinkCountForStep,
2251
- radiusMaxLinearSteps: this.nodeSettings.nodeRadiusMaxLinearSteps,
2252
- radiusLogFactor: this.nodeSettings.nodeRadiusLogFactor,
2253
- radiusLinkCountDividerForLog: this.nodeSettings.nodeRadiusLinkCountDividerForLog,
2254
- });
2255
- return radius + this.forceSettings.collideAdditionalRadius;
2254
+ return nodeOptions.radius + this.forceSettings.collideAdditionalRadius;
2256
2255
  }
2257
2256
  case "square": {
2258
- const { height, width } = nodeSizeGetter({
2259
- heightInitial: nodeOptions.width,
2260
- widthInitial: nodeOptions.height,
2261
- linkCount: node.linkCount,
2262
- sizeFlexible: this.nodeSettings.nodeSizeFlexible,
2263
- sizeIncrementByStep: this.nodeSettings.nodeSizeIncrementByStep,
2264
- sizeLinkCountForStep: this.nodeSettings.nodeSizeLinkCountForStep,
2265
- sizeMaxLinearSteps: this.nodeSettings.nodeSizeMaxLinearSteps,
2266
- sizeLogFactor: this.nodeSettings.nodeSizeLogFactor,
2267
- sizeLinkCountDividerForLog: this.nodeSettings.nodeSizeLinkCountDividerForLog,
2268
- });
2269
- return (Math.sqrt(width ** 2 + height ** 2) / 2 +
2257
+ return (Math.sqrt(nodeOptions.width ** 2 + nodeOptions.height ** 2) / 2 +
2270
2258
  this.forceSettings.collideAdditionalRadius);
2271
2259
  }
2272
2260
  case "text": {
2273
- let { height, width } = nodeSizeGetter({
2274
- heightInitial: nodeOptions.width,
2275
- widthInitial: nodeOptions.height,
2276
- linkCount: node.linkCount,
2277
- sizeFlexible: this.nodeSettings.nodeSizeFlexible,
2278
- sizeIncrementByStep: this.nodeSettings.nodeSizeIncrementByStep,
2279
- sizeLinkCountForStep: this.nodeSettings.nodeSizeLinkCountForStep,
2280
- sizeMaxLinearSteps: this.nodeSettings.nodeSizeMaxLinearSteps,
2281
- sizeLogFactor: this.nodeSettings.nodeSizeLogFactor,
2282
- sizeLinkCountDividerForLog: this.nodeSettings.nodeSizeLinkCountDividerForLog,
2283
- });
2284
- if (this.context && nodeOptions.text) {
2285
- const textInfo = getTextLines({
2286
- context: this.context,
2287
- text: nodeOptions.text,
2288
- textAlign: nodeOptions.textAlign,
2289
- textColor: nodeOptions.textColor,
2290
- textFont: nodeOptions.textFont,
2291
- textSize: nodeOptions.textSize,
2292
- maxWidth: width,
2293
- textStyle: nodeOptions.textStyle,
2294
- textWeight: nodeOptions.textWeight,
2295
- });
2296
- height =
2297
- textInfo.lines.length * nodeOptions.textSize +
2298
- (textInfo.lines.length - 1) * nodeOptions.textGap +
2299
- nodeOptions.labelYPadding;
2300
- width = textInfo.currentMaxSize + nodeOptions.labelXPadding;
2301
- }
2302
- return (Math.sqrt(width ** 2 + height ** 2) / 2 +
2261
+ return (Math.sqrt(nodeOptions.width ** 2 + nodeOptions.height ** 2) / 2 +
2303
2262
  this.forceSettings.collideAdditionalRadius);
2304
2263
  }
2305
2264
  default: {
2306
2265
  if (this.forceSettings.collideRadius) {
2307
2266
  return nodeIterationExtractor(node, index, this.nodes, this, this.forceSettings.collideRadius, undefined);
2308
2267
  }
2309
- const radius = nodeRadiusGetter({
2310
- radiusFlexible: this.nodeSettings.nodeRadiusFlexible,
2311
- radiusInitial: nodeOptions.radius,
2312
- radiusIncrementByStep: this.nodeSettings.nodeRadiusIncrementByStep,
2313
- radiusLinkCountForStep: this.nodeSettings.nodeRadiusLinkCountForStep,
2314
- radiusMaxLinearSteps: this.nodeSettings.nodeRadiusMaxLinearSteps,
2315
- radiusLogFactor: this.nodeSettings.nodeRadiusLogFactor,
2316
- radiusLinkCountDividerForLog: this.nodeSettings.nodeRadiusLinkCountDividerForLog,
2317
- linkCount: node.linkCount,
2318
- });
2319
- return radius + this.forceSettings.collideAdditionalRadius;
2268
+ return nodeOptions.radius + this.forceSettings.collideAdditionalRadius;
2320
2269
  }
2321
2270
  }
2322
2271
  })
@@ -2435,9 +2384,9 @@ function updateNodeCache() {
2435
2384
  width = maxSize + nodeOptions.labelXPadding;
2436
2385
  this.cachedNodeLabel[node.id] = lines;
2437
2386
  }
2438
- nodeOptions.width = width;
2439
- nodeOptions.height = height;
2440
- nodeOptions.radius = radius;
2387
+ nodeOptions.width = node.visible === false ? 0 : width;
2388
+ nodeOptions.height = node.visible === false ? 0 : height;
2389
+ nodeOptions.radius = node.visible === false ? 0 : radius;
2441
2390
  nodeOptions.labelSize = labelSize;
2442
2391
  /** text */
2443
2392
  if (nodeOptions.text) {