@vitessce/image-utils 3.2.0 → 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-04d90826.js";
2
+ import { B as BaseDecoder } from "./index-4ea1f112.js";
3
3
  import "react";
4
4
  class DeflateDecoder extends BaseDecoder {
5
5
  decodeBlock(buffer) {
@@ -133362,16 +133362,16 @@ function addDecoder(cases, importFn) {
133362
133362
  }
133363
133363
  cases.forEach((c) => registry$1.set(c, importFn));
133364
133364
  }
133365
- addDecoder([void 0, 1], () => import("./raw-6d0c1d3d.js").then((m) => m.default));
133366
- addDecoder(5, () => import("./lzw-91f9d6dc.js").then((m) => m.default));
133365
+ addDecoder([void 0, 1], () => import("./raw-313ce7d6.js").then((m) => m.default));
133366
+ addDecoder(5, () => import("./lzw-1a9b457b.js").then((m) => m.default));
133367
133367
  addDecoder(6, () => {
133368
133368
  throw new Error("old style JPEG compression is not supported.");
133369
133369
  });
133370
- addDecoder(7, () => import("./jpeg-c2df92c1.js").then((m) => m.default));
133371
- addDecoder([8, 32946], () => import("./deflate-0fbdf7e6.js").then((m) => m.default));
133372
- addDecoder(32773, () => import("./packbits-7bebed8e.js").then((m) => m.default));
133373
- addDecoder(34887, () => import("./lerc-64a809b9.js").then((m) => m.default));
133374
- addDecoder(50001, () => import("./webimage-7382a375.js").then((m) => m.default));
133370
+ addDecoder(7, () => import("./jpeg-f9fe8321.js").then((m) => m.default));
133371
+ addDecoder([8, 32946], () => import("./deflate-7e090157.js").then((m) => m.default));
133372
+ addDecoder(32773, () => import("./packbits-2f01a6d2.js").then((m) => m.default));
133373
+ addDecoder(34887, () => import("./lerc-666d031c.js").then((m) => m.default));
133374
+ addDecoder(50001, () => import("./webimage-830864f6.js").then((m) => m.default));
133375
133375
  function decodeRowAcc(row, stride) {
133376
133376
  let length2 = row.length - stride;
133377
133377
  let offset = 0;
@@ -142277,6 +142277,67 @@ function makeBoundingBox(viewState) {
142277
142277
  viewport.unproject([0, viewport.height])
142278
142278
  ];
142279
142279
  }
142280
+ const TARGETS = [1, 2, 3, 4, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1e3];
142281
+ const MIN_TARGET = TARGETS[0];
142282
+ const MAX_TARGET = TARGETS[TARGETS.length - 1];
142283
+ const SI_PREFIXES = [
142284
+ { symbol: "Y", exponent: 24 },
142285
+ { symbol: "Z", exponent: 21 },
142286
+ { symbol: "E", exponent: 18 },
142287
+ { symbol: "P", exponent: 15 },
142288
+ { symbol: "T", exponent: 12 },
142289
+ { symbol: "G", exponent: 9 },
142290
+ { symbol: "M", exponent: 6 },
142291
+ { symbol: "k", exponent: 3 },
142292
+ { symbol: "h", exponent: 2 },
142293
+ { symbol: "da", exponent: 1 },
142294
+ { symbol: "", exponent: 0 },
142295
+ { symbol: "d", exponent: -1 },
142296
+ { symbol: "c", exponent: -2 },
142297
+ { symbol: "m", exponent: -3 },
142298
+ { symbol: "µ", exponent: -6 },
142299
+ { symbol: "n", exponent: -9 },
142300
+ { symbol: "p", exponent: -12 },
142301
+ { symbol: "f", exponent: -15 },
142302
+ { symbol: "a", exponent: -18 },
142303
+ { symbol: "z", exponent: -21 },
142304
+ { symbol: "y", exponent: -24 }
142305
+ ];
142306
+ function sizeToMeters(size2, unit2) {
142307
+ if (!unit2 || unit2 === "m") {
142308
+ return size2;
142309
+ }
142310
+ if (unit2.length > 1) {
142311
+ let unitPrefix = unit2.substring(0, unit2.length - 1);
142312
+ if (unitPrefix === "u") {
142313
+ unitPrefix = "µ";
142314
+ }
142315
+ const unitObj = SI_PREFIXES.find((p) => p.symbol === unitPrefix);
142316
+ if (unitObj) {
142317
+ return size2 * 10 ** unitObj.exponent;
142318
+ }
142319
+ }
142320
+ throw new Error("Received unknown unit");
142321
+ }
142322
+ function snapValue(value) {
142323
+ let magnitude = 0;
142324
+ if (value < MIN_TARGET || value > MAX_TARGET) {
142325
+ magnitude = Math.floor(Math.log10(value));
142326
+ }
142327
+ let snappedUnit = SI_PREFIXES.find(
142328
+ (p) => p.exponent % 3 === 0 && p.exponent <= magnitude
142329
+ );
142330
+ let adjustedValue = value / 10 ** snappedUnit.exponent;
142331
+ if (adjustedValue > 500 && adjustedValue <= 1e3) {
142332
+ snappedUnit = SI_PREFIXES.find(
142333
+ (p) => p.exponent % 3 === 0 && p.exponent <= magnitude + 3
142334
+ );
142335
+ adjustedValue = value / 10 ** snappedUnit.exponent;
142336
+ }
142337
+ const targetNewUnits = TARGETS.find((t2) => t2 > adjustedValue);
142338
+ const targetOrigUnits = targetNewUnits * 10 ** snappedUnit.exponent;
142339
+ return [targetOrigUnits, targetNewUnits, snappedUnit.symbol];
142340
+ }
142280
142341
  const fs$1$1 = `#define SHADER_NAME xr-layer-fragment-shader
142281
142342
 
142282
142343
  precision highp float;
@@ -143044,26 +143105,27 @@ const OverviewLayer = class extends CompositeLayer {
143044
143105
  OverviewLayer.layerName = "OverviewLayer";
143045
143106
  OverviewLayer.defaultProps = defaultProps$3;
143046
143107
  function getPosition(boundingBox, position, length2) {
143047
- const viewLength = boundingBox[2][0] - boundingBox[0][0];
143108
+ const viewWidth = boundingBox[2][0] - boundingBox[0][0];
143109
+ const viewHeight = boundingBox[2][1] - boundingBox[0][1];
143048
143110
  switch (position) {
143049
143111
  case "bottom-right": {
143050
- const yCoord = boundingBox[2][1] - (boundingBox[2][1] - boundingBox[0][1]) * length2;
143051
- const xLeftCoord = boundingBox[2][0] - viewLength * length2;
143112
+ const yCoord = boundingBox[2][1] - viewHeight * length2;
143113
+ const xLeftCoord = boundingBox[2][0] - viewWidth * length2;
143052
143114
  return [yCoord, xLeftCoord];
143053
143115
  }
143054
143116
  case "top-right": {
143055
- const yCoord = (boundingBox[2][1] - boundingBox[0][1]) * length2;
143056
- const xLeftCoord = boundingBox[2][0] - viewLength * length2;
143117
+ const yCoord = boundingBox[0][1] + viewHeight * length2;
143118
+ const xLeftCoord = boundingBox[2][0] - viewWidth * length2;
143057
143119
  return [yCoord, xLeftCoord];
143058
143120
  }
143059
143121
  case "top-left": {
143060
- const yCoord = (boundingBox[2][1] - boundingBox[0][1]) * length2;
143061
- const xLeftCoord = viewLength * length2;
143122
+ const yCoord = boundingBox[0][1] + viewHeight * length2;
143123
+ const xLeftCoord = boundingBox[0][0] + viewWidth * length2;
143062
143124
  return [yCoord, xLeftCoord];
143063
143125
  }
143064
143126
  case "bottom-left": {
143065
- const yCoord = boundingBox[2][1] - (boundingBox[2][1] - boundingBox[0][1]) * length2;
143066
- const xLeftCoord = viewLength * length2;
143127
+ const yCoord = boundingBox[2][1] - viewHeight * length2;
143128
+ const xLeftCoord = boundingBox[0][0] + viewWidth * length2;
143067
143129
  return [yCoord, xLeftCoord];
143068
143130
  }
143069
143131
  default: {
@@ -143081,11 +143143,12 @@ const defaultProps$2 = {
143081
143143
  unit: { type: "string", value: "", compare: true },
143082
143144
  size: { type: "number", value: 1, compare: true },
143083
143145
  position: { type: "string", value: "bottom-right", compare: true },
143084
- length: { type: "number", value: 0.085, compare: true }
143146
+ length: { type: "number", value: 0.085, compare: true },
143147
+ snap: { type: "boolean", value: false, compare: true }
143085
143148
  };
143086
143149
  const ScaleBarLayer = class extends CompositeLayer {
143087
143150
  renderLayers() {
143088
- const { id, unit: unit2, size: size2, position, viewState, length: length2 } = this.props;
143151
+ const { id, unit: unit2, size: size2, position, viewState, length: length2, snap } = this.props;
143089
143152
  const boundingBox = makeBoundingBox(viewState);
143090
143153
  const { zoom } = viewState;
143091
143154
  const viewLength = boundingBox[2][0] - boundingBox[0][0];
@@ -143094,15 +143157,27 @@ const ScaleBarLayer = class extends CompositeLayer {
143094
143157
  2 ** (-zoom + 1.5),
143095
143158
  (boundingBox[2][1] - boundingBox[0][1]) * 7e-3
143096
143159
  );
143097
- const numUnits = barLength * size2;
143160
+ let adjustedBarLength = barLength;
143161
+ let displayNumber = (barLength * size2).toPrecision(5);
143162
+ let displayUnit = unit2;
143163
+ if (snap) {
143164
+ const meterSize = sizeToMeters(size2, unit2);
143165
+ const numUnits = barLength * meterSize;
143166
+ const [snappedOrigUnits, snappedNewUnits, snappedUnitPrefix] = snapValue(numUnits);
143167
+ adjustedBarLength = snappedOrigUnits / meterSize;
143168
+ displayNumber = snappedNewUnits;
143169
+ displayUnit = `${snappedUnitPrefix}m`;
143170
+ }
143098
143171
  const [yCoord, xLeftCoord] = getPosition(boundingBox, position, length2);
143172
+ const xRightCoord = xLeftCoord + barLength;
143173
+ const isLeft = position.endsWith("-left");
143099
143174
  const lengthBar = new LineLayer({
143100
143175
  id: `scale-bar-length-${id}`,
143101
143176
  coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
143102
143177
  data: [
143103
143178
  [
143104
- [xLeftCoord, yCoord],
143105
- [xLeftCoord + barLength, yCoord]
143179
+ [isLeft ? xLeftCoord : xRightCoord - adjustedBarLength, yCoord],
143180
+ [isLeft ? xLeftCoord + adjustedBarLength : xRightCoord, yCoord]
143106
143181
  ]
143107
143182
  ],
143108
143183
  getSourcePosition: (d) => d[0],
@@ -143115,8 +143190,14 @@ const ScaleBarLayer = class extends CompositeLayer {
143115
143190
  coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
143116
143191
  data: [
143117
143192
  [
143118
- [xLeftCoord, yCoord - barHeight],
143119
- [xLeftCoord, yCoord + barHeight]
143193
+ [
143194
+ isLeft ? xLeftCoord : xRightCoord - adjustedBarLength,
143195
+ yCoord - barHeight
143196
+ ],
143197
+ [
143198
+ isLeft ? xLeftCoord : xRightCoord - adjustedBarLength,
143199
+ yCoord + barHeight
143200
+ ]
143120
143201
  ]
143121
143202
  ],
143122
143203
  getSourcePosition: (d) => d[0],
@@ -143129,8 +143210,14 @@ const ScaleBarLayer = class extends CompositeLayer {
143129
143210
  coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
143130
143211
  data: [
143131
143212
  [
143132
- [xLeftCoord + barLength, yCoord - barHeight],
143133
- [xLeftCoord + barLength, yCoord + barHeight]
143213
+ [
143214
+ isLeft ? xLeftCoord + adjustedBarLength : xRightCoord,
143215
+ yCoord - barHeight
143216
+ ],
143217
+ [
143218
+ isLeft ? xLeftCoord + adjustedBarLength : xRightCoord,
143219
+ yCoord + barHeight
143220
+ ]
143134
143221
  ]
143135
143222
  ],
143136
143223
  getSourcePosition: (d) => d[0],
@@ -143143,8 +143230,11 @@ const ScaleBarLayer = class extends CompositeLayer {
143143
143230
  coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
143144
143231
  data: [
143145
143232
  {
143146
- text: numUnits.toPrecision(5) + unit2,
143147
- position: [xLeftCoord + barLength * 0.5, yCoord + barHeight * 4]
143233
+ text: `${displayNumber}${displayUnit}`,
143234
+ position: [
143235
+ isLeft ? xLeftCoord + barLength * 0.5 : xRightCoord - barLength * 0.5,
143236
+ yCoord + barHeight * 4
143237
+ ]
143148
143238
  }
143149
143239
  ],
143150
143240
  getColor: [220, 220, 220, 255],
@@ -143153,7 +143243,7 @@ const ScaleBarLayer = class extends CompositeLayer {
143153
143243
  sizeUnits: "meters",
143154
143244
  sizeScale: 2 ** -zoom,
143155
143245
  characterSet: [
143156
- ...unit2.split(""),
143246
+ ...displayUnit.split(""),
143157
143247
  ...range(10).map((i2) => String(i2)),
143158
143248
  ".",
143159
143249
  "e",
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { I } from "./index-04d90826.js";
1
+ import { I } from "./index-4ea1f112.js";
2
2
  import "react";
3
3
  export {
4
4
  I as ImageWrapper
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-04d90826.js";
1
+ import { B as BaseDecoder } from "./index-4ea1f112.js";
2
2
  import "react";
3
3
  const dctZigZag = new Int32Array([
4
4
  0,
@@ -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-04d90826.js";
2
+ import { g as getDefaultExportFromCjs, B as BaseDecoder } from "./index-4ea1f112.js";
3
3
  import "react";
4
4
  const LercParameters = {
5
5
  Version: 0,
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-04d90826.js";
1
+ import { B as BaseDecoder } from "./index-4ea1f112.js";
2
2
  import "react";
3
3
  const MIN_BITS = 9;
4
4
  const CLEAR_CODE = 256;
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-04d90826.js";
1
+ import { B as BaseDecoder } from "./index-4ea1f112.js";
2
2
  import "react";
3
3
  class PackbitsDecoder extends BaseDecoder {
4
4
  decodeBlock(buffer) {
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-04d90826.js";
1
+ import { B as BaseDecoder } from "./index-4ea1f112.js";
2
2
  import "react";
3
3
  class RawDecoder extends BaseDecoder {
4
4
  decodeBlock(buffer) {
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-04d90826.js";
1
+ import { B as BaseDecoder } from "./index-4ea1f112.js";
2
2
  import "react";
3
3
  class WebImageDecoder extends BaseDecoder {
4
4
  constructor() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitessce/image-utils",
3
- "version": "3.2.0",
3
+ "version": "3.2.2",
4
4
  "author": "Gehlenborg Lab",
5
5
  "homepage": "http://vitessce.io",
6
6
  "repository": {
@@ -16,9 +16,9 @@
16
16
  "dist-tsc"
17
17
  ],
18
18
  "dependencies": {
19
- "@hms-dbmi/viv": "~0.13.7",
20
- "@vitessce/spatial-utils": "3.2.0",
21
- "@vitessce/utils": "3.2.0"
19
+ "@hms-dbmi/viv": "~0.13.8",
20
+ "@vitessce/spatial-utils": "3.2.2",
21
+ "@vitessce/utils": "3.2.2"
22
22
  },
23
23
  "devDependencies": {
24
24
  "vite": "^4.3.0",