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

58.93
/modules/aggregation-layers/src/hexagon-layer/hexagon-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 {PhongMaterial} from '@luma.gl/core';
22
import {CompositeLayer, log} from '@deck.gl/core';
23
import {ColumnLayer} from '@deck.gl/layers';
24

25
import {defaultColorRange} from '../utils/color-utils';
26

27
import {pointToHexbin} from './hexagon-aggregator';
28
import CPUAggregator from '../utils/cpu-aggregator';
29

30
function nop() {}
31

32
const defaultMaterial = new PhongMaterial();
1×
33

34
const defaultProps = {
1×
35
  // color
36
  colorDomain: null,
37
  colorRange: defaultColorRange,
38
  getColorValue: {type: 'accessor', value: null}, // default value is calcuated from `getColorWeight` and `colorAggregation`
39
  getColorWeight: {type: 'accessor', value: x => 1},
15,132×
40
  colorAggregation: 'SUM',
41
  lowerPercentile: {type: 'number', value: 0, min: 0, max: 100},
42
  upperPercentile: {type: 'number', value: 100, min: 0, max: 100},
43
  colorScaleType: 'quantize',
44
  onSetColorDomain: nop,
45

46
  // elevation
47
  elevationDomain: null,
48
  elevationRange: [0, 1000],
49
  getElevationValue: {type: 'accessor', value: null}, // default value is calcuated from `getElevationWeight` and `elevationAggregation`
50
  getElevationWeight: {type: 'accessor', value: x => 1},
15,135×
51
  elevationAggregation: 'SUM',
52
  elevationLowerPercentile: {type: 'number', value: 0, min: 0, max: 100},
53
  elevationUpperPercentile: {type: 'number', value: 100, min: 0, max: 100},
54
  elevationScale: {type: 'number', min: 0, value: 1},
55
  elevationScaleType: 'linear',
56
  onSetElevationDomain: nop,
57

58
  radius: {type: 'number', value: 1000, min: 1},
59
  coverage: {type: 'number', min: 0, max: 1, value: 1},
60
  extruded: false,
61
  hexagonAggregator: pointToHexbin,
UNCOV
62
  getPosition: {type: 'accessor', value: x => x.position},
!
63
  // Optional material for 'lighting' shader module
64
  material: defaultMaterial
65
};
66

67
export default class HexagonLayer extends CompositeLayer {
68
  initializeState() {
69
    const cpuAggregator = new CPUAggregator({
5×
70
      getAggregator: props => props.hexagonAggregator,
118×
71
      getCellSize: props => props.radius
120×
72
    });
73

74
    this.state = {
5×
75
      cpuAggregator,
76
      aggregatorState: cpuAggregator.state
77
    };
78
  }
79

80
  updateState({oldProps, props, changeFlags}) {
81
    const {cpuAggregator} = this.state;
60×
82
    const oldLayerData = cpuAggregator.state.layerData;
60×
83
    this.setState({
60×
84
      // make a copy of the internal state of cpuAggregator for testing
85
      aggregatorState: cpuAggregator.updateState(
86
        {oldProps, props, changeFlags},
87
        this.context.viewport
88
      )
89
    });
90

91
    if (oldLayerData !== cpuAggregator.state.layerData) {
60×
92
      const {hexagonVertices} = cpuAggregator.state.layerData;
16×
93
      this.updateRadiusAngle(hexagonVertices);
16×
94
    }
95
  }
96

97
  updateRadiusAngle(vertices) {
98
    let {radius} = this.props;
16×
99
    let angle = 90;
16×
100

101
    if (Array.isArray(vertices)) {
Branches [[1, 0]] missed. 16×
UNCOV
102
      if (vertices.length < 6) {
Branches [[2, 0], [2, 1]] missed. !
UNCOV
103
        log.error('HexagonCellLayer: hexagonVertices needs to be an array of 6 points')();
!
104
      }
105

106
      // calculate angle and vertices from hexagonVertices if provided
107
      const vertex0 = vertices[0];
!
UNCOV
108
      const vertex3 = vertices[3];
!
109

110
      // transform to space coordinates
UNCOV
111
      const {viewport} = this.context;
!
UNCOV
112
      const {pixelsPerMeter} = viewport.getDistanceScales();
!
UNCOV
113
      const spaceCoord0 = this.projectFlat(vertex0);
!
UNCOV
114
      const spaceCoord3 = this.projectFlat(vertex3);
!
115

116
      // distance between two close centroids
UNCOV
117
      const dx = spaceCoord0[0] - spaceCoord3[0];
!
UNCOV
118
      const dy = spaceCoord0[1] - spaceCoord3[1];
!
UNCOV
119
      const dxy = Math.sqrt(dx * dx + dy * dy);
!
120

121
      // Calculate angle that the perpendicular hexagon vertex axis is tilted
UNCOV
122
      angle = ((Math.acos(dx / dxy) * -Math.sign(dy)) / Math.PI) * 180 + 90;
!
UNCOV
123
      radius = dxy / 2 / pixelsPerMeter[0];
!
124
    }
125

126
    this.setState({angle, radius});
16×
127
  }
128

129
  getPickingInfo({info}) {
UNCOV
130
    return this.state.cpuAggregator.getPickingInfo({info});
!
131
  }
132

133
  // create a method for testing
134
  _onGetSublayerColor(cell) {
135
    return this.state.cpuAggregator.getAccessor('fillColor')(cell);
1,886×
136
  }
137

138
  // create a method for testing
139
  _onGetSublayerElevation(cell) {
140
    return this.state.cpuAggregator.getAccessor('elevation')(cell);
1,889×
141
  }
142

143
  _getSublayerUpdateTriggers() {
144
    return this.state.cpuAggregator.getUpdateTriggers(this.props);
61×
145
  }
146

147
  renderLayers() {
148
    const {elevationScale, extruded, coverage, material, transitions} = this.props;
61×
149
    const {angle, radius, cpuAggregator} = this.state;
61×
150

151
    const SubLayerClass = this.getSubLayerClass('hexagon-cell', ColumnLayer);
61×
152
    const updateTriggers = this._getSublayerUpdateTriggers();
61×
153

154
    return new SubLayerClass(
61×
155
      {
156
        radius,
157
        diskResolution: 6,
158
        elevationScale,
159
        angle,
160
        extruded,
161
        coverage,
162
        material,
163

164
        getFillColor: this._onGetSublayerColor.bind(this),
165
        getElevation: this._onGetSublayerElevation.bind(this),
166
        transitions: transitions && {
Branches [[3, 1]] missed.
167
          getFillColor: transitions.getColorValue || transitions.getColorWeight,
Branches [[4, 0], [4, 1]] missed.
168
          getElevation: transitions.getElevationValue || transitions.getElevationWeight
Branches [[5, 0], [5, 1]] missed.
169
        }
170
      },
171
      this.getSubLayerProps({
172
        id: 'hexagon-cell',
173
        updateTriggers
174
      }),
175
      {
176
        data: cpuAggregator.state.layerData.data
177
      }
178
    );
179
  }
180
}
181

182
HexagonLayer.layerName = 'HexagonLayer';
1×
183
HexagonLayer.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