hilbert-chart-3d 0.2.0 → 0.3.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.
@@ -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: {
@@ -42,6 +70,13 @@ var index = Kapsule({
42
70
  },
43
71
  triggerUpdate: false
44
72
  },
73
+ paddingAbsolute: {
74
+ default: 0,
75
+ onChange(v, state) {
76
+ state.hilbert.paddingAbsolute(v);
77
+ },
78
+ triggerUpdate: false
79
+ },
45
80
  color: {
46
81
  onChange(v, state) {
47
82
  state.hilbert.color(v);
@@ -147,36 +182,44 @@ var index = Kapsule({
147
182
 
148
183
  // Add renderObjs
149
184
  const roDomNode = document.createElement('div');
185
+ roDomNode.className = 'hilbert-scene-container';
150
186
  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;
187
+ const getHilbertObjData = (obj, intersection) => {
188
+ if (!obj) return null;
189
+ if (intersection && obj.isInstancedMesh) {
190
+ return obj.userData.data?.[intersection.instanceId] || null;
191
+ }
192
+ const hilbertObj = getHilbertObj(obj);
193
+ return hilbertObj?.__data || null;
194
+ function getHilbertObj(object) {
195
+ let obj = object;
196
+ // recurse up object chain until finding the globe object
197
+ while (obj && !obj.hasOwnProperty('__data')) {
198
+ obj = obj.parent;
199
+ }
200
+ return obj;
156
201
  }
157
- return obj;
158
202
  };
159
- state.renderObjs(roDomNode).tooltipContent(obj => {
160
- const o = getHilbertObj(obj);
161
- return !o ? '' : state.tooltipContent ? accessorFn(state.tooltipContent)(o.__data) || '' : (() => {
203
+ state.renderObjs(roDomNode).tooltipContent((obj, intersection) => {
204
+ const d = getHilbertObjData(obj, intersection);
205
+ return !d ? '' : state.tooltipContent ? accessorFn(state.tooltipContent)(d) || '' : (() => {
162
206
  // default content
163
- const d = o.__data;
164
207
  const label = accessorFn(state.label)(d);
165
208
  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
209
  })();
167
- }).onHover(obj => {
210
+ }).onHover((obj, _, intersection) => {
168
211
  // 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);
212
+ const hoverD = getHilbertObjData(obj, intersection);
213
+ if (hoverD !== state.hoverD) {
214
+ state.onHover?.(hoverD, state.hoverD || null);
172
215
 
173
216
  // 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;
217
+ state.renderObjs.renderer().domElement.classList[hoverD && state.onClick || !hoverD && state.onBackgroundClick ? 'add' : 'remove']('clickable');
218
+ state.hoverD = hoverD;
176
219
  }
177
- }).onClick((obj, ev) => {
178
- const o = getHilbertObj(obj);
179
- o ? state.onClick?.(o.__data, ev) : state.onBackgroundClick?.(ev);
220
+ }).onClick((obj, ev, intersection) => {
221
+ const d = getHilbertObjData(obj, intersection);
222
+ d ? state.onClick?.(d, ev) : state.onBackgroundClick?.(ev);
180
223
  });
181
224
  state.renderObjs.camera().position.z = 500;
182
225
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hilbert-chart-3d",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
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",