Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

uber / deck.gl / 13074

28 Aug 2019 - 0:36 coverage decreased (-2.5%) to 80.994%
13074

Pull #3496

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
use timeline
Pull Request #3496: Transition system refactor (1/2): use timeline

3394 of 4574 branches covered (74.2%)

Branch coverage included in aggregate %.

54 of 58 new or added lines in 9 files covered. (93.1%)

818 existing lines in 101 files now uncovered.

6953 of 8201 relevant lines covered (84.78%)

4628.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.54
/modules/layers/src/geojson-layer/geojson-layer.js
1
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
10×
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

21
import {CompositeLayer} from '@deck.gl/core';
22
import ScatterplotLayer from '../scatterplot-layer/scatterplot-layer';
23
import PathLayer from '../path-layer/path-layer';
24
import {PhongMaterial} from '@luma.gl/core';
25
// Use primitive layer to avoid "Composite Composite" layers for now
26
import SolidPolygonLayer from '../solid-polygon-layer/solid-polygon-layer';
27
import {replaceInRange} from '../utils';
28

29
import {getGeojsonFeatures, separateGeojsonFeatures} from './geojson';
30

31
const defaultLineColor = [0, 0, 0, 255];
1×
32
const defaultFillColor = [0, 0, 0, 255];
1×
33
const defaultMaterial = new PhongMaterial();
1×
34

35
const defaultProps = {
1×
36
  stroked: true,
37
  filled: true,
38
  extruded: false,
39
  wireframe: false,
40

41
  lineWidthUnits: 'meters',
42
  lineWidthScale: 1,
43
  lineWidthMinPixels: 0,
44
  lineWidthMaxPixels: Number.MAX_SAFE_INTEGER,
45
  lineJointRounded: false,
46
  lineMiterLimit: 4,
47

48
  elevationScale: 1,
49

50
  pointRadiusScale: 1,
51
  pointRadiusMinPixels: 0, //  min point radius in pixels
52
  pointRadiusMaxPixels: Number.MAX_SAFE_INTEGER, // max point radius in pixels
53

54
  lineDashJustified: false,
55

56
  // Line and polygon outline color
57
  getLineColor: {type: 'accessor', value: defaultLineColor},
58
  // Point and polygon fill color
59
  getFillColor: {type: 'accessor', value: defaultFillColor},
60
  // Point radius
61
  getRadius: {type: 'accessor', value: 1},
62
  // Line and polygon outline accessors
63
  getLineWidth: {type: 'accessor', value: 1},
64
  // Line dash array accessor
65
  getLineDashArray: {type: 'accessor', value: [0, 0]},
66
  // Polygon extrusion accessor
67
  getElevation: {type: 'accessor', value: 1000},
68
  // Optional material for 'lighting' shader module
69
  material: defaultMaterial
70
};
71

72
function getCoordinates(f) {
73
  return f.geometry.coordinates;
111×
74
}
75

76
export default class GeoJsonLayer extends CompositeLayer {
77
  initializeState() {
78
    this.state = {
7×
79
      features: {}
80
    };
81
  }
82

83
  updateState({props, changeFlags}) {
84
    if (!changeFlags.dataChanged) {
34×
85
      return;
25×
86
    }
87
    const features = getGeojsonFeatures(props.data);
9×
88
    const wrapFeature = this.getSubLayerRow.bind(this);
9×
89

90
    if (Array.isArray(changeFlags.dataChanged)) {
9×
91
      const oldFeatures = this.state.features;
1×
92
      const newFeatures = {};
1×
93
      const featuresDiff = {};
1×
94
      for (const key in oldFeatures) {
1×
95
        newFeatures[key] = oldFeatures[key].slice();
4×
96
        featuresDiff[key] = [];
4×
97
      }
98

99
      for (const dataRange of changeFlags.dataChanged) {
1×
100
        const partialFeatures = separateGeojsonFeatures(features, wrapFeature, dataRange);
1×
101
        for (const key in oldFeatures) {
1×
102
          featuresDiff[key].push(
4×
103
            replaceInRange({
104
              data: newFeatures[key],
105
              getIndex: f => f.__source.index,
8×
106
              dataRange,
107
              replace: partialFeatures[key]
108
            })
109
          );
110
        }
111
      }
112
      this.setState({features: newFeatures, featuresDiff});
1×
113
    } else {
114
      this.setState({
8×
115
        features: separateGeojsonFeatures(features, wrapFeature),
116
        featuresDiff: {}
117
      });
118
    }
119
  }
120

121
  /* eslint-disable complexity */
122
  renderLayers() {
123
    const {features, featuresDiff} = this.state;
34×
124
    const {pointFeatures, lineFeatures, polygonFeatures, polygonOutlineFeatures} = features;
34×
125

126
    // Layer composition props
127
    const {stroked, filled, extruded, wireframe, material, transitions} = this.props;
34×
128

129
    // Rendering props underlying layer
130
    const {
131
      lineWidthUnits,
132
      lineWidthScale,
133
      lineWidthMinPixels,
134
      lineWidthMaxPixels,
135
      lineJointRounded,
136
      lineMiterLimit,
137
      pointRadiusScale,
138
      pointRadiusMinPixels,
139
      pointRadiusMaxPixels,
140
      elevationScale,
141
      lineDashJustified
142
    } = this.props;
34×
143

144
    // Accessor props for underlying layers
145
    const {
146
      getLineColor,
147
      getFillColor,
148
      getRadius,
149
      getLineWidth,
150
      getLineDashArray,
151
      getElevation,
152
      updateTriggers
153
    } = this.props;
34×
154

155
    const PolygonFillLayer = this.getSubLayerClass('polygons-fill', SolidPolygonLayer);
34×
156
    const PolygonStrokeLayer = this.getSubLayerClass('polygons-stroke', PathLayer);
34×
157
    const LineStringsLayer = this.getSubLayerClass('line-strings', PathLayer);
34×
158
    const PointsLayer = this.getSubLayerClass('points', ScatterplotLayer);
34×
159

160
    // Filled Polygon Layer
161
    const polygonFillLayer =
162
      this.shouldRenderSubLayer('polygons-fill', polygonFeatures) &&
34×
163
      new PolygonFillLayer(
164
        {
165
          _dataDiff: featuresDiff.polygonFeatures && (() => featuresDiff.polygonFeatures),
1×
166

167
          extruded,
168
          elevationScale,
169
          filled,
170
          wireframe,
171
          material,
172
          getElevation: this.getSubLayerAccessor(getElevation),
173
          getFillColor: this.getSubLayerAccessor(getFillColor),
174
          getLineColor: this.getSubLayerAccessor(getLineColor),
175

176
          transitions: transitions && {
Branches [[4, 1]] missed.
177
            getPolygon: transitions.geometry,
178
            getElevation: transitions.getElevation,
179
            getFillColor: transitions.getFillColor,
180
            getLineColor: transitions.getLineColor
181
          }
182
        },
183
        this.getSubLayerProps({
184
          id: 'polygons-fill',
185
          updateTriggers: {
186
            getElevation: updateTriggers.getElevation,
187
            getFillColor: updateTriggers.getFillColor,
188
            getLineColor: updateTriggers.getLineColor
189
          }
190
        }),
191
        {
192
          data: polygonFeatures,
193
          getPolygon: getCoordinates
194
        }
195
      );
196

197
    const polygonLineLayer =
198
      !extruded &&
34×
199
      stroked &&
200
      this.shouldRenderSubLayer('polygons-stroke', polygonOutlineFeatures) &&
201
      new PolygonStrokeLayer(
202
        {
203
          _dataDiff:
UNCOV
204
            featuresDiff.polygonOutlineFeatures && (() => featuresDiff.polygonOutlineFeatures),
Branches [[6, 1]] missed. !
205

206
          widthUnits: lineWidthUnits,
207
          widthScale: lineWidthScale,
208
          widthMinPixels: lineWidthMinPixels,
209
          widthMaxPixels: lineWidthMaxPixels,
210
          rounded: lineJointRounded,
211
          miterLimit: lineMiterLimit,
212
          dashJustified: lineDashJustified,
213

214
          getColor: this.getSubLayerAccessor(getLineColor),
215
          getWidth: this.getSubLayerAccessor(getLineWidth),
216
          getDashArray: this.getSubLayerAccessor(getLineDashArray),
217

218
          transitions: transitions && {
Branches [[7, 1]] missed.
219
            getPath: transitions.geometry,
220
            getColor: transitions.getLineColor,
221
            getWidth: transitions.getLineWidth
222
          }
223
        },
224
        this.getSubLayerProps({
225
          id: 'polygons-stroke',
226
          updateTriggers: {
227
            getColor: updateTriggers.getLineColor,
228
            getWidth: updateTriggers.getLineWidth,
229
            getDashArray: updateTriggers.getLineDashArray
230
          }
231
        }),
232
        {
233
          data: polygonOutlineFeatures,
234
          getPath: getCoordinates
235
        }
236
      );
237

238
    const pathLayer =
239
      this.shouldRenderSubLayer('linestrings', lineFeatures) &&
Branches [[8, 1]] missed. 34×
240
      new LineStringsLayer(
241
        {
UNCOV
242
          _dataDiff: featuresDiff.lineFeatures && (() => featuresDiff.lineFeatures),
Branches [[9, 0], [9, 1]] missed. !
243

244
          widthUnits: lineWidthUnits,
245
          widthScale: lineWidthScale,
246
          widthMinPixels: lineWidthMinPixels,
247
          widthMaxPixels: lineWidthMaxPixels,
248
          rounded: lineJointRounded,
249
          miterLimit: lineMiterLimit,
250
          dashJustified: lineDashJustified,
251

252
          getColor: this.getSubLayerAccessor(getLineColor),
253
          getWidth: this.getSubLayerAccessor(getLineWidth),
254
          getDashArray: this.getSubLayerAccessor(getLineDashArray),
255

256
          transitions: transitions && {
Branches [[10, 0], [10, 1]] missed.
257
            getPath: transitions.geometry,
258
            getColor: transitions.getLineColor,
259
            getWidth: transitions.getLineWidth
260
          }
261
        },
262
        this.getSubLayerProps({
263
          id: 'line-strings',
264
          updateTriggers: {
265
            getColor: updateTriggers.getLineColor,
266
            getWidth: updateTriggers.getLineWidth,
267
            getDashArray: updateTriggers.getLineDashArray
268
          }
269
        }),
270
        {
271
          data: lineFeatures,
272
          getPath: getCoordinates
273
        }
274
      );
275

276
    const pointLayer =
277
      this.shouldRenderSubLayer('points', pointFeatures) &&
34×
278
      new PointsLayer(
279
        {
UNCOV
280
          _dataDiff: featuresDiff.pointFeatures && (() => featuresDiff.pointFeatures),
Branches [[12, 1]] missed. !
281

282
          stroked,
283
          filled,
284
          radiusScale: pointRadiusScale,
285
          radiusMinPixels: pointRadiusMinPixels,
286
          radiusMaxPixels: pointRadiusMaxPixels,
287
          lineWidthUnits,
288
          lineWidthScale,
289
          lineWidthMinPixels,
290
          lineWidthMaxPixels,
291

292
          getFillColor: this.getSubLayerAccessor(getFillColor),
293
          getLineColor: this.getSubLayerAccessor(getLineColor),
294
          getRadius: this.getSubLayerAccessor(getRadius),
295
          getLineWidth: this.getSubLayerAccessor(getLineWidth),
296

297
          transitions: transitions && {
Branches [[13, 1]] missed.
298
            getPosition: transitions.geometry,
299
            getFillColor: transitions.getFillColor,
300
            getLineColor: transitions.getLineColor,
301
            getRadius: transitions.getRadius,
302
            getLineWidth: transitions.getLineWidth
303
          }
304
        },
305
        this.getSubLayerProps({
306
          id: 'points',
307
          updateTriggers: {
308
            getFillColor: updateTriggers.getFillColor,
309
            getLineColor: updateTriggers.getLineColor,
310
            getRadius: updateTriggers.getRadius,
311
            getLineWidth: updateTriggers.getLineWidth
312
          }
313
        }),
314
        {
315
          data: pointFeatures,
316
          getPosition: getCoordinates
317
        }
318
      );
319

320
    return [
34×
321
      // If not extruded: flat fill layer is drawn below outlines
322
      !extruded && polygonFillLayer,
323
      polygonLineLayer,
324
      pathLayer,
325
      pointLayer,
326
      // If extruded: draw fill layer last for correct blending behavior
327
      extruded && polygonFillLayer
328
    ];
329
  }
330
  /* eslint-enable complexity */
331
}
332

333
GeoJsonLayer.layerName = 'GeoJsonLayer';
1×
334
GeoJsonLayer.defaultProps = defaultProps;
1×
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2019 Coveralls, LLC