hilbert-chart-3d 0.5.0 → 0.6.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
@@ -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.0 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,29 @@ 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((_a, _b, a, b) => {
153507
+ const [da, db] = [a, b].map(i => getHilbertObjData(i?.object, i));
153508
+ if (!da) return 1;
153509
+ if (!db) return -1;
153510
+ return dataComp(da, db);
153511
+ });
153512
+ return this;
153513
+ function getHilbertObjData(obj, intersection) {
153514
+ if (!obj) return null;
153515
+ const hilbertObj = getHilbertObj(obj);
153516
+ const d = hilbertObj?.__data || null;
153517
+ return intersection && hilbertObj.isInstancedMesh ? d?.[intersection.instanceId] : d;
153518
+ function getHilbertObj(object) {
153519
+ let obj = object;
153520
+ // recurse up object chain until finding the hilbert object
153521
+ while (obj && !obj.hasOwnProperty('__data')) {
153522
+ obj = obj.parent;
153523
+ }
153524
+ return obj;
153525
+ }
153526
+ }
153527
+ },
153505
153528
  _destructor: function (state) {
153506
153529
  cancelAnimationFrame(state.animationFrameRequestId);
153507
153530
  this.data([]);