@deck.gl/extensions 8.8.0-alpha.5 → 8.8.0-beta.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.
Files changed (128) hide show
  1. package/dist/dist.dev.js +480 -1335
  2. package/dist/es5/brushing/brushing.js +19 -15
  3. package/dist/es5/brushing/brushing.js.map +1 -1
  4. package/dist/es5/brushing/shader-module.js +1 -1
  5. package/dist/es5/brushing/shader-module.js.map +1 -1
  6. package/dist/es5/clip/clip.js +4 -2
  7. package/dist/es5/clip/clip.js.map +1 -1
  8. package/dist/es5/data-filter/aggregator.js +1 -1
  9. package/dist/es5/data-filter/aggregator.js.map +1 -1
  10. package/dist/es5/data-filter/data-filter.js +9 -9
  11. package/dist/es5/data-filter/data-filter.js.map +1 -1
  12. package/dist/es5/data-filter/shader-module.js +22 -13
  13. package/dist/es5/data-filter/shader-module.js.map +1 -1
  14. package/dist/es5/fill-style/fill-style.js +13 -11
  15. package/dist/es5/fill-style/fill-style.js.map +1 -1
  16. package/dist/es5/fill-style/shaders.glsl.js +8 -6
  17. package/dist/es5/fill-style/shaders.glsl.js.map +1 -1
  18. package/dist/es5/fp64/fp64.js +4 -2
  19. package/dist/es5/fp64/fp64.js.map +1 -1
  20. package/dist/es5/fp64/project64.glsl.js +1 -1
  21. package/dist/es5/fp64/project64.js +2 -5
  22. package/dist/es5/fp64/project64.js.map +1 -1
  23. package/dist/es5/index.js.map +1 -1
  24. package/dist/es5/mask/mask.js +7 -4
  25. package/dist/es5/mask/mask.js.map +1 -1
  26. package/dist/es5/mask/shader-module.js +6 -7
  27. package/dist/es5/mask/shader-module.js.map +1 -1
  28. package/dist/es5/path-style/path-style.js +5 -5
  29. package/dist/es5/path-style/path-style.js.map +1 -1
  30. package/dist/es5/path-style/shaders.glsl.js +1 -1
  31. package/dist/es5/path-style/shaders.glsl.js.map +1 -1
  32. package/dist/esm/brushing/brushing.js +20 -15
  33. package/dist/esm/brushing/brushing.js.map +1 -1
  34. package/dist/esm/brushing/shader-module.js +1 -1
  35. package/dist/esm/brushing/shader-module.js.map +1 -1
  36. package/dist/esm/clip/clip.js +5 -2
  37. package/dist/esm/clip/clip.js.map +1 -1
  38. package/dist/esm/data-filter/aggregator.js +1 -1
  39. package/dist/esm/data-filter/aggregator.js.map +1 -1
  40. package/dist/esm/data-filter/data-filter.js +6 -3
  41. package/dist/esm/data-filter/data-filter.js.map +1 -1
  42. package/dist/esm/data-filter/shader-module.js +21 -21
  43. package/dist/esm/data-filter/shader-module.js.map +1 -1
  44. package/dist/esm/fill-style/fill-style.js +18 -13
  45. package/dist/esm/fill-style/fill-style.js.map +1 -1
  46. package/dist/esm/fill-style/shaders.glsl.js +6 -2
  47. package/dist/esm/fill-style/shaders.glsl.js.map +1 -1
  48. package/dist/esm/fp64/fp64.js +4 -2
  49. package/dist/esm/fp64/fp64.js.map +1 -1
  50. package/dist/esm/fp64/project64.glsl.js +1 -1
  51. package/dist/esm/fp64/project64.glsl.js.map +1 -1
  52. package/dist/esm/fp64/project64.js +2 -3
  53. package/dist/esm/fp64/project64.js.map +1 -1
  54. package/dist/esm/index.js.map +1 -1
  55. package/dist/esm/mask/mask.js +7 -4
  56. package/dist/esm/mask/mask.js.map +1 -1
  57. package/dist/esm/mask/shader-module.js +6 -6
  58. package/dist/esm/mask/shader-module.js.map +1 -1
  59. package/dist/esm/path-style/path-style.js +6 -5
  60. package/dist/esm/path-style/path-style.js.map +1 -1
  61. package/dist/esm/path-style/shaders.glsl.js +1 -1
  62. package/dist/esm/path-style/shaders.glsl.js.map +1 -1
  63. package/dist.min.js +1 -1
  64. package/package.json +5 -3
  65. package/src/brushing/{brushing.js → brushing.ts} +45 -17
  66. package/src/brushing/{shader-module.js → shader-module.ts} +13 -3
  67. package/src/clip/{clip.js → clip.ts} +26 -9
  68. package/src/data-filter/{aggregator.js → aggregator.ts} +12 -8
  69. package/src/data-filter/{data-filter.js → data-filter.ts} +90 -13
  70. package/src/data-filter/{shader-module.js → shader-module.ts} +36 -27
  71. package/src/fill-style/{fill-style.js → fill-style.ts} +83 -19
  72. package/src/fill-style/{shaders.glsl.js → shaders.glsl.ts} +24 -4
  73. package/src/fp64/{fp64.js → fp64.ts} +6 -3
  74. package/src/fp64/{project64.glsl.js → project64.glsl.ts} +0 -0
  75. package/src/fp64/{project64.js → project64.ts} +16 -5
  76. package/src/index.ts +8 -0
  77. package/src/mask/{mask.js → mask.ts} +25 -8
  78. package/src/mask/shader-module.ts +86 -0
  79. package/src/path-style/{path-style.js → path-style.ts} +65 -14
  80. package/src/path-style/{shaders.glsl.js → shaders.glsl.ts} +0 -0
  81. package/typed/brushing/brushing.d.ts +37 -16
  82. package/typed/brushing/brushing.d.ts.map +1 -1
  83. package/typed/brushing/brushing.js +83 -0
  84. package/typed/brushing/shader-module.d.ts +9 -24
  85. package/typed/brushing/shader-module.d.ts.map +1 -1
  86. package/typed/brushing/shader-module.js +116 -0
  87. package/typed/clip/clip.d.ts +27 -10
  88. package/typed/clip/clip.d.ts.map +1 -1
  89. package/typed/clip/clip.js +114 -0
  90. package/typed/data-filter/aggregator.d.ts +10 -9
  91. package/typed/data-filter/aggregator.d.ts.map +1 -1
  92. package/typed/data-filter/aggregator.js +98 -0
  93. package/typed/data-filter/data-filter.d.ts +87 -29
  94. package/typed/data-filter/data-filter.d.ts.map +1 -1
  95. package/typed/data-filter/data-filter.js +159 -0
  96. package/typed/data-filter/shader-module.d.ts +7 -24
  97. package/typed/data-filter/shader-module.d.ts.map +1 -1
  98. package/typed/data-filter/shader-module.js +152 -0
  99. package/typed/fill-style/fill-style.d.ts +74 -41
  100. package/typed/fill-style/fill-style.d.ts.map +1 -1
  101. package/typed/fill-style/fill-style.js +152 -0
  102. package/typed/fill-style/shaders.glsl.d.ts +8 -33
  103. package/typed/fill-style/shaders.glsl.d.ts.map +1 -1
  104. package/typed/fill-style/shaders.glsl.js +95 -0
  105. package/typed/fp64/fp64.d.ts +6 -6
  106. package/typed/fp64/fp64.d.ts.map +1 -1
  107. package/typed/fp64/fp64.js +34 -0
  108. package/typed/fp64/project64.d.ts +5 -9
  109. package/typed/fp64/project64.d.ts.map +1 -1
  110. package/typed/fp64/project64.glsl.d.ts +1 -1
  111. package/typed/fp64/project64.glsl.d.ts.map +1 -1
  112. package/typed/fp64/project64.glsl.js +100 -0
  113. package/typed/fp64/project64.js +50 -0
  114. package/typed/index.d.ts +6 -0
  115. package/typed/index.d.ts.map +1 -1
  116. package/typed/index.js +9 -0
  117. package/typed/mask/mask.d.ts +21 -9
  118. package/typed/mask/mask.d.ts.map +1 -1
  119. package/typed/mask/mask.js +48 -0
  120. package/typed/mask/shader-module.d.ts +6 -20
  121. package/typed/mask/shader-module.d.ts.map +1 -1
  122. package/{src → typed}/mask/shader-module.js +16 -21
  123. package/typed/path-style/path-style.d.ts +63 -27
  124. package/typed/path-style/path-style.d.ts.map +1 -1
  125. package/typed/path-style/path-style.js +107 -0
  126. package/typed/path-style/shaders.glsl.d.ts +6 -7
  127. package/typed/path-style/shaders.glsl.d.ts.map +1 -1
  128. package/typed/path-style/shaders.glsl.js +93 -0
@@ -0,0 +1,114 @@
1
+ // Copyright (c) 2015 - 2017 Uber Technologies, Inc.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in
11
+ // all copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ // THE SOFTWARE.
20
+ import { LayerExtension } from '@deck.gl/core';
21
+ const defaultProps = {
22
+ clipBounds: [0, 0, 1, 1]
23
+ };
24
+ const shaderFunction = `
25
+ uniform vec4 clip_bounds;
26
+
27
+ bool clip_isInBounds(vec2 position) {
28
+ return position.x >= clip_bounds[0] && position.y >= clip_bounds[1] && position.x < clip_bounds[2] && position.y < clip_bounds[3];
29
+ }
30
+ `;
31
+ /*
32
+ * The vertex-shader version clips geometries by their anchor position
33
+ * e.g. ScatterplotLayer - show if the center of a circle is within bounds
34
+ */
35
+ const shaderModuleVs = {
36
+ name: 'clip-vs',
37
+ vs: shaderFunction
38
+ };
39
+ const injectionVs = {
40
+ 'vs:#decl': `
41
+ varying float clip_isVisible;
42
+ `,
43
+ 'vs:DECKGL_FILTER_GL_POSITION': `
44
+ clip_isVisible = float(clip_isInBounds(geometry.worldPosition.xy));
45
+ `,
46
+ 'fs:#decl': `
47
+ varying float clip_isVisible;
48
+ `,
49
+ 'fs:DECKGL_FILTER_COLOR': `
50
+ if (clip_isVisible < 0.5) discard;
51
+ `
52
+ };
53
+ /*
54
+ * The fragment-shader version clips pixels at the bounds
55
+ * e.g. PolygonLayer - show the part of the polygon that intersect with the bounds
56
+ */
57
+ const shaderModuleFs = {
58
+ name: 'clip-fs',
59
+ fs: shaderFunction
60
+ };
61
+ const injectionFs = {
62
+ 'vs:#decl': `
63
+ varying vec2 clip_commonPosition;
64
+ `,
65
+ 'vs:DECKGL_FILTER_GL_POSITION': `
66
+ clip_commonPosition = geometry.position.xy;
67
+ `,
68
+ 'fs:#decl': `
69
+ varying vec2 clip_commonPosition;
70
+ `,
71
+ 'fs:DECKGL_FILTER_COLOR': `
72
+ if (!clip_isInBounds(clip_commonPosition)) discard;
73
+ `
74
+ };
75
+ export default class ClipExtension extends LayerExtension {
76
+ getShaders() {
77
+ // If `clipByInstance: true`, the entire object is shown/hidden based on its anchor position (done by vertex shader)
78
+ // Otherwise, the object is trimmed by the clip bounds (done by fragment shader)
79
+ // Default behavior: consider a layer instanced if it has attribute `instancePositions`
80
+ let clipByInstance = 'instancePositions' in this.getAttributeManager().attributes;
81
+ // Users can override by setting the `clipByInstance` prop
82
+ if ('clipByInstance' in this.props) {
83
+ clipByInstance = this.props.clipByInstance;
84
+ }
85
+ this.state.clipByInstance = clipByInstance;
86
+ return clipByInstance
87
+ ? {
88
+ modules: [shaderModuleVs],
89
+ inject: injectionVs
90
+ }
91
+ : {
92
+ modules: [shaderModuleFs],
93
+ inject: injectionFs
94
+ };
95
+ }
96
+ draw({ uniforms }) {
97
+ const { clipBounds = defaultProps.clipBounds } = this.props;
98
+ if (this.state.clipByInstance) {
99
+ uniforms.clip_bounds = clipBounds;
100
+ }
101
+ else {
102
+ const corner0 = this.projectPosition([clipBounds[0], clipBounds[1], 0]);
103
+ const corner1 = this.projectPosition([clipBounds[2], clipBounds[3], 0]);
104
+ uniforms.clip_bounds = [
105
+ Math.min(corner0[0], corner1[0]),
106
+ Math.min(corner0[1], corner1[1]),
107
+ Math.max(corner0[0], corner1[0]),
108
+ Math.max(corner0[1], corner1[1])
109
+ ];
110
+ }
111
+ }
112
+ }
113
+ ClipExtension.extensionName = 'ClipExtension';
114
+ ClipExtension.defaultProps = defaultProps;
@@ -1,10 +1,11 @@
1
- export function supportsFloatTarget(gl: any): any;
2
- export function getFramebuffer(gl: any, useFloatTarget: any): any;
3
- export function getModel(gl: any, shaderOptions: any, useFloatTarget: any): any;
4
- export namespace parameters {
5
- const blend: boolean;
6
- const blendFunc: number[];
7
- const blendEquation: number[];
8
- const depthTest: boolean;
9
- }
1
+ import { Model, Framebuffer } from '@luma.gl/core';
2
+ export declare function supportsFloatTarget(gl: WebGLRenderingContext): boolean;
3
+ export declare function getFramebuffer(gl: WebGLRenderingContext, useFloatTarget: boolean): Framebuffer;
4
+ export declare function getModel(gl: WebGLRenderingContext, shaderOptions: any, useFloatTarget: boolean): Model;
5
+ export declare const parameters: {
6
+ blend: boolean;
7
+ blendFunc: number[];
8
+ blendEquation: number[];
9
+ depthTest: boolean;
10
+ };
10
11
  //# sourceMappingURL=aggregator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"aggregator.d.ts","sourceRoot":"","sources":["../../src/data-filter/aggregator.js"],"names":[],"mappings":"AAkDA,kDASC;AAGD,kEAmBC;AAGD,gFAeC"}
1
+ {"version":3,"file":"aggregator.d.ts","sourceRoot":"","sources":["../../src/data-filter/aggregator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAa,WAAW,EAAW,MAAM,eAAe,CAAC;AAkDtE,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,qBAAqB,GAAG,OAAO,CAStE;AAGD,wBAAgB,cAAc,CAAC,EAAE,EAAE,qBAAqB,EAAE,cAAc,EAAE,OAAO,GAAG,WAAW,CAmB9F;AAGD,wBAAgB,QAAQ,CACtB,EAAE,EAAE,qBAAqB,EACzB,aAAa,EAAE,GAAG,EAClB,cAAc,EAAE,OAAO,GACtB,KAAK,CAeP;AAED,eAAO,MAAM,UAAU;;;;;CAKtB,CAAC"}
@@ -0,0 +1,98 @@
1
+ import { Model, Texture2D, Framebuffer, isWebGL2 } from '@luma.gl/core';
2
+ import GL from '@luma.gl/constants';
3
+ const AGGREGATE_VS = `\
4
+ #define SHADER_NAME data-filter-vertex-shader
5
+
6
+ #ifdef FLOAT_TARGET
7
+ attribute float filterIndices;
8
+ attribute float filterPrevIndices;
9
+ #else
10
+ attribute vec2 filterIndices;
11
+ attribute vec2 filterPrevIndices;
12
+ #endif
13
+
14
+ varying vec4 vColor;
15
+ const float component = 1.0 / 255.0;
16
+
17
+ void main() {
18
+ #ifdef FLOAT_TARGET
19
+ dataFilter_value *= float(filterIndices != filterPrevIndices);
20
+ gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
21
+ vColor = vec4(0.0, 0.0, 0.0, 1.0);
22
+ #else
23
+ // Float texture is not supported: pack result into 4 channels x 256 px x 64px
24
+ dataFilter_value *= float(filterIndices.x != filterPrevIndices.x);
25
+ float col = filterIndices.x;
26
+ float row = filterIndices.y * 4.0;
27
+ float channel = floor(row);
28
+ row = fract(row);
29
+ vColor = component * vec4(bvec4(channel == 0.0, channel == 1.0, channel == 2.0, channel == 3.0));
30
+ gl_Position = vec4(col * 2.0 - 1.0, row * 2.0 - 1.0, 0.0, 1.0);
31
+ #endif
32
+ gl_PointSize = 1.0;
33
+ }
34
+ `;
35
+ const AGGREGATE_FS = `\
36
+ #define SHADER_NAME data-filter-fragment-shader
37
+ precision highp float;
38
+
39
+ varying vec4 vColor;
40
+
41
+ void main() {
42
+ if (dataFilter_value < 0.5) {
43
+ discard;
44
+ }
45
+ gl_FragColor = vColor;
46
+ }
47
+ `;
48
+ export function supportsFloatTarget(gl) {
49
+ // https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#Support_for_float_textures_doesnt_mean_you_can_render_into_them!
50
+ return (gl.getExtension('EXT_float_blend') &&
51
+ // WebGL 2
52
+ (gl.getExtension('EXT_color_buffer_float') ||
53
+ // WebGL 1
54
+ gl.getExtension('WEBGL_color_buffer_float')));
55
+ }
56
+ // A 1x1 framebuffer object that encodes the total count of filtered items
57
+ export function getFramebuffer(gl, useFloatTarget) {
58
+ if (useFloatTarget) {
59
+ return new Framebuffer(gl, {
60
+ width: 1,
61
+ height: 1,
62
+ attachments: {
63
+ [GL.COLOR_ATTACHMENT0]: new Texture2D(gl, {
64
+ format: isWebGL2(gl) ? GL.RGBA32F : GL.RGBA,
65
+ type: GL.FLOAT,
66
+ mipmaps: false
67
+ })
68
+ }
69
+ });
70
+ }
71
+ return new Framebuffer(gl, {
72
+ width: 256,
73
+ height: 64,
74
+ depth: false
75
+ });
76
+ }
77
+ // Increments the counter based on dataFilter_value
78
+ export function getModel(gl, shaderOptions, useFloatTarget) {
79
+ shaderOptions.defines.NON_INSTANCED_MODEL = 1;
80
+ if (useFloatTarget) {
81
+ shaderOptions.defines.FLOAT_TARGET = 1;
82
+ }
83
+ return new Model(gl, {
84
+ id: 'data-filter-aggregation-model',
85
+ vertexCount: 1,
86
+ isInstanced: false,
87
+ drawMode: GL.POINTS,
88
+ vs: AGGREGATE_VS,
89
+ fs: AGGREGATE_FS,
90
+ ...shaderOptions
91
+ });
92
+ }
93
+ export const parameters = {
94
+ blend: true,
95
+ blendFunc: [GL.ONE, GL.ONE, GL.ONE, GL.ONE],
96
+ blendEquation: [GL.FUNC_ADD, GL.FUNC_ADD],
97
+ depthTest: false
98
+ };
@@ -1,32 +1,90 @@
1
- declare class DataFilterExtension extends LayerExtension {
2
- constructor({ filterSize, fp64, countItems }?: {
3
- filterSize?: number | undefined;
4
- fp64?: boolean | undefined;
5
- countItems?: boolean | undefined;
6
- });
7
- }
8
- declare namespace DataFilterExtension {
9
- export const extensionName: string;
10
- export { defaultProps };
11
- }
12
- export default DataFilterExtension;
13
1
  import { LayerExtension } from '@deck.gl/core/typed';
14
- declare namespace defaultProps {
15
- namespace getFilterValue {
16
- const type: string;
17
- const value: number;
18
- }
19
- namespace onFilteredItemsChange {
20
- const type_1: string;
21
- export { type_1 as type };
22
- const value_1: null;
23
- export { value_1 as value };
24
- export const compare: boolean;
25
- }
26
- const filterEnabled: boolean;
27
- const filterRange: number[];
28
- const filterSoftRange: null;
29
- const filterTransformSize: boolean;
30
- const filterTransformColor: boolean;
2
+ import type { Layer, LayerContext, Accessor, UpdateParameters } from '@deck.gl/core/typed';
3
+ export declare type DataFilterExtensionProps<DataT = any> = {
4
+ /**
5
+ * Accessor to retrieve the value for each object that it will be filtered by.
6
+ * Returns either a number (if `filterSize: 1`) or an array of numbers.
7
+ */
8
+ getFilterValue?: Accessor<DataT, number | number[]>;
9
+ /**
10
+ * Enable/disable the data filter. If the data filter is disabled, all objects are rendered.
11
+ * @default true
12
+ */
13
+ filterEnabled?: boolean;
14
+ /**
15
+ * The [min, max] bounds which defines whether an object should be rendered.
16
+ * If an object's filtered value is within the bounds, the object will be rendered; otherwise it will be hidden.
17
+ * @default [-1, 1]
18
+ */
19
+ filterRange?: [number, number] | [number, number][];
20
+ /**
21
+ * If specified, objects will be faded in/out instead of abruptly shown/hidden.
22
+ * When the filtered value is outside of the bounds defined by `filterSoftRange` but still within the bounds defined by `filterRange`, the object will be rendered as "faded."
23
+ * @default null
24
+ */
25
+ filterSoftRange?: [number, number] | [number, number][] | null;
26
+ /**
27
+ * When an object is "faded", manipulate its size so that it appears smaller or thinner. Only works if `filterSoftRange` is specified.
28
+ * @default true
29
+ */
30
+ filterTransformSize?: boolean;
31
+ /**
32
+ * When an object is "faded", manipulate its opacity so that it appears more translucent. Only works if `filterSoftRange` is specified.
33
+ * @default true
34
+ */
35
+ filterTransformColor?: boolean;
36
+ /**
37
+ * Only called if the `countItems` option is enabled.
38
+ */
39
+ onFilteredItemsChange?: (evt: {
40
+ /** The id of the source layer. */
41
+ id: string;
42
+ /** The number of data objects that pass the filter. */
43
+ count: number;
44
+ }) => void;
45
+ };
46
+ declare type DataFilterExtensionOptions = {
47
+ /**
48
+ * The size of the filter (number of columns to filter by). The data filter can show/hide data based on 1-4 numeric properties of each object.
49
+ * @default 1
50
+ */
51
+ filterSize: number;
52
+ /**
53
+ * Use 64-bit precision instead of 32-bit.
54
+ * @default false
55
+ */
56
+ fp64: boolean;
57
+ /**
58
+ * If `true`, reports the number of filtered objects with the `onFilteredItemsChange` callback.
59
+ * @default `false`.
60
+ */
61
+ countItems: boolean;
62
+ };
63
+ /** Adds GPU-based data filtering functionalities to layers. It allows the layer to show/hide objects based on user-defined properties. */
64
+ export default class DataFilterExtension extends LayerExtension<DataFilterExtensionOptions> {
65
+ static defaultProps: {
66
+ getFilterValue: {
67
+ type: string;
68
+ value: number;
69
+ };
70
+ onFilteredItemsChange: {
71
+ type: string;
72
+ value: null;
73
+ compare: boolean;
74
+ };
75
+ filterEnabled: boolean;
76
+ filterRange: number[];
77
+ filterSoftRange: null;
78
+ filterTransformSize: boolean;
79
+ filterTransformColor: boolean;
80
+ };
81
+ static extensionName: string;
82
+ constructor({ filterSize, fp64, countItems }?: Partial<DataFilterExtensionOptions>);
83
+ getShaders(this: Layer<DataFilterExtensionProps>, extension: this): any;
84
+ initializeState(this: Layer<DataFilterExtensionProps>, context: LayerContext, extension: this): void;
85
+ updateState(this: Layer<DataFilterExtensionProps>, { props, oldProps }: UpdateParameters<Layer<DataFilterExtensionProps>>): void;
86
+ draw(this: Layer<DataFilterExtensionProps>, params: any, extension: this): void;
87
+ finalizeState(this: Layer<DataFilterExtensionProps>): void;
31
88
  }
89
+ export {};
32
90
  //# sourceMappingURL=data-filter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"data-filter.d.ts","sourceRoot":"","sources":["../../src/data-filter/data-filter.js"],"names":[],"mappings":"AA4CA;IACE;;;;OAMC;CA6HF"}
1
+ {"version":3,"file":"data-filter.d.ts","sourceRoot":"","sources":["../../src/data-filter/data-filter.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAM7C,OAAO,KAAK,EAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAC,MAAM,eAAe,CAAC;AAanF,oBAAY,wBAAwB,CAAC,KAAK,GAAG,GAAG,IAAI;IAClD;;;OAGG;IACH,cAAc,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IACpD;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACpD;;;;OAIG;IACH,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC;IAC/D;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;OAEG;IACH,qBAAqB,CAAC,EAAE,CAAC,GAAG,EAAE;QAC5B,kCAAkC;QAClC,EAAE,EAAE,MAAM,CAAC;QACX,uDAAuD;QACvD,KAAK,EAAE,MAAM,CAAC;KACf,KAAK,IAAI,CAAC;CACZ,CAAC;AAEF,aAAK,0BAA0B,GAAG;IAChC;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,IAAI,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AASF,0IAA0I;AAC1I,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,cAAc,CAAC,0BAA0B,CAAC;IACzF,MAAM,CAAC,YAAY;;;;;;;;;;;;;;;MAAgB;IACnC,MAAM,CAAC,aAAa,SAAyB;gBAEjC,EACV,UAAc,EACd,IAAY,EACZ,UAAkB,EACnB,GAAE,OAAO,CAAC,0BAA0B,CAAM;IAQ3C,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,wBAAwB,CAAC,EAAE,SAAS,EAAE,IAAI,GAAG,GAAG;IAYvE,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,wBAAwB,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI;IAyD7F,WAAW,CACT,IAAI,EAAE,KAAK,CAAC,wBAAwB,CAAC,EACrC,EAAC,KAAK,EAAE,QAAQ,EAAC,EAAE,gBAAgB,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAgBtE,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,wBAAwB,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI;IAoCxE,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,wBAAwB,CAAC;CAQpD"}
@@ -0,0 +1,159 @@
1
+ // Copyright (c) 2015 - 2017 Uber Technologies, Inc.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in
11
+ // all copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ // THE SOFTWARE.
20
+ import { LayerExtension } from '@deck.gl/core';
21
+ import { shaderModule, shaderModule64 } from './shader-module';
22
+ import * as aggregator from './aggregator';
23
+ import { readPixelsToArray, clear } from '@luma.gl/core';
24
+ import GL from '@luma.gl/constants';
25
+ const defaultProps = {
26
+ getFilterValue: { type: 'accessor', value: 0 },
27
+ onFilteredItemsChange: { type: 'function', value: null, compare: false },
28
+ filterEnabled: true,
29
+ filterRange: [-1, 1],
30
+ filterSoftRange: null,
31
+ filterTransformSize: true,
32
+ filterTransformColor: true
33
+ };
34
+ const DATA_TYPE_FROM_SIZE = {
35
+ 1: 'float',
36
+ 2: 'vec2',
37
+ 3: 'vec3',
38
+ 4: 'vec4'
39
+ };
40
+ export default class DataFilterExtension extends LayerExtension {
41
+ constructor({ filterSize = 1, fp64 = false, countItems = false } = {}) {
42
+ if (!DATA_TYPE_FROM_SIZE[filterSize]) {
43
+ throw new Error('filterSize out of range');
44
+ }
45
+ super({ filterSize, fp64, countItems });
46
+ }
47
+ getShaders(extension) {
48
+ const { filterSize, fp64 } = extension.opts;
49
+ return {
50
+ modules: [fp64 ? shaderModule64 : shaderModule],
51
+ defines: {
52
+ DATAFILTER_TYPE: DATA_TYPE_FROM_SIZE[filterSize],
53
+ DATAFILTER_DOUBLE: Boolean(fp64)
54
+ }
55
+ };
56
+ }
57
+ initializeState(context, extension) {
58
+ const attributeManager = this.getAttributeManager();
59
+ if (attributeManager) {
60
+ attributeManager.add({
61
+ filterValues: {
62
+ size: extension.opts.filterSize,
63
+ type: extension.opts.fp64 ? GL.DOUBLE : GL.FLOAT,
64
+ accessor: 'getFilterValue',
65
+ shaderAttributes: {
66
+ filterValues: {
67
+ divisor: 0
68
+ },
69
+ instanceFilterValues: {
70
+ divisor: 1
71
+ }
72
+ }
73
+ }
74
+ });
75
+ }
76
+ const { gl } = this.context;
77
+ if (attributeManager && extension.opts.countItems) {
78
+ const useFloatTarget = aggregator.supportsFloatTarget(gl);
79
+ // This attribute is needed for variable-width data, e.g. Path, SolidPolygon, Text
80
+ // The vertex shader checks if a vertex has the same "index" as the previous vertex
81
+ // so that we only write one count cross multiple vertices of the same object
82
+ attributeManager.add({
83
+ filterIndices: {
84
+ size: useFloatTarget ? 1 : 2,
85
+ vertexOffset: 1,
86
+ type: GL.UNSIGNED_BYTE,
87
+ normalized: true,
88
+ accessor: (object, { index }) => {
89
+ const i = object && object.__source ? object.__source.index : index;
90
+ return useFloatTarget ? (i + 1) % 255 : [(i + 1) % 255, Math.floor(i / 255) % 255];
91
+ },
92
+ shaderAttributes: {
93
+ filterPrevIndices: {
94
+ vertexOffset: 0
95
+ },
96
+ filterIndices: {
97
+ vertexOffset: 1
98
+ }
99
+ }
100
+ }
101
+ });
102
+ const filterFBO = aggregator.getFramebuffer(gl, useFloatTarget);
103
+ const filterModel = aggregator.getModel(gl, extension.getShaders(extension), useFloatTarget);
104
+ this.setState({ filterFBO, filterModel });
105
+ }
106
+ }
107
+ updateState({ props, oldProps }) {
108
+ if (this.state.filterModel) {
109
+ const attributeManager = this.getAttributeManager();
110
+ const filterNeedsUpdate = attributeManager.attributes.filterValues.needsUpdate() ||
111
+ props.filterEnabled !== oldProps.filterEnabled ||
112
+ props.filterRange !== oldProps.filterRange ||
113
+ props.filterSoftRange !== oldProps.filterSoftRange;
114
+ if (filterNeedsUpdate) {
115
+ this.setState({ filterNeedsUpdate });
116
+ }
117
+ }
118
+ }
119
+ draw(params, extension) {
120
+ const { filterFBO, filterModel, filterNeedsUpdate } = this.state;
121
+ const { onFilteredItemsChange } = this.props;
122
+ if (filterNeedsUpdate && onFilteredItemsChange && filterModel) {
123
+ const { attributes: { filterValues, filterIndices } } = this.getAttributeManager();
124
+ filterModel.setVertexCount(this.getNumInstances());
125
+ const { gl } = this.context;
126
+ clear(gl, { framebuffer: filterFBO, color: [0, 0, 0, 0] });
127
+ filterModel
128
+ .updateModuleSettings(params.moduleParameters)
129
+ .setAttributes({
130
+ ...filterValues.getShaderAttributes(),
131
+ ...(filterIndices && filterIndices.getShaderAttributes())
132
+ })
133
+ .draw({
134
+ framebuffer: filterFBO,
135
+ parameters: {
136
+ ...aggregator.parameters,
137
+ viewport: [0, 0, filterFBO.width, filterFBO.height]
138
+ }
139
+ });
140
+ const color = readPixelsToArray(filterFBO);
141
+ let count = 0;
142
+ for (let i = 0; i < color.length; i++) {
143
+ count += color[i];
144
+ }
145
+ onFilteredItemsChange({ id: this.id, count });
146
+ this.state.filterNeedsUpdate = false;
147
+ }
148
+ }
149
+ finalizeState() {
150
+ const { filterFBO, filterModel } = this.state;
151
+ if (filterFBO) {
152
+ filterFBO.color.delete();
153
+ filterFBO.delete();
154
+ filterModel.delete();
155
+ }
156
+ }
157
+ }
158
+ DataFilterExtension.extensionName = 'DataFilterExtension';
159
+ DataFilterExtension.defaultProps = defaultProps;
@@ -1,26 +1,9 @@
1
- export namespace shaderModule {
2
- export const name: string;
3
- export { vs };
4
- export { fs };
5
- export { inject };
6
- export { getUniforms };
7
- }
8
- export namespace shaderModule64 {
9
- const name_1: string;
10
- export { name_1 as name };
11
- export { vs };
12
- export { fs };
13
- export { inject };
14
- export { getUniforms64 as getUniforms };
15
- }
16
- declare const vs: "\nuniform DATAFILTER_TYPE filter_min;\nuniform DATAFILTER_TYPE filter_softMin;\nuniform DATAFILTER_TYPE filter_softMax;\nuniform DATAFILTER_TYPE filter_max;\nuniform bool filter_useSoftMargin;\nuniform bool filter_enabled;\nuniform bool filter_transformSize;\n\n#ifdef NON_INSTANCED_MODEL\n #define DATAFILTER_ATTRIB filterValues\n #define DATAFILTER_ATTRIB_64LOW filterValues64Low\n#else\n #define DATAFILTER_ATTRIB instanceFilterValues\n #define DATAFILTER_ATTRIB_64LOW instanceFilterValues64Low\n#endif\n\nattribute DATAFILTER_TYPE DATAFILTER_ATTRIB;\n#ifdef DATAFILTER_DOUBLE\n attribute DATAFILTER_TYPE DATAFILTER_ATTRIB_64LOW;\n\n uniform DATAFILTER_TYPE filter_min64High;\n uniform DATAFILTER_TYPE filter_max64High;\n#endif\n\nvarying float dataFilter_value;\n\nfloat dataFilter_reduceValue(float value) {\n return value;\n}\nfloat dataFilter_reduceValue(vec2 value) {\n return min(value.x, value.y);\n}\nfloat dataFilter_reduceValue(vec3 value) {\n return min(min(value.x, value.y), value.z);\n}\nfloat dataFilter_reduceValue(vec4 value) {\n return min(min(value.x, value.y), min(value.z, value.w));\n}\nvoid dataFilter_setValue(DATAFILTER_TYPE valueFromMin, DATAFILTER_TYPE valueFromMax) {\n if (filter_enabled) {\n if (filter_useSoftMargin) {\n dataFilter_value = dataFilter_reduceValue(\n smoothstep(filter_min, filter_softMin, valueFromMin) *\n (1.0 - smoothstep(filter_softMax, filter_max, valueFromMax))\n );\n } else {\n dataFilter_value = dataFilter_reduceValue(\n step(filter_min, valueFromMin) * step(valueFromMax, filter_max)\n );\n }\n } else {\n dataFilter_value = 1.0;\n }\n}\n";
17
- declare const fs: "\nuniform bool filter_transformColor;\nvarying float dataFilter_value;\n";
18
- declare const inject: {
19
- 'vs:#main-start': string;
20
- 'vs:DECKGL_FILTER_SIZE': string;
21
- 'fs:DECKGL_FILTER_COLOR': string;
22
- };
23
- declare function getUniforms(opts: any): {};
24
- declare function getUniforms64(opts: any): {};
1
+ import { _ShaderModule as ShaderModule } from '@deck.gl/core/typed';
2
+ import type { DataFilterExtensionProps } from './data-filter';
3
+ declare type DataFilterModuleSettings = {
4
+ extensions: any[];
5
+ } & DataFilterExtensionProps;
6
+ export declare const shaderModule: ShaderModule<DataFilterModuleSettings>;
7
+ export declare const shaderModule64: ShaderModule<DataFilterModuleSettings>;
25
8
  export {};
26
9
  //# sourceMappingURL=shader-module.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shader-module.d.ts","sourceRoot":"","sources":["../../src/data-filter/shader-module.js"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,upDAuDE;AAEF,6FAGE;AAgEF;;;;EAwBE;AAtFF,4CA+BC;AAED,8CA2BC"}
1
+ {"version":3,"file":"shader-module.d.ts","sourceRoot":"","sources":["../../src/data-filter/shader-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,IAAI,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAElE,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,eAAe,CAAC;AAmE5D,aAAK,wBAAwB,GAAG;IAC9B,UAAU,EAAE,GAAG,EAAE,CAAC;CACnB,GAAG,wBAAwB,CAAC;AA2F7B,eAAO,MAAM,YAAY,EAAE,YAAY,CAAC,wBAAwB,CAM/D,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,YAAY,CAAC,wBAAwB,CAMjE,CAAC"}