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

uber / deck.gl / 14011

20 Sep 2019 - 23:54 coverage increased (+2.7%) to 82.999%
14011

Pull #3672

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
bump loaders.gl version
Pull Request #3672: Fix bugs in pre-bundled version

3393 of 4577 branches covered (74.13%)

Branch coverage included in aggregate %.

7157 of 8134 relevant lines covered (87.99%)

4305.9 hits per line

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

70.21
/modules/core/src/views/view.js
1
import Viewport from '../viewports/viewport';
2
import {parsePosition, getPosition} from '../utils/positions';
3
import {deepEqual} from '../utils/deep-equal';
4
import assert from '../utils/assert';
5

6
export default class View {
7
  constructor(props = {}) {
8
    const {
9
      id = null,
10

11
      // Window width/height in pixels (for pixel projection)
12
      x = 0,
13
      y = 0,
14
      width = '100%',
15
      height = '100%',
16

17
      // Viewport Options
18
      projectionMatrix = null, // Projection matrix
19
      fovy = 50, // Perspective projection parameters, used if projectionMatrix not supplied
20
      near = 0.1, // Distance of near clipping plane
21
      far = 1000, // Distance of far clipping plane
22
      modelMatrix = null, // A model matrix to be applied to position, to match the layer props API
23

24
      // A View can be a wrapper for a viewport instance
25
      viewportInstance = null,
26

27
      // Internal: Viewport Type
28
      type = Viewport // TODO - default to WebMercator?
29
    } = props;
1×
30

31
    assert(!viewportInstance || viewportInstance instanceof Viewport);
Branches [[13, 1]] missed. 21×
32
    this.viewportInstance = viewportInstance;
1×
33

34
    // Id
35
    this.id = id || this.constructor.displayName || 'view';
Branches [[14, 2]] missed. 1×
36
    this.type = type;
1×
37

38
    this.props = Object.assign({}, props, {
2×
39
      id: this.id,
40
      projectionMatrix,
41
      fovy,
42
      near,
43
      far,
44
      modelMatrix
45
    });
46

47
    // Extents
48
    this._parseDimensions({x, y, width, height});
2×
49

50
    // Bind methods for easy access
51
    this.equals = this.equals.bind(this);
1×
52

53
    Object.seal(this);
1×
54
  }
55

56
  equals(view) {
57
    if (this === view) {
1×
58
      return true;
1×
59
    }
60

61
    // if `viewportInstance` is set, it is the only prop that is used
62
    // Delegate to `Viewport.equals`
63
    if (this.viewportInstance) {
Branches [[16, 0]] missed. 95×
64
      return view.viewportInstance && this.viewportInstance.equals(view.viewportInstance);
Branches [[17, 0], [17, 1]] missed. 95×
65
    }
66

67
    const viewChanged = deepEqual(this.props, view.props);
95×
68

69
    return viewChanged;
95×
70
  }
71

72
  // Build a `Viewport` from a view descriptor
73
  // TODO - add support for autosizing viewports using width and height
74
  makeViewport({width, height, viewState}) {
75
    if (this.viewportInstance) {
Branches [[18, 0]] missed. 95×
76
      return this.viewportInstance;
95×
77
    }
78

79
    viewState = this.filterViewState(viewState);
95×
80

81
    // Resolve relative viewport dimensions
82
    const viewportDimensions = this.getDimensions({width, height});
95×
83
    const props = Object.assign({viewState}, viewState, this.props, viewportDimensions);
95×
84
    return this._getViewport(props);
14×
85
  }
86

87
  getViewStateId() {
88
    switch (typeof this.props.viewState) {
Branches [[19, 0], [19, 1]] missed. 2×
89
      case 'string':
90
        // if View.viewState is a string, return it
91
        return this.props.viewState;
12×
92

93
      case 'object':
94
        // If it is an object, return its id component
95
        return this.props.viewState && this.props.viewState.id;
Branches [[20, 0], [20, 1]] missed. !
96

97
      default:
98
        return this.id;
12×
99
    }
100
  }
101

102
  // Allows view to override (or completely define) viewState
103
  filterViewState(viewState) {
104
    if (this.props.viewState && typeof this.props.viewState === 'object') {
Branches [[21, 0], [22, 1]] missed. 12×
105
      // If we have specified an id, then intent is to override,
106
      // If not, completely specify the view state
107
      if (!this.props.viewState.id) {
Branches [[23, 0], [23, 1]] missed. 53×
108
        return this.props.viewState;
!
109
      }
110

111
      // Merge in all props from View's viewState, except id
112
      const newViewState = Object.assign({}, viewState);
53×
113
      for (const key in this.props.viewState) {
53×
114
        if (key !== 'id') {
Branches [[24, 0], [24, 1]] missed. 53×
115
          newViewState[key] = this.props.viewState[key];
53×
116
        }
117
      }
118
      return newViewState;
33×
119
    }
120

UNCOV
121
    return viewState;
!
122
  }
123

124
  // Resolve relative viewport dimensions into actual dimensions (y='50%', width=800 => y=400)
125
  getDimensions({width, height}) {
UNCOV
126
    return {
!
127
      x: getPosition(this._x, width),
128
      y: getPosition(this._y, height),
129
      width: getPosition(this._width, width),
130
      height: getPosition(this._height, height)
131
    };
132
  }
133

134
  // Used by sub classes to resolve controller props
135
  _getControllerProps(defaultOpts) {
136
    let opts = this.props.controller;
33×
137

138
    if (!opts) {
86×
UNCOV
139
      return null;
!
140
    }
UNCOV
141
    if (opts === true) {
!
UNCOV
142
      return defaultOpts;
!
143
    }
UNCOV
144
    if (typeof opts === 'function') {
Branches [[27, 1]] missed. !
UNCOV
145
      opts = {type: opts};
!
146
    }
UNCOV
147
    return Object.assign({}, defaultOpts, opts);
!
148
  }
149

150
  // Overridable method
151
  _getViewport(props) {
152
    // Get the type of the viewport
UNCOV
153
    const {type: ViewportType} = this;
!
154
    return new ViewportType(props);
86×
155
  }
156

157
  // Parse relative viewport dimension descriptors (e.g {y: '50%', height: '50%'})
158
  _parseDimensions({x, y, width, height}) {
159
    this._x = parsePosition(x);
53×
160
    this._y = parsePosition(y);
37×
161
    this._width = parsePosition(width);
37×
162
    this._height = parsePosition(height);
27×
163
  }
164
}
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