hilbert-chart-3d 0.2.0 → 0.2.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.
@@ -4,6 +4,34 @@ import ThreeRenderObjects from 'three-render-objects';
4
4
  import { AmbientLight, DirectionalLight } from 'three';
5
5
  import ThreeHilbert from 'three-hilbert';
6
6
 
7
+ function styleInject(css, ref) {
8
+ if (ref === void 0) ref = {};
9
+ var insertAt = ref.insertAt;
10
+ if (typeof document === 'undefined') {
11
+ return;
12
+ }
13
+ var head = document.head || document.getElementsByTagName('head')[0];
14
+ var style = document.createElement('style');
15
+ style.type = 'text/css';
16
+ if (insertAt === 'top') {
17
+ if (head.firstChild) {
18
+ head.insertBefore(style, head.firstChild);
19
+ } else {
20
+ head.appendChild(style);
21
+ }
22
+ } else {
23
+ head.appendChild(style);
24
+ }
25
+ if (style.styleSheet) {
26
+ style.styleSheet.cssText = css;
27
+ } else {
28
+ style.appendChild(document.createTextNode(css));
29
+ }
30
+ }
31
+
32
+ var css_248z = ".hilbert-scene-container .clickable {\n cursor: pointer;\n}";
33
+ styleInject(css_248z);
34
+
7
35
  var index = Kapsule({
8
36
  props: {
9
37
  width: {
@@ -147,36 +175,44 @@ var index = Kapsule({
147
175
 
148
176
  // Add renderObjs
149
177
  const roDomNode = document.createElement('div');
178
+ roDomNode.className = 'hilbert-scene-container';
150
179
  el.appendChild(roDomNode);
151
- const getHilbertObj = object => {
152
- let obj = object;
153
- // recurse up object chain until finding the globe object
154
- while (obj && !obj.hasOwnProperty('__data')) {
155
- obj = obj.parent;
180
+ const getHilbertObjData = (obj, intersection) => {
181
+ if (!obj) return null;
182
+ if (intersection && obj.isInstancedMesh) {
183
+ return obj.userData.data?.[intersection.instanceId] || null;
184
+ }
185
+ const hilbertObj = getHilbertObj(obj);
186
+ return hilbertObj?.__data || null;
187
+ function getHilbertObj(object) {
188
+ let obj = object;
189
+ // recurse up object chain until finding the globe object
190
+ while (obj && !obj.hasOwnProperty('__data')) {
191
+ obj = obj.parent;
192
+ }
193
+ return obj;
156
194
  }
157
- return obj;
158
195
  };
159
- state.renderObjs(roDomNode).tooltipContent(obj => {
160
- const o = getHilbertObj(obj);
161
- return !o ? '' : state.tooltipContent ? accessorFn(state.tooltipContent)(o.__data) || '' : (() => {
196
+ state.renderObjs(roDomNode).tooltipContent((obj, intersection) => {
197
+ const d = getHilbertObjData(obj, intersection);
198
+ return !d ? '' : state.tooltipContent ? accessorFn(state.tooltipContent)(d) || '' : (() => {
162
199
  // default content
163
- const d = o.__data;
164
200
  const label = accessorFn(state.label)(d);
165
201
  return `${label ? `<b>${label}</b>: ` : ''}${state.valFormatter(d.start) + (d.length > 1 ? ' - ' + state.valFormatter(d.start + d.length - (typeof d.start === 'bigint' ? 1n : 1)) : '')}`;
166
202
  })();
167
- }).onHover(obj => {
203
+ }).onHover((obj, _, intersection) => {
168
204
  // Update tooltip and trigger onHover events
169
- const hoverObj = getHilbertObj(obj);
170
- if (hoverObj !== state.hoverObj) {
171
- state.onHover?.(hoverObj?.__data || null, state.hoverObj?.__data || null);
205
+ const hoverD = getHilbertObjData(obj, intersection);
206
+ if (hoverD !== state.hoverD) {
207
+ state.onHover?.(hoverD, state.hoverD || null);
172
208
 
173
209
  // set pointer if hovered object is clickable
174
- state.renderObjs.renderer().domElement.classList[hoverObj && state.onClick || !hoverObj && state.onBackgroundClick ? 'add' : 'remove']('clickable');
175
- state.hoverObj = hoverObj;
210
+ state.renderObjs.renderer().domElement.classList[hoverD && state.onClick || !hoverD && state.onBackgroundClick ? 'add' : 'remove']('clickable');
211
+ state.hoverD = hoverD;
176
212
  }
177
- }).onClick((obj, ev) => {
178
- const o = getHilbertObj(obj);
179
- o ? state.onClick?.(o.__data, ev) : state.onBackgroundClick?.(ev);
213
+ }).onClick((obj, ev, intersection) => {
214
+ const d = getHilbertObjData(obj, intersection);
215
+ d ? state.onClick?.(d, ev) : state.onBackgroundClick?.(ev);
180
216
  });
181
217
  state.renderObjs.camera().position.z = 500;
182
218
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hilbert-chart-3d",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "A 3d hilbert space-filling curve D3 chart for representing one-dimensional lengths on a three-dimensional space.",
5
5
  "type": "module",
6
6
  "jsdelivr": "dist/hilbert-chart-3d.min.js",