@vitessce/layer-controller 3.1.2 → 3.2.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.
Files changed (43) hide show
  1. package/dist/{deflate-460ebda8.js → deflate-4152c8e9.js} +1 -1
  2. package/dist/{index-7295e6e7.js → index-64da21ec.js} +982 -244
  3. package/dist/index.js +9 -2
  4. package/dist/{jpeg-5e6a02ae.js → jpeg-29889288.js} +1 -1
  5. package/dist/{lerc-f147b9b3.js → lerc-899a010f.js} +1 -1
  6. package/dist/{lzw-328dcf22.js → lzw-f5a9e721.js} +1 -1
  7. package/dist/{packbits-d1842d12.js → packbits-5fc9c646.js} +1 -1
  8. package/dist/{raw-e59a20ba.js → raw-0ae87697.js} +1 -1
  9. package/dist/{webimage-30f949aa.js → webimage-1731afb4.js} +1 -1
  10. package/dist-tsc/ChannelOptions.d.ts.map +1 -1
  11. package/dist-tsc/ChannelOptions.js +6 -1
  12. package/dist-tsc/LayerController.d.ts.map +1 -1
  13. package/dist-tsc/LayerController.js +1 -4
  14. package/dist-tsc/LayerOptions.d.ts.map +1 -1
  15. package/dist-tsc/LayerOptions.js +3 -4
  16. package/dist-tsc/RasterChannelController.d.ts.map +1 -1
  17. package/dist-tsc/RasterChannelController.js +1 -25
  18. package/dist-tsc/VolumeOptions.js +1 -1
  19. package/dist-tsc/index.d.ts +1 -0
  20. package/dist-tsc/index.js +1 -0
  21. package/dist-tsc/styles.d.ts +3 -3
  22. package/dist-tsc/styles.d.ts.map +1 -1
  23. package/dist-tsc/styles.js +10 -13
  24. package/package.json +6 -6
  25. package/src/ChannelOptions.js +7 -1
  26. package/src/LayerController.js +6 -5
  27. package/src/LayerOptions.js +11 -7
  28. package/src/RasterChannelController.js +7 -29
  29. package/src/VolumeOptions.js +1 -1
  30. package/src/index.js +9 -0
  31. package/src/styles.js +10 -14
  32. package/dist-tsc/RasterChannelController.test.d.ts +0 -2
  33. package/dist-tsc/RasterChannelController.test.d.ts.map +0 -1
  34. package/dist-tsc/RasterChannelController.test.js +0 -22
  35. package/dist-tsc/constants.d.ts +0 -2
  36. package/dist-tsc/constants.d.ts.map +0 -1
  37. package/dist-tsc/constants.js +0 -12
  38. package/dist-tsc/utils.d.ts +0 -24
  39. package/dist-tsc/utils.d.ts.map +0 -1
  40. package/dist-tsc/utils.js +0 -117
  41. package/src/RasterChannelController.test.js +0 -24
  42. package/src/constants.js +0 -14
  43. package/src/utils.js +0 -138
package/dist-tsc/utils.js DELETED
@@ -1,117 +0,0 @@
1
- import { viv } from '@vitessce/gl';
2
- import { Matrix4 } from 'math.gl';
3
- // Returns an rgb string for display, and changes the color (arr)
4
- // to use a grey for light theme + white color or if the colormap is on.
5
- export const toRgbUIString = (on, arr, theme) => {
6
- const color = on || (theme === 'light' && arr.every(i => i === 255))
7
- ? [220, 220, 220]
8
- : arr;
9
- return `rgb(${color})`;
10
- };
11
- async function getSingleSelectionStats2D({ loader, selection }) {
12
- const data = Array.isArray(loader) ? loader[loader.length - 1] : loader;
13
- const raster = await data.getRaster({ selection });
14
- const selectionStats = viv.getChannelStats(raster.data);
15
- const { domain, contrastLimits: slider } = selectionStats;
16
- return { domain, slider };
17
- }
18
- async function getSingleSelectionStats3D({ loader, selection }) {
19
- const lowResSource = loader[loader.length - 1];
20
- const { shape, labels } = lowResSource;
21
- // eslint-disable-next-line no-bitwise
22
- const sizeZ = shape[labels.indexOf('z')] >> (loader.length - 1);
23
- const raster0 = await lowResSource.getRaster({
24
- selection: { ...selection, z: 0 },
25
- });
26
- const rasterMid = await lowResSource.getRaster({
27
- selection: { ...selection, z: Math.floor(sizeZ / 2) },
28
- });
29
- const rasterTop = await lowResSource.getRaster({
30
- selection: { ...selection, z: Math.max(0, sizeZ - 1) },
31
- });
32
- const stats0 = viv.getChannelStats(raster0.data);
33
- const statsMid = viv.getChannelStats(rasterMid.data);
34
- const statsTop = viv.getChannelStats(rasterTop.data);
35
- return {
36
- domain: [
37
- Math.min(stats0.domain[0], statsMid.domain[0], statsTop.domain[0]),
38
- Math.max(stats0.domain[1], statsMid.domain[1], statsTop.domain[1]),
39
- ],
40
- slider: [
41
- Math.min(stats0.contrastLimits[0], statsMid.contrastLimits[0], statsTop.contrastLimits[0]),
42
- Math.max(stats0.contrastLimits[1], statsMid.contrastLimits[1], statsTop.contrastLimits[1]),
43
- ],
44
- };
45
- }
46
- /**
47
- * Get bounding cube for a given loader i.e [[0, width], [0, height], [0, depth]]
48
- * @param {Object} loader PixelSource|PixelSource[]
49
- * @param {[]} selection Selection for stats.
50
- * @param {boolean} use3d Whether or not to get 3d stats.
51
- * @returns {Object} { domains, sliders }
52
- */
53
- export const getSingleSelectionStats = async ({ loader, selection, use3d }) => {
54
- const getStats = use3d
55
- ? getSingleSelectionStats3D
56
- : getSingleSelectionStats2D;
57
- return getStats({ loader, selection });
58
- };
59
- export const getMultiSelectionStats = async ({ loader, selections, use3d }) => {
60
- const stats = await Promise.all(selections.map(selection => getSingleSelectionStats({ loader, selection, use3d })));
61
- const domains = stats.map(stat => stat.domain);
62
- const sliders = stats.map(stat => stat.slider);
63
- return { domains, sliders };
64
- };
65
- /**
66
- * Get physical size scaling Matrix4
67
- * @param {Object} loader PixelSource
68
- * @returns {Object} matrix
69
- */
70
- export function getPhysicalSizeScalingMatrix(loader) {
71
- const { x, y, z } = loader?.meta?.physicalSizes ?? {};
72
- if (x?.size && y?.size && z?.size) {
73
- const min = Math.min(z.size, x.size, y.size);
74
- const ratio = [x.size / min, y.size / min, z.size / min];
75
- return new Matrix4().scale(ratio);
76
- }
77
- return new Matrix4().identity();
78
- }
79
- /**
80
- * Get bounding cube for a given loader
81
- * @param {Object} loader PixelSource|PixelSource[]
82
- * @returns {Array} [0, width], [0, height], [0, depth]]
83
- */
84
- export function getBoundingCube(loader) {
85
- const source = Array.isArray(loader) ? loader[0] : loader;
86
- const { shape, labels } = source;
87
- const physicalSizeScalingMatrix = getPhysicalSizeScalingMatrix(source);
88
- const xSlice = [0, physicalSizeScalingMatrix[0] * shape[labels.indexOf('x')]];
89
- const ySlice = [0, physicalSizeScalingMatrix[5] * shape[labels.indexOf('y')]];
90
- const zSlice = [
91
- 0,
92
- physicalSizeScalingMatrix[10] * shape[labels.indexOf('z')],
93
- ];
94
- return [xSlice, ySlice, zSlice];
95
- }
96
- export function abbreviateNumber(value) {
97
- // Return an abbreviated representation of value, in 5 characters or less.
98
- const maxLength = 5;
99
- let maxNaiveDigits = maxLength;
100
- /* eslint-disable no-plusplus */
101
- if (!Number.isInteger(value)) {
102
- --maxNaiveDigits;
103
- } // Wasted on "."
104
- if (value < 1) {
105
- --maxNaiveDigits;
106
- } // Wasted on "0."
107
- /* eslint-disable no-plusplus */
108
- const naive = Intl.NumberFormat('en-US', {
109
- maximumSignificantDigits: maxNaiveDigits,
110
- useGrouping: false,
111
- }).format(value);
112
- if (naive.length <= maxLength)
113
- return naive;
114
- // "e+9" consumes 3 characters, so if we even had two significant digits,
115
- // it would take take us to six characters, including the decimal point.
116
- return value.toExponential(0);
117
- }
@@ -1,24 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { toRgbUIString } from './utils.js';
3
-
4
- const GREY = [220, 220, 220];
5
-
6
- describe('layer-controller/RasterChannelController.js', () => {
7
- describe('toRgbUIString()', () => {
8
- it('Maps color value to itself when colormap off and not white with dark theme', () => {
9
- expect(toRgbUIString(false, [200, 200, 200], 'dark')).toEqual(`rgb(${[200, 200, 200]})`);
10
- });
11
- it('Maps color value to grey when colormap on with dark theme', () => {
12
- expect(toRgbUIString(true, [200, 200, 200], 'dark')).toEqual(`rgb(${GREY})`);
13
- });
14
- it('Maps color value to grey when colormap on with light theme', () => {
15
- expect(toRgbUIString(true, [200, 200, 200], 'light')).toEqual(`rgb(${GREY})`);
16
- });
17
- it('Maps color value to grey when colormap off and white with light theme', () => {
18
- expect(toRgbUIString(false, [255, 255, 255], 'light')).toEqual(`rgb(${GREY})`);
19
- });
20
- it('Maps color value to grey when colormap off and white with light theme', () => {
21
- expect(toRgbUIString(false, [200, 200, 200], 'light')).toEqual(`rgb(${[200, 200, 200]})`);
22
- });
23
- });
24
- });
package/src/constants.js DELETED
@@ -1,14 +0,0 @@
1
- import { viv } from '@vitessce/gl';
2
-
3
- function getDomains() {
4
- const domains = {};
5
- const needMin = ['Int8', 'Int16', 'Int32'];
6
- Object.keys(viv.DTYPE_VALUES).forEach((dtype) => {
7
- const { max } = viv.DTYPE_VALUES[dtype];
8
- const min = needMin.includes(dtype) ? -(max + 1) : 0;
9
- domains[dtype] = [min, max];
10
- });
11
- return domains;
12
- }
13
-
14
- export const DOMAINS = getDomains();
package/src/utils.js DELETED
@@ -1,138 +0,0 @@
1
- import { viv } from '@vitessce/gl';
2
- import { Matrix4 } from 'math.gl';
3
-
4
- // Returns an rgb string for display, and changes the color (arr)
5
- // to use a grey for light theme + white color or if the colormap is on.
6
- export const toRgbUIString = (on, arr, theme) => {
7
- const color = on || (theme === 'light' && arr.every(i => i === 255))
8
- ? [220, 220, 220]
9
- : arr;
10
- return `rgb(${color})`;
11
- };
12
-
13
- async function getSingleSelectionStats2D({ loader, selection }) {
14
- const data = Array.isArray(loader) ? loader[loader.length - 1] : loader;
15
- const raster = await data.getRaster({ selection });
16
- const selectionStats = viv.getChannelStats(raster.data);
17
- const { domain, contrastLimits: slider } = selectionStats;
18
- return { domain, slider };
19
- }
20
-
21
- async function getSingleSelectionStats3D({ loader, selection }) {
22
- const lowResSource = loader[loader.length - 1];
23
- const { shape, labels } = lowResSource;
24
- // eslint-disable-next-line no-bitwise
25
- const sizeZ = shape[labels.indexOf('z')] >> (loader.length - 1);
26
- const raster0 = await lowResSource.getRaster({
27
- selection: { ...selection, z: 0 },
28
- });
29
- const rasterMid = await lowResSource.getRaster({
30
- selection: { ...selection, z: Math.floor(sizeZ / 2) },
31
- });
32
- const rasterTop = await lowResSource.getRaster({
33
- selection: { ...selection, z: Math.max(0, sizeZ - 1) },
34
- });
35
- const stats0 = viv.getChannelStats(raster0.data);
36
- const statsMid = viv.getChannelStats(rasterMid.data);
37
- const statsTop = viv.getChannelStats(rasterTop.data);
38
- return {
39
- domain: [
40
- Math.min(stats0.domain[0], statsMid.domain[0], statsTop.domain[0]),
41
- Math.max(stats0.domain[1], statsMid.domain[1], statsTop.domain[1]),
42
- ],
43
- slider: [
44
- Math.min(
45
- stats0.contrastLimits[0],
46
- statsMid.contrastLimits[0],
47
- statsTop.contrastLimits[0],
48
- ),
49
- Math.max(
50
- stats0.contrastLimits[1],
51
- statsMid.contrastLimits[1],
52
- statsTop.contrastLimits[1],
53
- ),
54
- ],
55
- };
56
- }
57
-
58
- /**
59
- * Get bounding cube for a given loader i.e [[0, width], [0, height], [0, depth]]
60
- * @param {Object} loader PixelSource|PixelSource[]
61
- * @param {[]} selection Selection for stats.
62
- * @param {boolean} use3d Whether or not to get 3d stats.
63
- * @returns {Object} { domains, sliders }
64
- */
65
- export const getSingleSelectionStats = async ({ loader, selection, use3d }) => {
66
- const getStats = use3d
67
- ? getSingleSelectionStats3D
68
- : getSingleSelectionStats2D;
69
- return getStats({ loader, selection });
70
- };
71
-
72
- export const getMultiSelectionStats = async ({ loader, selections, use3d }) => {
73
- const stats = await Promise.all(
74
- selections.map(selection => getSingleSelectionStats({ loader, selection, use3d })),
75
- );
76
- const domains = stats.map(stat => stat.domain);
77
- const sliders = stats.map(stat => stat.slider);
78
- return { domains, sliders };
79
- };
80
-
81
- /**
82
- * Get physical size scaling Matrix4
83
- * @param {Object} loader PixelSource
84
- * @returns {Object} matrix
85
- */
86
- export function getPhysicalSizeScalingMatrix(loader) {
87
- const { x, y, z } = loader?.meta?.physicalSizes ?? {};
88
- if (x?.size && y?.size && z?.size) {
89
- const min = Math.min(z.size, x.size, y.size);
90
- const ratio = [x.size / min, y.size / min, z.size / min];
91
- return new Matrix4().scale(ratio);
92
- }
93
- return new Matrix4().identity();
94
- }
95
-
96
- /**
97
- * Get bounding cube for a given loader
98
- * @param {Object} loader PixelSource|PixelSource[]
99
- * @returns {Array} [0, width], [0, height], [0, depth]]
100
- */
101
- export function getBoundingCube(loader) {
102
- const source = Array.isArray(loader) ? loader[0] : loader;
103
- const { shape, labels } = source;
104
- const physicalSizeScalingMatrix = getPhysicalSizeScalingMatrix(source);
105
- const xSlice = [0, physicalSizeScalingMatrix[0] * shape[labels.indexOf('x')]];
106
- const ySlice = [0, physicalSizeScalingMatrix[5] * shape[labels.indexOf('y')]];
107
- const zSlice = [
108
- 0,
109
- physicalSizeScalingMatrix[10] * shape[labels.indexOf('z')],
110
- ];
111
- return [xSlice, ySlice, zSlice];
112
- }
113
-
114
- export function abbreviateNumber(value) {
115
- // Return an abbreviated representation of value, in 5 characters or less.
116
-
117
- const maxLength = 5;
118
- let maxNaiveDigits = maxLength;
119
-
120
- /* eslint-disable no-plusplus */
121
- if (!Number.isInteger(value)) {
122
- --maxNaiveDigits;
123
- } // Wasted on "."
124
- if (value < 1) {
125
- --maxNaiveDigits;
126
- } // Wasted on "0."
127
- /* eslint-disable no-plusplus */
128
-
129
- const naive = Intl.NumberFormat('en-US', {
130
- maximumSignificantDigits: maxNaiveDigits,
131
- useGrouping: false,
132
- }).format(value);
133
- if (naive.length <= maxLength) return naive;
134
-
135
- // "e+9" consumes 3 characters, so if we even had two significant digits,
136
- // it would take take us to six characters, including the decimal point.
137
- return value.toExponential(0);
138
- }