@vitessce/gl 3.5.8 → 3.5.10

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/index.js CHANGED
@@ -1,18 +1,19 @@
1
- import { f as distEs6 } from "./index-06f9318c.js";
2
- import { o, n, A, r, q, p, i, j, C, l, D, G, e, H, c, M, k, m, d, P, S, h, T, t, b, s, u, v } from "./index-06f9318c.js";
1
+ import { f as distEs6 } from "./index-e113c88f.js";
2
+ import { p, o, A, s, r, q, i, j, l, C, m, D, G, e, H, c, M, k, n, d, P, S, h, T, u, b, t, w, v } from "./index-e113c88f.js";
3
3
  import "react";
4
4
  const SELECTION_TYPE = distEs6.SELECTION_TYPE;
5
5
  export {
6
- o as AXIS_FONT_FAMILY,
7
- n as AXIS_LABEL_TEXT_SIZE,
6
+ p as AXIS_FONT_FAMILY,
7
+ o as AXIS_LABEL_TEXT_SIZE,
8
8
  A as AXIS_MARGIN,
9
- r as AXIS_MAX_SIZE,
10
- q as AXIS_MIN_SIZE,
11
- p as AXIS_PADDING,
9
+ s as AXIS_MAX_SIZE,
10
+ r as AXIS_MIN_SIZE,
11
+ q as AXIS_PADDING,
12
12
  i as BitmaskLayer,
13
13
  j as BitmaskLayerBeta,
14
- C as COLOR_BAR_SIZE,
15
- l as DATA_TEXTURE_SIZE,
14
+ l as COLOR_BAR_SIZE,
15
+ C as ContourLayerWithText,
16
+ m as DATA_TEXTURE_SIZE,
16
17
  D as DEFAULT_GL_OPTIONS,
17
18
  G as GLSL_COLORMAPS,
18
19
  e as GLSL_COLORMAP_DEFAULT,
@@ -20,16 +21,16 @@ export {
20
21
  c as HeatmapCompositeTextLayer,
21
22
  M as MAX_ROW_AGG,
22
23
  k as MIN_ROW_AGG,
23
- m as PIXELATED_TEXTURE_PARAMETERS,
24
+ n as PIXELATED_TEXTURE_PARAMETERS,
24
25
  d as PaddedExpressionHeatmapBitmapLayer,
25
26
  P as PixelatedBitmapLayer,
26
27
  SELECTION_TYPE,
27
28
  S as ScaledExpressionExtension,
28
29
  h as SelectionExtension,
29
30
  T as TILE_SIZE,
30
- t as deck,
31
+ u as deck,
31
32
  b as getSelectionLayer,
32
- s as luma,
33
- u as math,
33
+ t as luma,
34
+ w as math,
34
35
  v as viv
35
36
  };
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-06f9318c.js";
1
+ import { B as BaseDecoder } from "./index-e113c88f.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, L as LercParameters, a as LercAddCompression } from "./index-06f9318c.js";
2
+ import { g as getDefaultExportFromCjs, B as BaseDecoder, L as LercParameters, a as LercAddCompression } from "./index-e113c88f.js";
3
3
  import "react";
4
4
  var LercDecode = { exports: {} };
5
5
  (function(module) {
@@ -1,4 +1,4 @@
1
- import { B as BaseDecoder } from "./index-06f9318c.js";
1
+ import { B as BaseDecoder } from "./index-e113c88f.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-06f9318c.js";
1
+ import { B as BaseDecoder } from "./index-e113c88f.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-06f9318c.js";
1
+ import { B as BaseDecoder } from "./index-e113c88f.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-06f9318c.js";
1
+ import { B as BaseDecoder } from "./index-e113c88f.js";
2
2
  import "react";
3
3
  class WebImageDecoder extends BaseDecoder {
4
4
  constructor() {
@@ -0,0 +1,83 @@
1
+ declare class ContourLayerWithText {
2
+ /**
3
+ * Construct line and text layers to render.
4
+ * @returns {object[]} Array of DeckGL layers.
5
+ */
6
+ getLineAndTextLayers(): object[];
7
+ /**
8
+ * Overrides the ContourLayer renderLayers function,
9
+ * so that the custom text/line layers can be
10
+ * appended to the contour line/polygon layers.
11
+ * @returns {object[]} Array of DeckGL layers.
12
+ */
13
+ renderLayers(): object[];
14
+ }
15
+ declare namespace ContourLayerWithText {
16
+ export let layerName: string;
17
+ export { defaultProps };
18
+ }
19
+ export default ContourLayerWithText;
20
+ declare namespace defaultProps {
21
+ namespace obsSetPath {
22
+ let type: string;
23
+ }
24
+ namespace sampleSetPath {
25
+ let type_1: string;
26
+ export { type_1 as type };
27
+ }
28
+ namespace circleInfo {
29
+ let type_2: string;
30
+ export { type_2 as type };
31
+ }
32
+ namespace circlePointSet {
33
+ let type_3: string;
34
+ export { type_3 as type };
35
+ }
36
+ namespace obsSetLabelsVisible {
37
+ let type_4: string;
38
+ export { type_4 as type };
39
+ }
40
+ namespace obsSetLabelSize {
41
+ let type_5: string;
42
+ export { type_5 as type };
43
+ export let min: number;
44
+ export let max: number;
45
+ export let value: number;
46
+ }
47
+ namespace cellSize {
48
+ let type_6: string;
49
+ export { type_6 as type };
50
+ let min_1: number;
51
+ export { min_1 as min };
52
+ let max_1: number;
53
+ export { max_1 as max };
54
+ let value_1: number;
55
+ export { value_1 as value };
56
+ }
57
+ namespace getPosition {
58
+ let type_7: string;
59
+ export { type_7 as type };
60
+ export function value_2(x: any): any;
61
+ export { value_2 as value };
62
+ }
63
+ namespace getWeight {
64
+ let type_8: string;
65
+ export { type_8 as type };
66
+ let value_3: number;
67
+ export { value_3 as value };
68
+ }
69
+ let gpuAggregation: boolean;
70
+ let aggregation: string;
71
+ namespace contours {
72
+ let type_9: string;
73
+ export { type_9 as type };
74
+ let value_4: {
75
+ threshold: number;
76
+ }[];
77
+ export { value_4 as value };
78
+ export let optional: boolean;
79
+ export let compare: number;
80
+ }
81
+ let zOffset: number;
82
+ }
83
+ //# sourceMappingURL=ContourLayerWithText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContourLayerWithText.d.ts","sourceRoot":"","sources":["../src/ContourLayerWithText.js"],"names":[],"mappings":"AA8GA;IACE;;;OAGG;IACH,wBAFa,MAAM,EAAE,CAuHpB;IAED;;;;;OAKG;IACH,gBAFa,MAAM,EAAE,CAYpB;CACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAlOyC,qCAAe"}
@@ -0,0 +1,220 @@
1
+ import { ContourLayer } from '@deck.gl/aggregation-layers';
2
+ import { LineLayer, TextLayer } from '@deck.gl/layers';
3
+ import { point as turfPoint, polygons } from '@turf/helpers';
4
+ import { getGeom } from '@turf/invariant';
5
+ import { flattenReduce } from '@turf/meta';
6
+ import { union } from '@turf/union';
7
+ import { area } from '@turf/area';
8
+ import { distance } from '@turf/distance';
9
+ import { range } from 'lodash-es';
10
+ import { AXIS_FONT_FAMILY } from './heatmap-constants.js';
11
+ const DEFAULT_THRESHOLD = 1;
12
+ const defaultProps = {
13
+ // for text
14
+ obsSetPath: { type: 'object' },
15
+ sampleSetPath: { type: 'object' },
16
+ circleInfo: { type: 'object' },
17
+ circlePointSet: { type: 'object' },
18
+ obsSetLabelsVisible: { type: 'boolean' },
19
+ obsSetLabelSize: { type: 'number', min: 1, max: 100, value: 12 },
20
+ // grid aggregation
21
+ cellSize: { type: 'number', min: 1, max: 1000, value: 1000 },
22
+ getPosition: { type: 'accessor', value: x => x.position },
23
+ getWeight: { type: 'accessor', value: 1 },
24
+ gpuAggregation: true,
25
+ aggregation: 'SUM',
26
+ // contour lines
27
+ contours: {
28
+ type: 'object',
29
+ value: [{ threshold: DEFAULT_THRESHOLD }],
30
+ optional: true,
31
+ compare: 3,
32
+ },
33
+ zOffset: 0.005,
34
+ };
35
+ const MIN_AREA_THRESHOLD = 10;
36
+ const MAX_NUM_VERTICES = 36;
37
+ /**
38
+ * Get the polygon with the maximum area,
39
+ * and also return its area value.
40
+ * @param {{contour, vertices}[]} levelToUse The
41
+ * contourPolygons array filtered to a given level.
42
+ * @returns {[number, object]} A tuple of
43
+ * [area value, Turf polygon object].
44
+ */
45
+ function getMaxAreaPolygon(levelToUse) {
46
+ if (levelToUse.length === 0) {
47
+ return [0, null];
48
+ }
49
+ const levelPolygons = levelToUse.map(d => ([
50
+ // The vertices are 3D, but we only need 2D.
51
+ [
52
+ ...d.vertices.map(v => ([v[0], v[1]])),
53
+ // Need four vertices (not 3), so repeat the first vertex.
54
+ [d.vertices[0][0], d.vertices[0][1]],
55
+ ],
56
+ ]));
57
+ const levelPolygonsUnion = union(polygons(levelPolygons));
58
+ const [maxAreaValue, maxAreaPolygon] = flattenReduce(levelPolygonsUnion, (previousValue, currentFeature) => {
59
+ if (getGeom(currentFeature).type === 'Polygon') {
60
+ const currArea = area(currentFeature);
61
+ if (currArea >= previousValue[0]) {
62
+ return [currArea, currentFeature];
63
+ }
64
+ }
65
+ return previousValue;
66
+ },
67
+ // Initial value
68
+ [0, null]);
69
+ return [maxAreaValue, maxAreaPolygon];
70
+ }
71
+ /**
72
+ * Get the area, polygon, and level associated with
73
+ * the "polygon of maximum area". (Not actually maximum
74
+ * among all levels but the max within a given level)
75
+ * @param {{contour, vertices}[]} contourPolygons The
76
+ * contourPolygons value within state.contourData
77
+ * @returns {[number, object, number]} A tuple of
78
+ * [area value, Turf polygon object, level index].
79
+ */
80
+ function getMaxAreaPolygonAndLevel(contourPolygons) {
81
+ const l2 = contourPolygons?.filter(d => d.contour.i === 2) ?? [];
82
+ const [l2area, l2polygon] = getMaxAreaPolygon(l2);
83
+ if (Math.log10(l2area) >= MIN_AREA_THRESHOLD) {
84
+ return [l2area, l2polygon, 2];
85
+ }
86
+ const l1 = contourPolygons?.filter(d => d.contour.i === 1) ?? [];
87
+ const [l1area, l1polygon] = getMaxAreaPolygon(l1);
88
+ if (Math.log10(l1area) >= MIN_AREA_THRESHOLD) {
89
+ return [l1area, l1polygon, 1];
90
+ }
91
+ const l0 = contourPolygons?.filter(d => d.contour.i === 0) ?? [];
92
+ const [l0area, l0polygon] = getMaxAreaPolygon(l0);
93
+ return [l0area, l0polygon, 0];
94
+ }
95
+ // Reference: https://github.com/visgl/deck.gl/blob/v8.9.36/modules/aggregation-layers/src/contour-layer/contour-layer.ts
96
+ export default class ContourLayerWithText extends ContourLayer {
97
+ /**
98
+ * Construct line and text layers to render.
99
+ * @returns {object[]} Array of DeckGL layers.
100
+ */
101
+ getLineAndTextLayers() {
102
+ const lineAndTextLayers = [];
103
+ const { contourPolygons } = this.state.contourData;
104
+ const { obsSetPath, contours, circleInfo, circlePointSet, obsSetLabelSize } = this.props;
105
+ if (!circleInfo) {
106
+ return lineAndTextLayers;
107
+ }
108
+ const obsSetName = obsSetPath?.at(-1);
109
+ const [maxAreaValue, maxAreaPolygon, levelI] = getMaxAreaPolygonAndLevel(contourPolygons);
110
+ // Get a circle polygon which outlines the whole plot.
111
+ const { center, steps, polygon: circlePolygon } = circleInfo;
112
+ if (maxAreaValue > 0 && maxAreaPolygon) {
113
+ let minDist = Infinity;
114
+ let minCirclePoint;
115
+ let minCirclePointI;
116
+ let minPolygonPoint;
117
+ const numVertices = maxAreaPolygon.geometry.coordinates[0].length;
118
+ // Only consider a maximum of 36 vertices from the polygon,
119
+ // since it may be complex with many vertices.
120
+ const polygonVertices = numVertices > MAX_NUM_VERTICES
121
+ ? range(MAX_NUM_VERTICES).map(i => maxAreaPolygon
122
+ .geometry
123
+ .coordinates[0][Math.floor(i * numVertices / MAX_NUM_VERTICES)])
124
+ : [...maxAreaPolygon.geometry.coordinates[0]];
125
+ // Find the pair (vertex on circle, vertex on contourPolygon) which
126
+ // have the shortest distance.
127
+ circlePolygon.geometry.coordinates[0].forEach((circleCoord, circlePointI) => {
128
+ const circlePoint = turfPoint(circleCoord);
129
+ polygonVertices.forEach((polyCoord) => {
130
+ const polyPoint = turfPoint(polyCoord);
131
+ const dist = distance(circlePoint, polyPoint);
132
+ if (dist < minDist) {
133
+ minDist = dist;
134
+ minCirclePoint = circleCoord;
135
+ minCirclePointI = circlePointI;
136
+ minPolygonPoint = polyCoord;
137
+ }
138
+ });
139
+ });
140
+ // If this circle vertex has already been used, then its index
141
+ // will be in the circlePointSet, so we instead try the subsequent
142
+ // vertex until we find one that is unused
143
+ // (or until the set is full, in which case we must reuse a vertex).
144
+ while (circlePointSet.size < steps && circlePointSet.has(minCirclePointI)) {
145
+ const nextCirclePointI = (minCirclePointI + 1) % steps;
146
+ minCirclePointI = nextCirclePointI;
147
+ }
148
+ circlePointSet.add(minCirclePointI);
149
+ minCirclePoint = circlePolygon.geometry.coordinates[0][minCirclePointI];
150
+ // Compute the angle formed by the line
151
+ // (from the circle's center point).
152
+ const angleRadians = Math.atan2(minCirclePoint[1] - center[1], minCirclePoint[0] - center[0]);
153
+ let angleDegrees = angleRadians * 180 / Math.PI;
154
+ // Create the line and text layers.
155
+ lineAndTextLayers.push(new LineLayer({
156
+ id: `line-${obsSetName}`,
157
+ data: [
158
+ {
159
+ from: minPolygonPoint,
160
+ to: minCirclePoint,
161
+ color: contours[levelI].color,
162
+ },
163
+ ],
164
+ getColor: d => d.color,
165
+ getSourcePosition: d => d.from,
166
+ getTargetPosition: d => d.to,
167
+ getWidth: levelI + 0.5,
168
+ }));
169
+ // Determine textAnchor based on angle formed on circle.
170
+ let textAnchor = 'start';
171
+ if (angleDegrees < 0) {
172
+ angleDegrees += 360;
173
+ }
174
+ if (angleDegrees > 90 && angleDegrees < 270) {
175
+ angleDegrees -= 180;
176
+ textAnchor = 'end';
177
+ }
178
+ lineAndTextLayers.push(new TextLayer({
179
+ id: `text-${obsSetName}`,
180
+ data: [
181
+ {
182
+ label: obsSetName,
183
+ to: minCirclePoint,
184
+ color: contours[levelI].color,
185
+ },
186
+ ],
187
+ getPosition: d => d.to,
188
+ getText: d => d.label,
189
+ getColor: d => d.color,
190
+ getSize: obsSetLabelSize,
191
+ getAngle: -angleDegrees,
192
+ getTextAnchor: textAnchor,
193
+ getAlignmentBaseline: 'center',
194
+ fontFamily: AXIS_FONT_FAMILY,
195
+ fontWeight: 'normal',
196
+ // maxWidth: 80 * obsSetLabelSize,
197
+ }));
198
+ }
199
+ return lineAndTextLayers;
200
+ }
201
+ /**
202
+ * Overrides the ContourLayer renderLayers function,
203
+ * so that the custom text/line layers can be
204
+ * appended to the contour line/polygon layers.
205
+ * @returns {object[]} Array of DeckGL layers.
206
+ */
207
+ renderLayers() {
208
+ const { obsSetLabelsVisible } = this.props;
209
+ const contourLayers = super.renderLayers();
210
+ const lineAndTextLayers = obsSetLabelsVisible
211
+ ? this.getLineAndTextLayers()
212
+ : [];
213
+ return [
214
+ ...contourLayers,
215
+ ...lineAndTextLayers,
216
+ ];
217
+ }
218
+ }
219
+ ContourLayerWithText.layerName = 'ContourLayerWithText';
220
+ ContourLayerWithText.defaultProps = defaultProps;
@@ -4,10 +4,10 @@
4
4
  // https://github.com/uber/nebula.gl/blob/8e9c2ec8d7cf4ca7050909ed826eb847d5e2cd9c/modules/layers/src/layers/selection-layer.js
5
5
  import { CompositeLayer } from 'deck.gl';
6
6
  import { polygon as turfPolygon, point as turfPoint } from '@turf/helpers';
7
- import booleanWithin from '@turf/boolean-within';
8
- import booleanContains from '@turf/boolean-contains';
9
- import booleanOverlap from '@turf/boolean-overlap';
10
- import booleanPointInPolygon from '@turf/boolean-point-in-polygon';
7
+ import { booleanWithin } from '@turf/boolean-within';
8
+ import { booleanContains } from '@turf/boolean-contains';
9
+ import { booleanOverlap } from '@turf/boolean-overlap';
10
+ import { booleanPointInPolygon } from '@turf/boolean-point-in-polygon';
11
11
  import { ScatterplotLayer } from '@deck.gl/layers';
12
12
  import { SELECTION_TYPE } from 'nebula.gl';
13
13
  import { EditableGeoJsonLayer } from '@nebula.gl/layers';
@@ -7,6 +7,7 @@ export { default as ScaledExpressionExtension } from "./ScaledExpressionExtensio
7
7
  export { default as SelectionExtension } from "./SelectionExtension/index.js";
8
8
  export { default as BitmaskLayer } from "./BitmaskLayer.js";
9
9
  export { default as BitmaskLayerBeta } from "./BitmaskLayerBeta.js";
10
+ export { default as ContourLayerWithText } from "./ContourLayerWithText.js";
10
11
  export * as viv from "./viv.js";
11
12
  export * as luma from "./luma.js";
12
13
  export * as deck from "./deck.js";
package/dist-tsc/index.js CHANGED
@@ -11,6 +11,7 @@ export { default as ScaledExpressionExtension } from './ScaledExpressionExtensio
11
11
  export { default as SelectionExtension } from './SelectionExtension/index.js';
12
12
  export { default as BitmaskLayer } from './BitmaskLayer.js';
13
13
  export { default as BitmaskLayerBeta } from './BitmaskLayerBeta.js';
14
+ export { default as ContourLayerWithText } from './ContourLayerWithText.js';
14
15
  export { TILE_SIZE, MAX_ROW_AGG, MIN_ROW_AGG, COLOR_BAR_SIZE, AXIS_MARGIN, DATA_TEXTURE_SIZE, PIXELATED_TEXTURE_PARAMETERS, AXIS_LABEL_TEXT_SIZE, AXIS_FONT_FAMILY, AXIS_PADDING, AXIS_MIN_SIZE, AXIS_MAX_SIZE, } from './heatmap-constants.js';
15
16
  // eslint-disable-next-line react-refresh/only-export-components
16
17
  export * as viv from './viv.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitessce/gl",
3
- "version": "3.5.8",
3
+ "version": "3.5.10",
4
4
  "author": "HIDIVE Lab at HMS",
5
5
  "homepage": "http://vitessce.io",
6
6
  "repository": {
@@ -38,13 +38,17 @@
38
38
  "@math.gl/core": "^3.5.6",
39
39
  "@nebula.gl/edit-modes": "0.23.8",
40
40
  "@nebula.gl/layers": "0.23.8",
41
- "@turf/area": "^6.5.0",
42
- "@turf/boolean-contains": "^6.5.0",
43
- "@turf/boolean-overlap": "^6.5.0",
44
- "@turf/boolean-point-in-polygon": "^6.5.0",
45
- "@turf/boolean-within": "^6.5.0",
46
- "@turf/centroid": "^6.5.0",
47
- "@turf/helpers": "^6.5.0",
41
+ "@turf/area": "^7.2.0",
42
+ "@turf/boolean-contains": "^7.2.0",
43
+ "@turf/boolean-overlap": "^7.2.0",
44
+ "@turf/boolean-point-in-polygon": "^7.2.0",
45
+ "@turf/boolean-within": "^7.2.0",
46
+ "@turf/centroid": "^7.2.0",
47
+ "@turf/helpers": "^7.2.0",
48
+ "@turf/union": "^7.2.0",
49
+ "@turf/meta": "^7.2.0",
50
+ "@turf/invariant": "^7.2.0",
51
+ "@turf/distance": "^7.2.0",
48
52
  "d3-array": "^2.4.0",
49
53
  "deck.gl": "8.8.27",
50
54
  "glslify": "^7.0.0",
@@ -52,8 +56,8 @@
52
56
  "math.gl": "^3.5.6",
53
57
  "mathjs": "^9.2.0",
54
58
  "nebula.gl": "0.23.8",
55
- "@vitessce/utils": "3.5.8",
56
- "@vitessce/globals": "3.5.8"
59
+ "@vitessce/utils": "3.5.10",
60
+ "@vitessce/globals": "3.5.10"
57
61
  },
58
62
  "devDependencies": {
59
63
  "glsl-colormap": "^1.0.1"