@vitessce/layer-controller 3.2.1 → 3.2.2

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,5 +1,5 @@
1
1
  import { i as inflate_1 } from "./pako.esm-68f84e2a.js";
2
- import { B as BaseDecoder } from "./index-f8a9f462.js";
2
+ import { B as BaseDecoder } from "./index-a79502da.js";
3
3
  import "react";
4
4
  import "@vitessce/vit-s";
5
5
  import "react-dom";
@@ -135596,16 +135596,16 @@ function addDecoder(cases, importFn) {
135596
135596
  }
135597
135597
  cases.forEach((c) => registry$1.set(c, importFn));
135598
135598
  }
135599
- addDecoder([void 0, 1], () => import("./raw-dd52cf7d.js").then((m) => m.default));
135600
- addDecoder(5, () => import("./lzw-3b2cc6cd.js").then((m) => m.default));
135599
+ addDecoder([void 0, 1], () => import("./raw-af4639cb.js").then((m) => m.default));
135600
+ addDecoder(5, () => import("./lzw-b6a080bc.js").then((m) => m.default));
135601
135601
  addDecoder(6, () => {
135602
135602
  throw new Error("old style JPEG compression is not supported.");
135603
135603
  });
135604
- addDecoder(7, () => import("./jpeg-932c57f1.js").then((m) => m.default));
135605
- addDecoder([8, 32946], () => import("./deflate-22ea8fc3.js").then((m) => m.default));
135606
- addDecoder(32773, () => import("./packbits-c8220e7f.js").then((m) => m.default));
135607
- addDecoder(34887, () => import("./lerc-0db1b156.js").then((m) => m.default));
135608
- addDecoder(50001, () => import("./webimage-d7166a5a.js").then((m) => m.default));
135604
+ addDecoder(7, () => import("./jpeg-f13e87d5.js").then((m) => m.default));
135605
+ addDecoder([8, 32946], () => import("./deflate-822f733b.js").then((m) => m.default));
135606
+ addDecoder(32773, () => import("./packbits-fbb728f4.js").then((m) => m.default));
135607
+ addDecoder(34887, () => import("./lerc-e0b9e6f7.js").then((m) => m.default));
135608
+ addDecoder(50001, () => import("./webimage-cf240654.js").then((m) => m.default));
135609
135609
  function decodeRowAcc(row, stride) {
135610
135610
  let length2 = row.length - stride;
135611
135611
  let offset4 = 0;
@@ -144613,6 +144613,67 @@ function makeBoundingBox(viewState) {
144613
144613
  viewport.unproject([0, viewport.height])
144614
144614
  ];
144615
144615
  }
144616
+ const TARGETS = [1, 2, 3, 4, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1e3];
144617
+ const MIN_TARGET = TARGETS[0];
144618
+ const MAX_TARGET = TARGETS[TARGETS.length - 1];
144619
+ const SI_PREFIXES = [
144620
+ { symbol: "Y", exponent: 24 },
144621
+ { symbol: "Z", exponent: 21 },
144622
+ { symbol: "E", exponent: 18 },
144623
+ { symbol: "P", exponent: 15 },
144624
+ { symbol: "T", exponent: 12 },
144625
+ { symbol: "G", exponent: 9 },
144626
+ { symbol: "M", exponent: 6 },
144627
+ { symbol: "k", exponent: 3 },
144628
+ { symbol: "h", exponent: 2 },
144629
+ { symbol: "da", exponent: 1 },
144630
+ { symbol: "", exponent: 0 },
144631
+ { symbol: "d", exponent: -1 },
144632
+ { symbol: "c", exponent: -2 },
144633
+ { symbol: "m", exponent: -3 },
144634
+ { symbol: "µ", exponent: -6 },
144635
+ { symbol: "n", exponent: -9 },
144636
+ { symbol: "p", exponent: -12 },
144637
+ { symbol: "f", exponent: -15 },
144638
+ { symbol: "a", exponent: -18 },
144639
+ { symbol: "z", exponent: -21 },
144640
+ { symbol: "y", exponent: -24 }
144641
+ ];
144642
+ function sizeToMeters(size, unit) {
144643
+ if (!unit || unit === "m") {
144644
+ return size;
144645
+ }
144646
+ if (unit.length > 1) {
144647
+ let unitPrefix = unit.substring(0, unit.length - 1);
144648
+ if (unitPrefix === "u") {
144649
+ unitPrefix = "µ";
144650
+ }
144651
+ const unitObj = SI_PREFIXES.find((p) => p.symbol === unitPrefix);
144652
+ if (unitObj) {
144653
+ return size * 10 ** unitObj.exponent;
144654
+ }
144655
+ }
144656
+ throw new Error("Received unknown unit");
144657
+ }
144658
+ function snapValue(value) {
144659
+ let magnitude = 0;
144660
+ if (value < MIN_TARGET || value > MAX_TARGET) {
144661
+ magnitude = Math.floor(Math.log10(value));
144662
+ }
144663
+ let snappedUnit = SI_PREFIXES.find(
144664
+ (p) => p.exponent % 3 === 0 && p.exponent <= magnitude
144665
+ );
144666
+ let adjustedValue = value / 10 ** snappedUnit.exponent;
144667
+ if (adjustedValue > 500 && adjustedValue <= 1e3) {
144668
+ snappedUnit = SI_PREFIXES.find(
144669
+ (p) => p.exponent % 3 === 0 && p.exponent <= magnitude + 3
144670
+ );
144671
+ adjustedValue = value / 10 ** snappedUnit.exponent;
144672
+ }
144673
+ const targetNewUnits = TARGETS.find((t2) => t2 > adjustedValue);
144674
+ const targetOrigUnits = targetNewUnits * 10 ** snappedUnit.exponent;
144675
+ return [targetOrigUnits, targetNewUnits, snappedUnit.symbol];
144676
+ }
144616
144677
  const fs$1$1 = `#define SHADER_NAME xr-layer-fragment-shader
144617
144678
 
144618
144679
  precision highp float;
@@ -145380,26 +145441,27 @@ const OverviewLayer = class extends CompositeLayer {
145380
145441
  OverviewLayer.layerName = "OverviewLayer";
145381
145442
  OverviewLayer.defaultProps = defaultProps$3;
145382
145443
  function getPosition(boundingBox, position, length2) {
145383
- const viewLength = boundingBox[2][0] - boundingBox[0][0];
145444
+ const viewWidth = boundingBox[2][0] - boundingBox[0][0];
145445
+ const viewHeight = boundingBox[2][1] - boundingBox[0][1];
145384
145446
  switch (position) {
145385
145447
  case "bottom-right": {
145386
- const yCoord = boundingBox[2][1] - (boundingBox[2][1] - boundingBox[0][1]) * length2;
145387
- const xLeftCoord = boundingBox[2][0] - viewLength * length2;
145448
+ const yCoord = boundingBox[2][1] - viewHeight * length2;
145449
+ const xLeftCoord = boundingBox[2][0] - viewWidth * length2;
145388
145450
  return [yCoord, xLeftCoord];
145389
145451
  }
145390
145452
  case "top-right": {
145391
- const yCoord = (boundingBox[2][1] - boundingBox[0][1]) * length2;
145392
- const xLeftCoord = boundingBox[2][0] - viewLength * length2;
145453
+ const yCoord = boundingBox[0][1] + viewHeight * length2;
145454
+ const xLeftCoord = boundingBox[2][0] - viewWidth * length2;
145393
145455
  return [yCoord, xLeftCoord];
145394
145456
  }
145395
145457
  case "top-left": {
145396
- const yCoord = (boundingBox[2][1] - boundingBox[0][1]) * length2;
145397
- const xLeftCoord = viewLength * length2;
145458
+ const yCoord = boundingBox[0][1] + viewHeight * length2;
145459
+ const xLeftCoord = boundingBox[0][0] + viewWidth * length2;
145398
145460
  return [yCoord, xLeftCoord];
145399
145461
  }
145400
145462
  case "bottom-left": {
145401
- const yCoord = boundingBox[2][1] - (boundingBox[2][1] - boundingBox[0][1]) * length2;
145402
- const xLeftCoord = viewLength * length2;
145463
+ const yCoord = boundingBox[2][1] - viewHeight * length2;
145464
+ const xLeftCoord = boundingBox[0][0] + viewWidth * length2;
145403
145465
  return [yCoord, xLeftCoord];
145404
145466
  }
145405
145467
  default: {
@@ -145417,11 +145479,12 @@ const defaultProps$2 = {
145417
145479
  unit: { type: "string", value: "", compare: true },
145418
145480
  size: { type: "number", value: 1, compare: true },
145419
145481
  position: { type: "string", value: "bottom-right", compare: true },
145420
- length: { type: "number", value: 0.085, compare: true }
145482
+ length: { type: "number", value: 0.085, compare: true },
145483
+ snap: { type: "boolean", value: false, compare: true }
145421
145484
  };
145422
145485
  const ScaleBarLayer = class extends CompositeLayer {
145423
145486
  renderLayers() {
145424
- const { id, unit, size, position, viewState, length: length2 } = this.props;
145487
+ const { id, unit, size, position, viewState, length: length2, snap } = this.props;
145425
145488
  const boundingBox = makeBoundingBox(viewState);
145426
145489
  const { zoom } = viewState;
145427
145490
  const viewLength = boundingBox[2][0] - boundingBox[0][0];
@@ -145430,15 +145493,27 @@ const ScaleBarLayer = class extends CompositeLayer {
145430
145493
  2 ** (-zoom + 1.5),
145431
145494
  (boundingBox[2][1] - boundingBox[0][1]) * 7e-3
145432
145495
  );
145433
- const numUnits = barLength * size;
145496
+ let adjustedBarLength = barLength;
145497
+ let displayNumber = (barLength * size).toPrecision(5);
145498
+ let displayUnit = unit;
145499
+ if (snap) {
145500
+ const meterSize = sizeToMeters(size, unit);
145501
+ const numUnits = barLength * meterSize;
145502
+ const [snappedOrigUnits, snappedNewUnits, snappedUnitPrefix] = snapValue(numUnits);
145503
+ adjustedBarLength = snappedOrigUnits / meterSize;
145504
+ displayNumber = snappedNewUnits;
145505
+ displayUnit = `${snappedUnitPrefix}m`;
145506
+ }
145434
145507
  const [yCoord, xLeftCoord] = getPosition(boundingBox, position, length2);
145508
+ const xRightCoord = xLeftCoord + barLength;
145509
+ const isLeft = position.endsWith("-left");
145435
145510
  const lengthBar = new LineLayer({
145436
145511
  id: `scale-bar-length-${id}`,
145437
145512
  coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
145438
145513
  data: [
145439
145514
  [
145440
- [xLeftCoord, yCoord],
145441
- [xLeftCoord + barLength, yCoord]
145515
+ [isLeft ? xLeftCoord : xRightCoord - adjustedBarLength, yCoord],
145516
+ [isLeft ? xLeftCoord + adjustedBarLength : xRightCoord, yCoord]
145442
145517
  ]
145443
145518
  ],
145444
145519
  getSourcePosition: (d) => d[0],
@@ -145451,8 +145526,14 @@ const ScaleBarLayer = class extends CompositeLayer {
145451
145526
  coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
145452
145527
  data: [
145453
145528
  [
145454
- [xLeftCoord, yCoord - barHeight],
145455
- [xLeftCoord, yCoord + barHeight]
145529
+ [
145530
+ isLeft ? xLeftCoord : xRightCoord - adjustedBarLength,
145531
+ yCoord - barHeight
145532
+ ],
145533
+ [
145534
+ isLeft ? xLeftCoord : xRightCoord - adjustedBarLength,
145535
+ yCoord + barHeight
145536
+ ]
145456
145537
  ]
145457
145538
  ],
145458
145539
  getSourcePosition: (d) => d[0],
@@ -145465,8 +145546,14 @@ const ScaleBarLayer = class extends CompositeLayer {
145465
145546
  coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
145466
145547
  data: [
145467
145548
  [
145468
- [xLeftCoord + barLength, yCoord - barHeight],
145469
- [xLeftCoord + barLength, yCoord + barHeight]
145549
+ [
145550
+ isLeft ? xLeftCoord + adjustedBarLength : xRightCoord,
145551
+ yCoord - barHeight
145552
+ ],
145553
+ [
145554
+ isLeft ? xLeftCoord + adjustedBarLength : xRightCoord,
145555
+ yCoord + barHeight
145556
+ ]
145470
145557
  ]
145471
145558
  ],
145472
145559
  getSourcePosition: (d) => d[0],
@@ -145479,8 +145566,11 @@ const ScaleBarLayer = class extends CompositeLayer {
145479
145566
  coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
145480
145567
  data: [
145481
145568
  {
145482
- text: numUnits.toPrecision(5) + unit,
145483
- position: [xLeftCoord + barLength * 0.5, yCoord + barHeight * 4]
145569
+ text: `${displayNumber}${displayUnit}`,
145570
+ position: [
145571
+ isLeft ? xLeftCoord + barLength * 0.5 : xRightCoord - barLength * 0.5,
145572
+ yCoord + barHeight * 4
145573
+ ]
145484
145574
  }
145485
145575
  ],
145486
145576
  getColor: [220, 220, 220, 255],
@@ -145489,7 +145579,7 @@ const ScaleBarLayer = class extends CompositeLayer {
145489
145579
  sizeUnits: "meters",
145490
145580
  sizeScale: 2 ** -zoom,
145491
145581
  characterSet: [
145492
- ...unit.split(""),
145582
+ ...displayUnit.split(""),
145493
145583
  ...range(10).map((i2) => String(i2)),
145494
145584
  ".",
145495
145585
  "e",
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a, L, V, d, c, e, f, b, h, u } from "./index-f8a9f462.js";
1
+ import { a, L, V, d, c, e, f, b, h, u } from "./index-a79502da.js";
2
2
  import "react";
3
3
  import "@vitessce/vit-s";
4
4
  import "react-dom";
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-f8a9f462.js";
1
+ import { B as BaseDecoder } from "./index-a79502da.js";
2
2
  import "react";
3
3
  import "@vitessce/vit-s";
4
4
  import "react-dom";
@@ -1,5 +1,5 @@
1
1
  import { i as inflate_1 } from "./pako.esm-68f84e2a.js";
2
- import { g as getDefaultExportFromCjs, B as BaseDecoder } from "./index-f8a9f462.js";
2
+ import { g as getDefaultExportFromCjs, B as BaseDecoder } from "./index-a79502da.js";
3
3
  import "react";
4
4
  import "@vitessce/vit-s";
5
5
  import "react-dom";
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-f8a9f462.js";
1
+ import { B as BaseDecoder } from "./index-a79502da.js";
2
2
  import "react";
3
3
  import "@vitessce/vit-s";
4
4
  import "react-dom";
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-f8a9f462.js";
1
+ import { B as BaseDecoder } from "./index-a79502da.js";
2
2
  import "react";
3
3
  import "@vitessce/vit-s";
4
4
  import "react-dom";
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-f8a9f462.js";
1
+ import { B as BaseDecoder } from "./index-a79502da.js";
2
2
  import "react";
3
3
  import "@vitessce/vit-s";
4
4
  import "react-dom";
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-f8a9f462.js";
1
+ import { B as BaseDecoder } from "./index-a79502da.js";
2
2
  import "react";
3
3
  import "@vitessce/vit-s";
4
4
  import "react-dom";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitessce/layer-controller",
3
- "version": "3.2.1",
3
+ "version": "3.2.2",
4
4
  "author": "Gehlenborg Lab",
5
5
  "homepage": "http://vitessce.io",
6
6
  "repository": {
@@ -21,11 +21,11 @@
21
21
  "lodash-es": "^4.17.21",
22
22
  "math.gl": "^3.5.6",
23
23
  "react-aria": "^3.28.0",
24
- "@vitessce/constants-internal": "3.2.1",
25
- "@vitessce/gl": "3.2.1",
26
- "@vitessce/spatial-utils": "3.2.1",
27
- "@vitessce/utils": "3.2.1",
28
- "@vitessce/vit-s": "3.2.1"
24
+ "@vitessce/gl": "3.2.2",
25
+ "@vitessce/constants-internal": "3.2.2",
26
+ "@vitessce/spatial-utils": "3.2.2",
27
+ "@vitessce/utils": "3.2.2",
28
+ "@vitessce/vit-s": "3.2.2"
29
29
  },
30
30
  "devDependencies": {
31
31
  "react": "^18.0.0",