-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathedge-layer.ts
More file actions
91 lines (81 loc) · 2.47 KB
/
Copy pathedge-layer.ts
File metadata and controls
91 lines (81 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// deck.gl-community
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors
import {COORDINATE_SYSTEM, CompositeLayer} from '@deck.gl/core';
import {StraightLineEdgeLayer} from '../layers/edge-layers/straight-line-edge-layer';
import {PathEdgeLayer} from './edge-layers/path-edge-layer';
import {CurvedEdgeLayer} from './edge-layers/curved-edge-layer';
const EDGE_LAYER_MAP = {
'line': StraightLineEdgeLayer,
'path': PathEdgeLayer,
'spline-curve': CurvedEdgeLayer
};
export class EdgeLayer extends CompositeLayer {
static layerName = 'EdgeLayer';
static defaultProps = {
data: [],
pickable: true,
getLayoutInfo: (d) => ({
type: d.type,
sourcePosition: d.sourcePosition,
targetPosition: d.targetPosition,
controlPoints: []
}),
positionUpdateTrigger: 0
};
updateState({props, oldProps, changeFlags}) {
super.updateState({props, oldProps, changeFlags} as any);
if (changeFlags.dataChanged) {
this.updateStateData();
}
}
updateStateData() {
const {data, getLayoutInfo} = this.props as any;
// bucket edges by types
const typedEdgeData = data.reduce(
(res, d) => {
const {type} = getLayoutInfo(d);
res[type].push(d);
return res;
},
{
'line': [],
'path': [],
'spline-curve': []
}
);
this.setState({typedEdgeData});
}
renderLayers() {
const {getLayoutInfo, pickable, positionUpdateTrigger, stylesheet, id, transitions} =
this.props as any;
const {typedEdgeData} = this.state;
// render lines by types (straight line, path, curves)
return Object.entries(typedEdgeData).map((e, idx) => {
const [type, edgeData] = e;
const Layer = EDGE_LAYER_MAP[type];
// invalid edge layer type
if (!Layer) {
return null;
}
return new Layer(
this.getSubLayerProps({
id: `${id}-${idx}`,
data: edgeData,
getLayoutInfo,
getColor: stylesheet.getDeckGLAccessor('getColor'),
getWidth: stylesheet.getDeckGLAccessor('getWidth'),
colorUpdateTrigger: stylesheet.getDeckGLAccessorUpdateTrigger('getColor'),
widthUpdateTrigger: stylesheet.getDeckGLAccessorUpdateTrigger('getWidth'),
positionUpdateTrigger,
pickable,
transitions,
coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
parameters: {
depthCompare: 'always'
}
})
);
});
}
}