@fusion.dev/helix-plot 0.191.0 → 0.193.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.
@@ -145,7 +145,11 @@ export const createStage = (container, options) => {
145
145
  }
146
146
  const mark = document.createElement('span');
147
147
  mark.textContent = text;
148
- mark.style.cssText = `position:absolute;left:${((on.x + 1) / 2) * width}px;top:${((1 - on.y) / 2) * height}px;translate:-50% -50%;white-space:nowrap;font:${strong ? 600 : 500} ${strong ? 13 : 11}px ${font};color:${strong ? colors?.ink : colors?.quiet};text-shadow:0 0 3px ${colors?.ground},0 0 3px ${colors?.ground}`;
148
+ const size = strong ? 'var(--helix-text-sm, 13px)' : 'var(--helix-text-xs, 11px)';
149
+ const weight = strong
150
+ ? 'var(--helix-weight-semibold, 600)'
151
+ : 'var(--helix-weight-medium, 500)';
152
+ mark.style.cssText = `position:absolute;left:${((on.x + 1) / 2) * width}px;top:${((1 - on.y) / 2) * height}px;translate:-50% -50%;white-space:nowrap;font-family:${font};font-size:${size};font-weight:${weight};line-height:1;color:${strong ? colors?.ink : colors?.quiet};text-shadow:0 0 3px ${colors?.ground},0 0 3px ${colors?.ground}`;
149
153
  marks.push(mark);
150
154
  };
151
155
  const h = HALF;
@@ -226,22 +230,47 @@ export const createStage = (container, options) => {
226
230
  return;
227
231
  }
228
232
  const { high, low } = framed;
229
- const center = low.clone().add(high).multiplyScalar(0.5);
230
233
  const toward = camera.position.clone().sub(controls.target).normalize();
231
234
  const right = new Vector3(0, 1, 0).cross(toward).normalize();
232
235
  const up = toward.clone().cross(right).normalize();
233
236
  const tanUp = Math.tan((camera.fov * Math.PI) / 360);
234
237
  const tanAcross = tanUp * camera.aspect;
235
- let distance = 0;
238
+ const corners = [];
236
239
  for (const x of [low.x, high.x]) {
237
240
  for (const y of [low.y, high.y]) {
238
241
  for (const z of [low.z, high.z]) {
239
- const corner = new Vector3(x, y, z).sub(center);
240
- const ahead = corner.dot(toward);
241
- distance = Math.max(distance, ahead + Math.abs(corner.dot(right)) / tanAcross, ahead + Math.abs(corner.dot(up)) / tanUp);
242
+ corners.push(new Vector3(x, y, z));
242
243
  }
243
244
  }
244
245
  }
246
+ const distanceFrom = (center) => {
247
+ let far = 0;
248
+ for (const corner of corners) {
249
+ const off = corner.clone().sub(center);
250
+ const ahead = off.dot(toward);
251
+ far = Math.max(far, ahead + Math.abs(off.dot(right)) / tanAcross, ahead + Math.abs(off.dot(up)) / tanUp);
252
+ }
253
+ return far;
254
+ };
255
+ const center = low.clone().add(high).multiplyScalar(0.5);
256
+ let distance = distanceFrom(center);
257
+ for (let round = 0; round < 4; round++) {
258
+ let [left, rightmost, bottom, top] = [Infinity, -Infinity, Infinity, -Infinity];
259
+ for (const corner of corners) {
260
+ const off = corner.clone().sub(center);
261
+ const depth = Math.max(distance - off.dot(toward), 1e-6);
262
+ const across = off.dot(right) / depth / tanAcross;
263
+ const rise = off.dot(up) / depth / tanUp;
264
+ left = Math.min(left, across);
265
+ rightmost = Math.max(rightmost, across);
266
+ bottom = Math.min(bottom, rise);
267
+ top = Math.max(top, rise);
268
+ }
269
+ center
270
+ .add(right.clone().multiplyScalar(((left + rightmost) / 2) * tanAcross * distance))
271
+ .add(up.clone().multiplyScalar(((bottom + top) / 2) * tanUp * distance));
272
+ distance = distanceFrom(center);
273
+ }
245
274
  distance *= 1.06;
246
275
  controls.target.copy(center);
247
276
  camera.position.copy(center).add(toward.multiplyScalar(distance));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fusion.dev/helix-plot",
3
3
  "description": "Connects the Helix Spatial Heatmap, Spatial Scatter Chart, and Spatial Surface Chart to three.js, which draws them in three dimensions.",
4
- "version": "0.191.0",
4
+ "version": "0.193.0",
5
5
  "license": "MIT",
6
6
  "author": "Ross Sheppard <ross.sheppard@fusion.dev>",
7
7
  "repository": {
@@ -35,11 +35,11 @@
35
35
  },
36
36
  "bugs": "https://github.com/project-fusion/fusion/issues",
37
37
  "dependencies": {
38
- "@fusion.dev/helix-core": "0.191.0"
38
+ "@fusion.dev/helix-core": "0.193.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@fusion.dev/helix-headless": "0.191.0",
42
- "@fusion.dev/helix-testing": "0.191.0",
41
+ "@fusion.dev/helix-headless": "0.193.0",
42
+ "@fusion.dev/helix-testing": "0.193.0",
43
43
  "@types/bun": "^1.4.2",
44
44
  "@types/three": "^0.186.0",
45
45
  "three": "^0.186.1"