@vitessce/gl 2.0.3-beta.0 → 2.0.3
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.04b04545.mjs +11 -0
- package/dist/index.9aaafdeb.mjs +118035 -0
- package/dist/index.mjs +33 -0
- package/dist/jpeg.060c9bc0.mjs +838 -0
- package/dist/lerc.62b02b29.mjs +1933 -0
- package/dist/lzw.19cdd4de.mjs +126 -0
- package/dist/packbits.03fc75de.mjs +28 -0
- package/dist/pako.esm.0e57f323.mjs +3940 -0
- package/dist/raw.739ce163.mjs +10 -0
- package/dist/webimage.4e868fb9.mjs +30 -0
- package/{dist → dist-tsc}/index.js +0 -0
- package/package.json +7 -7
- package/src/BitmaskLayer.js +165 -0
- package/src/HeatmapBitmapLayer.js +144 -0
- package/src/HeatmapCompositeTextLayer.js +156 -0
- package/src/PaddedExpressionHeatmapBitmapLayer.js +154 -0
- package/src/PixelatedBitmapLayer.js +30 -0
- package/src/ScaledExpressionExtension/ScaledExpressionExtension.js +117 -0
- package/{dist → src}/ScaledExpressionExtension/index.js +1 -0
- package/{dist → src}/ScaledExpressionExtension/shader-module.js +7 -4
- package/src/SelectionExtension/SelectionExtension.js +34 -0
- package/{dist → src}/SelectionExtension/index.js +1 -0
- package/{dist → src}/SelectionExtension/shader-module.js +7 -5
- package/src/SelectionLayer.js +198 -0
- package/{dist → src}/bitmask-layer-shaders.js +2 -0
- package/{dist → src}/constants.js +5 -3
- package/{dist → src}/deck.js +0 -0
- package/src/glsl/README.md +8 -0
- package/src/glsl/colormaps.in.glsl +15 -0
- package/{dist → src}/glsl/index.js +1 -0
- package/{dist → src}/heatmap-bitmap-layer-shaders.js +2 -0
- package/{dist → src}/heatmap-constants.js +11 -8
- package/src/index.js +33 -0
- package/{dist → src}/luma.js +0 -0
- package/{dist → src}/padded-expression-heatmap-bitmap-layer-shaders.js +2 -0
- package/src/selection-utils.js +109 -0
- package/src/viv.js +20 -0
- package/dist/BitmaskLayer.js +0 -132
- package/dist/HeatmapBitmapLayer.js +0 -123
- package/dist/HeatmapCompositeTextLayer.js +0 -129
- package/dist/PaddedExpressionHeatmapBitmapLayer.js +0 -129
- package/dist/PixelatedBitmapLayer.js +0 -26
- package/dist/ScaledExpressionExtension/ScaledExpressionExtension.js +0 -105
- package/dist/SelectionExtension/SelectionExtension.js +0 -31
- package/dist/SelectionLayer.js +0 -167
- package/dist/layer-controller.js +0 -109
- package/dist/selection-utils.js +0 -92
- package/dist/spatial.js +0 -281
- package/dist/spatial.test.js +0 -8
- package/dist/viv.js +0 -3
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import GL from '@luma.gl/constants'; // eslint-disable-line import/no-extraneous-dependencies
|
|
2
|
+
|
|
2
3
|
// Image texture dimensions
|
|
3
4
|
export const TILE_SIZE = 4096;
|
|
4
5
|
// Reshaped data texture dimensions
|
|
5
6
|
export const DATA_TEXTURE_SIZE = 4096;
|
|
6
7
|
export const MIN_ROW_AGG = 1;
|
|
7
8
|
export const MAX_ROW_AGG = 16;
|
|
9
|
+
|
|
8
10
|
export const COLOR_BAR_SIZE = 20;
|
|
9
11
|
export const AXIS_LABEL_TEXT_SIZE = 11;
|
|
10
12
|
export const AXIS_TITLE_TEXT_SIZE = 15;
|
|
@@ -13,15 +15,16 @@ export const AXIS_MAX_SIZE = 120;
|
|
|
13
15
|
export const AXIS_MARGIN = 3;
|
|
14
16
|
export const AXIS_PADDING = 10;
|
|
15
17
|
export const THEME_TO_TEXT_COLOR = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
dark: [224, 224, 224],
|
|
19
|
+
light: [64, 64, 64],
|
|
18
20
|
};
|
|
19
21
|
export const AXIS_FONT_FAMILY = "-apple-system, 'Helvetica Neue', Arial, sans-serif";
|
|
22
|
+
|
|
20
23
|
export const PIXELATED_TEXTURE_PARAMETERS = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
// NEAREST for integer data to prevent interpolation.
|
|
25
|
+
[GL.TEXTURE_MIN_FILTER]: GL.NEAREST,
|
|
26
|
+
[GL.TEXTURE_MAG_FILTER]: GL.NEAREST,
|
|
27
|
+
// CLAMP_TO_EDGE to remove tile artifacts.
|
|
28
|
+
[GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
|
|
29
|
+
[GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE,
|
|
27
30
|
};
|
package/src/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Selection Layers
|
|
2
|
+
export { getSelectionLayers } from './selection-utils';
|
|
3
|
+
|
|
4
|
+
// Heatmap Layers
|
|
5
|
+
export { default as HeatmapBitmapLayer } from './HeatmapBitmapLayer';
|
|
6
|
+
export { default as PixelatedBitmapLayer } from './PixelatedBitmapLayer';
|
|
7
|
+
export { default as HeatmapCompositeTextLayer } from './HeatmapCompositeTextLayer';
|
|
8
|
+
export { default as PaddedExpressionHeatmapBitmapLayer } from './PaddedExpressionHeatmapBitmapLayer';
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
GLSL_COLORMAPS, GLSL_COLORMAP_DEFAULT, DEFAULT_GL_OPTIONS, SELECTION_TYPE,
|
|
12
|
+
} from './constants';
|
|
13
|
+
|
|
14
|
+
// Layer extensions
|
|
15
|
+
export { default as ScaledExpressionExtension } from './ScaledExpressionExtension';
|
|
16
|
+
export { default as SelectionExtension } from './SelectionExtension';
|
|
17
|
+
export { default as BitmaskLayer } from './BitmaskLayer';
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
TILE_SIZE, MAX_ROW_AGG, MIN_ROW_AGG,
|
|
21
|
+
COLOR_BAR_SIZE,
|
|
22
|
+
AXIS_MARGIN,
|
|
23
|
+
DATA_TEXTURE_SIZE,
|
|
24
|
+
PIXELATED_TEXTURE_PARAMETERS,
|
|
25
|
+
AXIS_LABEL_TEXT_SIZE,
|
|
26
|
+
AXIS_FONT_FAMILY,
|
|
27
|
+
AXIS_PADDING,
|
|
28
|
+
AXIS_MIN_SIZE,
|
|
29
|
+
AXIS_MAX_SIZE,
|
|
30
|
+
} from './heatmap-constants';
|
|
31
|
+
export * as viv from './viv';
|
|
32
|
+
export * as luma from './luma';
|
|
33
|
+
export * as deck from './deck';
|
package/{dist → src}/luma.js
RENAMED
|
File without changes
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { colormaps } from './glsl';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* No change to the vertex shader from the base BitmapLayer.
|
|
4
5
|
* Reference: https://github.com/visgl/deck.gl/blob/8.2-release/modules/layers/src/bitmap-layer/bitmap-layer-vertex.js
|
|
@@ -28,6 +29,7 @@ void main(void) {
|
|
|
28
29
|
DECKGL_FILTER_COLOR(color, geometry);
|
|
29
30
|
}
|
|
30
31
|
`;
|
|
32
|
+
|
|
31
33
|
/**
|
|
32
34
|
* Fragment shader adapted to perform aggregation and
|
|
33
35
|
* take color scale functions + sliders into account.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { COORDINATE_SYSTEM } from '@deck.gl/core'; // eslint-disable-line import/no-extraneous-dependencies
|
|
2
|
+
import { DataFilterExtension } from '@deck.gl/extensions'; // eslint-disable-line import/no-extraneous-dependencies
|
|
3
|
+
import SelectionLayer from './SelectionLayer';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Convert a DeckGL layer ID to a "base" layer ID for selection.
|
|
7
|
+
* @param {string} layerId The layer ID to convert.
|
|
8
|
+
* @returns {string} The base layer ID.
|
|
9
|
+
*/
|
|
10
|
+
function getBaseLayerId(layerId) {
|
|
11
|
+
return `base-${layerId}`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Convert a DeckGL layer ID to a "selected" layer ID for selection.
|
|
16
|
+
* @param {string} layerId The layer ID to convert.
|
|
17
|
+
* @returns {string} The base layer ID.
|
|
18
|
+
*/
|
|
19
|
+
function getSelectedLayerId(layerId) {
|
|
20
|
+
return `selected-${layerId}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Construct DeckGL selection layers.
|
|
25
|
+
* @param {string} tool
|
|
26
|
+
* @param {number} zoom
|
|
27
|
+
* @param {string} cellBaseLayerId
|
|
28
|
+
* @param {function} getCellCoords
|
|
29
|
+
* @param {function} updateCellsSelection
|
|
30
|
+
* @returns {object[]} The array of DeckGL selection layers.
|
|
31
|
+
*/
|
|
32
|
+
export function getSelectionLayers(
|
|
33
|
+
tool,
|
|
34
|
+
zoom,
|
|
35
|
+
layerId,
|
|
36
|
+
getCellCoords,
|
|
37
|
+
obsIndex,
|
|
38
|
+
updateCellsSelection,
|
|
39
|
+
cellsQuadTree,
|
|
40
|
+
flipY = false,
|
|
41
|
+
) {
|
|
42
|
+
if (!tool) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const cellBaseLayerId = getBaseLayerId(layerId);
|
|
47
|
+
const editHandlePointRadius = 5 / (zoom + 16);
|
|
48
|
+
|
|
49
|
+
return [new SelectionLayer({
|
|
50
|
+
id: 'selection',
|
|
51
|
+
flipY,
|
|
52
|
+
cellsQuadTree,
|
|
53
|
+
getCellCoords,
|
|
54
|
+
coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
|
|
55
|
+
selectionType: tool,
|
|
56
|
+
onSelect: ({ pickingInfos }) => {
|
|
57
|
+
const cellIds = pickingInfos.map(i => obsIndex[i]);
|
|
58
|
+
if (updateCellsSelection) {
|
|
59
|
+
updateCellsSelection(cellIds);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
layerIds: [cellBaseLayerId],
|
|
63
|
+
getTentativeFillColor: () => [255, 255, 255, 95],
|
|
64
|
+
getTentativeLineColor: () => [143, 143, 143, 255],
|
|
65
|
+
getTentativeLineDashArray: () => [7, 4],
|
|
66
|
+
lineWidthMinPixels: 2,
|
|
67
|
+
lineWidthMaxPixels: 2,
|
|
68
|
+
getEditHandlePointColor: () => [0xff, 0xff, 0xff, 0xff],
|
|
69
|
+
getEditHandlePointRadius: () => editHandlePointRadius,
|
|
70
|
+
editHandlePointRadiusScale: 1,
|
|
71
|
+
editHandlePointRadiusMinPixels: editHandlePointRadius,
|
|
72
|
+
editHandlePointRadiusMaxPixels: 2 * editHandlePointRadius,
|
|
73
|
+
})];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get deck.gl layer props for selection overlays.
|
|
78
|
+
* @param {object} props
|
|
79
|
+
* @returns {object} Object with two properties,
|
|
80
|
+
* overlay: overlayProps, base: baseProps,
|
|
81
|
+
* where the values are deck.gl layer props.
|
|
82
|
+
*/
|
|
83
|
+
export function overlayBaseProps(props) {
|
|
84
|
+
const {
|
|
85
|
+
id, getColor, data, isSelected, ...rest
|
|
86
|
+
} = props;
|
|
87
|
+
return {
|
|
88
|
+
overlay: {
|
|
89
|
+
id: getSelectedLayerId(id),
|
|
90
|
+
getFillColor: getColor,
|
|
91
|
+
getLineColor: getColor,
|
|
92
|
+
data,
|
|
93
|
+
getFilterValue: isSelected,
|
|
94
|
+
extensions: [new DataFilterExtension({ filterSize: 1 })],
|
|
95
|
+
filterRange: [1, 1],
|
|
96
|
+
...rest,
|
|
97
|
+
},
|
|
98
|
+
base: {
|
|
99
|
+
id: getBaseLayerId(id),
|
|
100
|
+
getLineColor: getColor,
|
|
101
|
+
getFillColor: getColor,
|
|
102
|
+
// Alternatively: contrast outlines with solids:
|
|
103
|
+
// getLineColor: getColor,
|
|
104
|
+
// getFillColor: [255, 255, 255],
|
|
105
|
+
data: data.slice(),
|
|
106
|
+
...rest,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
package/src/viv.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export {
|
|
2
|
+
ZarrPixelSource,
|
|
3
|
+
loadOmeTiff,
|
|
4
|
+
loadOmeZarr,
|
|
5
|
+
XRLayer,
|
|
6
|
+
getChannelStats,
|
|
7
|
+
RENDERING_MODES,
|
|
8
|
+
MAX_CHANNELS,
|
|
9
|
+
getDefaultInitialViewState,
|
|
10
|
+
ScaleBarLayer,
|
|
11
|
+
MultiscaleImageLayer,
|
|
12
|
+
AdditiveColormapExtension,
|
|
13
|
+
ColorPaletteExtension,
|
|
14
|
+
ImageLayer,
|
|
15
|
+
VolumeLayer,
|
|
16
|
+
AdditiveColormap3DExtensions,
|
|
17
|
+
ColorPalette3DExtensions,
|
|
18
|
+
// TODO: deprecated
|
|
19
|
+
DTYPE_VALUES,
|
|
20
|
+
} from '@hms-dbmi/viv';
|
package/dist/BitmaskLayer.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import GL from '@luma.gl/constants'; // eslint-disable-line import/no-extraneous-dependencies
|
|
2
|
-
import { project32, picking } from '@deck.gl/core'; // eslint-disable-line import/no-extraneous-dependencies
|
|
3
|
-
import { Texture2D, isWebGL2 } from '@luma.gl/core';
|
|
4
|
-
import { XRLayer } from '@hms-dbmi/viv';
|
|
5
|
-
import { fs, vs } from './bitmask-layer-shaders';
|
|
6
|
-
import { GLSL_COLORMAPS, GLSL_COLORMAP_DEFAULT, COLORMAP_SHADER_PLACEHOLDER, } from './constants';
|
|
7
|
-
function padWithDefault(arr, defaultValue, padWidth) {
|
|
8
|
-
const newArr = [...arr];
|
|
9
|
-
for (let i = 0; i < padWidth; i += 1) {
|
|
10
|
-
newArr.push(defaultValue);
|
|
11
|
-
}
|
|
12
|
-
return newArr;
|
|
13
|
-
}
|
|
14
|
-
const defaultProps = {
|
|
15
|
-
hoveredCell: { type: 'number', value: null, compare: true },
|
|
16
|
-
cellColorData: { type: 'object', value: null, compare: true },
|
|
17
|
-
colormap: { type: 'string', value: GLSL_COLORMAP_DEFAULT, compare: true },
|
|
18
|
-
expressionData: { type: 'object', value: null, compare: true },
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* A BitmapLayer that performs aggregation in the fragment shader,
|
|
22
|
-
* and renders its texture from a Uint8Array rather than an ImageData.
|
|
23
|
-
*/
|
|
24
|
-
export default class BitmaskLayer extends XRLayer {
|
|
25
|
-
// eslint-disable-next-line class-methods-use-this
|
|
26
|
-
getShaders() {
|
|
27
|
-
const { colormap } = this.props;
|
|
28
|
-
return {
|
|
29
|
-
fs,
|
|
30
|
-
vs,
|
|
31
|
-
modules: [project32, picking],
|
|
32
|
-
defines: {
|
|
33
|
-
[COLORMAP_SHADER_PLACEHOLDER]: GLSL_COLORMAPS.includes(colormap)
|
|
34
|
-
? colormap
|
|
35
|
-
: GLSL_COLORMAP_DEFAULT,
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
updateState({ props, oldProps, changeFlags }) {
|
|
40
|
-
super.updateState({ props, oldProps, changeFlags });
|
|
41
|
-
if (props.cellColorData !== oldProps.cellColorData) {
|
|
42
|
-
this.setColorTexture();
|
|
43
|
-
}
|
|
44
|
-
if (props.expressionData !== oldProps.expressionData) {
|
|
45
|
-
const { expressionData, cellTexHeight, cellTexWidth } = this.props;
|
|
46
|
-
const expressionTex = this.dataToTexture(expressionData, cellTexWidth, cellTexHeight);
|
|
47
|
-
this.setState({ expressionTex });
|
|
48
|
-
}
|
|
49
|
-
if (props.colormap !== oldProps.colormap) {
|
|
50
|
-
const { gl } = this.context;
|
|
51
|
-
if (this.state.model) {
|
|
52
|
-
this.state.model.delete();
|
|
53
|
-
}
|
|
54
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
55
|
-
this.setState({ model: this._getModel(gl) });
|
|
56
|
-
this.getAttributeManager().invalidateAll();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
setColorTexture() {
|
|
60
|
-
const { cellColorData: data, cellTexHeight: height, cellTexWidth: width, } = this.props;
|
|
61
|
-
const colorTex = new Texture2D(this.context.gl, {
|
|
62
|
-
width,
|
|
63
|
-
height,
|
|
64
|
-
// Only use Float32 so we don't have to write two shaders
|
|
65
|
-
data,
|
|
66
|
-
// we don't want or need mimaps
|
|
67
|
-
mipmaps: false,
|
|
68
|
-
parameters: {
|
|
69
|
-
// NEAREST for integer data
|
|
70
|
-
[GL.TEXTURE_MIN_FILTER]: GL.NEAREST,
|
|
71
|
-
[GL.TEXTURE_MAG_FILTER]: GL.NEAREST,
|
|
72
|
-
// CLAMP_TO_EDGE to remove tile artifacts
|
|
73
|
-
[GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
|
|
74
|
-
[GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE,
|
|
75
|
-
},
|
|
76
|
-
format: GL.RGB,
|
|
77
|
-
dataFormat: GL.RGB,
|
|
78
|
-
type: GL.UNSIGNED_BYTE,
|
|
79
|
-
});
|
|
80
|
-
this.setState({ colorTex });
|
|
81
|
-
}
|
|
82
|
-
draw(opts) {
|
|
83
|
-
const { uniforms } = opts;
|
|
84
|
-
const { channelsVisible, hoveredCell, colorScaleLo, colorScaleHi, isExpressionMode, } = this.props;
|
|
85
|
-
const { textures, model, colorTex, expressionTex, } = this.state;
|
|
86
|
-
// Render the image
|
|
87
|
-
if (textures && model && colorTex) {
|
|
88
|
-
model
|
|
89
|
-
.setUniforms(Object.assign({}, uniforms, {
|
|
90
|
-
hovered: hoveredCell || 0,
|
|
91
|
-
colorTex,
|
|
92
|
-
expressionTex,
|
|
93
|
-
colorTexHeight: colorTex.height,
|
|
94
|
-
colorTexWidth: colorTex.width,
|
|
95
|
-
channelsVisible: padWithDefault(channelsVisible, false,
|
|
96
|
-
// There are six texture entries on the shaders
|
|
97
|
-
6 - channelsVisible.length),
|
|
98
|
-
uColorScaleRange: [colorScaleLo, colorScaleHi],
|
|
99
|
-
uIsExpressionMode: isExpressionMode,
|
|
100
|
-
...textures,
|
|
101
|
-
}))
|
|
102
|
-
.draw();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* This function creates textures from the data
|
|
107
|
-
*/
|
|
108
|
-
dataToTexture(data, width, height) {
|
|
109
|
-
const isWebGL2On = isWebGL2(this.context.gl);
|
|
110
|
-
return new Texture2D(this.context.gl, {
|
|
111
|
-
width,
|
|
112
|
-
height,
|
|
113
|
-
// Only use Float32 so we don't have to write two shaders
|
|
114
|
-
data: new Float32Array(data),
|
|
115
|
-
// we don't want or need mimaps
|
|
116
|
-
mipmaps: false,
|
|
117
|
-
parameters: {
|
|
118
|
-
// NEAREST for integer data
|
|
119
|
-
[GL.TEXTURE_MIN_FILTER]: GL.NEAREST,
|
|
120
|
-
[GL.TEXTURE_MAG_FILTER]: GL.NEAREST,
|
|
121
|
-
// CLAMP_TO_EDGE to remove tile artifacts
|
|
122
|
-
[GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
|
|
123
|
-
[GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE,
|
|
124
|
-
},
|
|
125
|
-
format: isWebGL2On ? GL.R32F : GL.LUMINANCE,
|
|
126
|
-
dataFormat: isWebGL2On ? GL.RED : GL.LUMINANCE,
|
|
127
|
-
type: GL.FLOAT,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
BitmaskLayer.layerName = 'BitmaskLayer';
|
|
132
|
-
BitmaskLayer.defaultProps = defaultProps;
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import GL from '@luma.gl/constants'; // eslint-disable-line import/no-extraneous-dependencies
|
|
2
|
-
import { _mergeShaders, project32, picking } from '@deck.gl/core'; // eslint-disable-line import/no-extraneous-dependencies
|
|
3
|
-
import { BitmapLayer } from '@deck.gl/layers'; // eslint-disable-line import/no-extraneous-dependencies
|
|
4
|
-
import { Texture2D } from '@luma.gl/core';
|
|
5
|
-
import { PIXELATED_TEXTURE_PARAMETERS, TILE_SIZE } from './heatmap-constants';
|
|
6
|
-
import { GLSL_COLORMAPS, GLSL_COLORMAP_DEFAULT, COLORMAP_SHADER_PLACEHOLDER, } from './constants';
|
|
7
|
-
import { vertexShader, fragmentShader } from './heatmap-bitmap-layer-shaders';
|
|
8
|
-
const defaultProps = {
|
|
9
|
-
image: { type: 'object', value: null, async: true },
|
|
10
|
-
colormap: { type: 'string', value: GLSL_COLORMAP_DEFAULT, compare: true },
|
|
11
|
-
bounds: { type: 'array', value: [1, 0, 0, 1], compare: true },
|
|
12
|
-
aggSizeX: { type: 'number', value: 8.0, compare: true },
|
|
13
|
-
aggSizeY: { type: 'number', value: 8.0, compare: true },
|
|
14
|
-
colorScaleLo: { type: 'number', value: 0.0, compare: true },
|
|
15
|
-
colorScaleHi: { type: 'number', value: 1.0, compare: true },
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* A BitmapLayer that performs aggregation in the fragment shader,
|
|
19
|
-
* and renders its texture from a Uint8Array rather than an ImageData.
|
|
20
|
-
*/
|
|
21
|
-
export default class HeatmapBitmapLayer extends BitmapLayer {
|
|
22
|
-
/**
|
|
23
|
-
* Copy of getShaders from Layer (grandparent, parent of BitmapLayer).
|
|
24
|
-
* Reference: https://github.com/visgl/deck.gl/blob/0afd4e99a6199aeec979989e0c361c97e6c17a16/modules/core/src/lib/layer.js#L302
|
|
25
|
-
* @param {object} shaders
|
|
26
|
-
* @returns {object} Merged shaders.
|
|
27
|
-
*/
|
|
28
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
29
|
-
_getShaders(shaders) {
|
|
30
|
-
this.props.extensions.forEach((extension) => {
|
|
31
|
-
// eslint-disable-next-line no-param-reassign
|
|
32
|
-
shaders = _mergeShaders(shaders, extension.getShaders.call(this, extension));
|
|
33
|
-
});
|
|
34
|
-
return shaders;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Need to override to provide custom shaders.
|
|
38
|
-
*/
|
|
39
|
-
getShaders() {
|
|
40
|
-
const { colormap } = this.props;
|
|
41
|
-
const fragmentShaderWithColormap = GLSL_COLORMAPS.includes(colormap)
|
|
42
|
-
? fragmentShader.replace(COLORMAP_SHADER_PLACEHOLDER, colormap)
|
|
43
|
-
: fragmentShader.replace(COLORMAP_SHADER_PLACEHOLDER, GLSL_COLORMAP_DEFAULT);
|
|
44
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
45
|
-
return this._getShaders({
|
|
46
|
-
vs: vertexShader,
|
|
47
|
-
fs: fragmentShaderWithColormap,
|
|
48
|
-
modules: [project32, picking],
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
updateState(args) {
|
|
52
|
-
super.updateState(args);
|
|
53
|
-
this.loadTexture(this.props.image);
|
|
54
|
-
const { props, oldProps } = args;
|
|
55
|
-
if (props.colormap !== oldProps.colormap) {
|
|
56
|
-
const { gl } = this.context;
|
|
57
|
-
// eslint-disable-next-line no-unused-expressions
|
|
58
|
-
this.state.model?.delete();
|
|
59
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
60
|
-
this.state.model = this._getModel(gl);
|
|
61
|
-
this.getAttributeManager().invalidateAll();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Need to override to provide additional uniform values.
|
|
66
|
-
* Simplified by removing video-related code.
|
|
67
|
-
* Reference: https://github.com/visgl/deck.gl/blob/0afd4e99a6199aeec979989e0c361c97e6c17a16/modules/layers/src/bitmap-layer/bitmap-layer.js#L173
|
|
68
|
-
* @param {*} opts
|
|
69
|
-
*/
|
|
70
|
-
draw(opts) {
|
|
71
|
-
const { uniforms } = opts;
|
|
72
|
-
const { bitmapTexture, model } = this.state;
|
|
73
|
-
const { aggSizeX, aggSizeY, colorScaleLo, colorScaleHi, } = this.props;
|
|
74
|
-
// Render the image
|
|
75
|
-
if (bitmapTexture && model) {
|
|
76
|
-
model
|
|
77
|
-
.setUniforms(Object.assign({}, uniforms, {
|
|
78
|
-
uBitmapTexture: bitmapTexture,
|
|
79
|
-
uTextureSize: [TILE_SIZE, TILE_SIZE],
|
|
80
|
-
uAggSize: [aggSizeX, aggSizeY],
|
|
81
|
-
uColorScaleRange: [colorScaleLo, colorScaleHi],
|
|
82
|
-
}))
|
|
83
|
-
.draw();
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Need to override to provide the custom DEFAULT_TEXTURE_PARAMETERS
|
|
88
|
-
* object.
|
|
89
|
-
* Simplified by removing video-related code.
|
|
90
|
-
* Reference: https://github.com/visgl/deck.gl/blob/0afd4e99a6199aeec979989e0c361c97e6c17a16/modules/layers/src/bitmap-layer/bitmap-layer.js#L218
|
|
91
|
-
* @param {Uint8Array} image
|
|
92
|
-
*/
|
|
93
|
-
loadTexture(image) {
|
|
94
|
-
const { gl } = this.context;
|
|
95
|
-
if (this.state.bitmapTexture) {
|
|
96
|
-
this.state.bitmapTexture.delete();
|
|
97
|
-
}
|
|
98
|
-
if (image instanceof Texture2D) {
|
|
99
|
-
this.setState({
|
|
100
|
-
bitmapTexture: image,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
else if (image) {
|
|
104
|
-
this.setState({
|
|
105
|
-
bitmapTexture: new Texture2D(gl, {
|
|
106
|
-
data: image,
|
|
107
|
-
mipmaps: false,
|
|
108
|
-
parameters: PIXELATED_TEXTURE_PARAMETERS,
|
|
109
|
-
// Each color contains a single luminance value.
|
|
110
|
-
// When sampled, rgb are all set to this luminance, alpha is 1.0.
|
|
111
|
-
// Reference: https://luma.gl/docs/api-reference/webgl/texture#texture-formats
|
|
112
|
-
format: GL.LUMINANCE,
|
|
113
|
-
dataFormat: GL.LUMINANCE,
|
|
114
|
-
type: GL.UNSIGNED_BYTE,
|
|
115
|
-
width: TILE_SIZE,
|
|
116
|
-
height: TILE_SIZE,
|
|
117
|
-
}),
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
HeatmapBitmapLayer.layerName = 'HeatmapBitmapLayer';
|
|
123
|
-
HeatmapBitmapLayer.defaultProps = defaultProps;
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-underscore-dangle */
|
|
2
|
-
import { COORDINATE_SYSTEM, CompositeLayer } from '@deck.gl/core'; // eslint-disable-line import/no-extraneous-dependencies
|
|
3
|
-
import { TextLayer } from '@deck.gl/layers'; // eslint-disable-line import/no-extraneous-dependencies
|
|
4
|
-
import { AXIS_LABEL_TEXT_SIZE, AXIS_TITLE_TEXT_SIZE, AXIS_MARGIN, THEME_TO_TEXT_COLOR, AXIS_FONT_FAMILY, COLOR_BAR_SIZE, } from './heatmap-constants';
|
|
5
|
-
export default class HeatmapCompositeTextLayer extends CompositeLayer {
|
|
6
|
-
_renderAxisTopLayers() {
|
|
7
|
-
const { axisTopLabelData, matrixLeft, width, matrixWidth, viewWidth, theme, targetX, targetY, axisTopTitle, cellWidth, axisOffsetTop, scaleFactor, hideTopLabels, } = this.props;
|
|
8
|
-
const showAxisTopLabels = cellWidth >= AXIS_LABEL_TEXT_SIZE;
|
|
9
|
-
const axisLabelTop = targetY + (axisOffsetTop - AXIS_MARGIN) / 2 / scaleFactor;
|
|
10
|
-
return hideTopLabels ? [] : [
|
|
11
|
-
new TextLayer({
|
|
12
|
-
id: 'axisTopLabels',
|
|
13
|
-
coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
|
|
14
|
-
data: axisTopLabelData,
|
|
15
|
-
getText: d => d[1],
|
|
16
|
-
getPosition: d => [matrixLeft + ((d[0] + 0.5) / width) * matrixWidth, axisLabelTop],
|
|
17
|
-
getTextAnchor: 'start',
|
|
18
|
-
getColor: () => THEME_TO_TEXT_COLOR[theme],
|
|
19
|
-
getSize: (showAxisTopLabels ? AXIS_LABEL_TEXT_SIZE : 0),
|
|
20
|
-
getAngle: 75,
|
|
21
|
-
fontFamily: AXIS_FONT_FAMILY,
|
|
22
|
-
updateTriggers: {
|
|
23
|
-
getPosition: [axisLabelTop, matrixLeft, matrixWidth, viewWidth],
|
|
24
|
-
getSize: [showAxisTopLabels],
|
|
25
|
-
getColor: [theme],
|
|
26
|
-
},
|
|
27
|
-
}),
|
|
28
|
-
new TextLayer({
|
|
29
|
-
id: 'axisTopTitle',
|
|
30
|
-
coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
|
|
31
|
-
data: [{ title: axisTopTitle }],
|
|
32
|
-
getText: d => d.title,
|
|
33
|
-
getPosition: [targetX, targetY],
|
|
34
|
-
getTextAnchor: 'middle',
|
|
35
|
-
getColor: () => THEME_TO_TEXT_COLOR[theme],
|
|
36
|
-
getSize: (!showAxisTopLabels ? AXIS_TITLE_TEXT_SIZE : 0),
|
|
37
|
-
getAngle: 0,
|
|
38
|
-
fontFamily: AXIS_FONT_FAMILY,
|
|
39
|
-
updateTriggers: {
|
|
40
|
-
getSize: [showAxisTopLabels],
|
|
41
|
-
getColor: [theme],
|
|
42
|
-
},
|
|
43
|
-
}),
|
|
44
|
-
];
|
|
45
|
-
}
|
|
46
|
-
_renderCornerLayers() {
|
|
47
|
-
const { theme, targetX, targetY, axisOffsetTop, scaleFactor, cellColorLabelsData, axisOffsetLeft, transpose, } = this.props;
|
|
48
|
-
const axisLabelTop = targetY + (axisOffsetTop - AXIS_MARGIN) / 2 / scaleFactor;
|
|
49
|
-
const axisLabelLeft = targetX + (axisOffsetLeft - AXIS_MARGIN) / 2 / scaleFactor;
|
|
50
|
-
return cellColorLabelsData.map(data => (new TextLayer({
|
|
51
|
-
id: `cellColorLabel-${data[0]}`,
|
|
52
|
-
coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
|
|
53
|
-
data: [data],
|
|
54
|
-
getText: d => d[1],
|
|
55
|
-
getTextAnchor: (transpose ? 'end' : 'start'),
|
|
56
|
-
getAlignmentBaseline: 'top',
|
|
57
|
-
getColor: () => THEME_TO_TEXT_COLOR[theme],
|
|
58
|
-
getSize: AXIS_LABEL_TEXT_SIZE,
|
|
59
|
-
getPosition: d => [
|
|
60
|
-
(transpose
|
|
61
|
-
? axisLabelLeft
|
|
62
|
-
: targetX
|
|
63
|
-
+ ((-cellColorLabelsData.length + d[0] * 2) * COLOR_BAR_SIZE + AXIS_MARGIN)
|
|
64
|
-
/ 2 / scaleFactor),
|
|
65
|
-
(transpose
|
|
66
|
-
? targetY
|
|
67
|
-
+ ((-cellColorLabelsData.length + d[0] * 2) * COLOR_BAR_SIZE + AXIS_MARGIN)
|
|
68
|
-
/ 2 / scaleFactor
|
|
69
|
-
: axisLabelTop),
|
|
70
|
-
],
|
|
71
|
-
getAngle: (transpose ? 0 : 90),
|
|
72
|
-
fontFamily: AXIS_FONT_FAMILY,
|
|
73
|
-
})));
|
|
74
|
-
}
|
|
75
|
-
_renderAxisLeftLayers() {
|
|
76
|
-
const { axisLeftLabelData, matrixTop, height, matrixHeight, viewHeight, theme, axisLeftTitle, targetX, targetY, cellHeight, axisOffsetLeft, scaleFactor, hideLeftLabels, } = this.props;
|
|
77
|
-
const showAxisLeftLabels = cellHeight >= AXIS_LABEL_TEXT_SIZE;
|
|
78
|
-
const axisLabelLeft = targetX + (axisOffsetLeft - AXIS_MARGIN) / 2 / scaleFactor;
|
|
79
|
-
return hideLeftLabels ? [] : [
|
|
80
|
-
new TextLayer({
|
|
81
|
-
id: 'axisLeftLabels',
|
|
82
|
-
coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
|
|
83
|
-
data: axisLeftLabelData,
|
|
84
|
-
getText: d => d[1],
|
|
85
|
-
getPosition: d => [axisLabelLeft, matrixTop + ((d[0] + 0.5) / height) * matrixHeight],
|
|
86
|
-
getTextAnchor: 'end',
|
|
87
|
-
getColor: () => THEME_TO_TEXT_COLOR[theme],
|
|
88
|
-
getSize: (showAxisLeftLabels ? AXIS_LABEL_TEXT_SIZE : 0),
|
|
89
|
-
getAngle: 0,
|
|
90
|
-
fontFamily: AXIS_FONT_FAMILY,
|
|
91
|
-
updateTriggers: {
|
|
92
|
-
getPosition: [axisLabelLeft, matrixTop, matrixHeight, viewHeight],
|
|
93
|
-
getSize: [showAxisLeftLabels],
|
|
94
|
-
getColor: [theme],
|
|
95
|
-
},
|
|
96
|
-
}),
|
|
97
|
-
new TextLayer({
|
|
98
|
-
id: 'axisLeftTitle',
|
|
99
|
-
coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
|
|
100
|
-
data: [{ title: axisLeftTitle }],
|
|
101
|
-
getText: d => d.title,
|
|
102
|
-
getPosition: [targetX, targetY],
|
|
103
|
-
getTextAnchor: 'middle',
|
|
104
|
-
getColor: () => THEME_TO_TEXT_COLOR[theme],
|
|
105
|
-
getSize: (!showAxisLeftLabels ? AXIS_TITLE_TEXT_SIZE : 0),
|
|
106
|
-
getAngle: 90,
|
|
107
|
-
fontFamily: AXIS_FONT_FAMILY,
|
|
108
|
-
updateTriggers: {
|
|
109
|
-
getSize: [showAxisLeftLabels],
|
|
110
|
-
getColor: [theme],
|
|
111
|
-
},
|
|
112
|
-
}),
|
|
113
|
-
];
|
|
114
|
-
}
|
|
115
|
-
renderLayers() {
|
|
116
|
-
const { axis } = this.props;
|
|
117
|
-
if (axis === 'left') {
|
|
118
|
-
return this._renderAxisLeftLayers();
|
|
119
|
-
}
|
|
120
|
-
if (axis === 'top') {
|
|
121
|
-
return this._renderAxisTopLayers();
|
|
122
|
-
}
|
|
123
|
-
if (axis === 'corner') {
|
|
124
|
-
return this._renderCornerLayers();
|
|
125
|
-
}
|
|
126
|
-
return [];
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
HeatmapCompositeTextLayer.layerName = 'HeatmapCompositeTextLayer';
|