install.js
6.4 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// TODO ECharts GL must be imported whatever component,charts is imported.
import '../../echarts-gl';
import * as echarts from 'echarts/lib/echarts';
import GraphGLSeries from './GraphGLSeries';
import GraphGLView from './GraphGLView';
function normalize(a) {
if (!(a instanceof Array)) {
a = [a, a];
}
return a;
}
export function install(registers) {
registers.registerChartView(GraphGLView);
registers.registerSeriesModel(GraphGLSeries);
registers.registerVisual(function (ecModel) {
const paletteScope = {};
ecModel.eachSeriesByType('graphGL', function (seriesModel) {
var categoriesData = seriesModel.getCategoriesData();
var data = seriesModel.getData();
var categoryNameIdxMap = {};
categoriesData.each(function (idx) {
var name = categoriesData.getName(idx);
// Add prefix to avoid conflict with Object.prototype.
categoryNameIdxMap['ec-' + name] = idx;
var itemModel = categoriesData.getItemModel(idx);
var style = itemModel.getModel('itemStyle').getItemStyle();
if (!style.fill) {
// Get color from palette.
style.fill = seriesModel.getColorFromPalette(name, paletteScope);
}
categoriesData.setItemVisual(idx, 'style', style);
var symbolVisualList = ['symbol', 'symbolSize', 'symbolKeepAspect'];
for (let i = 0; i < symbolVisualList.length; i++) {
var symbolVisual = itemModel.getShallow(symbolVisualList[i], true);
if (symbolVisual != null) {
categoriesData.setItemVisual(idx, symbolVisualList[i], symbolVisual);
}
}
});
// Assign category color to visual
if (categoriesData.count()) {
data.each(function (idx) {
var model = data.getItemModel(idx);
let categoryIdx = model.getShallow('category');
if (categoryIdx != null) {
if (typeof categoryIdx === 'string') {
categoryIdx = categoryNameIdxMap['ec-' + categoryIdx];
}
var categoryStyle = categoriesData.getItemVisual(categoryIdx, 'style');
var style = data.ensureUniqueItemVisual(idx, 'style');
echarts.util.extend(style, categoryStyle);
var visualList = ['symbol', 'symbolSize', 'symbolKeepAspect'];
for (let i = 0; i < visualList.length; i++) {
data.setItemVisual(
idx, visualList[i],
categoriesData.getItemVisual(categoryIdx, visualList[i])
);
}
}
});
}
});
});
registers.registerVisual(function (ecModel) {
ecModel.eachSeriesByType('graphGL', function (seriesModel) {
var graph = seriesModel.getGraph();
var edgeData = seriesModel.getEdgeData();
var symbolType = normalize(seriesModel.get('edgeSymbol'));
var symbolSize = normalize(seriesModel.get('edgeSymbolSize'));
edgeData.setVisual('drawType', 'stroke');
// var colorQuery = ['lineStyle', 'color'];
// var opacityQuery = ['lineStyle', 'opacity'];
edgeData.setVisual('fromSymbol', symbolType && symbolType[0]);
edgeData.setVisual('toSymbol', symbolType && symbolType[1]);
edgeData.setVisual('fromSymbolSize', symbolSize && symbolSize[0]);
edgeData.setVisual('toSymbolSize', symbolSize && symbolSize[1]);
edgeData.setVisual('style', seriesModel.getModel('lineStyle').getLineStyle());
edgeData.each(function (idx) {
var itemModel = edgeData.getItemModel(idx);
var edge = graph.getEdgeByIndex(idx);
var symbolType = normalize(itemModel.getShallow('symbol', true));
var symbolSize = normalize(itemModel.getShallow('symbolSize', true));
// Edge visual must after node visual
var style = itemModel.getModel('lineStyle').getLineStyle();
var existsStyle = edgeData.ensureUniqueItemVisual(idx, 'style');
echarts.util.extend(existsStyle, style);
switch (existsStyle.stroke) {
case 'source': {
var nodeStyle = edge.node1.getVisual('style');
existsStyle.stroke = nodeStyle && nodeStyle.fill;
break;
}
case 'target': {
var nodeStyle = edge.node2.getVisual('style');
existsStyle.stroke = nodeStyle && nodeStyle.fill;
break;
}
}
symbolType[0] && edge.setVisual('fromSymbol', symbolType[0]);
symbolType[1] && edge.setVisual('toSymbol', symbolType[1]);
symbolSize[0] && edge.setVisual('fromSymbolSize', symbolSize[0]);
symbolSize[1] && edge.setVisual('toSymbolSize', symbolSize[1]);
});
});
});
registers.registerAction({
type: 'graphGLRoam',
event: 'graphglroam',
update: 'series.graphGL:roam'
}, function (payload, ecModel) {
ecModel.eachComponent({
mainType: 'series', query: payload
}, function (componentModel) {
componentModel.setView(payload);
});
});
function noop() {}
registers.registerAction({
type: 'graphGLStartLayout',
event: 'graphgllayoutstarted',
update: 'series.graphGL:startLayout'
}, noop);
registers.registerAction({
type: 'graphGLStopLayout',
event: 'graphgllayoutstopped',
update: 'series.graphGL:stopLayout'
}, noop);
registers.registerAction({
type: 'graphGLFocusNodeAdjacency',
event: 'graphGLFocusNodeAdjacency',
update: 'series.graphGL:focusNodeAdjacency'
}, noop);
registers.registerAction({
type: 'graphGLUnfocusNodeAdjacency',
event: 'graphGLUnfocusNodeAdjacency',
update: 'series.graphGL:unfocusNodeAdjacency'
}, noop);
}