LinesGLSeries.js
6.3 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import * as echarts from 'echarts/lib/echarts';
import { concatArray } from 'zrender/lib/core/util';
var LinesGLSeries = echarts.SeriesModel.extend({
type: 'series.linesGL',
dependencies: ['grid', 'geo'],
visualStyleAccessPath: 'lineStyle',
visualDrawType: 'stroke',
streamEnabled: true,
init: function (option) {
var result = this._processFlatCoordsArray(option.data);
this._flatCoords = result.flatCoords;
this._flatCoordsOffset = result.flatCoordsOffset;
if (result.flatCoords) {
option.data = new Float32Array(result.count);
}
LinesGLSeries.superApply(this, 'init', arguments);
},
mergeOption: function (option) {
var result = this._processFlatCoordsArray(option.data);
this._flatCoords = result.flatCoords;
this._flatCoordsOffset = result.flatCoordsOffset;
if (result.flatCoords) {
option.data = new Float32Array(result.count);
}
LinesGLSeries.superApply(this, 'mergeOption', arguments);
},
appendData: function (params) {
var result = this._processFlatCoordsArray(params.data);
if (result.flatCoords) {
if (!this._flatCoords) {
this._flatCoords = result.flatCoords;
this._flatCoordsOffset = result.flatCoordsOffset;
}
else {
this._flatCoords = concatArray(this._flatCoords, result.flatCoords);
this._flatCoordsOffset = concatArray(this._flatCoordsOffset, result.flatCoordsOffset);
}
params.data = new Float32Array(result.count);
}
this.getRawData().appendData(params.data);
},
_getCoordsFromItemModel: function (idx) {
var itemModel = this.getData().getItemModel(idx);
var coords = (itemModel.option instanceof Array)
? itemModel.option : itemModel.getShallow('coords');
if (process.env.NODE_ENV !== 'production') {
if (!(coords instanceof Array && coords.length > 0 && coords[0] instanceof Array)) {
throw new Error('Invalid coords ' + JSON.stringify(coords) + '. Lines must have 2d coords array in data item.');
}
}
return coords;
},
getLineCoordsCount: function (idx) {
if (this._flatCoordsOffset) {
return this._flatCoordsOffset[idx * 2 + 1];
}
else {
return this._getCoordsFromItemModel(idx).length;
}
},
getLineCoords: function (idx, out) {
if (this._flatCoordsOffset) {
var offset = this._flatCoordsOffset[idx * 2];
var len = this._flatCoordsOffset[idx * 2 + 1];
for (var i = 0; i < len; i++) {
out[i] = out[i] || [];
out[i][0] = this._flatCoords[offset + i * 2];
out[i][1] = this._flatCoords[offset + i * 2 + 1];
}
return len;
}
else {
var coords = this._getCoordsFromItemModel(idx);
for (var i = 0; i < coords.length; i++) {
out[i] = out[i] || [];
out[i][0] = coords[i][0];
out[i][1] = coords[i][1];
}
return coords.length;
}
},
_processFlatCoordsArray: function (data) {
var startOffset = 0;
if (this._flatCoords) {
startOffset = this._flatCoords.length;
}
// Stored as a typed array. In format
// Points Count(2) | x | y | x | y | Points Count(3) | x | y | x | y | x | y |
if (typeof data[0] === 'number') {
var len = data.length;
// Store offset and len of each segment
var coordsOffsetAndLenStorage = new Uint32Array(len);
var coordsStorage = new Float64Array(len);
var coordsCursor = 0;
var offsetCursor = 0;
var dataCount = 0;
for (var i = 0; i < len;) {
dataCount++;
var count = data[i++];
// Offset
coordsOffsetAndLenStorage[offsetCursor++] = coordsCursor + startOffset;
// Len
coordsOffsetAndLenStorage[offsetCursor++] = count;
for (var k = 0; k < count; k++) {
var x = data[i++];
var y = data[i++];
coordsStorage[coordsCursor++] = x;
coordsStorage[coordsCursor++] = y;
if (i > len) {
if (process.env.NODE_ENV !== 'production') {
throw new Error('Invalid data format.');
}
}
}
}
return {
flatCoordsOffset: new Uint32Array(coordsOffsetAndLenStorage.buffer, 0, offsetCursor),
flatCoords: coordsStorage,
count: dataCount
};
}
return {
flatCoordsOffset: null,
flatCoords: null,
count: data.length
};
},
getInitialData: function (option, ecModel) {
var lineData = new echarts.List(['value'], this);
lineData.hasItemOption = false;
lineData.initData(option.data, [], function (dataItem, dimName, dataIndex, dimIndex) {
// dataItem is simply coords
if (dataItem instanceof Array) {
return NaN;
}
else {
lineData.hasItemOption = true;
var value = dataItem.value;
if (value != null) {
return value instanceof Array ? value[dimIndex] : value;
}
}
});
return lineData;
},
defaultOption: {
coordinateSystem: 'geo',
zlevel: 10,
progressive: 1e4,
progressiveThreshold: 5e4,
// Cartesian coordinate system
// xAxisIndex: 0,
// yAxisIndex: 0,
// Geo coordinate system
// geoIndex: 0,
// Support source-over, lighter
blendMode: 'source-over',
lineStyle: {
opacity: 0.8
},
postEffect: {
enable: false,
colorCorrection: {
exposure: 0,
brightness: 0,
contrast: 1,
saturation: 1,
enable: true
}
}
}
});
export default LinesGLSeries;