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

97.14
/modules/geo-layers/src/trips-layer/trips-layer.js
1
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
4×
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 {PathLayer} from '@deck.gl/layers';
22
import {createIterable} from '@deck.gl/core';
23

24
const defaultProps = {
1×
25
  trailLength: {type: 'number', value: 120, min: 0},
26
  currentTime: {type: 'number', value: 0, min: 0},
27
  getTimestamps: {type: 'accessor', value: null}
28
};
29

30
export default class TripsLayer extends PathLayer {
31
  getShaders() {
32
    const shaders = super.getShaders();
1×
33
    shaders.inject = {
1×
34
      // Timestamp of the vertex
35
      'vs:#decl': `\
36
uniform float trailLength;
37
uniform bool isPath3D;
38
attribute vec2 instanceTimestamps;
39
varying float vTime;
40
`,
41
      // Remove the z component (timestamp) from position
42
      // TODO - Legacy use case, remove in v8
43
      'vec3 nextPosition = mix(instanceEndPositions, instanceRightPositions, isEnd);': `\
44
vec2 timestamps = instanceTimestamps;
45
if (!isPath3D) {
46
  prevPosition.z = 0.0;
47
  currPosition.z = 0.0;
48
  nextPosition.z = 0.0;
49
  timestamps.x = instanceStartPositions.z;
50
  timestamps.y = instanceEndPositions.z;
51
}
52
`,
53
      // Apply a small shift to battle z-fighting
54
      'vs:#main-end': `\
55
float shiftZ = sin(timestamps.x) * 1e-4;
56
gl_Position.z += shiftZ;
57
vTime = timestamps.x + (timestamps.y - timestamps.x) * vPathPosition.y / vPathLength;
58
`,
59
      'fs:#decl': `\
60
uniform float trailLength;
61
uniform float currentTime;
62
varying float vTime;
63
`,
64
      // Drop the segments outside of the time window
65
      'fs:#main-start': `\
66
if(vTime > currentTime || vTime < currentTime - trailLength) {
67
  discard;
68
}
69
`,
70
      // Fade the color (currentTime - 100%, end of trail - 0%)
71
      'fs:DECKGL_FILTER_COLOR': 'color.a *= 1.0 - (currentTime - vTime) / trailLength;'
72
    };
73
    return shaders;
1×
74
  }
75

76
  initializeState(params) {
77
    super.initializeState(params);
1×
78

79
    const attributeManager = this.getAttributeManager();
1×
80
    attributeManager.addInstanced({
1×
81
      instanceTimestamps: {
82
        size: 2,
83
        update: this.calculateInstanceTimestamps
84
      }
85
    });
86
  }
87

88
  draw(params) {
89
    const {trailLength, currentTime, getTimestamps} = this.props;
8×
90

91
    params.uniforms = Object.assign({}, params.uniforms, {
8×
92
      trailLength,
93
      currentTime,
94
      // TODO - remove in v8
95
      isPath3D: Boolean(getTimestamps)
96
    });
97

98
    super.draw(params);
8×
99
  }
100

101
  calculateInstanceTimestamps(attribute, {startRow, endRow}) {
102
    const {data, getTimestamps} = this.props;
6×
103

104
    if (!getTimestamps) {
6×
105
      // TODO - Legacy use case, remove in v8
106
      attribute.constant = true;
1×
107
      attribute.value = new Float32Array(2);
1×
108
      return;
1×
109
    }
110

111
    const {
112
      pathTesselator: {bufferLayout, instanceCount}
113
    } = this.state;
5×
114
    const value = new Float32Array(instanceCount * 2);
5×
115

116
    const {iterable, objectInfo} = createIterable(data, startRow, endRow);
5×
117
    let i = 0;
5×
118

119
    for (let objectIndex = 0; objectIndex < startRow; objectIndex++) {
5×
UNCOV
120
      i += bufferLayout[objectIndex] * 2;
!
121
    }
122

123
    for (const object of iterable) {
5×
124
      objectInfo.index++;
250×
125

126
      const geometrySize = bufferLayout[objectInfo.index];
250×
127
      const timestamps = getTimestamps(object, objectInfo);
250×
128
      // For each line segment, we have [startTimestamp, endTimestamp]
129
      for (let j = 0; j < geometrySize; j++) {
250×
130
        value[i++] = timestamps[j];
1,790×
131
        value[i++] = timestamps[j + 1];
1,790×
132
      }
133
    }
134
    attribute.constant = false;
5×
135
    attribute.value = value;
5×
136
  }
137
}
138

139
TripsLayer.layerName = 'TripsLayer';
1×
140
TripsLayer.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