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

uber / deck.gl / 13873

19 Sep 2019 - 20:02 coverage increased (+2.8%) to 82.702%
13873

Pull #3639

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
Update
Pull Request #3639: Set default pydeck notebook width to 700px

3398 of 4611 branches covered (73.69%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

488 existing lines in 85 files now uncovered.

7192 of 8194 relevant lines covered (87.77%)

4273.96 hits per line

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

96.0
/modules/layers/src/polygon-layer/polygon-layer.js
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

21
import {PhongMaterial} from '@luma.gl/core';
22
import {CompositeLayer, createIterable} from '@deck.gl/core';
23
import SolidPolygonLayer from '../solid-polygon-layer/solid-polygon-layer';
24
import PathLayer from '../path-layer/path-layer';
25
import * as Polygon from '../solid-polygon-layer/polygon';
26
import {replaceInRange} from '../utils';
27

28
const defaultLineColor = [0, 0, 0, 255];
1×
29
const defaultFillColor = [0, 0, 0, 255];
1×
30
const defaultMaterial = new PhongMaterial();
11×
31

32
const defaultProps = {
1×
33
  stroked: true,
34
  filled: true,
35
  extruded: false,
36
  elevationScale: 1,
37
  wireframe: false,
38

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

47
  getPolygon: {type: 'accessor', value: f => f.polygon},
1×
48
  // Polygon fill color
49
  getFillColor: {type: 'accessor', value: defaultFillColor},
50
  // Point, line and polygon outline color
51
  getLineColor: {type: 'accessor', value: defaultLineColor},
52
  // Line and polygon outline accessors
53
  getLineWidth: {type: 'accessor', value: 1},
54
  // Line dash array accessor
55
  getLineDashArray: {type: 'accessor', value: [0, 0]},
56
  // Polygon extrusion accessor
57
  getElevation: {type: 'accessor', value: 1000},
58

59
  // Optional material for 'lighting' shader module
60
  material: defaultMaterial
61
};
62

63
export default class PolygonLayer extends CompositeLayer {
64
  initializeState() {
65
    this.state = {
1×
66
      paths: []
67
    };
68
  }
69

70
  updateState({oldProps, props, changeFlags}) {
71
    const geometryChanged =
72
      changeFlags.dataChanged ||
1×
73
      (changeFlags.updateTriggersChanged &&
74
        (changeFlags.updateTriggersChanged.all || changeFlags.updateTriggersChanged.getPolygon));
75

76
    if (geometryChanged && Array.isArray(changeFlags.dataChanged)) {
1×
77
      const paths = this.state.paths.slice();
1×
78
      const pathsDiff = changeFlags.dataChanged.map(dataRange =>
3×
79
        replaceInRange({
1×
80
          data: paths,
81
          getIndex: p => p.__source.index,
1×
82
          dataRange,
83
          replace: this._getPaths(dataRange)
84
        })
85
      );
86
      this.setState({paths, pathsDiff});
1×
87
    } else if (geometryChanged) {
1×
88
      this.setState({
1×
89
        paths: this._getPaths(),
90
        pathsDiff: null
91
      });
92
    }
93
  }
94

95
  _getPaths(dataRange = {}) {
96
    const {data, getPolygon, positionFormat} = this.props;
2×
97
    const paths = [];
1×
98
    const positionSize = positionFormat === 'XY' ? 2 : 3;
Branches [[5, 0]] missed. 1×
99
    const {startRow, endRow} = dataRange;
1×
100

101
    const {iterable, objectInfo} = createIterable(data, startRow, endRow);
1×
UNCOV
102
    for (const object of iterable) {
!
103
      objectInfo.index++;
7×
104
      const {positions, holeIndices} = Polygon.normalize(
84×
105
        getPolygon(object, objectInfo),
106
        positionSize
107
      );
108

109
      if (holeIndices) {
84×
110
        // split the positions array into `holeIndices.length + 1` rings
111
        // holeIndices[-1] falls back to 0
112
        // holeIndices[holeIndices.length] falls back to positions.length
113
        for (let i = 0; i <= holeIndices.length; i++) {
1×
114
          const path = positions.subarray(
1×
115
            holeIndices[i - 1] || 0,
116
            holeIndices[i] || positions.length
117
          );
118
          paths.push(this.getSubLayerRow({path}, object, objectInfo.index));
3×
119
        }
120
      } else {
121
        paths.push(this.getSubLayerRow({path: positions}, object, objectInfo.index));
1×
122
      }
123
    }
124
    return paths;
83×
125
  }
126

127
  /* eslint-disable complexity */
128
  renderLayers() {
129
    // Layer composition props
130
    const {
131
      data,
132
      _dataDiff,
133
      stroked,
134
      filled,
135
      extruded,
136
      wireframe,
137
      elevationScale,
138
      transitions,
139
      positionFormat
140
    } = this.props;
25×
141

142
    // Rendering props underlying layer
143
    const {
144
      lineWidthUnits,
145
      lineWidthScale,
146
      lineWidthMinPixels,
147
      lineWidthMaxPixels,
148
      lineJointRounded,
149
      lineMiterLimit,
150
      lineDashJustified
151
    } = this.props;
26×
152

153
    // Accessor props for underlying layers
154
    const {
155
      getFillColor,
156
      getLineColor,
157
      getLineWidth,
158
      getLineDashArray,
159
      getElevation,
160
      getPolygon,
161
      updateTriggers,
162
      material
163
    } = this.props;
26×
164

165
    const {paths, pathsDiff} = this.state;
26×
166

167
    const FillLayer = this.getSubLayerClass('fill', SolidPolygonLayer);
26×
168
    const StrokeLayer = this.getSubLayerClass('stroke', PathLayer);
26×
169

170
    // Filled Polygon Layer
171
    const polygonLayer =
172
      this.shouldRenderSubLayer('fill', paths) &&
26×
173
      new FillLayer(
174
        {
175
          _dataDiff,
176
          extruded,
177
          elevationScale,
178

179
          filled,
180
          wireframe,
181

182
          getElevation,
183
          getFillColor,
184
          getLineColor,
185

186
          material,
187
          transitions
188
        },
189
        this.getSubLayerProps({
190
          id: 'fill',
191
          updateTriggers: {
192
            getPolygon: updateTriggers.getPolygon,
193
            getElevation: updateTriggers.getElevation,
194
            getFillColor: updateTriggers.getFillColor,
195
            getLineColor: updateTriggers.getLineColor
196
          }
197
        }),
198
        {
199
          data,
200
          positionFormat,
201
          getPolygon
202
        }
203
      );
204

205
    // Polygon line layer
206
    const polygonLineLayer =
207
      !extruded &&
1,284×
208
      stroked &&
209
      this.shouldRenderSubLayer('stroke', paths) &&
210
      new StrokeLayer(
211
        {
212
          _dataDiff: pathsDiff && (() => pathsDiff),
1,284×
213
          widthUnits: lineWidthUnits,
214
          widthScale: lineWidthScale,
215
          widthMinPixels: lineWidthMinPixels,
216
          widthMaxPixels: lineWidthMaxPixels,
217
          rounded: lineJointRounded,
218
          miterLimit: lineMiterLimit,
219
          dashJustified: lineDashJustified,
220

221
          transitions: transitions && {
Branches [[12, 1]] missed.
222
            getWidth: transitions.getLineWidth,
223
            getColor: transitions.getLineColor,
224
            getPath: transitions.getPolygon
225
          },
226

227
          getColor: this.getSubLayerAccessor(getLineColor),
228
          getWidth: this.getSubLayerAccessor(getLineWidth),
229
          getDashArray: this.getSubLayerAccessor(getLineDashArray)
230
        },
231
        this.getSubLayerProps({
232
          id: 'stroke',
233
          updateTriggers: {
234
            getWidth: updateTriggers.getLineWidth,
235
            getColor: updateTriggers.getLineColor,
236
            getDashArray: updateTriggers.getLineDashArray
237
          }
238
        }),
239
        {
240
          data: paths,
241
          positionFormat,
242
          getPath: x => x.path
1,284×
243
        }
244
      );
245

246
    return [
270×
247
      // If not extruded: flat fill layer is drawn below outlines
248
      !extruded && polygonLayer,
249
      polygonLineLayer,
250
      // If extruded: draw fill layer last for correct blending behavior
251
      extruded && polygonLayer
252
    ];
253
  }
254
  /* eslint-enable complexity */
255
}
256

257
PolygonLayer.layerName = 'PolygonLayer';
270×
258
PolygonLayer.defaultProps = defaultProps;
270×
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