Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress committed Aug 22, 2024
1 parent a218340 commit c8cfba4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type AggregationProps = {
/** Additional options to control bin sorting, e.g. bin size */
binOptions: Record<string, number | number[]>;
/** Callback after a channel is updated */
onUpdate?: (channel: number) => void;
onUpdate?: (event: {channel: number}) => void;
};

/** Descriptor of an aggregated bin */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class CPUAggregator implements Aggregator {
target: this.results[channel]?.value
});
this.results[channel] = {value, domain, type: 'float32', size: 1};
this.props.onUpdate?.(channel);
this.props.onUpdate?.({channel});
}
}
this.needsUpdate = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class WebGLAggregator implements Aggregator {
for (let i = 0; i < this.channelCount; i++) {
if (this.needsUpdate[i]) {
this.needsUpdate[i] = false;
this.props.onUpdate?.(i);
this.props.onUpdate?.({channel: i});
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export default `#version 300 es
// deck.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

export default /* glsl */ `#version 300 es
#define SHADER_NAME grid-cell-layer-vertex-shader
Expand Down
22 changes: 3 additions & 19 deletions modules/aggregation-layers/src/grid-layer/grid-cell-layer.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
// Copyright (c) 2015 - 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// deck.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import {Texture} from '@luma.gl/core';
import {UpdateParameters, Color} from '@deck.gl/core';
Expand Down
23 changes: 20 additions & 3 deletions modules/aggregation-layers/src/grid-layer/grid-layer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// deck.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import {
Accessor,
Color,
Expand Down Expand Up @@ -57,6 +61,7 @@ const defaultProps: DefaultProps<GridLayerProps> = {
cellSize: {type: 'number', min: 0, max: 1000, value: 1000},
coverage: {type: 'number', min: 0, max: 1, value: 1},
getPosition: {type: 'accessor', value: (x: any) => x.position},
gridAggregator: {type: 'function', optional: true, value: null},
extruded: false,

// Optional material for 'lighting' shader module
Expand All @@ -68,6 +73,11 @@ export type GridLayerProps<DataT = unknown> = _GridLayerProps<DataT> & Composite

/** Properties added by GridLayer. */
type _GridLayerProps<DataT> = {
/**
* Accessor to retrieve a grid bin index from each data object.
*/
gridAggregator?: ((position: number[], cellSize: number) => [number, number]) | null;

/**
* Size of each cell in meters.
* @default 1000
Expand Down Expand Up @@ -271,6 +281,7 @@ export default class GridLayer<DataT = any, ExtraPropsT extends {} = {}> extends
getAggregatorType(): string {
const {
gpuAggregation,
gridAggregator,
// lowerPercentile,
// upperPercentile,
getColorValue,
Expand All @@ -282,6 +293,8 @@ export default class GridLayer<DataT = any, ExtraPropsT extends {} = {}> extends
gpuAggregation &&
// GPU aggregation is supported by the device
WebGLAggregator.isSupported(this.context.device) &&
// Default grid
!gridAggregator &&
// Does not need custom aggregation operation
!getColorValue &&
!getElevationValue
Expand All @@ -298,6 +311,7 @@ export default class GridLayer<DataT = any, ExtraPropsT extends {} = {}> extends

createAggregator(type: string): WebGLAggregator | CPUAggregator {
if (type === 'cpu') {
const {gridAggregator, cellSize} = this.props;
return new CPUAggregator({
dimensions: 2,
getBin: {
Expand All @@ -310,6 +324,9 @@ export default class GridLayer<DataT = any, ExtraPropsT extends {} = {}> extends
cellOriginCommon: [number, number];
}
) => {
if (gridAggregator) {
return gridAggregator(positions, cellSize);
}
const viewport = this.state.aggregatorViewport;
// project to common space
const p = viewport.projectPosition(positions);
Expand All @@ -332,7 +349,7 @@ export default class GridLayer<DataT = any, ExtraPropsT extends {} = {}> extends
bufferLayout: this.getAttributeManager()!.getBufferLayouts({isInstanced: false}),
...super.getShaders({
modules: [project32],
vs: `
vs: /* glsl */ `
uniform vec2 cellOriginCommon;
uniform vec2 cellSizeCommon;
in vec3 positions;
Expand Down Expand Up @@ -458,7 +475,7 @@ export default class GridLayer<DataT = any, ExtraPropsT extends {} = {}> extends
const centroidCommon = viewport.projectFlat(centroid);
cellOriginCommon = [
Math.floor(centroidCommon[0] / cellSizeCommon[0]) * cellSizeCommon[0],
Math.floor(centroidCommon[1] / cellSizeCommon[1]) * cellSizeCommon[1],
Math.floor(centroidCommon[1] / cellSizeCommon[1]) * cellSizeCommon[1]
];
centroid = viewport.unprojectFlat(cellOriginCommon);

Expand Down Expand Up @@ -501,7 +518,7 @@ export default class GridLayer<DataT = any, ExtraPropsT extends {} = {}> extends
super.draw(opts);
}

private _onAggregationUpdate(channel: number) {
private _onAggregationUpdate({channel}: {channel: number}) {
const props = this.getCurrentLayer()!.props;
const {aggregator} = this.state;
if (channel === 0) {
Expand Down

0 comments on commit c8cfba4

Please sign in to comment.