hilbert-chart-3d 0.1.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: {
@@ -69,6 +97,13 @@ var index = Kapsule({
69
97
  },
70
98
  triggerUpdate: false
71
99
  },
100
+ useInstancedMeshes: {
101
+ default: false,
102
+ onChange(v, state) {
103
+ state.hilbert.useInstancedMeshes(v);
104
+ },
105
+ triggerUpdate: false
106
+ },
72
107
  valFormatter: {
73
108
  default: d => d
74
109
  },
@@ -140,36 +175,44 @@ var index = Kapsule({
140
175
 
141
176
  // Add renderObjs
142
177
  const roDomNode = document.createElement('div');
178
+ roDomNode.className = 'hilbert-scene-container';
143
179
  el.appendChild(roDomNode);
144
- const getHilbertObj = object => {
145
- let obj = object;
146
- // recurse up object chain until finding the globe object
147
- while (obj && !obj.hasOwnProperty('__data')) {
148
- 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;
149
194
  }
150
- return obj;
151
195
  };
152
- state.renderObjs(roDomNode).tooltipContent(obj => {
153
- const o = getHilbertObj(obj);
154
- 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) || '' : (() => {
155
199
  // default content
156
- const d = o.__data;
157
200
  const label = accessorFn(state.label)(d);
158
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)) : '')}`;
159
202
  })();
160
- }).onHover(obj => {
203
+ }).onHover((obj, _, intersection) => {
161
204
  // Update tooltip and trigger onHover events
162
- const hoverObj = getHilbertObj(obj);
163
- if (hoverObj !== state.hoverObj) {
164
- 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);
165
208
 
166
209
  // set pointer if hovered object is clickable
167
- state.renderObjs.renderer().domElement.classList[hoverObj && state.onClick || !hoverObj && state.onBackgroundClick ? 'add' : 'remove']('clickable');
168
- state.hoverObj = hoverObj;
210
+ state.renderObjs.renderer().domElement.classList[hoverD && state.onClick || !hoverD && state.onBackgroundClick ? 'add' : 'remove']('clickable');
211
+ state.hoverD = hoverD;
169
212
  }
170
- }).onClick((obj, ev) => {
171
- const o = getHilbertObj(obj);
172
- 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);
173
216
  });
174
217
  state.renderObjs.camera().position.z = 500;
175
218
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hilbert-chart-3d",
3
- "version": "0.1.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",