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.
@@ -1,4 +1,4 @@
1
- // Version 0.2.0 hilbert-chart-3d - https://github.com/vasturiano/hilbert-chart-3d
1
+ // Version 0.3.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) :
@@ -25395,6 +25395,48 @@
25395
25395
 
25396
25396
  }
25397
25397
 
25398
+ /**
25399
+ * Creates a texture from a canvas element.
25400
+ *
25401
+ * This is almost the same as the base texture class, except that it sets {@link Texture#needsUpdate}
25402
+ * to `true` immediately since a canvas can directly be used for rendering.
25403
+ *
25404
+ * @augments Texture
25405
+ */
25406
+ class CanvasTexture extends Texture {
25407
+
25408
+ /**
25409
+ * Constructs a new texture.
25410
+ *
25411
+ * @param {HTMLCanvasElement} [canvas] - The HTML canvas element.
25412
+ * @param {number} [mapping=Texture.DEFAULT_MAPPING] - The texture mapping.
25413
+ * @param {number} [wrapS=ClampToEdgeWrapping] - The wrapS value.
25414
+ * @param {number} [wrapT=ClampToEdgeWrapping] - The wrapT value.
25415
+ * @param {number} [magFilter=LinearFilter] - The mag filter value.
25416
+ * @param {number} [minFilter=LinearMipmapLinearFilter] - The min filter value.
25417
+ * @param {number} [format=RGBAFormat] - The texture format.
25418
+ * @param {number} [type=UnsignedByteType] - The texture type.
25419
+ * @param {number} [anisotropy=Texture.DEFAULT_ANISOTROPY] - The anisotropy value.
25420
+ */
25421
+ constructor( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
25422
+
25423
+ super( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
25424
+
25425
+ /**
25426
+ * This flag can be used for type testing.
25427
+ *
25428
+ * @type {boolean}
25429
+ * @readonly
25430
+ * @default true
25431
+ */
25432
+ this.isCanvasTexture = true;
25433
+
25434
+ this.needsUpdate = true;
25435
+
25436
+ }
25437
+
25438
+ }
25439
+
25398
25440
  /**
25399
25441
  * This class can be used to automatically save the depth information of a
25400
25442
  * rendering into a texture.
@@ -143749,7 +143791,7 @@ var<${access}> ${ name } : ${ structName };`;
143749
143791
  Q(reactElement2VNode(jsx), domEl);
143750
143792
  };
143751
143793
 
143752
- function styleInject$1(css, ref) {
143794
+ function styleInject$2(css, ref) {
143753
143795
  if (ref === void 0) ref = {};
143754
143796
  var insertAt = ref.insertAt;
143755
143797
  if (typeof document === 'undefined') {
@@ -143774,8 +143816,8 @@ var<${access}> ${ name } : ${ structName };`;
143774
143816
  }
143775
143817
  }
143776
143818
 
143777
- var css_248z$1 = ".float-tooltip-kap {\n position: absolute;\n width: max-content; /* prevent shrinking near right edge */\n max-width: max(50%, 150px);\n padding: 3px 5px;\n border-radius: 3px;\n font: 12px sans-serif;\n color: #eee;\n background: rgba(0,0,0,0.6);\n pointer-events: none;\n}\n";
143778
- styleInject$1(css_248z$1);
143819
+ var css_248z$2 = ".float-tooltip-kap {\n position: absolute;\n width: max-content; /* prevent shrinking near right edge */\n max-width: max(50%, 150px);\n padding: 3px 5px;\n border-radius: 3px;\n font: 12px sans-serif;\n color: #eee;\n background: rgba(0,0,0,0.6);\n pointer-events: none;\n}\n";
143820
+ styleInject$2(css_248z$2);
143779
143821
 
143780
143822
  var index$2 = index$4({
143781
143823
  props: {
@@ -143853,7 +143895,7 @@ var<${access}> ${ name } : ${ structName };`;
143853
143895
  }
143854
143896
  });
143855
143897
 
143856
- function styleInject(css, ref) {
143898
+ function styleInject$1(css, ref) {
143857
143899
  if (ref === void 0) ref = {};
143858
143900
  var insertAt = ref.insertAt;
143859
143901
  if (typeof document === 'undefined') {
@@ -143878,8 +143920,8 @@ var<${access}> ${ name } : ${ structName };`;
143878
143920
  }
143879
143921
  }
143880
143922
 
143881
- var css_248z = ".scene-nav-info {\n position: absolute;\n bottom: 5px;\n width: 100%;\n text-align: center;\n color: slategrey;\n opacity: 0.7;\n font-size: 10px;\n font-family: sans-serif;\n pointer-events: none;\n user-select: none;\n}\n\n.scene-container canvas:focus {\n outline: none;\n}";
143882
- styleInject(css_248z);
143923
+ var css_248z$1 = ".scene-nav-info {\n position: absolute;\n bottom: 5px;\n width: 100%;\n text-align: center;\n color: slategrey;\n opacity: 0.7;\n font-size: 10px;\n font-family: sans-serif;\n pointer-events: none;\n user-select: none;\n}\n\n.scene-container canvas:focus {\n outline: none;\n}";
143924
+ styleInject$1(css_248z$1);
143883
143925
 
143884
143926
  const materialDispose$1 = material => {
143885
143927
  if (material instanceof Array) {
@@ -144349,6 +144391,7 @@ var<${access}> ${ name } : ${ structName };`;
144349
144391
  state.controlsEngaged = false;
144350
144392
  state.controlsDragging = false;
144351
144393
  });
144394
+ state.renderer.domElement.style.cursor = null; // remove cursor: auto property on canvas
144352
144395
  }
144353
144396
  [state.renderer, state.postProcessingComposer, ...state.extraRenderers].forEach(r => r.setSize(state.width, state.height));
144354
144397
  state.camera.aspect = state.width / state.height;
@@ -144627,14 +144670,25 @@ var<${access}> ${ name } : ${ structName };`;
144627
144670
  this.boundingSphere = new Sphere(new Vector3(x, y, z), Math.sqrt(3) * halfWidth);
144628
144671
  return;
144629
144672
  }
144673
+ const turnTolerance = 1e-6;
144630
144674
  const path = [];
144675
+ const incoming = new Vector3();
144676
+ const outgoing = new Vector3();
144631
144677
  for (let index = 0; index < points.length; index++) {
144632
144678
  const point = points[index];
144633
144679
  if (!point || !Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z)) {
144634
144680
  throw new TypeError(`points[${index}] must have finite x, y, and z coordinates`);
144635
144681
  }
144636
144682
  const copy = new Vector3(point.x, point.y, point.z);
144637
- if (index === 0 || copy.distanceToSquared(path[path.length - 1]) > 0) path.push(copy);
144683
+ if (path.length && copy.distanceToSquared(path[path.length - 1]) === 0) continue;
144684
+ while (path.length >= 2) {
144685
+ incoming.subVectors(path[path.length - 1], path[path.length - 2]);
144686
+ outgoing.subVectors(copy, path[path.length - 1]);
144687
+ const dot = incoming.dot(outgoing) / Math.sqrt(incoming.lengthSq() * outgoing.lengthSq());
144688
+ if (dot < 1 - turnTolerance) break;
144689
+ path.pop();
144690
+ }
144691
+ path.push(copy);
144638
144692
  }
144639
144693
  this.parameters = {
144640
144694
  points: path.map(point => point.clone()),
@@ -144671,7 +144725,6 @@ var<${access}> ${ name } : ${ structName };`;
144671
144725
  for (let i = 0; i < directions.length; i++) {
144672
144726
  directions[i] = path[i + 1].clone().sub(path[i]).normalize();
144673
144727
  }
144674
- const turnTolerance = 1e-6;
144675
144728
  const isClosed = path.length > 2 && path[0].distanceToSquared(path[path.length - 1]) === 0;
144676
144729
  for (let i = 1; i < directions.length; i++) {
144677
144730
  const dot = directions[i - 1].dot(directions[i]);
@@ -144794,10 +144847,10 @@ var<${access}> ${ name } : ${ structName };`;
144794
144847
  positions[positionOffset++] = point.z;
144795
144848
  if (hasCustomUVs) {
144796
144849
  uvs[uvOffset++] = customUVs[i * 2];
144797
- uvs[uvOffset++] = customUVs[i * 2 + 1];
144850
+ uvs[uvOffset++] = 1 - customUVs[i * 2 + 1];
144798
144851
  } else {
144799
144852
  uvs[uvOffset++] = i === 1 || i === 2 ? 1 : 0;
144800
- uvs[uvOffset++] = i >= 2 ? 1 : 0;
144853
+ uvs[uvOffset++] = i >= 2 ? 0 : 1;
144801
144854
  }
144802
144855
  }
144803
144856
  indices[indexOffset++] = vertexOffset;
@@ -144824,8 +144877,8 @@ var<${access}> ${ name } : ${ structName };`;
144824
144877
  const endV = i === directions.length - 1 && !isClosed ? 1 : (pathDistances[i + 1] + (isClosed ? 0 : halfWidth)) / totalLength;
144825
144878
  for (const a of faceCorners) {
144826
144879
  const b = (a + 1) % 4;
144827
- const startU = a / 4;
144828
- const endU = (a + 1) / 4;
144880
+ const startU = 0;
144881
+ const endU = 1;
144829
144882
  sideUVs[0] = startU;
144830
144883
  sideUVs[1] = startV;
144831
144884
  sideUVs[2] = endU;
@@ -144863,6 +144916,7 @@ var<${access}> ${ name } : ${ structName };`;
144863
144916
  class ThreeHilbertGeometry extends SquareTubeGeometry {
144864
144917
  constructor(order, start, length, {
144865
144918
  padding = 0,
144919
+ paddingAbsolute = 0,
144866
144920
  simplifyCurves = true
144867
144921
  } = {}) {
144868
144922
  super(...getSuperParams());
@@ -144874,6 +144928,7 @@ var<${access}> ${ name } : ${ structName };`;
144874
144928
  start,
144875
144929
  length,
144876
144930
  padding,
144931
+ paddingAbsolute,
144877
144932
  simplifyCurves
144878
144933
  };
144879
144934
  function getSuperParams() {
@@ -144889,7 +144944,8 @@ var<${access}> ${ name } : ${ structName };`;
144889
144944
  }
144890
144945
  }
144891
144946
  const points = hilbert3D(undefined, 1, order - 1, start, length);
144892
- const lineWidth = 1 / 2 ** (order - 1) * (1 - Math.min(1, padding));
144947
+ const w = 2 ** (1 - order); // Full width without padding
144948
+ const lineWidth = (w - Math.min(paddingAbsolute, w * 0.5)) * (1 - Math.min(1, padding));
144893
144949
  return [points, lineWidth];
144894
144950
  }
144895
144951
  }
@@ -147715,6 +147771,424 @@ var<${access}> ${ name } : ${ structName };`;
147715
147771
  const colorStr2Hex = str => isNaN(str) ? parseInt(tinycolor(str).toHex(), 16) : str;
147716
147772
  const colorAlpha = str => str && isNaN(str) ? color(str).opacity : 1;
147717
147773
 
147774
+ const MAX_LABEL_CHARS = 32;
147775
+ const GLYPH_COUNT = 256;
147776
+ const GLYPHS_PER_ROW = 16;
147777
+ const GLYPH_SIZE = 64;
147778
+ const MIN_LABEL_FONT_SIZE = 0.05;
147779
+ const MAX_LABEL_FONT_SIZE = 0.8;
147780
+ const MAX_CUBE_LABEL_FONT_SIZE = 0.5;
147781
+ const MAX_LABEL_WIDTH = 0.92;
147782
+ const LABEL_CHARACTER_ADVANCE = 0.8;
147783
+ function createLabelAtlas(data, labelAccessor, labelColorAccessor) {
147784
+ const labelIds = new Map();
147785
+ const labels = new WeakMap();
147786
+ data.forEach(d => {
147787
+ const label = labelAccessor(d);
147788
+ const color = labelColorAccessor(d);
147789
+ if (!label || !color) return;
147790
+ const characters = Array.from(String(label));
147791
+ const text = characters.length > MAX_LABEL_CHARS ? `${characters.slice(0, MAX_LABEL_CHARS - 3).join('')}...` : characters.join('');
147792
+ let id = labelIds.get(text);
147793
+ if (id === undefined) {
147794
+ id = labelIds.size;
147795
+ labelIds.set(text, id);
147796
+ }
147797
+ labels.set(d, {
147798
+ id,
147799
+ length: Array.from(text).length,
147800
+ text,
147801
+ color
147802
+ });
147803
+ });
147804
+ if (!labelIds.size) return null;
147805
+ const glyphCanvas = document.createElement('canvas');
147806
+ glyphCanvas.width = GLYPHS_PER_ROW * GLYPH_SIZE;
147807
+ glyphCanvas.height = GLYPHS_PER_ROW * GLYPH_SIZE;
147808
+ const glyphContext = glyphCanvas.getContext('2d');
147809
+ if (!glyphContext) throw new Error('Unable to create canvas context for label glyphs');
147810
+ glyphContext.font = 'bold 64px monospace';
147811
+ glyphContext.textAlign = 'center';
147812
+ glyphContext.textBaseline = 'middle';
147813
+ for (let code = 0; code < GLYPH_COUNT; code++) {
147814
+ const character = String.fromCharCode(code);
147815
+ if (code < 32 || code === 127) continue;
147816
+ const x = code % GLYPHS_PER_ROW * GLYPH_SIZE + GLYPH_SIZE / 2;
147817
+ const y = Math.floor(code / GLYPHS_PER_ROW) * GLYPH_SIZE + GLYPH_SIZE / 2;
147818
+ glyphContext.fillStyle = '#fff';
147819
+ glyphContext.fillText(character, x, y);
147820
+ }
147821
+ const glyphTexture = new CanvasTexture(glyphCanvas);
147822
+ glyphTexture.magFilter = LinearFilter;
147823
+ glyphTexture.minFilter = LinearFilter;
147824
+ glyphTexture.colorSpace = SRGBColorSpace;
147825
+ const labelsPerRow = 128;
147826
+ const textureWidth = labelsPerRow * MAX_LABEL_CHARS;
147827
+ const textureHeight = Math.ceil(labelIds.size / labelsPerRow);
147828
+ const labelData = new Uint8Array(textureWidth * textureHeight * 4);
147829
+ labelIds.forEach((id, text) => {
147830
+ Array.from(text).forEach((character, charIndex) => {
147831
+ const code = character.codePointAt(0);
147832
+ const x = id % labelsPerRow * MAX_LABEL_CHARS + charIndex;
147833
+ const y = Math.floor(id / labelsPerRow);
147834
+ const supported = code >= 32 && code <= 255 && (code < 127 || code >= 160);
147835
+ labelData[(y * textureWidth + x) * 4] = supported ? code : 63;
147836
+ });
147837
+ });
147838
+ const labelTexture = new DataTexture(labelData, textureWidth, textureHeight, RGBAFormat, UnsignedByteType);
147839
+ labelTexture.magFilter = NearestFilter;
147840
+ labelTexture.minFilter = NearestFilter;
147841
+ labelTexture.generateMipmaps = false;
147842
+ labelTexture.needsUpdate = true;
147843
+ return {
147844
+ labels,
147845
+ glyphTexture,
147846
+ labelTexture,
147847
+ labelsPerRow,
147848
+ labelCount: labelIds.size
147849
+ };
147850
+ }
147851
+ function createLabelMaterial(color, labelAtlas) {
147852
+ const material = new MeshLambertMaterial();
147853
+ const opacity = colorAlpha(color);
147854
+ material.color.set(colorStr2Hex(color));
147855
+ material.transparent = opacity < 1;
147856
+ material.opacity = opacity;
147857
+ if (labelAtlas) {
147858
+ material.onBeforeCompile = shader => {
147859
+ shader.uniforms.labelGlyphTexture = {
147860
+ value: labelAtlas.glyphTexture
147861
+ };
147862
+ shader.uniforms.labelDataTexture = {
147863
+ value: labelAtlas.labelTexture
147864
+ };
147865
+ shader.uniforms.labelDataTextureSize = {
147866
+ value: new Vector2(labelAtlas.labelTexture.image.width, labelAtlas.labelTexture.image.height)
147867
+ };
147868
+ shader.uniforms.labelLabelsPerRow = {
147869
+ value: labelAtlas.labelsPerRow
147870
+ };
147871
+ shader.vertexShader = shader.vertexShader.replace('#include <common>', `#include <common>
147872
+ attribute float hilbertLabelId;
147873
+ attribute float hilbertLabelLength;
147874
+ attribute float hilbertLabelAspect;
147875
+ attribute float hilbertLabelMaxFontSize;
147876
+ attribute float hilbertLabelReverse;
147877
+ attribute vec4 hilbertLabelColor;
147878
+ varying vec2 vHilbertLabelUv;
147879
+ varying float vHilbertLabelId;
147880
+ varying float vHilbertLabelLength;
147881
+ varying float vHilbertLabelAspect;
147882
+ varying float vHilbertLabelMaxFontSize;
147883
+ varying float vHilbertLabelReverse;
147884
+ varying vec4 vHilbertLabelColor;`).replace('#include <begin_vertex>', `#include <begin_vertex>
147885
+ vHilbertLabelUv = uv;
147886
+ vHilbertLabelId = hilbertLabelId;
147887
+ vHilbertLabelLength = hilbertLabelLength;
147888
+ vHilbertLabelAspect = hilbertLabelAspect;
147889
+ vHilbertLabelMaxFontSize = hilbertLabelMaxFontSize;
147890
+ vHilbertLabelReverse = hilbertLabelReverse;
147891
+ vHilbertLabelColor = hilbertLabelColor;`);
147892
+ shader.fragmentShader = shader.fragmentShader.replace('#include <common>', `#include <common>
147893
+ uniform sampler2D labelGlyphTexture;
147894
+ uniform sampler2D labelDataTexture;
147895
+ uniform vec2 labelDataTextureSize;
147896
+ uniform float labelLabelsPerRow;
147897
+ varying vec2 vHilbertLabelUv;
147898
+ varying float vHilbertLabelId;
147899
+ varying float vHilbertLabelLength;
147900
+ varying float vHilbertLabelAspect;
147901
+ varying float vHilbertLabelMaxFontSize;
147902
+ varying float vHilbertLabelReverse;
147903
+ varying vec4 vHilbertLabelColor;`).replace('#include <map_fragment>', `#include <map_fragment>
147904
+ if (vHilbertLabelId >= 0.0 && vHilbertLabelUv.x >= 0.0 && vHilbertLabelUv.x <= 1.0) {
147905
+ float aspect = max(vHilbertLabelAspect, 0.001);
147906
+ float visibleLength = vHilbertLabelLength;
147907
+ float textUnits = 1.0 + max(visibleLength - 1.0, 0.0) * ${LABEL_CHARACTER_ADVANCE.toFixed(2)};
147908
+ float maxFontSize = min(${MAX_LABEL_FONT_SIZE.toFixed(2)}, vHilbertLabelMaxFontSize);
147909
+ float fontSize = min(maxFontSize, aspect * ${MAX_LABEL_WIDTH.toFixed(2)} / textUnits);
147910
+ bool isTruncated = fontSize < ${MIN_LABEL_FONT_SIZE.toFixed(2)};
147911
+ if (isTruncated) visibleLength = min(visibleLength, max(3.0, floor((aspect * ${MAX_LABEL_WIDTH.toFixed(2)} / ${MIN_LABEL_FONT_SIZE.toFixed(2)} - 1.0) / ${LABEL_CHARACTER_ADVANCE.toFixed(2)}) + 1.0));
147912
+ textUnits = 1.0 + max(visibleLength - 1.0, 0.0) * ${LABEL_CHARACTER_ADVANCE.toFixed(2)};
147913
+ fontSize = min(maxFontSize, aspect * ${MAX_LABEL_WIDTH.toFixed(2)} / textUnits);
147914
+ float characterSize = fontSize / aspect;
147915
+ float characterAdvance = characterSize * ${LABEL_CHARACTER_ADVANCE.toFixed(2)};
147916
+ float textWidth = characterSize + characterAdvance * max(visibleLength - 1.0, 0.0);
147917
+ float textStart = (1.0 - textWidth) * 0.5;
147918
+ float textPosition = vHilbertLabelUv.x - textStart;
147919
+ if (textPosition >= 0.0 && textPosition < textWidth) {
147920
+ float glyphVerticalPosition = (vHilbertLabelUv.y - 0.5) / max(fontSize, 0.001) + 0.5;
147921
+ if (glyphVerticalPosition >= 0.0 && glyphVerticalPosition <= 1.0) {
147922
+ float charPosition = textPosition / max(characterAdvance, 0.001);
147923
+ float charSlot = floor(charPosition);
147924
+ float charIndex = mix(charSlot, visibleLength - 1.0 - charSlot, vHilbertLabelReverse);
147925
+ float glyphHorizontalPosition = (textPosition - charSlot * characterAdvance) / max(characterSize, 0.001);
147926
+ glyphHorizontalPosition = mix(glyphHorizontalPosition, 1.0 - glyphHorizontalPosition, vHilbertLabelReverse);
147927
+ float labelRow = floor(vHilbertLabelId / labelLabelsPerRow);
147928
+ float labelColumn = mod(vHilbertLabelId, labelLabelsPerRow);
147929
+ vec2 dataUv = (vec2(labelColumn * ${MAX_LABEL_CHARS}.0 + charIndex, labelRow) + 0.5) / labelDataTextureSize;
147930
+ float charCode = floor(texture2D(labelDataTexture, dataUv).r * 255.0 + 0.5);
147931
+ if (isTruncated && charIndex >= visibleLength - 3.0) charCode = 46.0;
147932
+ vec2 glyphCell = vec2(mod(charCode, 16.0), floor(charCode / 16.0));
147933
+ vec2 glyphUv = vec2(0.015625 + clamp(glyphHorizontalPosition, 0.0, 1.0) * 0.96875, 0.015625 + (1.0 - glyphVerticalPosition) * 0.96875);
147934
+ vec2 glyphAtlasUv = vec2(glyphCell.x + glyphUv.x, 16.0 - glyphCell.y - glyphUv.y) / 16.0;
147935
+ float glyphCoverage = texture2D(labelGlyphTexture, glyphAtlasUv).a;
147936
+ float previousCharSlot = charSlot - 1.0;
147937
+ float previousCharIndex = mix(previousCharSlot, visibleLength - 1.0 - previousCharSlot, vHilbertLabelReverse);
147938
+ float previousGlyphPosition = (textPosition - previousCharSlot * characterAdvance) / max(characterSize, 0.001);
147939
+ previousGlyphPosition = mix(previousGlyphPosition, 1.0 - previousGlyphPosition, vHilbertLabelReverse);
147940
+ if (charSlot > 0.0 && previousGlyphPosition < 1.0) {
147941
+ vec2 previousDataUv = (vec2(labelColumn * ${MAX_LABEL_CHARS}.0 + previousCharIndex, labelRow) + 0.5) / labelDataTextureSize;
147942
+ float previousCharCode = floor(texture2D(labelDataTexture, previousDataUv).r * 255.0 + 0.5);
147943
+ if (isTruncated && previousCharIndex >= visibleLength - 3.0) previousCharCode = 46.0;
147944
+ vec2 previousGlyphCell = vec2(mod(previousCharCode, 16.0), floor(previousCharCode / 16.0));
147945
+ vec2 previousGlyphAtlasUv = vec2(
147946
+ previousGlyphCell.x + 0.015625 + clamp(previousGlyphPosition, 0.0, 1.0) * 0.96875,
147947
+ 16.0 - previousGlyphCell.y - glyphUv.y
147948
+ ) / 16.0;
147949
+ glyphCoverage = max(glyphCoverage, texture2D(labelGlyphTexture, previousGlyphAtlasUv).a);
147950
+ }
147951
+ float glyphAlpha = glyphCoverage * vHilbertLabelColor.a;
147952
+ diffuseColor.rgb = mix(diffuseColor.rgb, vHilbertLabelColor.rgb, glyphAlpha);
147953
+ }
147954
+ }
147955
+ }`);
147956
+ };
147957
+ material.customProgramCacheKey = () => 'three-hilbert-label-glyph-atlas';
147958
+ }
147959
+ return material;
147960
+ }
147961
+ function addLabelAttributes(geometry, records, instanced = false) {
147962
+ const vertexCount = geometry.getAttribute('position').count;
147963
+ const count = instanced ? records.length : vertexCount;
147964
+ const makeAttribute = (array, itemSize) => instanced ? new InstancedBufferAttribute(array, itemSize) : new Float32BufferAttribute(array, itemSize);
147965
+ const ids = new Float32Array(count);
147966
+ const lengths = new Float32Array(count);
147967
+ const colors = new Float32Array(count * 4);
147968
+ records.forEach(({
147969
+ info
147970
+ }, index) => {
147971
+ const labelColor = info?.color;
147972
+ const color = new Color$1(labelColor ? colorStr2Hex(labelColor) : 0xffffff);
147973
+ const start = instanced ? index : 0;
147974
+ const end = instanced ? index + 1 : count;
147975
+ for (let i = start; i < end; i++) {
147976
+ ids[i] = info ? info.id : -1;
147977
+ lengths[i] = info ? info.length : 0;
147978
+ colors[i * 4] = color.r;
147979
+ colors[i * 4 + 1] = color.g;
147980
+ colors[i * 4 + 2] = color.b;
147981
+ colors[i * 4 + 3] = labelColor ? colorAlpha(labelColor) : 0;
147982
+ }
147983
+ });
147984
+ geometry.setAttribute('hilbertLabelId', makeAttribute(ids, 1));
147985
+ geometry.setAttribute('hilbertLabelLength', makeAttribute(lengths, 1));
147986
+ geometry.setAttribute('hilbertLabelColor', makeAttribute(colors, 4));
147987
+ }
147988
+ function mapLabelUVs(geometry) {
147989
+ const uvs = geometry.getAttribute('uv');
147990
+ if (!uvs) return;
147991
+ const positions = geometry.getAttribute('position');
147992
+ const points = geometry.parameters?.points;
147993
+ const labelAspects = new Float32Array(uvs.count);
147994
+ const labelMaxFontSizes = new Float32Array(uvs.count).fill(MAX_LABEL_FONT_SIZE);
147995
+ const labelReverse = new Float32Array(uvs.count);
147996
+ const uTurnInteriorFaces = getUTurnInteriorFaces(points, positions);
147997
+ const sideQuads = [];
147998
+ if (points?.length > 1) {
147999
+ const sideQuadCount = (points.length - 1) * 4;
148000
+ for (let vertex = 0; vertex + 3 < uvs.count && vertex / 4 < sideQuadCount; vertex += 4) {
148001
+ let minU = Infinity;
148002
+ let maxU = -Infinity;
148003
+ let minV = Infinity;
148004
+ let maxV = -Infinity;
148005
+ for (let corner = 0; corner < 4; corner++) {
148006
+ minU = Math.min(minU, uvs.getX(vertex + corner));
148007
+ maxU = Math.max(maxU, uvs.getX(vertex + corner));
148008
+ minV = Math.min(minV, uvs.getY(vertex + corner));
148009
+ maxV = Math.max(maxV, uvs.getY(vertex + corner));
148010
+ }
148011
+ if (maxU <= minU || maxV === minV) continue;
148012
+ sideQuads.push({
148013
+ vertex,
148014
+ minU,
148015
+ maxU,
148016
+ minV,
148017
+ maxV
148018
+ });
148019
+ }
148020
+ } else {
148021
+ for (let vertex = 0; vertex + 3 < uvs.count; vertex += 4) {
148022
+ let minU = Infinity;
148023
+ let maxU = -Infinity;
148024
+ let minV = Infinity;
148025
+ let maxV = -Infinity;
148026
+ for (let corner = 0; corner < 4; corner++) {
148027
+ minU = Math.min(minU, uvs.getX(vertex + corner));
148028
+ maxU = Math.max(maxU, uvs.getX(vertex + corner));
148029
+ minV = Math.min(minV, uvs.getY(vertex + corner));
148030
+ maxV = Math.max(maxV, uvs.getY(vertex + corner));
148031
+ }
148032
+ if (Math.abs(maxU - minU - 0.25) > 0.01 || maxV <= minV) continue;
148033
+ sideQuads.push({
148034
+ vertex,
148035
+ minU,
148036
+ maxU,
148037
+ minV,
148038
+ maxV
148039
+ });
148040
+ }
148041
+ }
148042
+ const sideQuadVertices = new Set(sideQuads.map(({
148043
+ vertex
148044
+ }) => vertex));
148045
+ sideQuads.forEach(({
148046
+ vertex,
148047
+ minU,
148048
+ maxU,
148049
+ minV,
148050
+ maxV
148051
+ }, index) => {
148052
+ for (let corner = 0; corner < 4; corner++) labelReverse[vertex + corner] = 1;
148053
+ if (uTurnInteriorFaces.has(vertex)) {
148054
+ for (let corner = 0; corner < 4; corner++) uvs.setX(vertex + corner, -1);
148055
+ return;
148056
+ }
148057
+ if (positions && !isRectangularFace(positions, vertex)) {
148058
+ for (let corner = 0; corner < 4; corner++) uvs.setX(vertex + corner, -1);
148059
+ return;
148060
+ }
148061
+ const pathSegment = Math.floor(index / 4);
148062
+ const startPoint = points?.[pathSegment];
148063
+ const endPoint = points?.[pathSegment + 1];
148064
+ const dx = endPoint ? endPoint.x - startPoint.x : 0;
148065
+ const dy = endPoint ? endPoint.y - startPoint.y : 0;
148066
+ const dz = endPoint ? endPoint.z - startPoint.z : 0;
148067
+ const segmentLength = Math.hypot(dx, dy, dz);
148068
+ const projectedDistances = Array.from({
148069
+ length: 4
148070
+ }, (_, corner) => {
148071
+ const positionIndex = vertex + corner;
148072
+ return positions && startPoint && segmentLength ? ((positions.getX(positionIndex) - startPoint.x) * dx + (positions.getY(positionIndex) - startPoint.y) * dy + (positions.getZ(positionIndex) - startPoint.z) * dz) / segmentLength : segmentLength * (uvs.getY(positionIndex) - minV) / (maxV - minV);
148073
+ });
148074
+ const minDistance = Math.min(...projectedDistances);
148075
+ const maxDistance = Math.max(...projectedDistances);
148076
+ const labelLength = maxDistance - minDistance;
148077
+ const sideWidth = positions ? new Vector3().fromBufferAttribute(positions, vertex).distanceTo(new Vector3().fromBufferAttribute(positions, vertex + 1)) : 0;
148078
+ if (sideWidth > 0) {
148079
+ for (let corner = 0; corner < 4; corner++) labelAspects[vertex + corner] = labelLength / sideWidth;
148080
+ }
148081
+ if (labelLength < 1e-6) {
148082
+ for (let corner = 0; corner < 4; corner++) uvs.setX(vertex + corner, -1);
148083
+ return;
148084
+ }
148085
+ for (let corner = 0; corner < 4; corner++) {
148086
+ const positionIndex = vertex + corner;
148087
+ const alongLabel = (projectedDistances[corner] - minDistance) / labelLength;
148088
+ const sidePosition = uvs.getX(positionIndex);
148089
+ uvs.setXY(positionIndex, 1 - alongLabel, 1 - (sidePosition - minU) / (maxU - minU));
148090
+ }
148091
+ });
148092
+ if (!sideQuads.length) {
148093
+ mapSingleCellSideUVs(geometry, uvs, labelAspects, labelMaxFontSizes);
148094
+ } else {
148095
+ for (let vertex = 0; vertex + 3 < uvs.count; vertex += 4) {
148096
+ if (sideQuadVertices.has(vertex)) continue;
148097
+ for (let corner = 0; corner < 4; corner++) {
148098
+ uvs.setX(vertex + corner, -1);
148099
+ }
148100
+ }
148101
+ }
148102
+ geometry.setAttribute('hilbertLabelAspect', new Float32BufferAttribute(labelAspects, 1));
148103
+ geometry.setAttribute('hilbertLabelMaxFontSize', new Float32BufferAttribute(labelMaxFontSizes, 1));
148104
+ geometry.setAttribute('hilbertLabelReverse', new Float32BufferAttribute(labelReverse, 1));
148105
+ uvs.needsUpdate = true;
148106
+ }
148107
+ function getUTurnInteriorFaces(points, positions) {
148108
+ const hiddenFaces = new Set();
148109
+ if (!points || points.length < 4 || !positions) return hiddenFaces;
148110
+ const directions = points.slice(1).map((point, index) => point.clone().sub(points[index]).normalize());
148111
+ for (let middleSegment = 1; middleSegment < directions.length - 1; middleSegment++) {
148112
+ const incoming = directions[middleSegment - 1];
148113
+ const middle = directions[middleSegment];
148114
+ const outgoing = directions[middleSegment + 1];
148115
+ if (incoming.dot(outgoing) > -0.999999 || Math.abs(incoming.dot(middle)) > 1e-6) continue;
148116
+ const interiorNormals = [{
148117
+ segment: middleSegment - 1,
148118
+ normal: middle
148119
+ }, {
148120
+ segment: middleSegment,
148121
+ normal: incoming.clone().negate()
148122
+ }, {
148123
+ segment: middleSegment + 1,
148124
+ normal: middle
148125
+ }];
148126
+ interiorNormals.forEach(({
148127
+ segment,
148128
+ normal
148129
+ }) => {
148130
+ const pathCenter = points[segment].clone().add(points[segment + 1]).multiplyScalar(0.5);
148131
+ for (let side = 0; side < 4; side++) {
148132
+ const vertex = (segment * 4 + side) * 4;
148133
+ const faceCenter = new Vector3();
148134
+ for (let corner = 0; corner < 4; corner++) {
148135
+ faceCenter.add(new Vector3().fromBufferAttribute(positions, vertex + corner));
148136
+ }
148137
+ faceCenter.multiplyScalar(0.25).sub(pathCenter);
148138
+ faceCenter.addScaledVector(directions[segment], -faceCenter.dot(directions[segment]));
148139
+ if (faceCenter.lengthSq() > 0 && faceCenter.normalize().dot(normal) > 0.9) hiddenFaces.add(vertex);
148140
+ }
148141
+ });
148142
+ }
148143
+ return hiddenFaces;
148144
+ }
148145
+ function isRectangularFace(positions, vertex) {
148146
+ const corners = Array.from({
148147
+ length: 4
148148
+ }, (_, corner) => new Vector3().fromBufferAttribute(positions, vertex + corner));
148149
+ const edges = corners.map((corner, index) => corners[(index + 1) % 4].clone().sub(corner));
148150
+ const scale = Math.max(...edges.map(edge => edge.length()));
148151
+ const tolerance = scale * 1e-4;
148152
+ const oppositeEdgesMatch = edges[0].clone().add(edges[2]).length() <= tolerance && edges[1].clone().add(edges[3]).length() <= tolerance;
148153
+ const adjacentEdgesPerpendicular = Math.abs(edges[0].dot(edges[1])) <= edges[0].length() * edges[1].length() * 1e-4;
148154
+ return oppositeEdgesMatch && adjacentEdgesPerpendicular;
148155
+ }
148156
+ function mapSingleCellSideUVs(geometry, uvs, labelAspects, labelMaxFontSizes) {
148157
+ const positions = geometry.getAttribute('position');
148158
+ const normals = geometry.getAttribute('normal');
148159
+ if (!positions || !normals || positions.count !== 24) return;
148160
+ for (let vertex = 0; vertex + 3 < positions.count; vertex += 4) {
148161
+ const normalX = normals.getX(vertex);
148162
+ const normalY = normals.getY(vertex);
148163
+ const normalZ = normals.getZ(vertex);
148164
+ const rightX = Math.abs(normalY) > 0.9 ? 1 : normalZ > 0.9 ? 1 : normalZ < -0.9 ? -1 : 0;
148165
+ const rightZ = Math.abs(normalY) > 0.9 ? 0 : normalX > 0.9 ? -1 : normalX < -0.9 ? 1 : 0;
148166
+ const upY = Math.abs(normalY) > 0.9 ? 0 : 1;
148167
+ const upZ = Math.abs(normalY) > 0.9 ? normalY > 0 ? -1 : 1 : 0;
148168
+ let minRight = Infinity;
148169
+ let maxRight = -Infinity;
148170
+ let minUp = Infinity;
148171
+ let maxUp = -Infinity;
148172
+ for (let corner = 0; corner < 4; corner++) {
148173
+ const index = vertex + corner;
148174
+ const right = positions.getX(index) * rightX + positions.getZ(index) * rightZ;
148175
+ const up = positions.getY(index) * upY + positions.getZ(index) * upZ;
148176
+ minRight = Math.min(minRight, right);
148177
+ maxRight = Math.max(maxRight, right);
148178
+ minUp = Math.min(minUp, up);
148179
+ maxUp = Math.max(maxUp, up);
148180
+ }
148181
+ for (let corner = 0; corner < 4; corner++) {
148182
+ const index = vertex + corner;
148183
+ const right = positions.getX(index) * rightX + positions.getZ(index) * rightZ;
148184
+ const up = positions.getY(index) * upY + positions.getZ(index) * upZ;
148185
+ uvs.setXY(index, (right - minRight) / (maxRight - minRight), (up - minUp) / (maxUp - minUp));
148186
+ labelAspects[index] = (maxRight - minRight) / (maxUp - minUp);
148187
+ labelMaxFontSizes[index] = MAX_CUBE_LABEL_FONT_SIZE;
148188
+ }
148189
+ }
148190
+ }
148191
+
147718
148192
  const CHILD_PERMUTATIONS = [[0, 3, 4, 7, 6, 5, 2, 1], [0, 7, 6, 1, 2, 5, 4, 3], [0, 7, 6, 1, 2, 5, 4, 3], [2, 3, 0, 1, 6, 7, 4, 5], [2, 3, 0, 1, 6, 7, 4, 5], [4, 3, 2, 5, 6, 1, 0, 7], [4, 3, 2, 5, 6, 1, 0, 7], [6, 5, 2, 1, 0, 3, 4, 7]];
147719
148193
  const {
147720
148194
  orientations: HILBERT_ORIENTATIONS,
@@ -147750,8 +148224,10 @@ var<${access}> ${ name } : ${ structName };`;
147750
148224
  data,
147751
148225
  order,
147752
148226
  paddingAccessor,
148227
+ paddingAbsoluteAccessor,
147753
148228
  colorAccessor,
147754
148229
  labelAccessor,
148230
+ labelAtlas,
147755
148231
  defaultColorScale,
147756
148232
  simplifyCurves,
147757
148233
  SCALE
@@ -147764,57 +148240,74 @@ var<${access}> ${ name } : ${ structName };`;
147764
148240
  const usedGeometryKeys = new Set();
147765
148241
  data.forEach(d => {
147766
148242
  const padding = paddingAccessor(d);
148243
+ const paddingAbsolute = paddingAbsoluteAccessor(d);
148244
+ const labelInfo = labelAtlas?.labels.get(d);
148245
+ const label = labelInfo?.text ?? labelAccessor(d);
147767
148246
  if (!useInstancing) {
147768
- geometries.set(d, createGeometry(order, d, padding, simplifyCurves));
148247
+ const geometry = createGeometry(order, d, padding, paddingAbsolute, simplifyCurves, Boolean(labelAtlas));
148248
+ if (labelAtlas) addLabelAttributes(geometry, [{
148249
+ info: labelInfo
148250
+ }]);
148251
+ geometries.set(d, geometry);
147769
148252
  fallbackData.push(d);
147770
148253
  return;
147771
148254
  }
147772
- const description = getSimpleHilbertGeometry(order, d.start, d.length, padding, simplifyCurves);
148255
+ const description = getSimpleHilbertGeometry(order, d.start, d.length, padding, paddingAbsolute, simplifyCurves);
147773
148256
  if (!description) {
147774
- geometries.set(d, createGeometry(order, d, padding, simplifyCurves));
148257
+ const geometry = createGeometry(order, d, padding, paddingAbsolute, simplifyCurves, Boolean(labelAtlas));
148258
+ if (labelAtlas) addLabelAttributes(geometry, [{
148259
+ info: labelInfo
148260
+ }]);
148261
+ geometries.set(d, geometry);
147775
148262
  fallbackData.push(d);
147776
148263
  return;
147777
148264
  }
147778
- const color = colorAccessor?.(d) || defaultColorScale(labelAccessor(d) || '');
148265
+ const color = colorAccessor?.(d) || defaultColorScale(label || '');
147779
148266
  const {
147780
148267
  points,
147781
148268
  width,
147782
148269
  scale
147783
148270
  } = description;
147784
148271
  const key = getCurvePath(points);
147785
- const geometryKey = `${key}|${width / scale}`;
148272
+ const geometryKey = `${key}|${width / scale}|${Boolean(labelAtlas)}`;
147786
148273
  usedGeometryKeys.add(geometryKey);
147787
148274
  let templateGeometry = geometryCache.get(geometryKey);
147788
148275
  if (!templateGeometry) {
147789
- const geometry = createGeometry(order, d, padding, simplifyCurves);
148276
+ const geometry = createGeometry(order, d, padding, paddingAbsolute, simplifyCurves, Boolean(labelAtlas));
147790
148277
  templateGeometry = createTemplateGeometry(geometry, points[0], scale);
147791
148278
  geometryCache.set(geometryKey, templateGeometry);
147792
148279
  geometry.dispose();
147793
148280
  }
147794
- let material = instanceMaterialCache.get(color);
148281
+ const materialKey = color;
148282
+ let material = instanceMaterialCache.get(materialKey);
147795
148283
  if (!material) {
147796
- const opacity = colorAlpha(color);
147797
- material = new MeshLambertMaterial();
147798
- material.color.set(colorStr2Hex(color));
147799
- material.transparent = opacity < 1;
147800
- material.opacity = opacity;
147801
- instanceMaterialCache.set(color, material);
148284
+ if (!labelAtlas) {
148285
+ const opacity = colorAlpha(color);
148286
+ material = new MeshLambertMaterial();
148287
+ material.color.set(colorStr2Hex(color));
148288
+ material.transparent = opacity < 1;
148289
+ material.opacity = opacity;
148290
+ } else {
148291
+ material = createLabelMaterial(color, labelAtlas);
148292
+ }
148293
+ instanceMaterialCache.set(materialKey, material);
147802
148294
  }
147803
148295
  let colorBatches = batches.get(geometryKey);
147804
148296
  if (!colorBatches) {
147805
148297
  colorBatches = new Map();
147806
148298
  batches.set(geometryKey, colorBatches);
147807
148299
  }
147808
- let batch = colorBatches.get(color);
148300
+ let batch = colorBatches.get(materialKey);
147809
148301
  if (!batch) {
147810
148302
  batch = {
147811
148303
  geometry: templateGeometry,
147812
148304
  material,
147813
148305
  transforms: new Float32Array(256),
147814
148306
  count: 0,
147815
- data: []
148307
+ data: [],
148308
+ labelRecords: []
147816
148309
  };
147817
- colorBatches.set(color, batch);
148310
+ colorBatches.set(materialKey, batch);
147818
148311
  }
147819
148312
  const instanceScale = scale * SCALE;
147820
148313
  let transforms = batch.transforms;
@@ -147830,6 +148323,9 @@ var<${access}> ${ name } : ${ structName };`;
147830
148323
  transforms[transformOffset + 3] = points[0].z * SCALE;
147831
148324
  batch.count++;
147832
148325
  batch.data.push(d);
148326
+ if (labelAtlas) batch.labelRecords.push({
148327
+ info: labelInfo
148328
+ });
147833
148329
  });
147834
148330
  geometryCache.forEach((geometry, key) => {
147835
148331
  if (!usedGeometryKeys.has(key)) {
@@ -147840,7 +148336,9 @@ var<${access}> ${ name } : ${ structName };`;
147840
148336
  const meshes = [];
147841
148337
  batches.forEach(colorBatches => {
147842
148338
  colorBatches.forEach(batch => {
147843
- const mesh = new InstancedMesh(batch.geometry, batch.material, batch.count);
148339
+ const geometry = batch.geometry.clone();
148340
+ if (labelAtlas) addLabelAttributes(geometry, batch.labelRecords, true);
148341
+ const mesh = new InstancedMesh(geometry, batch.material, batch.count);
147844
148342
  const matrices = mesh.instanceMatrix.array;
147845
148343
  for (let i = 0; i < batch.count; i++) {
147846
148344
  const transformOffset = i * 4;
@@ -147860,17 +148358,21 @@ var<${access}> ${ name } : ${ structName };`;
147860
148358
  meshes.push(mesh);
147861
148359
  });
147862
148360
  });
148361
+ geometryCache.forEach(geometry => geometry.dispose());
147863
148362
  return {
147864
148363
  fallbackData,
147865
148364
  geometries,
147866
148365
  meshes
147867
148366
  };
147868
148367
  }
147869
- function createGeometry(order, datum, padding, simplifyCurves) {
147870
- return new ThreeHilbertGeometry(order, datum.start, datum.length, {
148368
+ function createGeometry(order, datum, padding, paddingAbsolute, simplifyCurves, labeled) {
148369
+ const geometry = new ThreeHilbertGeometry(order, datum.start, datum.length, {
147871
148370
  padding,
148371
+ paddingAbsolute,
147872
148372
  simplifyCurves
147873
148373
  });
148374
+ if (labeled) mapLabelUVs(geometry);
148375
+ return geometry;
147874
148376
  }
147875
148377
  function createTemplateGeometry(geometry, origin, scale) {
147876
148378
  const templateGeometry = new BufferGeometry();
@@ -147889,7 +148391,7 @@ var<${access}> ${ name } : ${ structName };`;
147889
148391
  templateGeometry.computeBoundingSphere();
147890
148392
  return templateGeometry;
147891
148393
  }
147892
- function getSimpleHilbertGeometry(order, start, length, padding, simplifyCurves) {
148394
+ function getSimpleHilbertGeometry(order, start, length, padding, paddingAbsolute, simplifyCurves) {
147893
148395
  const isBigInt = typeof start === 'bigint' && typeof length === 'bigint';
147894
148396
  if (!Number.isInteger(order) || typeof start === 'bigint' !== (typeof length === 'bigint')) return null;
147895
148397
  if (!isBigInt && (!Number.isFinite(start) || !Number.isFinite(length))) return null;
@@ -147897,15 +148399,16 @@ var<${access}> ${ name } : ${ structName };`;
147897
148399
  let first = isBigInt ? start : Math.round(start);
147898
148400
  let pointCount = isBigInt ? length : Math.round(length);
147899
148401
  const unit = isBigInt ? 8n : 8;
148402
+ const zero = isBigInt ? 0n : 0;
147900
148403
  if (simplifyCurves) {
147901
- while (pointOrder > 0 && first % unit === 0 && pointCount % unit === 0) {
148404
+ while (pointOrder > 0 && first % unit === zero && pointCount % unit === zero) {
147902
148405
  first /= unit;
147903
148406
  pointCount /= unit;
147904
148407
  pointOrder--;
147905
148408
  }
147906
148409
  }
147907
148410
  const cellSize = 1 / 2 ** (pointOrder - 1);
147908
- const width = cellSize * (1 - Math.min(1, padding));
148411
+ const width = (cellSize - Math.min(paddingAbsolute, cellSize * 0.5)) * (1 - Math.min(1, padding));
147909
148412
  if (!(width > 0) || !Number.isFinite(width)) return null;
147910
148413
  if (pointOrder <= 0) {
147911
148414
  const points = [{
@@ -148000,12 +148503,15 @@ var<${access}> ${ name } : ${ structName };`;
148000
148503
  padding: {
148001
148504
  default: 0
148002
148505
  },
148506
+ paddingAbsolute: {
148507
+ default: 0
148508
+ },
148003
148509
  color: {},
148004
148510
  label: {
148005
148511
  default: 'name'
148006
148512
  },
148007
148513
  labelColor: {
148008
- default: () => 'white'
148514
+ default: () => 'lavender'
148009
148515
  },
148010
148516
  simplifyCurves: {
148011
148517
  default: true
@@ -148024,6 +148530,7 @@ var<${access}> ${ name } : ${ structName };`;
148024
148530
  const g = new ThreeHilbertGeometry(state.order, start, length);
148025
148531
  g.computeBoundingBox();
148026
148532
  const bbox = g.boundingBox.clone();
148533
+ g.dispose();
148027
148534
  bbox.min.multiplyScalar(SCALE);
148028
148535
  bbox.max.multiplyScalar(SCALE);
148029
148536
  return bbox;
@@ -148032,7 +148539,8 @@ var<${access}> ${ name } : ${ structName };`;
148032
148539
  stateInit() {
148033
148540
  return {
148034
148541
  defaultColorScale: ordinal(Paired),
148035
- instancedMeshes: []
148542
+ instancedMeshes: [],
148543
+ labelAtlas: null
148036
148544
  };
148037
148545
  },
148038
148546
  init: function (threeObj, state) {
@@ -148053,9 +148561,13 @@ var<${access}> ${ name } : ${ structName };`;
148053
148561
  update: function (state, changedProps) {
148054
148562
  // Data accessors
148055
148563
  const paddingAccessor = index$3(state.padding);
148564
+ const paddingAbsoluteAccessor = index$3(state.paddingAbsolute);
148056
148565
  const colorAccessor = index$3(state.color);
148057
148566
  const labelAccessor = index$3(state.label);
148058
- index$3(state.labelColor);
148567
+ const labelColorAccessor = index$3(state.labelColor);
148568
+ const previousLabelAtlas = state.labelAtlas;
148569
+ const labelAtlas = createLabelAtlas(state.data, labelAccessor, labelColorAccessor);
148570
+ state.labelAtlas = labelAtlas;
148059
148571
  const {
148060
148572
  fallbackData,
148061
148573
  geometries,
@@ -148065,8 +148577,10 @@ var<${access}> ${ name } : ${ structName };`;
148065
148577
  data: state.data,
148066
148578
  order: state.order,
148067
148579
  paddingAccessor,
148580
+ paddingAbsoluteAccessor,
148068
148581
  colorAccessor,
148069
148582
  labelAccessor,
148583
+ labelAtlas,
148070
148584
  defaultColorScale: state.defaultColorScale,
148071
148585
  simplifyCurves: state.simplifyCurves,
148072
148586
  SCALE
@@ -148082,20 +148596,29 @@ var<${access}> ${ name } : ${ structName };`;
148082
148596
  const [hilbertObj] = obj.children;
148083
148597
 
148084
148598
  // update color
148085
- const color = colorAccessor?.(d) || state.defaultColorScale(labelAccessor(d) || '');
148086
- let material = materialCache.get(color);
148087
- if (!material) {
148599
+ const label = labelAtlas?.labels.get(d)?.text ?? labelAccessor(d);
148600
+ const color = colorAccessor?.(d) || state.defaultColorScale(label || '');
148601
+ const materialKey = color;
148602
+ let material = materialCache.get(materialKey);
148603
+ if (!material && labelAtlas) {
148604
+ material = createLabelMaterial(color, labelAtlas);
148605
+ materialCache.set(materialKey, material);
148606
+ } else if (!material) {
148088
148607
  const opacity = colorAlpha(color);
148089
148608
  material = new MeshLambertMaterial();
148090
148609
  material.color.set(colorStr2Hex(color));
148091
148610
  material.transparent = opacity < 1;
148092
148611
  material.opacity = opacity;
148093
- materialCache.set(color, material);
148612
+ materialCache.set(materialKey, material);
148094
148613
  }
148095
148614
  hilbertObj.material = material;
148096
148615
  hilbertObj.geometry?.dispose();
148097
148616
  hilbertObj.geometry = geometries.get(d);
148098
148617
  }).digest(fallbackData);
148618
+ if (previousLabelAtlas) {
148619
+ previousLabelAtlas.glyphTexture.dispose();
148620
+ previousLabelAtlas.labelTexture.dispose();
148621
+ }
148099
148622
  }
148100
148623
  });
148101
148624
 
@@ -148120,6 +148643,36 @@ var<${access}> ${ name } : ${ structName };`;
148120
148643
 
148121
148644
  var index$1 = fromKapsule(ThreeHilbert, Group$1, true);
148122
148645
 
148646
+ function styleInject(css, ref) {
148647
+ if ( ref === void 0 ) ref = {};
148648
+ var insertAt = ref.insertAt;
148649
+
148650
+ if (typeof document === 'undefined') { return; }
148651
+
148652
+ var head = document.head || document.getElementsByTagName('head')[0];
148653
+ var style = document.createElement('style');
148654
+ style.type = 'text/css';
148655
+
148656
+ if (insertAt === 'top') {
148657
+ if (head.firstChild) {
148658
+ head.insertBefore(style, head.firstChild);
148659
+ } else {
148660
+ head.appendChild(style);
148661
+ }
148662
+ } else {
148663
+ head.appendChild(style);
148664
+ }
148665
+
148666
+ if (style.styleSheet) {
148667
+ style.styleSheet.cssText = css;
148668
+ } else {
148669
+ style.appendChild(document.createTextNode(css));
148670
+ }
148671
+ }
148672
+
148673
+ var css_248z = ".hilbert-scene-container .clickable {\n cursor: pointer;\n}";
148674
+ styleInject(css_248z);
148675
+
148123
148676
  var index = index$4({
148124
148677
  props: {
148125
148678
  width: {
@@ -148158,6 +148711,13 @@ var<${access}> ${ name } : ${ structName };`;
148158
148711
  },
148159
148712
  triggerUpdate: false
148160
148713
  },
148714
+ paddingAbsolute: {
148715
+ default: 0,
148716
+ onChange(v, state) {
148717
+ state.hilbert.paddingAbsolute(v);
148718
+ },
148719
+ triggerUpdate: false
148720
+ },
148161
148721
  color: {
148162
148722
  onChange(v, state) {
148163
148723
  state.hilbert.color(v);
@@ -148263,36 +148823,44 @@ var<${access}> ${ name } : ${ structName };`;
148263
148823
 
148264
148824
  // Add renderObjs
148265
148825
  const roDomNode = document.createElement('div');
148826
+ roDomNode.className = 'hilbert-scene-container';
148266
148827
  el.appendChild(roDomNode);
148267
- const getHilbertObj = object => {
148268
- let obj = object;
148269
- // recurse up object chain until finding the globe object
148270
- while (obj && !obj.hasOwnProperty('__data')) {
148271
- obj = obj.parent;
148828
+ const getHilbertObjData = (obj, intersection) => {
148829
+ if (!obj) return null;
148830
+ if (intersection && obj.isInstancedMesh) {
148831
+ return obj.userData.data?.[intersection.instanceId] || null;
148832
+ }
148833
+ const hilbertObj = getHilbertObj(obj);
148834
+ return hilbertObj?.__data || null;
148835
+ function getHilbertObj(object) {
148836
+ let obj = object;
148837
+ // recurse up object chain until finding the globe object
148838
+ while (obj && !obj.hasOwnProperty('__data')) {
148839
+ obj = obj.parent;
148840
+ }
148841
+ return obj;
148272
148842
  }
148273
- return obj;
148274
148843
  };
148275
- state.renderObjs(roDomNode).tooltipContent(obj => {
148276
- const o = getHilbertObj(obj);
148277
- return !o ? '' : state.tooltipContent ? index$3(state.tooltipContent)(o.__data) || '' : (() => {
148844
+ state.renderObjs(roDomNode).tooltipContent((obj, intersection) => {
148845
+ const d = getHilbertObjData(obj, intersection);
148846
+ return !d ? '' : state.tooltipContent ? index$3(state.tooltipContent)(d) || '' : (() => {
148278
148847
  // default content
148279
- const d = o.__data;
148280
148848
  const label = index$3(state.label)(d);
148281
148849
  return `${label ? `<b>${label}</b>: ` : ''}${state.valFormatter(d.start) + (d.length > 1 ? ' - ' + state.valFormatter(d.start + d.length - (typeof d.start === 'bigint' ? 1n : 1)) : '')}`;
148282
148850
  })();
148283
- }).onHover(obj => {
148851
+ }).onHover((obj, _, intersection) => {
148284
148852
  // Update tooltip and trigger onHover events
148285
- const hoverObj = getHilbertObj(obj);
148286
- if (hoverObj !== state.hoverObj) {
148287
- state.onHover?.(hoverObj?.__data || null, state.hoverObj?.__data || null);
148853
+ const hoverD = getHilbertObjData(obj, intersection);
148854
+ if (hoverD !== state.hoverD) {
148855
+ state.onHover?.(hoverD, state.hoverD || null);
148288
148856
 
148289
148857
  // set pointer if hovered object is clickable
148290
- state.renderObjs.renderer().domElement.classList[hoverObj && state.onClick || !hoverObj && state.onBackgroundClick ? 'add' : 'remove']('clickable');
148291
- state.hoverObj = hoverObj;
148858
+ state.renderObjs.renderer().domElement.classList[hoverD && state.onClick || !hoverD && state.onBackgroundClick ? 'add' : 'remove']('clickable');
148859
+ state.hoverD = hoverD;
148292
148860
  }
148293
- }).onClick((obj, ev) => {
148294
- const o = getHilbertObj(obj);
148295
- o ? state.onClick?.(o.__data, ev) : state.onBackgroundClick?.(ev);
148861
+ }).onClick((obj, ev, intersection) => {
148862
+ const d = getHilbertObjData(obj, intersection);
148863
+ d ? state.onClick?.(d, ev) : state.onBackgroundClick?.(ev);
148296
148864
  });
148297
148865
  state.renderObjs.camera().position.z = 500;
148298
148866