@vitessce/spatial-utils 3.6.10 → 3.6.12
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.
- package/dist/{deflate-D50eseYg.js → deflate-TxuAgoYJ.js} +1 -1
- package/dist/{index-RMBcVNTZ.js → index-B7UQn9SL.js} +170 -52
- package/dist/index.js +17 -16
- package/dist/{jpeg-Dp762_Sy.js → jpeg-C55SiNtf.js} +1 -1
- package/dist/{lerc-R19D-u1d.js → lerc-cC8m0WBJ.js} +1 -1
- package/dist/{lzw-CS9qpOLK.js → lzw-CEZtZPvs.js} +1 -1
- package/dist/{packbits-smBOUAP8.js → packbits-BDxIgeb9.js} +1 -1
- package/dist/{raw-B-RRtlid.js → raw-NP8gx4mT.js} +1 -1
- package/dist/{webimage-CZyj01Qe.js → webimage-BMtq3qgy.js} +1 -1
- package/dist-tsc/dag.d.ts +35 -0
- package/dist-tsc/dag.d.ts.map +1 -0
- package/dist-tsc/dag.js +75 -0
- package/dist-tsc/dag.test.d.ts +2 -0
- package/dist-tsc/dag.test.d.ts.map +1 -0
- package/dist-tsc/dag.test.js +29 -0
- package/dist-tsc/index.d.ts +1 -1
- package/dist-tsc/index.js +1 -1
- package/dist-tsc/spatial.d.ts +25 -0
- package/dist-tsc/spatial.d.ts.map +1 -1
- package/dist-tsc/spatial.js +71 -29
- package/dist-tsc/spatial.test.js +544 -1
- package/package.json +8 -7
- package/src/dag.js +83 -0
- package/src/dag.test.js +34 -0
- package/src/index.js +1 -0
- package/src/spatial.js +85 -30
- package/src/spatial.test.js +547 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as inflate_1 } from "./pako.esm-SxljTded.js";
|
|
2
|
-
import { B as BaseDecoder } from "./index-
|
|
2
|
+
import { B as BaseDecoder } from "./index-B7UQn9SL.js";
|
|
3
3
|
class DeflateDecoder extends BaseDecoder {
|
|
4
4
|
decodeBlock(buffer) {
|
|
5
5
|
return inflate_1(new Uint8Array(buffer)).buffer;
|
|
@@ -119276,7 +119276,8 @@ const PIXELATED_TEXTURE_PARAMETERS = {
|
|
|
119276
119276
|
const GLSL_COLORMAPS = [
|
|
119277
119277
|
"plasma",
|
|
119278
119278
|
"viridis",
|
|
119279
|
-
"jet"
|
|
119279
|
+
"jet",
|
|
119280
|
+
"greys"
|
|
119280
119281
|
];
|
|
119281
119282
|
const GLSL_COLORMAP_DEFAULT = "plasma";
|
|
119282
119283
|
const COLORMAP_SHADER_PLACEHOLDER = "COLORMAP_FUNC";
|
|
@@ -120365,22 +120366,22 @@ function addDecoder(cases, importFn) {
|
|
|
120365
120366
|
}
|
|
120366
120367
|
cases.forEach((c) => registry$2.set(c, importFn));
|
|
120367
120368
|
}
|
|
120368
|
-
addDecoder([void 0, 1], () => import("./raw-
|
|
120369
|
-
addDecoder(5, () => import("./lzw-
|
|
120369
|
+
addDecoder([void 0, 1], () => import("./raw-NP8gx4mT.js").then((m) => m.default));
|
|
120370
|
+
addDecoder(5, () => import("./lzw-CEZtZPvs.js").then((m) => m.default));
|
|
120370
120371
|
addDecoder(6, () => {
|
|
120371
120372
|
throw new Error("old style JPEG compression is not supported.");
|
|
120372
120373
|
});
|
|
120373
|
-
addDecoder(7, () => import("./jpeg-
|
|
120374
|
-
addDecoder([8, 32946], () => import("./deflate-
|
|
120375
|
-
addDecoder(32773, () => import("./packbits-
|
|
120374
|
+
addDecoder(7, () => import("./jpeg-C55SiNtf.js").then((m) => m.default));
|
|
120375
|
+
addDecoder([8, 32946], () => import("./deflate-TxuAgoYJ.js").then((m) => m.default));
|
|
120376
|
+
addDecoder(32773, () => import("./packbits-BDxIgeb9.js").then((m) => m.default));
|
|
120376
120377
|
addDecoder(
|
|
120377
120378
|
34887,
|
|
120378
|
-
() => import("./lerc-
|
|
120379
|
+
() => import("./lerc-cC8m0WBJ.js").then(async (m) => {
|
|
120379
120380
|
await m.zstd.init();
|
|
120380
120381
|
return m;
|
|
120381
120382
|
}).then((m) => m.default)
|
|
120382
120383
|
);
|
|
120383
|
-
addDecoder(50001, () => import("./webimage-
|
|
120384
|
+
addDecoder(50001, () => import("./webimage-BMtq3qgy.js").then((m) => m.default));
|
|
120384
120385
|
function decodeRowAcc(row, stride) {
|
|
120385
120386
|
let length2 = row.length - stride;
|
|
120386
120387
|
let offset = 0;
|
|
@@ -137720,6 +137721,101 @@ function abbreviateNumber(value) {
|
|
|
137720
137721
|
if (naive.length <= maxLength) return naive;
|
|
137721
137722
|
return value.toExponential(0);
|
|
137722
137723
|
}
|
|
137724
|
+
class InternMap extends Map {
|
|
137725
|
+
constructor(entries, key = keyof) {
|
|
137726
|
+
super();
|
|
137727
|
+
Object.defineProperties(this, { _intern: { value: /* @__PURE__ */ new Map() }, _key: { value: key } });
|
|
137728
|
+
if (entries != null) for (const [key2, value] of entries) this.set(key2, value);
|
|
137729
|
+
}
|
|
137730
|
+
get(key) {
|
|
137731
|
+
return super.get(intern_get(this, key));
|
|
137732
|
+
}
|
|
137733
|
+
has(key) {
|
|
137734
|
+
return super.has(intern_get(this, key));
|
|
137735
|
+
}
|
|
137736
|
+
set(key, value) {
|
|
137737
|
+
return super.set(intern_set(this, key), value);
|
|
137738
|
+
}
|
|
137739
|
+
delete(key) {
|
|
137740
|
+
return super.delete(intern_delete(this, key));
|
|
137741
|
+
}
|
|
137742
|
+
}
|
|
137743
|
+
function intern_get({ _intern, _key }, value) {
|
|
137744
|
+
const key = _key(value);
|
|
137745
|
+
return _intern.has(key) ? _intern.get(key) : value;
|
|
137746
|
+
}
|
|
137747
|
+
function intern_set({ _intern, _key }, value) {
|
|
137748
|
+
const key = _key(value);
|
|
137749
|
+
if (_intern.has(key)) return _intern.get(key);
|
|
137750
|
+
_intern.set(key, value);
|
|
137751
|
+
return value;
|
|
137752
|
+
}
|
|
137753
|
+
function intern_delete({ _intern, _key }, value) {
|
|
137754
|
+
const key = _key(value);
|
|
137755
|
+
if (_intern.has(key)) {
|
|
137756
|
+
value = _intern.get(key);
|
|
137757
|
+
_intern.delete(key);
|
|
137758
|
+
}
|
|
137759
|
+
return value;
|
|
137760
|
+
}
|
|
137761
|
+
function keyof(value) {
|
|
137762
|
+
return value !== null && typeof value === "object" ? value.valueOf() : value;
|
|
137763
|
+
}
|
|
137764
|
+
class DAG {
|
|
137765
|
+
/**
|
|
137766
|
+
* DAG constructor.
|
|
137767
|
+
* @param {{ from: string, to: string, attributes: any}[]} edges
|
|
137768
|
+
*/
|
|
137769
|
+
constructor(edges) {
|
|
137770
|
+
this.graph = /* @__PURE__ */ new Map();
|
|
137771
|
+
this.edgeData = new InternMap([], JSON.stringify);
|
|
137772
|
+
edges.forEach((edge) => {
|
|
137773
|
+
const { from, to } = edge;
|
|
137774
|
+
if (!this.graph.has(from)) {
|
|
137775
|
+
this.graph.set(from, []);
|
|
137776
|
+
}
|
|
137777
|
+
this.graph.get(from).push(to);
|
|
137778
|
+
this.edgeData.set([from, to], edge.attributes);
|
|
137779
|
+
});
|
|
137780
|
+
}
|
|
137781
|
+
/**
|
|
137782
|
+
* Find a path from start to end using DFS.
|
|
137783
|
+
* @param {string} start
|
|
137784
|
+
* @param {string} end
|
|
137785
|
+
* @returns {{ from: string, to: string, attributes: any }[] | null} Returns
|
|
137786
|
+
* the path as an array of edges or null if no path exists.
|
|
137787
|
+
*/
|
|
137788
|
+
findPath(start, end) {
|
|
137789
|
+
const path = [];
|
|
137790
|
+
const visited = /* @__PURE__ */ new Set();
|
|
137791
|
+
const dfs = (node2) => {
|
|
137792
|
+
if (node2 === end) {
|
|
137793
|
+
return true;
|
|
137794
|
+
}
|
|
137795
|
+
visited.add(node2);
|
|
137796
|
+
const neighbors = this.graph.get(node2) || [];
|
|
137797
|
+
for (const neighbor of neighbors) {
|
|
137798
|
+
if (!visited.has(neighbor)) {
|
|
137799
|
+
path.push([node2, neighbor]);
|
|
137800
|
+
if (dfs(neighbor)) {
|
|
137801
|
+
return true;
|
|
137802
|
+
}
|
|
137803
|
+
path.pop();
|
|
137804
|
+
}
|
|
137805
|
+
}
|
|
137806
|
+
return false;
|
|
137807
|
+
};
|
|
137808
|
+
const found = dfs(start);
|
|
137809
|
+
if (found) {
|
|
137810
|
+
return path.map(([from, to]) => ({
|
|
137811
|
+
from,
|
|
137812
|
+
to,
|
|
137813
|
+
attributes: this.edgeData.get([from, to])
|
|
137814
|
+
}));
|
|
137815
|
+
}
|
|
137816
|
+
return null;
|
|
137817
|
+
}
|
|
137818
|
+
}
|
|
137723
137819
|
function getSourceFromLoader(loader, level) {
|
|
137724
137820
|
const { data } = loader;
|
|
137725
137821
|
const source = Array.isArray(data) ? data[level || data.length - 1] : data;
|
|
@@ -138048,8 +138144,14 @@ function coordinateTransformationsToMatrix(coordinateTransformations, axes) {
|
|
|
138048
138144
|
}
|
|
138049
138145
|
} else if (spatialOutputAxes.length === 2) {
|
|
138050
138146
|
const nextMat = new Matrix4().fromArray([
|
|
138051
|
-
|
|
138052
|
-
|
|
138147
|
+
filteredAffine[0][0],
|
|
138148
|
+
filteredAffine[0][1],
|
|
138149
|
+
0,
|
|
138150
|
+
filteredAffine[0][2],
|
|
138151
|
+
filteredAffine[1][0],
|
|
138152
|
+
filteredAffine[1][1],
|
|
138153
|
+
0,
|
|
138154
|
+
filteredAffine[1][2],
|
|
138053
138155
|
0,
|
|
138054
138156
|
0,
|
|
138055
138157
|
1,
|
|
@@ -138065,6 +138167,7 @@ function coordinateTransformationsToMatrix(coordinateTransformations, axes) {
|
|
|
138065
138167
|
const swapMat = new Matrix4().fromArray(swapMatNested.flat());
|
|
138066
138168
|
mat = mat.multiplyLeft(swapMat);
|
|
138067
138169
|
}
|
|
138170
|
+
mat = mat.transpose();
|
|
138068
138171
|
} else {
|
|
138069
138172
|
throw new Error("Affine transformation must have 2 or 3 rows.");
|
|
138070
138173
|
}
|
|
@@ -138091,6 +138194,9 @@ function coordinateTransformationsToMatrix(coordinateTransformations, axes) {
|
|
|
138091
138194
|
}
|
|
138092
138195
|
});
|
|
138093
138196
|
}
|
|
138197
|
+
if (mat.some((value) => Number.isNaN(value))) {
|
|
138198
|
+
throw new Error("Matrix contains NaN values");
|
|
138199
|
+
}
|
|
138094
138200
|
return mat;
|
|
138095
138201
|
}
|
|
138096
138202
|
function hexToRgb(hex) {
|
|
@@ -138109,6 +138215,9 @@ function normalizeAxes(axes) {
|
|
|
138109
138215
|
return axisInfo;
|
|
138110
138216
|
});
|
|
138111
138217
|
}
|
|
138218
|
+
function getIntrinsicCoordinateSystem(normAxes) {
|
|
138219
|
+
return normAxes.map((axis) => axis.name).join("");
|
|
138220
|
+
}
|
|
138112
138221
|
function normalizeCoordinateTransformations(coordinateTransformations, datasets) {
|
|
138113
138222
|
var _a3;
|
|
138114
138223
|
let result = [];
|
|
@@ -138116,35 +138225,13 @@ function normalizeCoordinateTransformations(coordinateTransformations, datasets)
|
|
|
138116
138225
|
result = coordinateTransformations.flatMap((transform2) => {
|
|
138117
138226
|
if (transform2.input && transform2.output) {
|
|
138118
138227
|
const { type } = transform2;
|
|
138119
|
-
if (type === "translation") {
|
|
138120
|
-
return {
|
|
138121
|
-
type,
|
|
138122
|
-
translation: transform2.translation
|
|
138123
|
-
};
|
|
138124
|
-
}
|
|
138125
|
-
if (type === "scale") {
|
|
138126
|
-
return {
|
|
138127
|
-
type,
|
|
138128
|
-
scale: transform2.scale
|
|
138129
|
-
};
|
|
138130
|
-
}
|
|
138131
|
-
if (type === "affine") {
|
|
138132
|
-
return {
|
|
138133
|
-
type,
|
|
138134
|
-
affine: transform2.affine,
|
|
138135
|
-
// Affine transformations can potentially swap axes,
|
|
138136
|
-
// so we need to include the input and output axes.
|
|
138137
|
-
input: transform2.input,
|
|
138138
|
-
output: transform2.output
|
|
138139
|
-
};
|
|
138140
|
-
}
|
|
138141
|
-
if (type === "identity") {
|
|
138142
|
-
return { type };
|
|
138143
|
-
}
|
|
138144
138228
|
if (type === "sequence") {
|
|
138145
|
-
return normalizeCoordinateTransformations(transform2.transformations,
|
|
138229
|
+
return normalizeCoordinateTransformations(transform2.transformations, null);
|
|
138146
138230
|
}
|
|
138147
|
-
|
|
138231
|
+
if (type === "affine" || type === "translation" || type === "scale" || type === "identity") {
|
|
138232
|
+
return transform2;
|
|
138233
|
+
}
|
|
138234
|
+
log$5.error(`Coordinate transformation type "${type}" is not supported.`);
|
|
138148
138235
|
}
|
|
138149
138236
|
return transform2;
|
|
138150
138237
|
});
|
|
@@ -138157,6 +138244,36 @@ function normalizeCoordinateTransformations(coordinateTransformations, datasets)
|
|
|
138157
138244
|
}
|
|
138158
138245
|
return result;
|
|
138159
138246
|
}
|
|
138247
|
+
function coordinateTransformationsToMatrixForSpatialData(ngffMetadata, targetCoordinateSystem) {
|
|
138248
|
+
const {
|
|
138249
|
+
datasets,
|
|
138250
|
+
coordinateTransformations,
|
|
138251
|
+
axes
|
|
138252
|
+
} = ngffMetadata;
|
|
138253
|
+
const normAxes = normalizeAxes(axes);
|
|
138254
|
+
const intrinsicCoordinateSystem = getIntrinsicCoordinateSystem(normAxes);
|
|
138255
|
+
const edges = coordinateTransformations.map((ct) => ({
|
|
138256
|
+
from: ct.input.name,
|
|
138257
|
+
to: ct.output.name,
|
|
138258
|
+
attributes: ct
|
|
138259
|
+
}));
|
|
138260
|
+
const dag = new DAG(edges);
|
|
138261
|
+
const ctPath = dag.findPath(intrinsicCoordinateSystem, targetCoordinateSystem);
|
|
138262
|
+
if (!ctPath) {
|
|
138263
|
+
if (!coordinateTransformations.find(
|
|
138264
|
+
(ct) => ct.output.name === targetCoordinateSystem
|
|
138265
|
+
)) {
|
|
138266
|
+
throw new Error(`No coordinate transformation found with output.name "${targetCoordinateSystem}".`);
|
|
138267
|
+
}
|
|
138268
|
+
throw new Error(`No path found from "${intrinsicCoordinateSystem}" to "${targetCoordinateSystem}".`);
|
|
138269
|
+
}
|
|
138270
|
+
const filteredTransformations = ctPath.map((ctEdge) => ctEdge.attributes);
|
|
138271
|
+
const normalizedTransformations = normalizeCoordinateTransformations(
|
|
138272
|
+
filteredTransformations,
|
|
138273
|
+
datasets
|
|
138274
|
+
);
|
|
138275
|
+
return coordinateTransformationsToMatrix(normalizedTransformations, normAxes);
|
|
138276
|
+
}
|
|
138160
138277
|
class NodeNotFoundError extends Error {
|
|
138161
138278
|
constructor(context, options = {}) {
|
|
138162
138279
|
super(`Node not found: ${context}`, options);
|
|
@@ -139740,13 +139857,14 @@ function getDomains() {
|
|
|
139740
139857
|
}
|
|
139741
139858
|
const DOMAINS = getDomains();
|
|
139742
139859
|
export {
|
|
139743
|
-
|
|
139860
|
+
getPhysicalSizeScalingMatrix as A,
|
|
139744
139861
|
BaseDecoder as B,
|
|
139745
|
-
|
|
139862
|
+
getBoundingCube as C,
|
|
139746
139863
|
DEFAULT_CELLS_LAYER as D,
|
|
139747
|
-
|
|
139748
|
-
|
|
139864
|
+
abbreviateNumber as E,
|
|
139865
|
+
filterSelection as F,
|
|
139749
139866
|
GLOBAL_LABELS as G,
|
|
139867
|
+
DOMAINS as H,
|
|
139750
139868
|
ZarritaPixelSource as Z,
|
|
139751
139869
|
DEFAULT_MOLECULES_LAYER as a,
|
|
139752
139870
|
DEFAULT_NEIGHBORHOODS_LAYER as b,
|
|
@@ -139762,16 +139880,16 @@ export {
|
|
|
139762
139880
|
getNgffAxes as l,
|
|
139763
139881
|
getNgffAxesForTiff as m,
|
|
139764
139882
|
coordinateTransformationsToMatrix as n,
|
|
139765
|
-
|
|
139883
|
+
coordinateTransformationsToMatrixForSpatialData as o,
|
|
139766
139884
|
physicalSizeToMatrix as p,
|
|
139767
|
-
|
|
139768
|
-
|
|
139769
|
-
|
|
139770
|
-
|
|
139771
|
-
|
|
139772
|
-
|
|
139773
|
-
|
|
139774
|
-
|
|
139775
|
-
|
|
139776
|
-
|
|
139885
|
+
hexToRgb as q,
|
|
139886
|
+
getStatsForResolution as r,
|
|
139887
|
+
canLoadResolution as s,
|
|
139888
|
+
normalizeCoordinateTransformations as t,
|
|
139889
|
+
normalizeAxes as u,
|
|
139890
|
+
loadOmeZarr as v,
|
|
139891
|
+
guessTileSize as w,
|
|
139892
|
+
toRgbUIString as x,
|
|
139893
|
+
getSingleSelectionStats as y,
|
|
139894
|
+
getMultiSelectionStats as z
|
|
139777
139895
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D, e, a, b, c, d,
|
|
1
|
+
import { D, e, a, b, c, d, H, G, Z, E, s, n, o, F, C, z, l, m, A, y, h, r, w, q, i, f, j, k, v, u, t, p, x } from "./index-B7UQn9SL.js";
|
|
2
2
|
export {
|
|
3
3
|
D as DEFAULT_CELLS_LAYER,
|
|
4
4
|
e as DEFAULT_LAYER_TYPE_ORDERING,
|
|
@@ -6,30 +6,31 @@ export {
|
|
|
6
6
|
b as DEFAULT_NEIGHBORHOODS_LAYER,
|
|
7
7
|
c as DEFAULT_RASTER_DOMAIN_TYPE,
|
|
8
8
|
d as DEFAULT_RASTER_LAYER_PROPS,
|
|
9
|
-
|
|
9
|
+
H as DOMAINS,
|
|
10
10
|
G as GLOBAL_LABELS,
|
|
11
11
|
Z as ZarritaPixelSource,
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
E as abbreviateNumber,
|
|
13
|
+
s as canLoadResolution,
|
|
14
14
|
n as coordinateTransformationsToMatrix,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
o as coordinateTransformationsToMatrixForSpatialData,
|
|
16
|
+
F as filterSelection,
|
|
17
|
+
C as getBoundingCube,
|
|
18
|
+
z as getMultiSelectionStats,
|
|
18
19
|
l as getNgffAxes,
|
|
19
20
|
m as getNgffAxesForTiff,
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
A as getPhysicalSizeScalingMatrix,
|
|
22
|
+
y as getSingleSelectionStats,
|
|
22
23
|
h as getSourceFromLoader,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
r as getStatsForResolution,
|
|
25
|
+
w as guessTileSize,
|
|
26
|
+
q as hexToRgb,
|
|
26
27
|
i as initializeLayerChannels,
|
|
27
28
|
f as initializeRasterLayersAndChannels,
|
|
28
29
|
j as isInterleaved,
|
|
29
30
|
k as isRgb,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
v as loadOmeZarr,
|
|
32
|
+
u as normalizeAxes,
|
|
33
|
+
t as normalizeCoordinateTransformations,
|
|
33
34
|
p as physicalSizeToMatrix,
|
|
34
|
-
|
|
35
|
+
x as toRgbUIString
|
|
35
36
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as inflate_1 } from "./pako.esm-SxljTded.js";
|
|
2
|
-
import { g as getDefaultExportFromCjs, B as BaseDecoder } from "./index-
|
|
2
|
+
import { g as getDefaultExportFromCjs, B as BaseDecoder } from "./index-B7UQn9SL.js";
|
|
3
3
|
const LercParameters = {
|
|
4
4
|
AddCompression: 1
|
|
5
5
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export class DAG {
|
|
2
|
+
/**
|
|
3
|
+
* DAG constructor.
|
|
4
|
+
* @param {{ from: string, to: string, attributes: any}[]} edges
|
|
5
|
+
*/
|
|
6
|
+
constructor(edges: {
|
|
7
|
+
from: string;
|
|
8
|
+
to: string;
|
|
9
|
+
attributes: any;
|
|
10
|
+
}[]);
|
|
11
|
+
/**
|
|
12
|
+
* Adjacency list representation of the DAG.
|
|
13
|
+
* Maps each input to an array of outputs.
|
|
14
|
+
* @type {Map<string, string[]>}
|
|
15
|
+
*/
|
|
16
|
+
graph: Map<string, string[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Mapping from [from, to] pairs to edge data.
|
|
19
|
+
* @type {InternMap<[string, string], any>}
|
|
20
|
+
*/
|
|
21
|
+
edgeData: InternMap<[string, string], any>;
|
|
22
|
+
/**
|
|
23
|
+
* Find a path from start to end using DFS.
|
|
24
|
+
* @param {string} start
|
|
25
|
+
* @param {string} end
|
|
26
|
+
* @returns {{ from: string, to: string, attributes: any }[] | null} Returns
|
|
27
|
+
* the path as an array of edges or null if no path exists.
|
|
28
|
+
*/
|
|
29
|
+
findPath(start: string, end: string): {
|
|
30
|
+
from: string;
|
|
31
|
+
to: string;
|
|
32
|
+
attributes: any;
|
|
33
|
+
}[] | null;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=dag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dag.d.ts","sourceRoot":"","sources":["../src/dag.js"],"names":[],"mappings":"AAMA;IACE;;;SAGK;IACL,mBAFa;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,GAAG,CAAA;KAAC,EAAE,EAwB1D;IArBC;;;;OAIG;IACH,OAFU,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAET;IACtB;;;OAGG;IACH,UAFU,SAAS,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,CAEO;IAanD;;;;;;OAMG;IACH,gBALW,MAAM,OACN,MAAM,GACJ;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,GAAG,CAAA;KAAE,EAAE,GAAG,IAAI,CA0ClE;CACF"}
|
package/dist-tsc/dag.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { InternMap } from 'internmap';
|
|
2
|
+
// Simple DAG class, with minimum functionality:
|
|
3
|
+
// to find a path from targetInput-to-targetOutput.
|
|
4
|
+
// Edges can have arbitrary attributes.
|
|
5
|
+
export class DAG {
|
|
6
|
+
/**
|
|
7
|
+
* DAG constructor.
|
|
8
|
+
* @param {{ from: string, to: string, attributes: any}[]} edges
|
|
9
|
+
*/
|
|
10
|
+
constructor(edges) {
|
|
11
|
+
/**
|
|
12
|
+
* Adjacency list representation of the DAG.
|
|
13
|
+
* Maps each input to an array of outputs.
|
|
14
|
+
* @type {Map<string, string[]>}
|
|
15
|
+
*/
|
|
16
|
+
this.graph = new Map();
|
|
17
|
+
/**
|
|
18
|
+
* Mapping from [from, to] pairs to edge data.
|
|
19
|
+
* @type {InternMap<[string, string], any>}
|
|
20
|
+
*/
|
|
21
|
+
this.edgeData = new InternMap([], JSON.stringify);
|
|
22
|
+
// Build adjacency list
|
|
23
|
+
edges.forEach((edge) => {
|
|
24
|
+
const { from, to } = edge;
|
|
25
|
+
if (!this.graph.has(from)) {
|
|
26
|
+
this.graph.set(from, []);
|
|
27
|
+
}
|
|
28
|
+
this.graph.get(from).push(to);
|
|
29
|
+
this.edgeData.set([from, to], edge.attributes);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Find a path from start to end using DFS.
|
|
34
|
+
* @param {string} start
|
|
35
|
+
* @param {string} end
|
|
36
|
+
* @returns {{ from: string, to: string, attributes: any }[] | null} Returns
|
|
37
|
+
* the path as an array of edges or null if no path exists.
|
|
38
|
+
*/
|
|
39
|
+
findPath(start, end) {
|
|
40
|
+
const path = [];
|
|
41
|
+
const visited = new Set();
|
|
42
|
+
// Depth-first search (DFS) to find a path from start to end.
|
|
43
|
+
const dfs = (node) => {
|
|
44
|
+
if (node === end) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
visited.add(node);
|
|
48
|
+
const neighbors = this.graph.get(node) || [];
|
|
49
|
+
// Do not use forEach to allow early exit (returning).
|
|
50
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
51
|
+
for (const neighbor of neighbors) {
|
|
52
|
+
if (!visited.has(neighbor)) {
|
|
53
|
+
path.push([node, neighbor]);
|
|
54
|
+
if (dfs(neighbor)) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
path.pop(); // backtrack
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
// Start DFS from the start node.
|
|
63
|
+
const found = dfs(start);
|
|
64
|
+
if (found) {
|
|
65
|
+
// Convert path to a list of edge objects with info
|
|
66
|
+
return path.map(([from, to]) => ({
|
|
67
|
+
from,
|
|
68
|
+
to,
|
|
69
|
+
attributes: this.edgeData.get([from, to]),
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
// If no path is found, return null.
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dag.test.d.ts","sourceRoot":"","sources":["../src/dag.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { DAG } from './dag.js';
|
|
3
|
+
describe('DAG', () => {
|
|
4
|
+
describe('findPath', () => {
|
|
5
|
+
it('Can find a path from start to end.', () => {
|
|
6
|
+
// Example usage:
|
|
7
|
+
const edges = [
|
|
8
|
+
{ from: 'A', to: 'B', attributes: { some_key: 'a_to_b' } },
|
|
9
|
+
{ from: 'B', to: 'C', attributes: { some_key: 'b_to_c', hello: 'world' } },
|
|
10
|
+
{ from: 'A', to: 'D', attributes: { some_key: 'a_to_d' } },
|
|
11
|
+
{ from: 'D', to: 'E', attributes: { some_key: 'd_to_e' } },
|
|
12
|
+
{ from: 'E', to: 'C', attributes: { some_key: 'e_to_c' } },
|
|
13
|
+
];
|
|
14
|
+
const dag = new DAG(edges);
|
|
15
|
+
const path = dag.findPath('A', 'C');
|
|
16
|
+
expect(path).toEqual([
|
|
17
|
+
{ from: 'A', to: 'B', attributes: { some_key: 'a_to_b' } },
|
|
18
|
+
{ from: 'B', to: 'C', attributes: { some_key: 'b_to_c', hello: 'world' } },
|
|
19
|
+
]);
|
|
20
|
+
const path2 = dag.findPath('D', 'C');
|
|
21
|
+
expect(path2).toEqual([
|
|
22
|
+
{ from: 'D', to: 'E', attributes: { some_key: 'd_to_e' } },
|
|
23
|
+
{ from: 'E', to: 'C', attributes: { some_key: 'e_to_c' } },
|
|
24
|
+
]);
|
|
25
|
+
const path3 = dag.findPath('D', 'B');
|
|
26
|
+
expect(path3).toEqual(null);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
package/dist-tsc/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { DOMAINS } from "./constants.js";
|
|
2
2
|
export { GLOBAL_LABELS, DEFAULT_CELLS_LAYER, DEFAULT_MOLECULES_LAYER, DEFAULT_NEIGHBORHOODS_LAYER, DEFAULT_RASTER_DOMAIN_TYPE, DEFAULT_RASTER_LAYER_PROPS, DEFAULT_LAYER_TYPE_ORDERING } from "@vitessce/constants-internal";
|
|
3
|
-
export { initializeLayerChannels, initializeRasterLayersAndChannels, getSourceFromLoader, isInterleaved, isRgb, getNgffAxes, getNgffAxesForTiff, coordinateTransformationsToMatrix, physicalSizeToMatrix, hexToRgb, getStatsForResolution, canLoadResolution, normalizeCoordinateTransformations, normalizeAxes } from "./spatial.js";
|
|
3
|
+
export { initializeLayerChannels, initializeRasterLayersAndChannels, getSourceFromLoader, isInterleaved, isRgb, getNgffAxes, getNgffAxesForTiff, coordinateTransformationsToMatrix, coordinateTransformationsToMatrixForSpatialData, physicalSizeToMatrix, hexToRgb, getStatsForResolution, canLoadResolution, normalizeCoordinateTransformations, normalizeAxes } from "./spatial.js";
|
|
4
4
|
export { loadOmeZarr, guessTileSize, ZarritaPixelSource } from "./load-ome-zarr.js";
|
|
5
5
|
export { toRgbUIString, getSingleSelectionStats, getMultiSelectionStats, getPhysicalSizeScalingMatrix, getBoundingCube, abbreviateNumber, filterSelection } from "./layer-controller.js";
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist-tsc/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { GLOBAL_LABELS, DEFAULT_CELLS_LAYER, DEFAULT_MOLECULES_LAYER, DEFAULT_NEIGHBORHOODS_LAYER, DEFAULT_RASTER_DOMAIN_TYPE, DEFAULT_RASTER_LAYER_PROPS, DEFAULT_LAYER_TYPE_ORDERING, } from '@vitessce/constants-internal';
|
|
2
|
-
export { initializeLayerChannels, initializeRasterLayersAndChannels, getSourceFromLoader, isInterleaved, isRgb, getNgffAxes, getNgffAxesForTiff, coordinateTransformationsToMatrix, physicalSizeToMatrix, hexToRgb, getStatsForResolution, canLoadResolution, normalizeCoordinateTransformations, normalizeAxes, } from './spatial.js';
|
|
2
|
+
export { initializeLayerChannels, initializeRasterLayersAndChannels, getSourceFromLoader, isInterleaved, isRgb, getNgffAxes, getNgffAxesForTiff, coordinateTransformationsToMatrix, coordinateTransformationsToMatrixForSpatialData, physicalSizeToMatrix, hexToRgb, getStatsForResolution, canLoadResolution, normalizeCoordinateTransformations, normalizeAxes, } from './spatial.js';
|
|
3
3
|
export { loadOmeZarr, guessTileSize, ZarritaPixelSource, } from './load-ome-zarr.js';
|
|
4
4
|
export { toRgbUIString, getSingleSelectionStats, getMultiSelectionStats, getPhysicalSizeScalingMatrix, getBoundingCube, abbreviateNumber, filterSelection, } from './layer-controller.js';
|
|
5
5
|
export { DOMAINS, } from './constants.js';
|
package/dist-tsc/spatial.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export function getSwapAxesMatrix(inputAxes: ("x" | "y" | "z")[], outputAxes: ("
|
|
|
61
61
|
export function coordinateTransformationsToMatrix(coordinateTransformations: object[] | undefined, axes: object[] | undefined): Matrix4;
|
|
62
62
|
export function hexToRgb(hex: any): number[];
|
|
63
63
|
export function normalizeAxes(axes: any): any;
|
|
64
|
+
export function getIntrinsicCoordinateSystem(normAxes: any): any;
|
|
64
65
|
/**
|
|
65
66
|
* Normalize coordinate transformations to the OME-NGFF v0.4 format,
|
|
66
67
|
* despite potentially being in the new format proposed in
|
|
@@ -72,6 +73,30 @@ export function normalizeAxes(axes: any): any;
|
|
|
72
73
|
* @returns {object[]} Array of coordinateTransformations in OME-NGFF v0.4 format.
|
|
73
74
|
*/
|
|
74
75
|
export function normalizeCoordinateTransformations(coordinateTransformations: object[] | undefined, datasets: object[]): object[];
|
|
76
|
+
/**
|
|
77
|
+
* Convert coordinate transformations to a 4x4 matrix for SpatialData
|
|
78
|
+
* spatial elements. This function is intended to be used with SpatialData
|
|
79
|
+
* objects which have named coordinate systems. This function should
|
|
80
|
+
* be compatible with any SpatialElement (shapes, points, labels, images).
|
|
81
|
+
* @param {{
|
|
82
|
+
* axe?: (string[]|{ name: string, type?: string, unit?: string }[]),
|
|
83
|
+
* coordinateTransformations?: object[],
|
|
84
|
+
* datasets?: object[]
|
|
85
|
+
* }} ngffMetadata For images/labels, this is multiscales[0] from .zattrs.
|
|
86
|
+
* For shapes/points, this is { axes, coordinateTransformations } from .zattrs.
|
|
87
|
+
* @param {string} targetCoordinateSystem A target coordinate system name.
|
|
88
|
+
* @returns {Matrix4} A 4x4 transformation matrix.
|
|
89
|
+
* This can later be multiplied with other matrices if needed.
|
|
90
|
+
*/
|
|
91
|
+
export function coordinateTransformationsToMatrixForSpatialData(ngffMetadata: {
|
|
92
|
+
axe?: (string[] | {
|
|
93
|
+
name: string;
|
|
94
|
+
type?: string;
|
|
95
|
+
unit?: string;
|
|
96
|
+
}[]);
|
|
97
|
+
coordinateTransformations?: object[];
|
|
98
|
+
datasets?: object[];
|
|
99
|
+
}, targetCoordinateSystem: string): Matrix4;
|
|
75
100
|
export function getStatsForResolution(loader: any, resolution: any): {
|
|
76
101
|
height: any;
|
|
77
102
|
width: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spatial.d.ts","sourceRoot":"","sources":["../src/spatial.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"spatial.d.ts","sourceRoot":"","sources":["../src/spatial.js"],"names":[],"mappings":"AASA;;;;;;GAMG;AACH,4CAJW,MAAM,SACN,MAAM,GAAG,SAAS,GAChB,MAAM,CAMlB;AAoCD;;;;GAIG;AACH,8BAHW,MAAM,YACN,KAAK,GAAC,IAAI,WAiBpB;AAID,sHAmCC;AAiHD;;GAEG;AACH,qCAFW,KAAK,CAAE,MAAM,CAAC,WAKxB;AAED;;;;;;GAMG;AACH,gDALW,MAAM,eAEJ,MAAM,EAAE,CAuCpB;AAED;;;;;;;;;GASG;AACH,gEAJW,MAAM,EAAE,sBAER,CAAC,MAAM,EAAE,GAAC,IAAI,CAAC,+CAuEzB;AASD;;;IAuBC;AAED,uDAQC;AAED;;;;;;GAMG;AACH,6CAJW,CAAC,GAAG,GAAC,GAAG,GAAC,GAAG,CAAC,EAAE,cACf,CAAC,GAAG,GAAC,GAAG,GAAC,GAAG,CAAC,EAAE,GACd,MAAM,EAAE,EAAE,CA6BrB;AAED;;;;;;;;GAQG;AACH,6EANW,MAAM,EAAE,GAAC,SAAS,QAElB,MAAM,EAAE,GAAC,SAAS,GAEhB,OAAO,CAiHnB;AAED,6CAOC;AAMD,8CASC;AAED,iEAKC;AAGD;;;;;;;;;GASG;AACH,8EANW,MAAM,EAAE,GAAC,SAAS,YAGlB,MAAM,EAAE,GACN,MAAM,EAAE,CA4CpB;AAED;;;;;;;;;;;;;;GAcG;AACH,8EAVW;IACV,GAAM,CAAC,EAAE,CAAC,MAAM,EAAE,GAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC,CAAC;IACrE,yBAA4B,CAAC,EAAE,MAAM,EAAE,CAAC;IACxC,QAAW,CAAC,EAAE,MAAM,EAAE,CAAA;CACnB,0BAEO,MAAM,GACJ,OAAO,CA2CnB;AAzqBM;;;;;EAYN;AAEM,yEAkBN;wBArDuB,SAAS"}
|