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

uber / deck.gl / 13873

19 Sep 2019 - 20:02 coverage increased (+2.8%) to 82.702%
13873

Pull #3639

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
Update
Pull Request #3639: Set default pydeck notebook width to 700px

3398 of 4611 branches covered (73.69%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

488 existing lines in 85 files now uncovered.

7192 of 8194 relevant lines covered (87.77%)

4273.96 hits per line

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

67.27
/modules/aggregation-layers/src/hexagon-layer/hexagon-layer.js
1
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
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},
9×
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},
1×
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,
62
  getPosition: {type: 'accessor', value: x => x.position},
1×
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({
1×
70
      getAggregator: props => props.hexagonAggregator,
1×
71
      getCellSize: props => props.radius
1×
72
    });
73

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

80
  updateState({oldProps, props, changeFlags}) {
81
    const {cpuAggregator} = this.state;
1×
82
    const oldLayerData = cpuAggregator.state.layerData;
1×
83
    this.setState({
1×
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) {
1×
92
      const {hexagonVertices} = cpuAggregator.state.layerData;
2×
93
      this.updateRadiusAngle(hexagonVertices);
1×
94
    }
95
  }
96

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

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
154
    return new SubLayerClass(
!
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

UNCOV
182
HexagonLayer.layerName = 'HexagonLayer';
!
UNCOV
183
HexagonLayer.defaultProps = defaultProps;
!
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