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

uber / deck.gl / 13758

17 Sep 2019 - 21:06 coverage increased (+2.9%) to 82.762%
13758

Pull #3621

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
fix CI
Pull Request #3621: Support spring transition in UniformTransitionManager

3406 of 4621 branches covered (73.71%)

Branch coverage included in aggregate %.

59 of 63 new or added lines in 6 files covered. (93.65%)

499 existing lines in 85 files now uncovered.

7200 of 8194 relevant lines covered (87.87%)

4274.03 hits per line

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

75.0
/modules/layers/src/text-layer/multi-icon-layer/multi-icon-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 {createIterable} from '@deck.gl/core';
22
import IconLayer from '../../icon-layer/icon-layer';
23

24
import vs from './multi-icon-layer-vertex.glsl';
25
import fs from './multi-icon-layer-fragment.glsl';
26

27
// TODO expose as layer properties
28
const DEFAULT_GAMMA = 0.2;
1×
29
const DEFAULT_BUFFER = 192.0 / 256;
10×
30

31
const defaultProps = {
1×
32
  // each paragraph can have one or multiple row(s)
33
  // each row can have one or multiple character(s)
34
  getRowSize: {type: 'accessor', value: x => x.rowSize || [0, 0]},
Branches [[0, 0], [0, 1]] missed. 1×
35
  // offset from the left, top position of the paragraph
36
  getOffsets: {type: 'accessor', value: x => x.offsets || [0, 0]},
Branches [[1, 0], [1, 1]] missed. 1×
37
  // [width, height] of the paragraph
38
  getParagraphSize: {type: 'accessor', value: x => x.size || [1, 1]},
Branches [[2, 0], [2, 1]] missed. 1×
39
  // 1: left, 0: middle, -1: right
40
  getAnchorX: {type: 'accessor', value: x => x.anchorX || 0},
Branches [[3, 0], [3, 1]] missed. 1×
41
  // 1: top, 0: center, -1: bottom
42
  getAnchorY: {type: 'accessor', value: x => x.anchorY || 0},
Branches [[4, 0], [4, 1]] missed. 2×
43
  getPixelOffset: {type: 'accessor', value: [0, 0]},
44

45
  // object with the same pickingIndex will be picked when any one of them is being picked
46
  getPickingIndex: {type: 'accessor', value: x => x.objectIndex}
1×
47
};
48

49
export default class MultiIconLayer extends IconLayer {
50
  getShaders() {
51
    return Object.assign({}, super.getShaders(), {
2×
52
      vs,
53
      fs
54
    });
55
  }
56

57
  initializeState() {
58
    super.initializeState();
1×
59

60
    const attributeManager = this.getAttributeManager();
1×
61
    attributeManager.addInstanced({
1×
62
      instanceOffsets: {
63
        size: 2,
64
        accessor: ['getIcon', 'getAnchorX', 'getAnchorY'],
65
        update: this.calculateInstanceOffsets
66
      },
67
      instancePixelOffset: {
68
        size: 2,
69
        transition: true,
70
        accessor: 'getPixelOffset'
71
      }
72
    });
73
  }
74

75
  updateState(updateParams) {
UNCOV
76
    super.updateState(updateParams);
!
UNCOV
77
    const {changeFlags} = updateParams;
!
78

UNCOV
79
    if (
!
80
      changeFlags.updateTriggersChanged &&
81
      (changeFlags.updateTriggersChanged.getAnchorX || changeFlags.updateTriggersChanged.getAnchorY)
82
    ) {
UNCOV
83
      this.getAttributeManager().invalidate('instanceOffsets');
!
84
    }
85
  }
86

87
  draw({uniforms}) {
UNCOV
88
    const {sdf} = this.props;
!
UNCOV
89
    super.draw({
!
90
      uniforms: Object.assign({}, uniforms, {
91
        // Refer the following doc about gamma and buffer
92
        // https://blog.mapbox.com/drawing-text-with-signed-distance-fields-in-mapbox-gl-b0933af6f817
93
        buffer: DEFAULT_BUFFER,
94
        gamma: DEFAULT_GAMMA,
95
        sdf: Boolean(sdf)
96
      })
97
    });
98
  }
99

100
  calculateInstanceOffsets(attribute, {startRow, endRow}) {
101
    const {
102
      data,
103
      iconMapping,
104
      getIcon,
105
      getAnchorX,
106
      getAnchorY,
107
      getParagraphSize,
108
      getRowSize,
109
      getOffsets
110
    } = this.props;
2×
111
    const {value, size} = attribute;
2×
112
    let i = startRow * size;
2×
113
    const {iterable} = createIterable(data, startRow, endRow);
2×
114

115
    for (const object of iterable) {
23×
116
      const icon = getIcon(object);
23×
117
      const rect = iconMapping[icon] || {};
Branches [[7, 1]] missed. 23×
118
      const [width, height] = getParagraphSize(object);
5×
119
      const [rowWidth] = getRowSize(object);
25×
120
      const [offsetX, offsetY] = getOffsets(object);
25×
121
      const anchorX = getAnchorX(object);
14×
122
      const anchorY = getAnchorY(object);
14×
123

124
      // For a multi-line object, offset in x-direction needs consider
125
      // the row offset in the paragraph and the object offset in the row
126
      const rowOffset = ((1 - anchorX) * (width - rowWidth)) / 2;
14×
127
      value[i++] = ((anchorX - 1) * width) / 2 + rowOffset + rect.width / 2 + offsetX || 0;
14×
128
      value[i++] = ((anchorY - 1) * height) / 2 + rect.height / 2 + offsetY || 0;
14×
129
    }
130
  }
131

132
  calculateInstancePickingColors(attribute, {startRow, endRow}) {
133
    const {data, getPickingIndex} = this.props;
417,444×
134
    const {value, size} = attribute;
417,444×
135
    let i = startRow * size;
417,444×
136
    const pickingColor = [];
417,444×
137
    const {iterable} = createIterable(data, startRow, endRow);
417,444×
138

139
    for (const point of iterable) {
417,444×
140
      const index = getPickingIndex(point);
417,444×
141
      this.encodePickingColor(index, pickingColor);
417,444×
142

143
      value[i++] = pickingColor[0];
417,444×
144
      value[i++] = pickingColor[1];
417,444×
145
      value[i++] = pickingColor[2];
9×
146
    }
147
  }
148
}
149

150
MultiIconLayer.layerName = 'MultiIconLayer';
9×
151
MultiIconLayer.defaultProps = defaultProps;
9×
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