/
heatmap-layer.spec.js
220 lines (203 loc) · 7.61 KB
/
heatmap-layer.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// Copyright (c) 2015 - 2017 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 * as FIXTURES from 'deck.gl-test/data';
import {testLayer, testInitializeLayer, generateLayerTests} from '@deck.gl/test-utils';
import {MapView} from '@deck.gl/core';
import {HeatmapLayer} from '@deck.gl/aggregation-layers';
import {default as TriangleLayer} from '@deck.gl/aggregation-layers/heatmap-layer/triangle-layer';
const getPosition = d => d.COORDINATES;
const viewport1 = new MapView().makeViewport({
width: 100,
height: 100,
viewState: {longitude: 0, latitude: 10, zoom: 10}
});
const viewport2_slightChange = new MapView().makeViewport({
width: 100,
height: 100,
viewState: {longitude: 0.01, latitude: 10, zoom: 10}
});
const viewport3_bigChange = new MapView().makeViewport({
width: 100,
height: 100,
viewState: {longitude: 10, latitude: 0, zoom: 10}
});
const viewport4_zoomChange = new MapView().makeViewport({
width: 100,
height: 100,
viewState: {longitude: 10, latitude: 0, zoom: 9}
});
test('HeatmapLayer', t => {
const testCases = generateLayerTests({
Layer: HeatmapLayer,
sampleProps: {
data: FIXTURES.points.slice(0, 3),
getPosition
},
assert: t.ok,
onBeforeUpdate: ({testCase}) => t.comment(testCase.title),
onAfterUpdate({layer}) {
t.ok(layer.state.worldBounds, 'should update state.worldBounds');
}
});
testLayer({Layer: HeatmapLayer, testCases, onError: t.notOk});
t.end();
});
test('HeatmapLayer#renderSubLayer', t => {
const layer = new HeatmapLayer({
id: 'contourLayer',
data: FIXTURES.points,
getPosition
});
testInitializeLayer({layer, onError: t.notOk});
// render sublayer
const subLayer = layer.renderLayers();
testInitializeLayer({layer: subLayer, onError: t.notOk});
t.ok(subLayer instanceof TriangleLayer, 'Sublayer Triangle layer rendered');
t.end();
});
test('HeatmapLayer#updates', t => {
testLayer({
Layer: HeatmapLayer,
onError: t.notOk,
testCases: [
{
props: {
data: FIXTURES.points,
getPosition,
pickable: false
},
onAfterUpdate({layer}) {
const {worldBounds, commonBounds} = layer.state;
t.ok(worldBounds, 'should compute worldBounds');
t.ok(commonBounds, 'should compute commonBounds');
}
},
{
updateProps: {
colorRange: HeatmapLayer.defaultProps.colorRange.slice()
},
spies: ['_updateColorTexture', '_updateBounds'],
onAfterUpdate({layer, subLayers, spies}) {
t.ok(subLayers.length === 1, 'Sublayer rendered');
t.ok(spies._updateColorTexture.called, 'should update color texture');
t.notOk(
spies._updateBounds.called,
'viewport not changed, should not call _updateBounds'
);
spies._updateColorTexture.restore();
spies._updateBounds.restore();
}
},
{
viewport: viewport1, // viewport changed
spies: [
'_updateColorTexture',
'_updateBounds',
'_updateWeightmapAttributes',
'_updateWeightmap',
'_updateTextureRenderingBounds'
],
onAfterUpdate({layer, subLayers, spies}) {
const {zoom} = layer.state;
t.notOk(spies._updateColorTexture.called, 'should not update color texture');
t.ok(spies._updateBounds.called, 'viewport changed, should call _updateBounds');
t.notOk(
spies._updateWeightmapAttributes.called,
'data not changed, should not call _updateWeightmapAttributes'
);
t.ok(spies._updateWeightmap.called, 'boundsChanged changed, should _updateWeightmap');
t.ok(
spies._updateTextureRenderingBounds.called,
'vieport changed, should call _updateTextureRenderingBounds'
);
t.equal(zoom, viewport1.zoom, 'should update state.zoom');
spies._updateColorTexture.restore();
spies._updateBounds.restore();
spies._updateWeightmapAttributes.restore();
spies._updateWeightmap.restore();
spies._updateTextureRenderingBounds.restore();
}
},
{
viewport: viewport2_slightChange, // panned slightly, no zoom change
spies: ['_updateBounds', '_updateWeightmap', '_updateTextureRenderingBounds'],
onAfterUpdate({layer, subLayers, spies}) {
t.ok(spies._updateBounds.called, 'viewport changed slightly, should call _updateBounds');
t.notOk(
spies._updateWeightmap.called,
'viewport changed slightly, should not call _updateWeightmap'
);
t.ok(
spies._updateTextureRenderingBounds.called,
'viewport changed slightly, should call _updateTextureRenderingBounds'
);
spies._updateBounds.restore();
spies._updateWeightmap.restore();
spies._updateTextureRenderingBounds.restore();
}
},
{
viewport: viewport3_bigChange, // panned too far, no zoom change
spies: ['_updateBounds', '_updateWeightmap'],
onAfterUpdate({layer, subLayers, spies}) {
t.ok(spies._updateBounds.called, 'viewport panned too far, should call _updateBounds');
t.ok(
spies._updateWeightmap.called,
'viewport panned too far, should call _updateWeightmap'
);
spies._updateBounds.restore();
spies._updateWeightmap.restore();
}
},
{
viewport: viewport4_zoomChange, // only zoom change
spies: ['_updateBounds', '_updateWeightmap'],
onAfterUpdate({layer, subLayers, spies}) {
const {zoom} = layer.state;
t.ok(spies._updateBounds.called, 'viewport zoom changed, should call _updateBounds');
t.ok(
spies._updateWeightmap.called,
'viewport zoom changed, should call _updateWeightmap'
);
spies._updateBounds.restore();
spies._updateWeightmap.restore();
t.equal(
zoom,
viewport4_zoomChange.zoom,
'viewport zoom changed, should update state.zoom'
);
}
},
{
updateProps: {
radiusPixels: 2.123 // change from default value (30)
},
viewport: viewport4_zoomChange, // keep the same viewport
spies: ['_updateWeightmap'],
onAfterUpdate({layer, subLayers, spies}) {
t.ok(spies._updateWeightmap.called, 'should update weight map on uniform change');
spies._updateWeightmap.restore();
}
}
]
});
t.end();
});