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

uber / deck.gl / 13340

10 Sep 2019 - 3:13 coverage decreased (-2.6%) to 80.892%
13340

Pull #3552

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
[#3548 - Part 4] Modify setup.py to specify that README is markdown
Pull Request #3552: [#3548 - Part 4] Update notebook documentation to include additional pydeck features

3330 of 4491 branches covered (74.15%)

Branch coverage included in aggregate %.

6860 of 8106 relevant lines covered (84.63%)

5923.39 hits per line

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

78.79
/modules/layers/src/line-layer/line-layer.js
1
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
9×
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 {Layer} from '@deck.gl/core';
22
import GL from '@luma.gl/constants';
23
import {Model, Geometry} from '@luma.gl/core';
24

25
import vs from './line-layer-vertex.glsl';
26
import fs from './line-layer-fragment.glsl';
27

28
const DEFAULT_COLOR = [0, 0, 0, 255];
1×
29

30
const defaultProps = {
1×
UNCOV
31
  getSourcePosition: {type: 'accessor', value: x => x.sourcePosition},
!
UNCOV
32
  getTargetPosition: {type: 'accessor', value: x => x.targetPosition},
!
33
  getColor: {type: 'accessor', value: DEFAULT_COLOR},
34
  getWidth: {type: 'accessor', value: 1},
35

36
  widthUnits: 'pixels',
37
  widthScale: {type: 'number', value: 1, min: 0},
38
  widthMinPixels: {type: 'number', value: 0, min: 0},
39
  widthMaxPixels: {type: 'number', value: Number.MAX_SAFE_INTEGER, min: 0},
40

41
  // Deprecated, remove in v8
42
  getStrokeWidth: {deprecatedFor: 'getWidth'}
43
};
44

45
export default class LineLayer extends Layer {
46
  getShaders() {
47
    return super.getShaders({vs, fs, modules: ['project32', 'picking']});
5×
48
  }
49

50
  initializeState() {
51
    const attributeManager = this.getAttributeManager();
5×
52

53
    /* eslint-disable max-len */
54
    attributeManager.addInstanced({
5×
55
      instanceSourcePositions: {
56
        size: 3,
57
        type: this.use64bitPositions() ? GL.DOUBLE : GL.FLOAT,
Branches [[0, 1]] missed.
58
        transition: true,
59
        accessor: 'getSourcePosition'
60
      },
61
      instanceTargetPositions: {
62
        size: 3,
63
        type: this.use64bitPositions() ? GL.DOUBLE : GL.FLOAT,
Branches [[1, 1]] missed.
64
        transition: true,
65
        accessor: 'getTargetPosition'
66
      },
67
      instanceColors: {
68
        size: this.props.colorFormat.length,
69
        type: GL.UNSIGNED_BYTE,
70
        normalized: true,
71
        transition: true,
72
        accessor: 'getColor',
73
        defaultValue: [0, 0, 0, 255]
74
      },
75
      instanceWidths: {
76
        size: 1,
77
        transition: true,
78
        accessor: 'getWidth',
79
        defaultValue: 1
80
      }
81
    });
82
    /* eslint-enable max-len */
83
  }
84

85
  updateState({props, oldProps, changeFlags}) {
86
    super.updateState({props, oldProps, changeFlags});
25×
87

88
    if (changeFlags.extensionsChanged) {
25×
89
      const {gl} = this.context;
5×
90
      if (this.state.model) {
Branches [[3, 0]] missed. 5×
UNCOV
91
        this.state.model.delete();
!
92
      }
93
      this.setState({model: this._getModel(gl)});
5×
94
      this.getAttributeManager().invalidateAll();
5×
95
    }
96
  }
97

98
  draw({uniforms}) {
99
    const {viewport} = this.context;
25×
100
    const {widthUnits, widthScale, widthMinPixels, widthMaxPixels} = this.props;
25×
101

102
    const widthMultiplier = widthUnits === 'pixels' ? viewport.distanceScales.metersPerPixel[2] : 1;
Branches [[4, 1]] missed. 25×
103

104
    this.state.model
25×
105
      .setUniforms(
106
        Object.assign({}, uniforms, {
107
          widthScale: widthScale * widthMultiplier,
108
          widthMinPixels,
109
          widthMaxPixels
110
        })
111
      )
112
      .draw();
113
  }
114

115
  _getModel(gl) {
116
    /*
117
     *  (0, -1)-------------_(1, -1)
118
     *       |          _,-"  |
119
     *       o      _,-"      o
120
     *       |  _,-"          |
121
     *   (0, 1)"-------------(1, 1)
122
     */
123
    const positions = [0, -1, 0, 0, 1, 0, 1, -1, 0, 1, 1, 0];
5×
124

125
    return new Model(
5×
126
      gl,
127
      Object.assign({}, this.getShaders(), {
128
        id: this.props.id,
129
        geometry: new Geometry({
130
          drawMode: GL.TRIANGLE_STRIP,
131
          attributes: {
132
            positions: new Float32Array(positions)
133
          }
134
        }),
135
        isInstanced: true
136
      })
137
    );
138
  }
139
}
140

141
LineLayer.layerName = 'LineLayer';
1×
142
LineLayer.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