• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

antvis / L7Plot / 9941196296

15 Jul 2024 02:22PM UTC coverage: 56.863% (-0.1%) from 56.968%
9941196296

push

github

web-flow
chore: 修改编译目标版本和主工程一致(es6),解决 legend 无法使用的问题。 (#360)

960 of 2222 branches covered (43.2%)

Branch coverage included in aggregate %.

2752 of 4306 relevant lines covered (63.91%)

236.24 hits per line

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

74.82
/packages/l7plot/src/adaptor/layer/index.ts
1
import { isFunction, isObject, isString, isNumber, isBoolean, isArray } from '@antv/util';
2
import {
254✔
3
  ILayer,
254✔
4
  ScaleConfig,
254✔
5
  ScaleConfigMap,
254✔
6
  ColorAttr,
7
  SizeAttr,
8
  ShapeAttr,
9
  RotateAttr,
10
  AnimateAttr,
11
  StateAttribute,
12
  TextureAttr,
102✔
13
  FilterAttr,
×
14
} from '../../types';
×
15

×
16
/**
17
 * 获得映射函数
×
18
 * @param mappingFields
×
19
 * @param callback
20
 */
21
export function getMappingFunction(mappingFields: string[], callback: (data: Record<string, any>) => any) {
22
  return (...args: any[]) => {
23
    const params: Record<string, any> = {};
24

25
    mappingFields.forEach((f: string, index: number) => {
26
      params[f] = args[index];
27
    });
28

29
    delete params['undefined'];
30

875✔
31
    return callback(params);
795✔
32
  };
33
}
80✔
34

35
export class MappingLayer {
17✔
36
  static shape(layer: ILayer, shape: ShapeAttr<string>) {
17✔
37
    /**
38
     * shape 的几种情况
63!
39
     * layer.shape('cicle');
63!
40
     * layer.shape('shape', ['cicle', 'square']);
63✔
41
     * layer.shape('x', (x) => 'cicle');
17!
42
     * layer.shape('x*y', (x, y) => 'cicle');
17✔
43
     */
44
    if (isString(shape)) {
45
      layer.shape(shape);
46✔
46
    } else if (isFunction(shape)) {
47
      // TODO: shape mappingFields
48
      const mappingFields = [];
63!
49
      layer.shape(mappingFields.join('*'), getMappingFunction(mappingFields, shape));
×
50
    } else if (isObject(shape)) {
51
      const field = shape.field ? shape.field : '';
52
      if (isFunction(shape.value)) {
53
        const mappingFields = isArray(field) ? field : field.split('*');
54
        layer.shape(field, getMappingFunction(mappingFields, shape.value));
55
      } else {
56
        layer.shape(field, shape.value);
57
      }
58
      // scale
59
      if (isString(field) && shape.scale) {
60
        MappingLayer.scale(layer, field, shape.scale);
61
      }
837✔
62
    }
638✔
63
  }
64

199✔
65
  static size(layer: ILayer, size: SizeAttr) {
3✔
66
    /**
67
     * size 的几种情况
196✔
68
     * layer.size(10);
69
     * layer.size('size', [10, 20]);
17✔
70
     * layer.size('x', (x) => 10);
17✔
71
     * layer.size('x*y', (x, y) => 10);
72
     */
179!
73
    if (isNumber(size)) {
179!
74
      layer.size(size);
179✔
75
    } else if (isArray(size)) {
17!
76
      layer.size(size);
17✔
77
    } else if (isFunction(size)) {
78
      // TODO: size mappingFields
79
      const mappingFields = [];
162✔
80
      layer.size(mappingFields.join('*'), getMappingFunction(mappingFields, size));
81
    } else if (isObject(size)) {
82
      const field = size.field ? size.field : '';
179✔
83
      if (isFunction(size.value)) {
17✔
84
        const mappingFields = isArray(field) ? field : field.split('*');
85
        layer.size(field, getMappingFunction(mappingFields, size.value));
86
      } else {
87
        layer.size(field, size.value);
88
      }
89
      // scale
90
      if (isString(field) && size.scale) {
91
        MappingLayer.scale(layer, field, size.scale);
92
      }
93
    }
94
  }
95

800✔
96
  static color(layer: ILayer, color: ColorAttr) {
669✔
97
    /**
98
     * color 的几种情况
131✔
99
     * layer.color('red');
100
     * layer.color('color', ['red', 'blue']);
17✔
101
     * layer.color('x', (x) => 'red');
17✔
102
     * layer.color('x*y', (x, y) => 'red');
103
     */
114!
104
    if (isString(color)) {
114!
105
      layer.color(color);
114✔
106
    } else if (isFunction(color)) {
17!
107
      // TODO: color mappingFields
17✔
108
      const mappingFields = [];
109
      layer.color(mappingFields.join('*'), getMappingFunction(mappingFields, color));
110
    } else if (isObject(color)) {
97✔
111
      const field = color.field ? color.field : '';
112
      if (isFunction(color.value)) {
113
        const mappingFields = isArray(field) ? field : field.split('*');
114✔
114
        layer.color(field, getMappingFunction(mappingFields, color.value));
15✔
115
      } else {
116
        layer.color(field, color.value);
117
      }
118
      // scale
119
      if (isString(field) && color.scale) {
319✔
120
        MappingLayer.scale(layer, field, color.scale);
121
      }
122
    }
96✔
123
  }
96✔
124

96✔
125
  static style(layer: ILayer, style: unknown) {
126
    style && layer.style(style);
127
  }
128

129
  static state(layer: ILayer, state: StateAttribute) {
130
    const { active, select } = state;
131
    active && layer.active(active);
132
    select && layer.select(select);
133
  }
134

×
135
  static rotate(layer: ILayer, rotate: RotateAttr) {
136
    /**
137
     * rotate 的几种情况
138
     * layer.rotate(45);
×
139
     * layer.rotate('rotate', [45, 90]);
140
     * layer.rotate('x', (x) => 45);
141
     * layer.rotate('x*y', (x, y) => 45);
×
142
     */
143
    if (isString(rotate)) {
144
      // TODO: L7 rotate
145
      // layer.rotate(rotate);
146
    } else if (isFunction(rotate)) {
147
      // TODO: rotate isFunction
148
    } else if (isObject(rotate)) {
149
      // TODO: L7 rotate
150
    }
34!
151
  }
34✔
152

153
  static texture(layer: ILayer, texture: TextureAttr) {
154
    /**
155
     * texture 的几种情况
156
     * layer.texture('plane');
157
     */
158
    if (isString(texture)) {
159
      layer.texture(texture);
160
    }
17!
161
  }
17✔
162

163
  static animate(layer: ILayer, animate: AnimateAttr) {
164
    /**
165
     * animate 的几种情况
166
     * layer.animate(true);
167
     * layer.animate({rings: 10});
168
     */
169
    if (isBoolean(animate) || isObject(animate)) {
170
      layer.animate(animate);
32✔
171
    }
172
  }
173

174
  static scale(layer: ILayer, field: string | ScaleConfigMap, cfg: ScaleConfig) {
175
    /**
176
     * scale 的几种情况
177
     * layer.scale('name', {type: 'cat'});
×
178
     * layer.scale({name: {type: 'cat'}, value: {type: 'linear'}});
×
179
     */
×
180
    layer.scale(field, cfg);
181
  }
182

254✔
183
  static filter(layer: ILayer, filter: FilterAttr) {
184
    /**
185
     * scale 的几种情况
186
     * layer.filter('name', ({ name }) => name === 'name');
187
     */
188
    const field = filter.field ? filter.field : '';
189
    const mappingFields = isArray(field) ? field : field.split('*');
190
    layer.filter(mappingFields.join('*'), getMappingFunction(mappingFields, filter.value));
191
  }
192
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc