3d-force-graph 1.74.6 → 1.75.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
@@ -107,7 +107,7 @@ new ForceGraph3d(<domElement>, { configOptions })
107
107
  | --- | --- | :--: |
108
108
  | <b>nodeRelSize</b>([<i>num</i>]) | Getter/setter for the ratio of node sphere volume (cubic px) per value unit. | 4 |
109
109
  | <b>nodeVal</b>([<i>num</i>, <i>str</i> or <i>fn</i>]) | Node object accessor function, attribute or a numeric constant for the node numeric value (affects sphere volume). | `val` |
110
- | <b>nodeLabel</b>([<i>str</i> or <i>fn</i>]) | Node object accessor function or attribute for name (shown in label). Supports plain text or HTML content. Note that this method uses `innerHTML` internally, so make sure to pre-sanitize any user-input content to prevent XSS vulnerabilities. | `name` |
110
+ | <b>nodeLabel</b>([<i>str</i> or <i>fn</i>]) | Node object accessor function or attribute for name (shown in label). Supports plain text, HTML string content or an [HTML element](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement). | `name` |
111
111
  | <b>nodeVisibility</b>([<i>boolean</i>, <i>str</i> or <i>fn</i>]) | Node object accessor function, attribute or a boolean constant for whether to display the node. | `true` |
112
112
  | <b>nodeColor</b>([<i>str</i> or <i>fn</i>]) | Node object accessor function or attribute for node color (affects sphere color). | `color` |
113
113
  | <b>nodeAutoColorBy</b>([<i>str</i> or <i>fn</i>]) | Node object accessor function (`fn(node)`) or attribute (e.g. `'type'`) to automatically group colors by. Only affects nodes without a color attribute. | |
@@ -120,7 +120,7 @@ new ForceGraph3d(<domElement>, { configOptions })
120
120
 
121
121
  | Method | Description | Default |
122
122
  | --- | --- | :--: |
123
- | <b>linkLabel</b>([<i>str</i> or <i>fn</i>]) | Link object accessor function or attribute for name (shown in label). Supports plain text or HTML content. Note that this method uses `innerHTML` internally, so make sure to pre-sanitize any user-input content to prevent XSS vulnerabilities. | `name` |
123
+ | <b>linkLabel</b>([<i>str</i> or <i>fn</i>]) | Link object accessor function or attribute for name (shown in label). Supports plain text, HTML string content or an [HTML element](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement). | `name` |
124
124
  | <b>linkVisibility</b>([<i>boolean</i>, <i>str</i> or <i>fn</i>]) | Link object accessor function, attribute or a boolean constant for whether to display the link line. A value of `false` maintains the link force without rendering it. | `true` |
125
125
  | <b>linkColor</b>([<i>str</i> or <i>fn</i>]) | Link object accessor function or attribute for line color. | `color` |
126
126
  | <b>linkAutoColorBy</b>([<i>str</i> or <i>fn</i>]) | Link object accessor function (`fn(link)`) or attribute (e.g. `'type'`) to automatically group colors by. Only affects links without a color attribute. | |
@@ -11,6 +11,8 @@ interface ConfigOptions {
11
11
  type Accessor<In, Out> = Out | string | ((obj: In) => Out);
12
12
  type ObjAccessor<T, InT = object> = Accessor<InT, T>;
13
13
 
14
+ type Label = string | HTMLElement;
15
+
14
16
  type Coords = { x: number; y: number; z: number; };
15
17
 
16
18
  // don't surface these internal props from inner ThreeForceGraph
@@ -32,10 +34,10 @@ interface ForceGraph3DGenericInstance<ChainableInstance, N extends NodeObject =
32
34
  showNavInfo(enabled: boolean): ChainableInstance;
33
35
 
34
36
  // Labels
35
- nodeLabel(): ObjAccessor<string, N>;
36
- nodeLabel(textAccessor: ObjAccessor<string, N>): ChainableInstance;
37
- linkLabel(): ObjAccessor<string, L>;
38
- linkLabel(textAccessor: ObjAccessor<string, L>): ChainableInstance;
37
+ nodeLabel(): ObjAccessor<Label, N>;
38
+ nodeLabel(textAccessor: ObjAccessor<Label, N>): ChainableInstance;
39
+ linkLabel(): ObjAccessor<Label, L>;
40
+ linkLabel(textAccessor: ObjAccessor<Label, L>): ChainableInstance;
39
41
 
40
42
  // Interaction
41
43
  onNodeClick(callback: (node: N, event: MouseEvent) => void): ChainableInstance;
@@ -1,4 +1,4 @@
1
- // Version 1.74.6 3d-force-graph - https://github.com/vasturiano/3d-force-graph
1
+ // Version 1.75.0 3d-force-graph - https://github.com/vasturiano/3d-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) :
@@ -106522,7 +106522,7 @@ var<${access}> ${name} : ${structName};`;
106522
106522
  }
106523
106523
  }
106524
106524
 
106525
- var css_248z$1 = ".float-tooltip-kap {\n position: absolute;\n padding: 2px 4px;\n border-radius: 3px;\n font: 12px sans-serif;\n color: #eee;\n background: rgba(0,0,0,0.6);\n pointer-events: none;\n}\n";
106525
+ var css_248z$1 = ".float-tooltip-kap {\n position: absolute;\n width: max-content; /* prevent shrinking near right edge */\n max-width: max(50%, 150px);\n padding: 3px 5px;\n border-radius: 3px;\n font: 12px sans-serif;\n color: #eee;\n background: rgba(0,0,0,0.6);\n pointer-events: none;\n}\n";
106526
106526
  styleInject$1(css_248z$1);
106527
106527
 
106528
106528
  var index = index$2({
@@ -106537,6 +106537,9 @@ var<${access}> ${name} : ${structName};`;
106537
106537
  style = _ref$style === undefined ? {} : _ref$style;
106538
106538
  var isD3Selection = !!domNode && _typeof(domNode) === 'object' && !!domNode.node && typeof domNode.node === 'function';
106539
106539
  var el = select(isD3Selection ? domNode.node() : domNode);
106540
+
106541
+ // make sure container is positioned, to provide anchor for tooltip
106542
+ el.style('position') === 'static' && el.style('position', 'relative');
106540
106543
  state.tooltipEl = el.append('div').attr('class', 'float-tooltip-kap');
106541
106544
  Object.entries(style).forEach(function (_ref2) {
106542
106545
  var _ref3 = _slicedToArray$1(_ref2, 2),
@@ -106545,7 +106548,7 @@ var<${access}> ${name} : ${structName};`;
106545
106548
  return state.tooltipEl.style(k, v);
106546
106549
  });
106547
106550
  state.tooltipEl // start off-screen
106548
- .style('left', '-100000px').style('display', 'none');
106551
+ .style('left', '-10000px').style('display', 'none');
106549
106552
  state.mouseInside = false;
106550
106553
  el.on('mousemove.tooltip', function (ev) {
106551
106554
  state.mouseInside = true;
@@ -106557,7 +106560,7 @@ var<${access}> ${name} : ${structName};`;
106557
106560
  // adjust horizontal position to not exceed canvas boundaries
106558
106561
  .style('transform', "translate(-".concat(mousePos[0] / canvasWidth * 100, "%, ").concat(
106559
106562
  // flip to above if near bottom
106560
- canvasHeight - mousePos[1] < 100 ? 'calc(-100% - 6px)' : '21px', ")"));
106563
+ canvasHeight > 130 && canvasHeight - mousePos[1] < 100 ? 'calc(-100% - 6px)' : '21px', ")"));
106561
106564
  });
106562
106565
  el.on('mouseover.tooltip', function () {
106563
106566
  state.mouseInside = true;
@@ -106570,7 +106573,14 @@ var<${access}> ${name} : ${structName};`;
106570
106573
  },
106571
106574
  update: function update(state) {
106572
106575
  state.tooltipEl.style('display', !!state.content && state.mouseInside ? 'inline' : 'none');
106573
- state.tooltipEl.html(state.content || '');
106576
+ if (state.content instanceof HTMLElement) {
106577
+ state.tooltipEl.text(''); // empty it
106578
+ state.tooltipEl.append(function () {
106579
+ return state.content;
106580
+ });
106581
+ } else {
106582
+ state.tooltipEl.html(state.content || '');
106583
+ }
106574
106584
  }
106575
106585
  });
106576
106586
 
@@ -106599,7 +106609,7 @@ var<${access}> ${name} : ${structName};`;
106599
106609
  }
106600
106610
  }
106601
106611
 
106602
- var css_248z = ".scene-nav-info {\n bottom: 5px;\n width: 100%;\n text-align: center;\n color: slategrey;\n opacity: 0.7;\n font-size: 10px;\n}\n\n.scene-tooltip {\n top: 0;\n color: lavender;\n font-size: 15px;\n background: rgba(0,0,0,0.5);\n padding: 2px 5px;\n border-radius: 3px;\n}\n\n.scene-nav-info, .scene-tooltip {\n position: absolute;\n font-family: sans-serif;\n pointer-events: none;\n user-select: none;\n}\n\n.scene-container canvas:focus {\n outline: none;\n}";
106612
+ var css_248z = ".scene-nav-info {\n position: absolute;\n bottom: 5px;\n width: 100%;\n text-align: center;\n color: slategrey;\n opacity: 0.7;\n font-size: 10px;\n font-family: sans-serif;\n pointer-events: none;\n user-select: none;\n}\n\n.scene-container canvas:focus {\n outline: none;\n}";
106603
106613
  styleInject(css_248z);
106604
106614
 
106605
106615
  function _arrayLikeToArray(r, a) {