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

uber / deck.gl / 13030

26 Aug 2019 - 19:27 coverage decreased (-2.6%) to 80.38%
13030

Pull #3490

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
integrate mapbox's near plane fix
Pull Request #3490: [MapboxLayer] integrate mapbox-gl's near plane fix

3369 of 4577 branches covered (73.61%)

Branch coverage included in aggregate %.

6877 of 8170 relevant lines covered (84.17%)

4644.76 hits per line

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

90.91
/modules/core/src/lib/composite-layer.js
1
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
7×
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
import Layer from './layer';
21
import log from '../utils/log';
22
import {flatten} from '../utils/flatten';
23

24
export default class CompositeLayer extends Layer {
25
  get isComposite() {
26
    return true;
1,883×
27
  }
28

29
  getSubLayers() {
30
    return (this.internalState && this.internalState.subLayers) || [];
Branches [[0, 2]] missed. 662×
31
  }
32

33
  // initializeState is usually not needed for composite layers
34
  // Provide empty definition to disable check for missing definition
35
  initializeState() {}
36

37
  // Updates selected state members and marks the composite layer to need rerender
38
  setState(updateObject) {
39
    super.setState(updateObject);
332×
40
    // Trigger a layer update
41
    // Although conceptually layer.draw and compositeLayer.renderLayers are equivalent,
42
    // they are executed during different lifecycles.
43
    // draw can be called without calling updateState (e.g. most viewport changes),
44
    // while renderLayers can only be called during a recursive layer update.
45
    this.setNeedsUpdate();
332×
46
  }
47

48
  // called to augment the info object that is bubbled up from a sublayer
49
  // override Layer.getPickingInfo() because decoding / setting uniform do
50
  // not apply to a composite layer.
51
  // @return null to cancel event
52
  getPickingInfo({info}) {
53
    const {object} = info;
3×
54
    const isDataWrapped =
55
      object && object.__source && object.__source.parent && object.__source.parent.id === this.id;
3×
56

57
    if (!isDataWrapped) {
3×
58
      return info;
1×
59
    }
60

61
    return Object.assign(info, {
2×
62
      // override object with picked data
63
      object: object.__source.object,
64
      index: object.__source.index
65
    });
66
  }
67

68
  // Implement to generate subLayers
69
  renderLayers() {
UNCOV
70
    return null;
!
71
  }
72

73
  // Returns true if sub layer needs to be rendered
74
  shouldRenderSubLayer(id, data) {
75
    const {_subLayerProps: overridingProps} = this.props;
202×
76

77
    return (data && data.length) || (overridingProps && overridingProps[id]);
Branches [[3, 3]] missed. 202×
78
  }
79

80
  // Returns sub layer class for a specific sublayer
81
  getSubLayerClass(id, DefaultLayerClass) {
82
    const {_subLayerProps: overridingProps} = this.props;
472×
83

84
    return (
472×
85
      (overridingProps && overridingProps[id] && overridingProps[id].type) || DefaultLayerClass
Branches [[4, 1], [4, 2]] missed.
86
    );
87
  }
88

89
  // When casting user data into another format to pass to sublayers,
90
  // add reference to the original object and object index
91
  getSubLayerRow(row, sourceObject, sourceObjectIndex) {
92
    row.__source = {
140,503×
93
      parent: this,
94
      object: sourceObject,
95
      index: sourceObjectIndex
96
    };
97
    return row;
140,503×
98
  }
99

100
  // Some composite layers cast user data into another format before passing to sublayers
101
  // We need to unwrap them before calling the accessor so that they see the original data
102
  // objects
103
  getSubLayerAccessor(accessor) {
104
    if (typeof accessor === 'function') {
337×
105
      const objectInfo = {
74×
106
        data: this.props.data,
107
        target: []
108
      };
109
      return (x, i) => {
74×
110
        if (x.__source) {
557,019×
111
          objectInfo.index = x.__source.index;
557,017×
112
          return accessor(x.__source.object, objectInfo);
557,017×
113
        }
114
        return accessor(x, i);
2×
115
      };
116
    }
117
    return accessor;
263×
118
  }
119

120
  // Returns sub layer props for a specific sublayer
121
  getSubLayerProps(sublayerProps) {
122
    const {
123
      opacity,
124
      pickable,
125
      visible,
126
      parameters,
127
      getPolygonOffset,
128
      highlightedObjectIndex,
129
      autoHighlight,
130
      highlightColor,
131
      coordinateSystem,
132
      coordinateOrigin,
133
      wrapLongitude,
134
      positionFormat,
135
      modelMatrix,
136
      extensions,
137
      _subLayerProps: overridingProps
138
    } = this.props;
332×
139
    const newProps = {
332×
140
      opacity,
141
      pickable,
142
      visible,
143
      parameters,
144
      getPolygonOffset,
145
      highlightedObjectIndex,
146
      autoHighlight,
147
      highlightColor,
148
      coordinateSystem,
149
      coordinateOrigin,
150
      wrapLongitude,
151
      positionFormat,
152
      modelMatrix,
153
      extensions
154
    };
155

156
    if (sublayerProps) {
332×
157
      const overridingSublayerProps = overridingProps && overridingProps[sublayerProps.id];
325×
158
      const overridingSublayerTriggers =
159
        overridingSublayerProps && overridingSublayerProps.updateTriggers;
325×
160
      Object.assign(
325×
161
        newProps,
162
        sublayerProps,
163
        // experimental feature that allows users to override sublayer props via parent layer prop
164
        overridingSublayerProps,
165
        {
166
          id: `${this.props.id}-${sublayerProps.id}`,
167
          updateTriggers: Object.assign(
168
            {
169
              all: this.props.updateTriggers.all
170
            },
171
            sublayerProps.updateTriggers,
172
            overridingSublayerTriggers
173
          )
174
        }
175
      );
176
    }
177

178
    // Pass through extension props
179
    for (const extension of extensions) {
332×
180
      const passThroughProps = extension.getSubLayerProps.call(this, extension);
2×
181
      Object.assign(newProps, passThroughProps, {
2×
182
        updateTriggers: Object.assign(newProps.updateTriggers, passThroughProps.updateTriggers)
183
      });
184
    }
185

186
    return newProps;
332×
187
  }
188

189
  _getAttributeManager() {
190
    return null;
45×
191
  }
192

193
  // Called by layer manager to render subLayers
194
  _renderLayers() {
195
    let {subLayers} = this.internalState;
320×
196
    if (subLayers && !this.needsUpdate()) {
Branches [[10, 0]] missed. 320×
UNCOV
197
      log.log(3, `Composite layer reused subLayers ${this}`, this.internalState.subLayers)();
!
198
    } else {
199
      subLayers = this.renderLayers();
320×
200
      // Flatten the returned array, removing any null, undefined or false
201
      // this allows layers to render sublayers conditionally
202
      // (see CompositeLayer.renderLayers docs)
203
      subLayers = flatten(subLayers, {filter: Boolean});
320×
204
      this.internalState.subLayers = subLayers;
320×
205
      log.log(2, `Composite layer rendered new subLayers ${this}`, subLayers)();
320×
206
    }
207

208
    // populate reference to parent layer (this layer)
209
    // NOTE: needs to be done even when reusing layers as the parent may have changed
210
    for (const layer of subLayers) {
320×
211
      layer.parent = this;
337×
212
    }
213
  }
214
}
215

216
CompositeLayer.layerName = 'CompositeLayer';
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