Skip to content

Commit

Permalink
Merge 6b3f882 into 89aa08d
Browse files Browse the repository at this point in the history
  • Loading branch information
1chandu committed Nov 12, 2019
2 parents 89aa08d + 6b3f882 commit e9592df
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 38 deletions.
2 changes: 1 addition & 1 deletion modules/aggregation-layers/src/aggregation-layer.js
Expand Up @@ -84,7 +84,7 @@ export default class AggregationLayer extends CompositeLayer {
}

_isAggregationDirty(opts) {
if (this.state.dataChanged) {
if (this.state.dataChanged || opts.changeFlags.extensionsChanged) {
return true;
}
const {aggregationProps} = this.state;
Expand Down
Expand Up @@ -71,17 +71,17 @@ export default class ScreenGridLayer extends GridAggregationLayer {
return this.state.supported && changeFlags.somethingChanged;
}

updateState({oldProps, props, changeFlags}) {
super.updateState({oldProps, props, changeFlags});
updateState(opts) {
super.updateState(opts);

const cellSizeChanged = props.cellSizePixels !== oldProps.cellSizePixels;
const dataChanged = this._isAggregationDirty({oldProps, props});
const cellSizeChanged = opts.props.cellSizePixels !== opts.oldProps.cellSizePixels;
const dataChanged = this._isAggregationDirty(opts);
const {viewportChanged} = opts.changeFlags;

if (cellSizeChanged || changeFlags.viewportChanged) {
if (cellSizeChanged || viewportChanged) {
this._updateGridParams();
}

const {viewportChanged} = changeFlags;
if (dataChanged || cellSizeChanged || viewportChanged) {
this._updateAggregation({
dataChanged,
Expand Down
62 changes: 31 additions & 31 deletions modules/core/src/lib/composite-layer.js
Expand Up @@ -118,7 +118,7 @@ export default class CompositeLayer extends Layer {
}

// Returns sub layer props for a specific sublayer
getSubLayerProps(sublayerProps) {
getSubLayerProps(sublayerProps = {}) {
const {
opacity,
pickable,
Expand Down Expand Up @@ -153,40 +153,40 @@ export default class CompositeLayer extends Layer {
extensions
};

if (sublayerProps) {
const overridingSublayerProps = overridingProps && overridingProps[sublayerProps.id];
const overridingSublayerTriggers =
overridingSublayerProps && overridingSublayerProps.updateTriggers;

if (overridingSublayerProps) {
const propTypes = this.constructor._propTypes;
for (const key in overridingSublayerProps) {
const propType = propTypes[key];
// eslint-disable-next-line
if (propType && propType.type === 'accessor') {
overridingSublayerProps[key] = this.getSubLayerAccessor(overridingSublayerProps[key]);
}
const overridingSublayerProps =
overridingProps && sublayerProps.id && overridingProps[sublayerProps.id];
const overridingSublayerTriggers =
overridingSublayerProps && overridingSublayerProps.updateTriggers;
const sublayerId = sublayerProps.id || 'sublayer';

if (overridingSublayerProps) {
const propTypes = this.constructor._propTypes;
for (const key in overridingSublayerProps) {
const propType = propTypes[key];
// eslint-disable-next-line
if (propType && propType.type === 'accessor') {
overridingSublayerProps[key] = this.getSubLayerAccessor(overridingSublayerProps[key]);
}
}

Object.assign(
newProps,
sublayerProps,
// experimental feature that allows users to override sublayer props via parent layer prop
overridingSublayerProps,
{
id: `${this.props.id}-${sublayerProps.id}`,
updateTriggers: Object.assign(
{
all: this.props.updateTriggers.all
},
sublayerProps.updateTriggers,
overridingSublayerTriggers
)
}
);
}

Object.assign(
newProps,
sublayerProps,
// experimental feature that allows users to override sublayer props via parent layer prop
overridingSublayerProps,
{
id: `${this.props.id}-${sublayerId}`,
updateTriggers: Object.assign(
{
all: this.props.updateTriggers.all
},
sublayerProps.updateTriggers,
overridingSublayerTriggers
)
}
);

// Pass through extension props
for (const extension of extensions) {
const passThroughProps = extension.getSubLayerProps.call(this, extension);
Expand Down
149 changes: 149 additions & 0 deletions test/modules/aggregation-layers/aggregation-layer.spec.js
@@ -0,0 +1,149 @@
// 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.

import test from 'tape-catch';
import AggregationLayer from '@deck.gl/aggregation-layers/aggregation-layer';
import {Layer} from 'deck.gl';
import {DataFilterExtension} from '@deck.gl/extensions';
import {testLayer} from '@deck.gl/test-utils';

const BASE_LAYER_ID = 'composite-layer-id';
const PROPS = {
cellSize: 10,
prop1: 5
};

class TestLayer extends Layer {
initializeState() {}
}

TestLayer.layerName = 'TestLayer';

const AGGREGATION_PROPS = ['cellSize'];

class TestAggregationLayer extends AggregationLayer {
initializeState() {
super.initializeState(AGGREGATION_PROPS);
}

renderLayers() {
return [
new TestLayer(this.getSubLayerProps(), {
scale: this.state.scale
})
];
}

updateState(opts) {
// clear state
this.setState({aggregationDirty: false});
super.updateState(opts);
this.setState({aggregationDirty: this._isAggregationDirty(opts)});
}
_updateShaders(shaderOptions) {}
//
// updateAttributes(changedAttributes) {}
}

TestAggregationLayer.layerName = 'TestAggregationLayer';

test('AggregationLayer#constructor', t => {
const layer = new TestAggregationLayer(Object.assign({id: BASE_LAYER_ID}, PROPS));
t.ok(layer, 'AggregationLayer created');
t.end();
});

test('AggregationLayer#updateState', t => {
testLayer({
Layer: TestAggregationLayer,
onError: t.notOk,
testCases: [
{
props: {
data: [0, 1],
cellSize: 400,
prop1: 10
},
onAfterUpdate({layer}) {
t.ok(layer.getAttributeManager(), 'should create AttributeManager');
t.ok(layer.state.aggregationDirty, 'Aggregation should be dirty on the first update');
}
},
{
updateProps: {
prop1: 20
},
spies: ['_updateShaders', 'updateAttributes'],
onAfterUpdate({spies, layer}) {
t.ok(spies.updateAttributes.called, 'should always call updateAttributes');
t.notOk(
spies._updateShaders.called,
'should not call _updateShaders when extensions not changed'
);
t.notOk(layer.state.aggregationDirty, 'Aggregation should not be dirty');
}
},
{
updateProps: {
cellSize: 21
},
spies: ['_updateShaders', 'updateAttributes'],
onAfterUpdate({layer}) {
t.ok(
layer.state.aggregationDirty,
'Aggregation should be dirty when an aggregation prop is changed'
);
}
},
{
updateProps: {
extensions: [new DataFilterExtension({filterSize: 2})] // default value is true
},
spies: ['_updateShaders'],
onAfterUpdate({spies, layer}) {
t.ok(spies._updateShaders.called, 'should call _updateShaders when extensions changed');
t.ok(layer.state.aggregationDirty, 'Aggregation should be dirty when extensions changed');
}
},
{
updateProps: {
extensions: [new DataFilterExtension({filterSize: 2})]
},
spies: ['updateState'],
onAfterUpdate({spies, layer}) {
t.notOk(spies.updateState.called, 'should not call updateState nothing changed');
}
},
{
updateProps: {
filterEnabled: false // default true earlier
},
onAfterUpdate({layer}) {
t.ok(
layer.state.aggregationDirty,
'Aggregation should not be dirty when extension prop is changed'
);
}
}
]
});

t.end();
});
1 change: 1 addition & 0 deletions test/modules/aggregation-layers/index.js
Expand Up @@ -34,3 +34,4 @@ import './utils/color-utils.spec';
import './utils/aggregation-operation-utils.spec';
import './heatmap-layer/heatmap-layer-utils.spec';
import './screengrid-cell-layer.spec';
import './aggregation-layer.spec';

0 comments on commit e9592df

Please sign in to comment.