ScatterGLView.js
3.5 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
import * as echarts from 'echarts/lib/echarts';
import graphicGL from '../../util/graphicGL';
import ViewGL from '../../core/ViewGL';
import PointsBuilder from '../common/PointsBuilder';
import GLViewHelper from '../common/GLViewHelper';
export default echarts.ChartView.extend({
type: 'scatterGL',
__ecgl__: true,
init: function (ecModel, api) {
this.groupGL = new graphicGL.Node();
this.viewGL = new ViewGL('orthographic');
this.viewGL.add(this.groupGL);
this._pointsBuilderList = [];
this._currentStep = 0;
this._sizeScale = 1;
this._glViewHelper = new GLViewHelper(this.viewGL);
},
render: function (seriesModel, ecModel, api) {
this.groupGL.removeAll();
this._glViewHelper.reset(seriesModel, api);
if (!seriesModel.getData().count()) {
return;
}
var pointsBuilder = this._pointsBuilderList[0];
if (!pointsBuilder) {
pointsBuilder = this._pointsBuilderList[0] = new PointsBuilder(true, api);
}
this._pointsBuilderList.length = 1;
this.groupGL.add(pointsBuilder.rootNode);
this._removeTransformInPoints(seriesModel.getData().getLayout('points'));
pointsBuilder.update(seriesModel, ecModel, api);
this.viewGL.setPostEffect(seriesModel.getModel('postEffect'), api);
},
incrementalPrepareRender: function (seriesModel, ecModel, api) {
this.groupGL.removeAll();
this._glViewHelper.reset(seriesModel, api);
this._currentStep = 0;
this.viewGL.setPostEffect(seriesModel.getModel('postEffect'), api);
},
incrementalRender: function (params, seriesModel, ecModel, api) {
if (params.end <= params.start) {
return;
}
var pointsBuilder = this._pointsBuilderList[this._currentStep];
if (!pointsBuilder) {
pointsBuilder = new PointsBuilder(true, api);
this._pointsBuilderList[this._currentStep] = pointsBuilder;
}
this.groupGL.add(pointsBuilder.rootNode);
this._removeTransformInPoints(seriesModel.getData().getLayout('points'));
pointsBuilder.setSizeScale(this._sizeScale);
pointsBuilder.update(seriesModel, ecModel, api, params.start, params.end);
api.getZr().refresh();
this._currentStep++;
},
updateTransform: function (seriesModel, ecModel, api) {
if (seriesModel.coordinateSystem.getRoamTransform) {
this._glViewHelper.updateTransform(seriesModel, api);
var zoom = this._glViewHelper.getZoom();
var sizeScale = Math.max((seriesModel.get('zoomScale') || 0) * (zoom - 1) + 1, 0);
this._sizeScale = sizeScale;
this._pointsBuilderList.forEach(function (pointsBuilder) {
pointsBuilder.setSizeScale(sizeScale);
});
}
},
_removeTransformInPoints: function (points) {
if (!points) {
return;
}
var pt = [];
for (var i = 0; i < points.length; i += 2) {
pt[0] = points[i];
pt[1] = points[i + 1];
this._glViewHelper.removeTransformInPoint(pt);
points[i] = pt[0];
points[i + 1] = pt[1];
}
},
dispose: function () {
this.groupGL.removeAll();
this._pointsBuilderList.forEach(function (pointsBuilder) {
pointsBuilder.dispose();
});
},
remove: function () {
this.groupGL.removeAll();
}
});