hilbert-chart-3d 0.5.0 → 0.6.1

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
@@ -88,6 +88,7 @@ new HilbertChart3D(<domElement>, { configOptions })
88
88
  | <b>onHover</b>(<i>fn</i>) | Callback function for range mouse over events. Receives the current range (or `null` if hovering out) and the previous range (or `null`). | - |
89
89
  | <b>onClick</b>(<i>fn</i>) | Callback function for range clicks. Receives the range object and the mouse event. | - |
90
90
  | <b>onBackgroundClick</b>(<i>fn</i>) | Callback function for click events on the empty background space. Receives the mouse event. | - |
91
+ | <b>hoverOrderComparator</b>(<i>fn</i>) | Comparator function to use when hovering over multiple ranges under the same line of sight. This function can be used to prioritize hovering some ranges over others. | By default, hovering priority is based solely on camera proximity (closest range wins). |
91
92
 
92
93
  Use BigInt literals (for example, `12345678901234567890n`) when values exceed JavaScript's safe integer range.
93
94
 
@@ -16,11 +16,14 @@ interface HilbertChartOptions {
16
16
 
17
17
  type RangeBounds = { start: number; length: number } | { start: bigint; length: bigint };
18
18
  type RangeAccessor<R extends RangeBounds, T> = Accessor<R, T>;
19
+ type RangeCompFn = (a: Range, b: Range) => number;
19
20
  type NumFormatter = (num: NumericValue) => string;
20
21
 
21
22
  declare class HilbertChart<R extends RangeBounds = Range> {
22
23
  constructor(element: HTMLElement, options?: HilbertChartOptions);
23
24
 
25
+ _destructor(): void;
26
+
24
27
  width(): number;
25
28
  width(width: number): HilbertChart<R>;
26
29
  height(): number;
@@ -67,6 +70,7 @@ declare class HilbertChart<R extends RangeBounds = Range> {
67
70
  onHover(cb: (range: R | null, previousRange: R | null) => void): HilbertChart<R>;
68
71
  onClick(cb: (range: R, event: MouseEvent) => void): HilbertChart<R>;
69
72
  onBackgroundClick(cb: (event: MouseEvent) => void): HilbertChart<R>;
73
+ hoverOrderComparator(compFn: RangeCompFn): HilbertChart<R>;
70
74
  }
71
75
 
72
76
  export { HilbertChart as default };
@@ -1,4 +1,4 @@
1
- // Version 0.5.0 hilbert-chart-3d - https://github.com/vasturiano/hilbert-chart-3d
1
+ // Version 0.6.1 hilbert-chart-3d - https://github.com/vasturiano/hilbert-chart-3d
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) :
@@ -148859,7 +148859,7 @@ var<${access}> ${ name } : ${ structName };`;
148859
148859
  let topObject = null;
148860
148860
  if (state.hoverDuringDrag || !state.isPointerDragging) {
148861
148861
  const intersects = this.intersectingObjects(state.pointerPos.x, state.pointerPos.y);
148862
- state.hoverOrderComparator && intersects.sort((a, b) => state.hoverOrderComparator(a.object, b.object));
148862
+ state.hoverOrderComparator && intersects.sort((a, b) => state.hoverOrderComparator(a.object, b.object, a, b));
148863
148863
  const topIntersect = intersects.find(d => state.hoverFilter(d.object)) || null;
148864
148864
  topObject = topIntersect ? topIntersect.object : null;
148865
148865
  state.intersection = topIntersect || null;
@@ -153502,6 +153502,13 @@ var<${access}> ${ name } : ${ structName };`;
153502
153502
  // Expose renderer
153503
153503
  controls: state => state.renderObjs.controls(),
153504
153504
  // Expose controls
153505
+ hoverOrderComparator: function (state, dataComp) {
153506
+ state.renderObjs.hoverOrderComparator(dataComp && ((_a, _b, a, b) => {
153507
+ const [da, db] = [a, b].map(i => getHilbertObjData(i?.object, i));
153508
+ return !da - !db || dataComp(da, db) || a.distance - b.distance;
153509
+ }));
153510
+ return this;
153511
+ },
153505
153512
  _destructor: function (state) {
153506
153513
  cancelAnimationFrame(state.animationFrameRequestId);
153507
153514
  this.data([]);
@@ -153530,20 +153537,6 @@ var<${access}> ${ name } : ${ structName };`;
153530
153537
  const roDomNode = document.createElement('div');
153531
153538
  roDomNode.className = 'hilbert-scene-container';
153532
153539
  el.appendChild(roDomNode);
153533
- const getHilbertObjData = (obj, intersection) => {
153534
- if (!obj) return null;
153535
- const hilbertObj = getHilbertObj(obj);
153536
- const d = hilbertObj?.__data || null;
153537
- return intersection && hilbertObj.isInstancedMesh ? d?.[intersection.instanceId] : d;
153538
- function getHilbertObj(object) {
153539
- let obj = object;
153540
- // recurse up object chain until finding the hilbert object
153541
- while (obj && !obj.hasOwnProperty('__data')) {
153542
- obj = obj.parent;
153543
- }
153544
- return obj;
153545
- }
153546
- };
153547
153540
  state.renderObjs(roDomNode).tooltipContent((obj, intersection) => {
153548
153541
  const d = getHilbertObjData(obj, intersection);
153549
153542
  return !d ? '' : state.tooltipContent ? index$3(state.tooltipContent)(d) || '' : (() => {
@@ -153574,6 +153567,20 @@ var<${access}> ${ name } : ${ structName };`;
153574
153567
  this._animationCycle();
153575
153568
  }
153576
153569
  });
153570
+ function getHilbertObjData(obj, intersection) {
153571
+ if (!obj) return null;
153572
+ const hilbertObj = getHilbertObj(obj);
153573
+ const d = hilbertObj?.__data || null;
153574
+ return intersection && hilbertObj.isInstancedMesh ? d?.[intersection.instanceId] : d;
153575
+ function getHilbertObj(object) {
153576
+ let obj = object;
153577
+ // recurse up object chain until finding the hilbert object
153578
+ while (obj && !obj.hasOwnProperty('__data')) {
153579
+ obj = obj.parent;
153580
+ }
153581
+ return obj;
153582
+ }
153583
+ }
153577
153584
 
153578
153585
  return index;
153579
153586