force-graph 1.47.3 → 1.48.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
@@ -92,7 +92,7 @@ const myGraph = new ForceGraph(<myDOMElement>)
92
92
  | --- | --- | :--: |
93
93
  | <b>nodeRelSize</b>([<i>num</i>]) | Getter/setter for the ratio of node circle area (square px) per value unit. | 4 |
94
94
  | <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 circle area). | `val` |
95
- | <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` |
95
+ | <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` |
96
96
  | <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` |
97
97
  | <b>nodeColor</b>([<i>str</i> or <i>fn</i>]) | Node object accessor function or attribute for node color (affects circle color). | `color` |
98
98
  | <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. | |
@@ -103,7 +103,7 @@ const myGraph = new ForceGraph(<myDOMElement>)
103
103
 
104
104
  | Method | Description | Default |
105
105
  | --- | --- | :--: |
106
- | <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` |
106
+ | <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` |
107
107
  | <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` |
108
108
  | <b>linkColor</b>([<i>str</i> or <i>fn</i>]) | Link object accessor function or attribute for line color. | `color` |
109
109
  | <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. | |
@@ -23,6 +23,8 @@ type Accessor<In, Out> = Out | string | ((obj: In) => Out);
23
23
  type NodeAccessor<T, N> = Accessor<N, T>;
24
24
  type LinkAccessor<T, N, L> = Accessor<L, T>;
25
25
 
26
+ type Label = string | HTMLElement;
27
+
26
28
  type CanvasCustomRenderMode = 'replace' | 'before' | 'after';
27
29
  type CanvasCustomRenderModeFn<T> = (obj: T) => CanvasCustomRenderMode | any;
28
30
  type CanvasCustomRenderFn<T> = (obj: T, canvasContext: CanvasRenderingContext2D, globalScale: number) => void;
@@ -64,8 +66,8 @@ declare class ForceGraphGeneric<ChainableInstance, N extends NodeObject = NodeOb
64
66
  nodeRelSize(size: number): ChainableInstance;
65
67
  nodeVal(): NodeAccessor<number, N>;
66
68
  nodeVal(valAccessor: NodeAccessor<number, N>): ChainableInstance;
67
- nodeLabel(): NodeAccessor<string, N>;
68
- nodeLabel(labelAccessor: NodeAccessor<string, N>): ChainableInstance;
69
+ nodeLabel(): NodeAccessor<Label, N>;
70
+ nodeLabel(labelAccessor: NodeAccessor<Label, N>): ChainableInstance;
69
71
  nodeVisibility(): NodeAccessor<boolean, N>;
70
72
  nodeVisibility(visibilityAccessor: NodeAccessor<boolean, N>): ChainableInstance;
71
73
  nodeColor(): NodeAccessor<string, N>;
@@ -80,8 +82,8 @@ declare class ForceGraphGeneric<ChainableInstance, N extends NodeObject = NodeOb
80
82
  nodePointerAreaPaint(renderFn: CanvasPointerAreaPaintFn<N>): ChainableInstance;
81
83
 
82
84
  // Link styling
83
- linkLabel(): LinkAccessor<string, N, L>;
84
- linkLabel(labelAccessor: LinkAccessor<string, N, L>): ChainableInstance;
85
+ linkLabel(): LinkAccessor<Label, N, L>;
86
+ linkLabel(labelAccessor: LinkAccessor<Label, N, L>): ChainableInstance;
85
87
  linkVisibility(): LinkAccessor<boolean, N, L>;
86
88
  linkVisibility(visibilityAccessor: LinkAccessor<boolean, N, L>): ChainableInstance;
87
89
  linkColor(): LinkAccessor<string, N, L>;
@@ -1,4 +1,4 @@
1
- // Version 1.47.3 force-graph - https://github.com/vasturiano/force-graph
1
+ // Version 1.48.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) :
@@ -7006,7 +7006,7 @@
7006
7006
  }
7007
7007
  }
7008
7008
 
7009
- var css_248z = ".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";
7009
+ var css_248z = ".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";
7010
7010
  styleInject(css_248z);
7011
7011
 
7012
7012
  var index$2 = index$4({
@@ -7021,6 +7021,9 @@
7021
7021
  style = _ref$style === undefined ? {} : _ref$style;
7022
7022
  var isD3Selection = !!domNode && _typeof(domNode) === 'object' && !!domNode.node && typeof domNode.node === 'function';
7023
7023
  var el = d3Select(isD3Selection ? domNode.node() : domNode);
7024
+
7025
+ // make sure container is positioned, to provide anchor for tooltip
7026
+ el.style('position') === 'static' && el.style('position', 'relative');
7024
7027
  state.tooltipEl = el.append('div').attr('class', 'float-tooltip-kap');
7025
7028
  Object.entries(style).forEach(function (_ref2) {
7026
7029
  var _ref3 = _slicedToArray$1(_ref2, 2),
@@ -7029,7 +7032,7 @@
7029
7032
  return state.tooltipEl.style(k, v);
7030
7033
  });
7031
7034
  state.tooltipEl // start off-screen
7032
- .style('left', '-100000px').style('display', 'none');
7035
+ .style('left', '-10000px').style('display', 'none');
7033
7036
  state.mouseInside = false;
7034
7037
  el.on('mousemove.tooltip', function (ev) {
7035
7038
  state.mouseInside = true;
@@ -7041,7 +7044,7 @@
7041
7044
  // adjust horizontal position to not exceed canvas boundaries
7042
7045
  .style('transform', "translate(-".concat(mousePos[0] / canvasWidth * 100, "%, ").concat(
7043
7046
  // flip to above if near bottom
7044
- canvasHeight - mousePos[1] < 100 ? 'calc(-100% - 6px)' : '21px', ")"));
7047
+ canvasHeight > 130 && canvasHeight - mousePos[1] < 100 ? 'calc(-100% - 6px)' : '21px', ")"));
7045
7048
  });
7046
7049
  el.on('mouseover.tooltip', function () {
7047
7050
  state.mouseInside = true;
@@ -7054,7 +7057,14 @@
7054
7057
  },
7055
7058
  update: function update(state) {
7056
7059
  state.tooltipEl.style('display', !!state.content && state.mouseInside ? 'inline' : 'none');
7057
- state.tooltipEl.html(state.content || '');
7060
+ if (state.content instanceof HTMLElement) {
7061
+ state.tooltipEl.text(''); // empty it
7062
+ state.tooltipEl.append(function () {
7063
+ return state.content;
7064
+ });
7065
+ } else {
7066
+ state.tooltipEl.html(state.content || '');
7067
+ }
7058
7068
  }
7059
7069
  });
7060
7070