Scatter3DView.js
4.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
import * as echarts from 'echarts/lib/echarts';
import graphicGL from '../../util/graphicGL';
import retrieve from '../../util/retrieve';
import format from '../../util/format';
import PointsBuilder from '../common/PointsBuilder';
export default echarts.ChartView.extend({
type: 'scatter3D',
hasSymbolVisual: true,
__ecgl__: true,
init: function (ecModel, api) {
this.groupGL = new graphicGL.Node();
this._pointsBuilderList = [];
this._currentStep = 0;
},
render: function (seriesModel, ecModel, api) {
this.groupGL.removeAll();
if (!seriesModel.getData().count()) {
return;
}
var coordSys = seriesModel.coordinateSystem;
if (coordSys && coordSys.viewGL) {
coordSys.viewGL.add(this.groupGL);
this._camera = coordSys.viewGL.camera;
var pointsBuilder = this._pointsBuilderList[0];
if (!pointsBuilder) {
pointsBuilder = this._pointsBuilderList[0] = new PointsBuilder(false, api);
}
this._pointsBuilderList.length = 1;
this.groupGL.add(pointsBuilder.rootNode);
pointsBuilder.update(seriesModel, ecModel, api);
pointsBuilder.updateView(coordSys.viewGL.camera);
}
else {
if (process.env.NODE_ENV !== 'production') {
throw new Error('Invalid coordinate system');
}
}
},
incrementalPrepareRender: function (seriesModel, ecModel, api) {
var coordSys = seriesModel.coordinateSystem;
if (coordSys && coordSys.viewGL) {
coordSys.viewGL.add(this.groupGL);
this._camera = coordSys.viewGL.camera;
}
else {
if (process.env.NODE_ENV !== 'production') {
throw new Error('Invalid coordinate system');
}
}
this.groupGL.removeAll();
this._currentStep = 0;
},
incrementalRender: function (params, seriesModel, ecModel, api) {
// TODO Sort transparency.
if (params.end <= params.start) {
return;
}
var pointsBuilder = this._pointsBuilderList[this._currentStep];
if (!pointsBuilder) {
pointsBuilder = new PointsBuilder(false, api);
this._pointsBuilderList[this._currentStep] = pointsBuilder;
}
this.groupGL.add(pointsBuilder.rootNode);
pointsBuilder.update(seriesModel, ecModel, api, params.start, params.end);
pointsBuilder.updateView(seriesModel.coordinateSystem.viewGL.camera);
this._currentStep++;
},
updateCamera: function () {
this._pointsBuilderList.forEach(function (pointsBuilder) {
pointsBuilder.updateView(this._camera);
}, this);
},
highlight: function (seriesModel, ecModel, api, payload) {
this._toggleStatus('highlight', seriesModel, ecModel, api, payload);
},
downplay: function (seriesModel, ecModel, api, payload) {
this._toggleStatus('downplay', seriesModel, ecModel, api, payload);
},
_toggleStatus: function (status, seriesModel, ecModel, api, payload) {
var data = seriesModel.getData();
var dataIndex = retrieve.queryDataIndex(data, payload);
var isHighlight = status === 'highlight';
if (dataIndex != null) {
echarts.util.each(format.normalizeToArray(dataIndex), function (dataIdx) {
for (var i = 0; i < this._pointsBuilderList.length; i++) {
var pointsBuilder = this._pointsBuilderList[i];
isHighlight ? pointsBuilder.highlight(data, dataIdx) : pointsBuilder.downplay(data, dataIdx);
}
}, this);
}
else {
// PENDING, OPTIMIZE
data.each(function (dataIdx) {
for (var i = 0; i < this._pointsBuilderList.length; i++) {
var pointsBuilder = this._pointsBuilderList[i];
isHighlight ? pointsBuilder.highlight(data, dataIdx) : pointsBuilder.downplay(data, dataIdx);
}
});
}
},
dispose: function () {
this._pointsBuilderList.forEach(function (pointsBuilder) {
pointsBuilder.dispose();
});
this.groupGL.removeAll();
},
remove: function () {
this.groupGL.removeAll();
}
});