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

antvis / L7Plot / 5252918396

pending completion
5252918396

Pull #295

github

GitHub
Merge 75ea3f48c into 9961b98c4
Pull Request #295:

818 of 2183 branches covered (37.47%)

Branch coverage included in aggregate %.

426 of 426 new or added lines in 15 files covered. (100.0%)

3379 of 5066 relevant lines covered (66.7%)

198.05 hits per line

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

59.52
/packages/composite-layers/src/composite-layers/flow-layer/data/index.ts
1
import EventEmitter from '@antv/event-emitter';
2
import { createSelector } from 'reselect';
23✔
3
import { ClusterState, FlowDataProviderState, FlowSource } from '../types';
23✔
4
import { buildIndex } from './build-index';
23✔
5
import { clusterFlows, clusterLocations } from './cluster';
23✔
6
import { transformSource } from './transform';
23✔
7

23✔
8
export class DataProvider extends EventEmitter {
23✔
9
  public getSourceData = (source: FlowSource, config: FlowDataProviderState) => source.data;
23✔
10
  public getSourceParser = (source: FlowSource, config: FlowDataProviderState) => source.parser;
23✔
11
  public getMapZoom = (source: FlowSource, config: FlowDataProviderState) => config.mapStatus.zoom;
23✔
12
  public getMapBounds = (source: FlowSource, config: FlowDataProviderState) => config.mapStatus.bounds;
13
  public getClusterType = (source: FlowSource, config: FlowDataProviderState) => config.clusterType;
44✔
14
  public getExtent = (source: FlowSource, config: FlowDataProviderState) => config.clusterExtent;
44✔
15
  public getNodeSize = (source: FlowSource, config: FlowDataProviderState) => config.clusterNodeSize;
44✔
16
  public getRadius = (source: FlowSource, config: FlowDataProviderState) => config.clusterRadius;
44✔
17
  public getMinZoom = (source: FlowSource, config: FlowDataProviderState) => config.minZoom;
44✔
18
  public getMaxZoom = (source: FlowSource, config: FlowDataProviderState) => config.maxZoom;
44✔
19
  public getZoomStep = (source: FlowSource, config: FlowDataProviderState) => config.clusterZoomStep;
44✔
20
  public getMaxTopFlowNum = (source: FlowSource, config: FlowDataProviderState) => config.maxTopFlowNum;
44✔
21

44✔
22
  /**
44✔
23
   * 将 source 转换成最底层的客流点/线数据
44✔
24
   */
44✔
25
  public getOriginData = createSelector(this.getSourceData, this.getSourceParser, (data, parser) => {
44✔
26
    return transformSource({ data, parser });
27
  });
28

29
  /**
44✔
30
   * 获取聚合配置
22✔
31
   */
32
  public getClusterOptions = createSelector(
33
    this.getClusterType,
34
    this.getExtent,
35
    this.getNodeSize,
44✔
36
    this.getRadius,
22✔
37
    this.getMinZoom,
38
    this.getMaxZoom,
39
    this.getZoomStep,
40
    function (
41
      clusterType,
44✔
42
      clusterExtent,
22✔
43
      clusterNodeSize,
22✔
44
      clusterRadius,
45
      minZoom,
46
      maxZoom,
47
      clusterZoomStep
48
    ): ClusterState {
44✔
49
      return { clusterType, clusterExtent, clusterNodeSize, clusterRadius, minZoom, maxZoom, clusterZoomStep };
22✔
50
    }
51
  );
52

53
  /**
54
   * 获取各个层级下的聚合点数组
44✔
55
   */
22✔
56
  public getClusterLevels = createSelector(
57
    this.getOriginData,
44✔
58
    this.getClusterOptions,
×
59
    ({ locations }, clusterOptions) => {
×
60
      return clusterLocations(locations, clusterOptions);
×
61
    }
62
  );
×
63

×
64
  /**
×
65
   * 获取聚合点的检索器
66
   */
67
  public getClusterIndex = createSelector(this.getClusterLevels, (clusterLevels) => {
68
    return buildIndex(clusterLevels);
69
  });
44✔
70

22✔
71
  /**
22✔
72
   * 获取当前需要展示的聚合点
73
   */
74
  public getFilterLocations = createSelector(
75
    this.getClusterIndex,
76
    this.getMapZoom,
44✔
77
    this.getMapBounds,
22!
78
    (clusterIndex, zoom, bounds) => {
22✔
79
      return clusterIndex.getMapLocations(zoom, bounds);
80
    }
×
81
  );
×
82

×
83
  public getLocationWeightRange = createSelector(this.getClusterIndex, this.getMapZoom, function (clusterIndex, zoom): [
×
84
    number,
85
    number
×
86
  ] {
×
87
    const { locations } = clusterIndex.getAppropriateLevel(zoom);
88
    if (!locations.length) {
×
89
      return [0, 0];
90
    }
91
    const { weight: minWeight } = locations[0];
92
    const { weight: maxWeight } = locations[locations.length - 1];
93
    return [minWeight, maxWeight];
44✔
94
  });
×
95

×
96
  /**
97
   * 获取当前层级下的聚合线数据
×
98
   */
×
99
  public getAggregatedFlows = createSelector(
×
100
    this.getClusterIndex,
101
    this.getOriginData,
102
    this.getMapZoom,
103
    (clusterIndex, { flows: originFlows }, zoom) => {
104
      return clusterFlows(originFlows, clusterIndex, zoom);
44✔
105
    }
×
106
  );
×
107

108
  /**
×
109
   * 获取当前需要展示的聚合线数据
×
110
   */
×
111
  public getFilterFlows = createSelector(
112
    this.getFilterLocations,
44✔
113
    this.getAggregatedFlows,
114
    this.getMaxTopFlowNum,
23✔
115
    (filterLocations, fullFlows, maxTopFlowNum) => {
116
      if (fullFlows.length <= maxTopFlowNum) {
23✔
117
        return fullFlows;
118
      }
119
      let flows = [...fullFlows];
120
      const filterLocationIdSet = new Set(filterLocations.map((location) => location.id));
121
      flows = flows.filter((flow) => {
122
        return filterLocationIdSet.has(flow.fromId) || filterLocationIdSet.has(flow.toId);
123
      });
124
      if (flows.length > maxTopFlowNum) {
125
        flows = flows.slice(flows.length - maxTopFlowNum, flows.length);
126
      }
127
      return flows;
128
    }
129
  );
130

131
  /**
132
   * 获取当前层级下筛选前的权重区间,用于计算客流线的宽度和颜色深浅
133
   */
134
  public getFlowWeightRange = createSelector(this.getAggregatedFlows, function (flows): [number, number] {
135
    if (!flows.length) {
136
      return [0, 0];
137
    }
138
    const { weight: minWeight } = flows[0];
139
    const { weight: maxWeight } = flows[flows.length - 1];
140
    return [minWeight, maxWeight];
141
  });
142

143
  /**
144
   * 获取当前层级下筛选后的客流线的权重区间,主要用于客流线透明度的计算
145
   */
146
  public getFilterFlowWeightRange = createSelector(this.getFilterFlows, function (flows): [number, number] {
147
    if (!flows.length) {
148
      return [0, 0];
149
    }
150
    const { weight: minWeight } = flows[0];
151
    const { weight: maxWeight } = flows[flows.length - 1];
152
    return [minWeight, maxWeight];
153
  });
154
}
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